From 32d5deba53fe83f4d06fbeb45cc276bc7453a10b Mon Sep 17 00:00:00 2001 From: Dan Graham Date: Thu, 10 Jan 2019 08:35:05 -0800 Subject: [PATCH] Shrinkwrap fixes (#11969) * Reinstall node modules before shrinkwrapping * Add script to check shrinkwrap will be packaged --- check-npm-pack-files.js | 21 +++++++++++++++++++ .../developers-overview.md | 2 +- package.json | 5 +++-- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 check-npm-pack-files.js diff --git a/check-npm-pack-files.js b/check-npm-pack-files.js new file mode 100644 index 00000000000..319fb7d8fb7 --- /dev/null +++ b/check-npm-pack-files.js @@ -0,0 +1,21 @@ +const childProcess = require('child_process'); +const _ = require('lodash'); + +const res = JSON.parse(childProcess.execSync('npm pack --dry-run --json --ignore-scripts', {encoding: 'utf8'}))[0]; + +// List of files we are testing to make sure they are included in package +const testFiles = [ + 'npm-shrinkwrap.json', // Check that npm-shrinkwrap.json is being packed + 'LICENSE', // Check that license is included + 'build/lib/appium.js', // Sanity check that build files are being included by testing just one file +]; + +// Get list of files in `testFiles` that aren't in the list of packaged fileNames +const missingFiles = _.without(testFiles, ..._.map(res.files, 'path')); + +if (!_.isEmpty(missingFiles)) { + throw new Error(`Files [${missingFiles.join(', ')}] are not included in package.json "files". ` + + `Please make sure these files are included before publishing.`); +} + +process.exit(0); diff --git a/docs/en/contributing-to-appium/developers-overview.md b/docs/en/contributing-to-appium/developers-overview.md index 302ff708534..50575208583 100644 --- a/docs/en/contributing-to-appium/developers-overview.md +++ b/docs/en/contributing-to-appium/developers-overview.md @@ -195,7 +195,7 @@ converted into the `npm-shrinkwrap.json` file. 1. Determine whether we have a `patch` (bugfix), `minor` (feature), or `major` (breaking) release according to the principles of SemVer. 1. Update `package.json` with the appropriate new version. 1. Update the CHANGELOG/README with appropriate changes and submit for review as a PR, along with shrinkwrap and `package.json` changes. Wait for it to be merged, then pull it into the release branch. -1. Run `npm run shrinkwrap-prod`. This script prunes dev dependencies (leaving only production dependencies), creates a production-only `npm-shrinkwrap.json` and then re-installs the dev dependencies by doing `npm install --no-shrinkwrap`. +1. Run `npm run shrinkwrap:prod`. This script removes `node_modules`, installs node production dependencies, creates `npm-shrinkwrap.json` (which only shrinkwrap prod dependencies) and then re-installs the dev dependencies by doing `npm install --no-shrinkwrap`. 1. Create a tag of the form `v` on the release branch (usually a minor branch like `1.5` or `1.4`), with: `git tag -a v`, e.g., `git tag -a v1.5.0`. This is not necessary for beta versions. 1. Push the tag to upstream: `git push --tags ` 1. Run `npm publish` (with `--tag beta` if this isn't an official release). diff --git a/package.json b/package.json index 427f48e048c..1a4df507d1c 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "files": [ "bin", "lib", - "build/lib" + "build/lib", + "npm-shrinkwrap.json" ], "dependencies": { "@babel/runtime": "^7.0.0", @@ -85,7 +86,7 @@ "lint:fix": "gulp eslint --fix", "coverage": "gulp coveralls", "generate-docs": "node ./build/commands-yml/parse.js", - "shrinkwrap-prod": "rimraf package-lock.json && npm prune --production && npm shrinkwrap && npm install --no-shrinkwrap", + "shrinkwrap:prod": "rimraf package-lock.json && rimraf node_modules && npm install --production && npm shrinkwrap && node ./check-npm-pack-files && npm install --no-shrinkwrap", "zip": "zip -qr appium.zip .", "upload": "gulp github-upload", "zip-and-upload": "npm run zip && npm run upload"