etcher/scripts/shrinkwrap.js
Juan Cruz Viotti 588c510778 chore(shrinkwrap): omit platform-specific deps (#503)
If you run an `npm install` and then run `npm shrinkwrap`, the resulting
shrinkwrap file will contain the installed optional dependencies, making
them "required". If such optional dependency is platform dependent, `npm
install` will fail on different platform.

This is a known `shrinkwrap` limitation whose only workaround seems to
be manually filtering out platform specific dependencies from
`npm-shrinkwrap.json`.

For this purpose, we introduced the following changes:

- A custom `shrinkwrapIgnore` property in `package.json`, where we can
list specific modules that need to be filtered out from
`npm-shrinkwrap.json`.

- A NodeJS script to generate `npm-shrinkwrap.json` and omit modules
specified in `shrinkwrapIgnore` automatically.

- An NPM script called `shrinkwrap`, for convenience.

- Add `macos-alias` and `fs-xattr` to `shrinkwrapIgnore`.

- Regenerate `npm-shrinkwrap.json` based on newer dependencies from PRs
created before we introduced `npm-shrinkwrap.json` but merged after that
file was in place.

See: https://github.com/npm/npm/issues/2679
Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
2016-06-21 15:21:08 -04:00

37 lines
1.3 KiB
JavaScript

/**
* This script is in charge of generating the `shrinkwrap` file.
*
* `npm shrinkwrap` has a bug where it will add optional dependencies
* to `npm-shrinkwrap.json`, therefore causing errors if these optional
* dependendencies are platform dependent and you then try to build
* the project in another platform.
*
* As a workaround, we keep a list of platform dependent dependencies in
* the `shrinkwrapIgnore` property of `package.json`, and manually remove
* them from `npm-shrinkwrap.json` if they exists.
*
* See: https://github.com/npm/npm/issues/2679
*/
const _ = require('lodash');
const path = require('path');
const jsonfile = require('jsonfile');
const child_process = require('child_process');
const shrinkwrapIgnore = require('../package.json').shrinkwrapIgnore;
const SHRINKWRAP_PATH = path.join(__dirname, '..', 'npm-shrinkwrap.json');
try {
console.log(child_process.execSync('npm shrinkwrap', {
cwd: path.dirname(SHRINKWRAP_PATH)
}));
} catch (error) {
console.error(error.stderr.toString());
process.exit(1);
}
const shrinkwrapContents = jsonfile.readFileSync(SHRINKWRAP_PATH);
shrinkwrapContents.dependencies = _.omit(shrinkwrapContents.dependencies, shrinkwrapIgnore);
jsonfile.writeFileSync(SHRINKWRAP_PATH, shrinkwrapContents, {
spaces: 2
});