etcher/scripts/shrinkwrap.js
Juan Cruz Viotti 82cb7ab689 upgrade: removedrive to v1.0.0 (#611)
This version contains the following improvements:

- https://github.com/jviotti/removedrive/pull/3
- https://github.com/jviotti/removedrive/pull/2

We also make sure error descriptions are passed to the dialog service
since this module now sets that property in its error objects.

Change-Type: patch
Changelog-Entry: Upgrade `removedrive` to v1.0.0.
Link: https://github.com/jviotti/removedrive/blob/master/CHANGELOG.md
See: https://github.com/resin-io/etcher/issues/573
Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
2016-07-28 15:53:47 -04:00

40 lines
1.4 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
*/
'use strict';
const _ = require('lodash');
const path = require('path');
const jsonfile = require('jsonfile');
const childProcess = require('child_process');
const packageJSON = require('../package.json');
const shrinkwrapIgnore = _.union(packageJSON.shrinkwrapIgnore, _.keys(packageJSON.optionalDependencies));
const SHRINKWRAP_PATH = path.join(__dirname, '..', 'npm-shrinkwrap.json');
try {
console.log(childProcess.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
});