Skip to content

Commit

Permalink
Add clean-shrinkwrap script to postshrinkwrap step
Browse files Browse the repository at this point in the history
Change-type: patch
Changelog-entry: Add clean-shrinkwrap script to postshrinkwrap step
Signed-off-by: Lorenzo Alberto Maria Ambrosi <[email protected]>
  • Loading branch information
Lorenzo Alberto Maria Ambrosi committed May 14, 2019
1 parent b65526d commit aa52735
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ rules:
- always
prefer-const:
- error
prefer-reflect:
- error
prefer-spread:
- error
prefer-numeric-literals:
Expand Down
11 changes: 10 additions & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -32,6 +33,10 @@
},
"author": "Balena Inc. <[email protected]>",
"license": "Apache-2.0",
"platformSpecificDependencies": [
"fsevents",
"winusb-driver-generator"
],
"dependencies": {
"@fortawesome/fontawesome-free-webfonts": "^1.0.9",
"angular": "1.7.6",
Expand Down Expand Up @@ -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",
Expand Down
37 changes: 37 additions & 0 deletions scripts/clean-shrinkwrap.js
Original file line number Diff line number Diff line change
@@ -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)}`)
}
})

0 comments on commit aa52735

Please sign in to comment.