From 29cf08d5ffca7d6a1f41532751ba24590b11a08c Mon Sep 17 00:00:00 2001 From: Jake Jarvis Date: Tue, 16 Jun 2020 11:52:33 -0400 Subject: [PATCH] add very basic linting & expand CI tests to Node >=10 --- .github/workflows/ci.yml | 15 ++++++++++++--- .gitignore | 6 +++++- .npmrc | 1 + example/package.json | 2 +- index.js | 21 ++++++++++++--------- package.json | 28 ++++++++++++++++++++++++---- 6 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 .npmrc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee8eef3..9cb39ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,14 +4,23 @@ on: [push, pull_request] jobs: build: + strategy: + matrix: + node: [14.x, 13.x, 12.x, 10.x] + fail-fast: false runs-on: ubuntu-latest + name: Node ${{ matrix.node }} steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: '12' - - run: npm install -g netlify-cli - - run: netlify build + node-version: ${{ matrix.node }} + - name: Install dependencies + run: npm install --no-package-lock --no-optional + - name: Run tests + run: npm run test + - name: Build example site locally with plugin + run: npm run build env: NETLIFY_SITE_ID: '8ceb6251-650b-481a-976c-fec1a4f95800' NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} diff --git a/.gitignore b/.gitignore index a013cf3..96defac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ # Local Netlify folder -.netlify \ No newline at end of file +.netlify + +node_modules/ +package-lock.json +npm-debug.log* diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/example/package.json b/example/package.json index ab35b35..e5e88a6 100644 --- a/example/package.json +++ b/example/package.json @@ -4,7 +4,7 @@ "version": "1.0.0", "description": "Just a test of netlify-plugin-cache.", "dependencies": { - "netlify-plugin-cache": "*", + "netlify-plugin-cache": "file:../", "netlify-plugin-debug-cache": "^1.0.3" } } diff --git a/index.js b/index.js index 0b88e78..437e0d9 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,11 @@ +// Netlify Plugin: netlify-plugin-cache +// https://github.com/jakejarvis/netlify-plugin-cache +// +// This plugin is essentially a wrapper around Netlify's native `cache-utils`: // https://github.com/netlify/build/blob/master/packages/cache-utils/README.md module.exports = { - // try to restore cache before build begins, if it exists + // Try to restore cache before build begins, if it exists onPreBuild: async ({ utils: { cache }, inputs }) => { if (await cache.restore(inputs.paths)) { const files = await cache.list(inputs.paths) @@ -11,24 +15,23 @@ module.exports = { } }, - // only save/update cache if build was successful + // Only save/update cache if build was successful onSuccess: async ({ utils: { cache, status }, inputs }) => { if (await cache.save(inputs.paths)) { const files = await cache.list(inputs.paths) console.log(`Successfully cached: ${inputs.paths.join(', ')} ... ${files.length} files in total.`) - // show success & more detail in deploy summary + // Show success & more detail in deploy summary status.show({ title: `${files.length} files cached`, summary: 'These will be restored on the next build! ⚡', - text: `${inputs.paths.join(', ')}`, + text: `${inputs.paths.join(', ')}` }) } else { - // this probably happened because the default `paths` is set, so provide instructions to fix + // This probably happened because the default `paths` is set, so provide instructions to fix console.log(`Attempted to cache: ${inputs.paths.join(', ')} ... but failed. :(`) - console.log(`Try setting the 'paths' input appropriately in your netlify.toml configuration.`) - console.log(`More details: https://jrvs.io/netlify-cache-usage`) + console.log('Try setting the \'paths\' input appropriately in your netlify.toml configuration.') + console.log('More details: https://jrvs.io/netlify-cache-usage') } - }, + } } - \ No newline at end of file diff --git a/package.json b/package.json index 18fb20b..bd712a8 100644 --- a/package.json +++ b/package.json @@ -2,17 +2,30 @@ "name": "netlify-plugin-cache", "version": "1.0.3", "description": "Generic cache plugin for saving and restoring files and/or folders between Netlify builds", - "author": "Jake Jarvis ", "license": "MIT", - "main": "index.js", + "author": { + "name": "Jake Jarvis", + "email": "jake@jarv.is", + "url": "http://jarv.is/" + }, "homepage": "https://github.com/jakejarvis/netlify-plugin-cache#readme", "bugs": "https://github.com/jakejarvis/netlify-plugin-cache/issues", "repository": { "type": "git", "url": "git+https://github.com/jakejarvis/netlify-plugin-cache.git" }, + "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "netlify build", + "test": "xo" + }, + "dependencies": {}, + "devDependencies": { + "netlify-cli": "*", + "xo": "~0.32.0" + }, + "engines": { + "node": ">=10.18" }, "keywords": [ "netlify", @@ -21,5 +34,12 @@ "ci", "build", "plugin" - ] + ], + "xo": { + "semicolon": false, + "space": 2, + "rules": { + "object-curly-spacing": 0 + } + } }