From aa527350067e3dc7460f8b5f893a755d4b8f8380 Mon Sep 17 00:00:00 2001 From: Lorenzo Alberto Maria Ambrosi Date: Mon, 6 May 2019 17:36:12 +0200 Subject: [PATCH] Add clean-shrinkwrap script to postshrinkwrap step Change-type: patch Changelog-entry: Add clean-shrinkwrap script to postshrinkwrap step Signed-off-by: Lorenzo Alberto Maria Ambrosi --- .eslintrc.yml | 2 -- npm-shrinkwrap.json | 11 ++++++++++- package.json | 6 ++++++ scripts/clean-shrinkwrap.js | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 scripts/clean-shrinkwrap.js diff --git a/.eslintrc.yml b/.eslintrc.yml index 99f5c1ea..78348ee5 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -318,8 +318,6 @@ rules: - always prefer-const: - error - prefer-reflect: - - error prefer-spread: - error prefer-numeric-literals: diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index f805c43c..fc148023 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -8844,6 +8844,15 @@ "isobject": "^3.0.1" } }, + "omit-deep-lodash": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/omit-deep-lodash/-/omit-deep-lodash-1.1.4.tgz", + "integrity": "sha512-5ge7dBDVDYEU8YiqYlKxjsVesB3wqXejgluGx+9Xd8+PJH7VEEK9D4Pqpq7VE0ZtQh9HBz0LMNRk1BA3+bsd4Q==", + "dev": true, + "requires": { + "lodash": "~4.17.11" + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -13952,4 +13961,4 @@ } } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 0d622ceb..317cb76b 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "scripts": { "test": "make lint test sanity-checks", "start": "./node_modules/.bin/electron .", + "postshrinkwrap": "node ./scripts/clean-shrinkwrap.js", "configure": "node-gyp configure", "build": "node-gyp build", "install": "node-gyp rebuild", @@ -32,6 +33,10 @@ }, "author": "Balena Inc. ", "license": "Apache-2.0", + "platformSpecificDependencies": [ + "fsevents", + "winusb-driver-generator" + ], "dependencies": { "@fortawesome/fontawesome-free-webfonts": "^1.0.9", "angular": "1.7.6", @@ -104,6 +109,7 @@ "nock": "^9.2.3", "node-gyp": "^3.8.0", "node-sass": "^4.7.2", + "omit-deep-lodash": "1.1.4", "pkg": "^4.3.0", "sass-lint": "^1.12.1", "simple-progress-webpack-plugin": "^1.1.2", diff --git a/scripts/clean-shrinkwrap.js b/scripts/clean-shrinkwrap.js new file mode 100644 index 00000000..66e985c1 --- /dev/null +++ b/scripts/clean-shrinkwrap.js @@ -0,0 +1,37 @@ +/** + * This script is in charge of cleaning 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 `platformSpecificDependencies` property of `package.json`, + * and manually remove them from `npm-shrinkwrap.json` if they exist. + * + * See: https://github.com/npm/npm/issues/2679 + */ + +'use strict' + +const fs = require('fs') +const path = require('path') +const omit = require('omit-deep-lodash') + +const JSON_INDENT = 2 +const SHRINKWRAP_FILENAME = path.join(__dirname, '..', 'npm-shrinkwrap.json') + +const packageInfo = require('../package.json') +const shrinkwrap = require('../npm-shrinkwrap.json') + +const cleaned = omit(shrinkwrap, packageInfo.platformSpecificDependencies) + +fs.writeFile(SHRINKWRAP_FILENAME, JSON.stringify(cleaned, null, JSON_INDENT), (error) => { + if (error) { + console.log(`[ERROR] Couldn't write shrinkwrap file: ${error.stack}`) + process.exitCode = 1 + } else { + console.log(`[OK] Wrote shrinkwrap file to ${path.relative(__dirname, SHRINKWRAP_FILENAME)}`) + } +})