mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-22 18:56:31 +00:00
chore(package): Make clean-shrinkwrap remove optional dependencies (#1236)
Previously dependencies weren't actually removed from `node_modules`, this runs `npm rm` on the optional dependencies, effectively excluding them, and their dependencies from the shrinkwrap file. Also the script has been hooked to the `preshrinkwrap` hook, to remove the need of having to run it manually. Change-Type: patch
This commit is contained in:
parent
8fff29224d
commit
d5ec71c5da
@ -44,10 +44,6 @@ Use the following steps to ensure everything goes flawlessly:
|
||||
- Install the new version of the dependency. For example: `npm install --save
|
||||
<package>@<version>`. This will update the `npm-shrinkwrap.json` file.
|
||||
|
||||
- Run `npm run clean-shrinkwrap`. This is a small script that ensures that
|
||||
operating system specific dependencies that could get included in the
|
||||
previous step are removed from `npm-shrinkwrap.json`.
|
||||
|
||||
- Commit *both* `package.json` and `npm-shrinkwrap.json`.
|
||||
|
||||
Testing
|
||||
|
@ -20,7 +20,7 @@
|
||||
"lint": "npm run jslint && npm run sasslint && npm run codespell && npm run htmllint",
|
||||
"changelog": "versionist",
|
||||
"start": "electron lib/start.js",
|
||||
"clean-shrinkwrap": "node ./scripts/clean-shrinkwrap.js"
|
||||
"preshrinkwrap": "node ./scripts/clean-shrinkwrap.js"
|
||||
},
|
||||
"author": "Juan Cruz Viotti <juan@resin.io>",
|
||||
"license": "Apache-2.0",
|
||||
@ -115,7 +115,6 @@
|
||||
"eslint-plugin-lodash": "^2.3.5",
|
||||
"file-exists": "^1.0.0",
|
||||
"html-angular-validate": "^0.1.9",
|
||||
"jsonfile": "^2.3.1",
|
||||
"mochainon": "^1.0.0",
|
||||
"node-sass": "^3.8.0",
|
||||
"sass-lint": "^1.10.2",
|
||||
|
@ -17,13 +17,28 @@
|
||||
|
||||
const _ = require('lodash');
|
||||
const path = require('path');
|
||||
const jsonfile = require('jsonfile');
|
||||
const packageJSON = require('../package.json');
|
||||
const spawn = require('child_process').spawn;
|
||||
const shrinkwrapIgnore = _.union(packageJSON.shrinkwrapIgnore, _.keys(packageJSON.optionalDependencies));
|
||||
const SHRINKWRAP_PATH = path.join(__dirname, '..', 'npm-shrinkwrap.json');
|
||||
|
||||
const shrinkwrapContents = jsonfile.readFileSync(SHRINKWRAP_PATH);
|
||||
shrinkwrapContents.dependencies = _.omit(shrinkwrapContents.dependencies, shrinkwrapIgnore);
|
||||
jsonfile.writeFileSync(SHRINKWRAP_PATH, shrinkwrapContents, {
|
||||
spaces: 2
|
||||
});
|
||||
console.log('Removing:', shrinkwrapIgnore.join(', '));
|
||||
|
||||
/**
|
||||
* Run an npm command
|
||||
* @param {Array} command - list of arguments
|
||||
* @returns {ChildProcess}
|
||||
*/
|
||||
const npm = (command) => {
|
||||
return spawn('npm', command, {
|
||||
cwd: path.join(__dirname, '..'),
|
||||
env: process.env,
|
||||
stdio: [ process.stdin, process.stdout, process.stderr ]
|
||||
});
|
||||
};
|
||||
|
||||
npm([ 'rm', '--ignore-scripts' ].concat(shrinkwrapIgnore))
|
||||
.once('close', () => {
|
||||
npm([ 'prune' ]).once('close', () => {
|
||||
console.log('Done.');
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user