Skip to content

Commit c912a9d

Browse files
committed
fix(lifecycle): platform check for default install scripts
This is a continuation of zkat#45, a side-effect of the provided fix for it in zkat#46 and was introduced in `cipm@1.6.2`. For the case where a default `install` script is used and a `binding.gyp` file is present in the package root, `npm ci` will fail with packages that target a different platform that the one currently running. Fixes zkat#49
1 parent 112565f commit c912a9d

4 files changed

Lines changed: 1134 additions & 1108 deletions

File tree

index.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const npa = require('npm-package-arg')
1414
const path = require('path')
1515
const readPkgJson = BB.promisify(require('read-package-json'))
1616
const rimraf = BB.promisify(require('rimraf'))
17+
const checkPlatform = BB.promisify(require('npm-install-checks').checkPlatform)
1718

1819
const readFileAsync = BB.promisify(fs.readFile)
1920
const statAsync = BB.promisify(fs.stat)
@@ -317,17 +318,21 @@ class Installer {
317318

318319
updateInstallScript (dep, pkg) {
319320
const depPath = dep.path(this.prefix)
320-
return statAsync(path.join(depPath, 'binding.gyp'))
321-
.catch(err => { if (err.code !== 'ENOENT') { throw err } })
322-
.then(stat => {
323-
if (stat) {
324-
if (!pkg.scripts) {
325-
pkg.scripts = {}
326-
}
327-
pkg.scripts.install = 'node-gyp rebuild'
328-
}
321+
return checkPlatform(pkg, this.config.get('force'))
322+
.then(() => {
323+
return statAsync(path.join(depPath, 'binding.gyp'))
324+
.catch(err => { if (err.code !== 'ENOENT') { throw err } })
325+
.then(stat => {
326+
if (stat) {
327+
if (!pkg.scripts) {
328+
pkg.scripts = {}
329+
}
330+
pkg.scripts.install = 'node-gyp rebuild'
331+
}
332+
})
333+
.then(pkg)
329334
})
330-
.then(pkg)
335+
.catch(() => 'ignore')
331336
}
332337

333338
// A cute little mark-and-sweep collector!

0 commit comments

Comments
 (0)