Skip to content

Commit

Permalink
fix(lifecycle): platform check for default install scripts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
reyronald committed May 11, 2018
1 parent 112565f commit c912a9d
Show file tree
Hide file tree
Showing 4 changed files with 1,134 additions and 1,108 deletions.
25 changes: 15 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const npa = require('npm-package-arg')
const path = require('path')
const readPkgJson = BB.promisify(require('read-package-json'))
const rimraf = BB.promisify(require('rimraf'))
const checkPlatform = BB.promisify(require('npm-install-checks').checkPlatform)

const readFileAsync = BB.promisify(fs.readFile)
const statAsync = BB.promisify(fs.stat)
Expand Down Expand Up @@ -317,17 +318,21 @@ class Installer {

updateInstallScript (dep, pkg) {
const depPath = dep.path(this.prefix)
return statAsync(path.join(depPath, 'binding.gyp'))
.catch(err => { if (err.code !== 'ENOENT') { throw err } })
.then(stat => {
if (stat) {
if (!pkg.scripts) {
pkg.scripts = {}
}
pkg.scripts.install = 'node-gyp rebuild'
}
return checkPlatform(pkg, this.config.get('force'))
.then(() => {
return statAsync(path.join(depPath, 'binding.gyp'))
.catch(err => { if (err.code !== 'ENOENT') { throw err } })
.then(stat => {
if (stat) {
if (!pkg.scripts) {
pkg.scripts = {}
}
pkg.scripts.install = 'node-gyp rebuild'
}
})
.then(pkg)
})
.then(pkg)
.catch(() => 'ignore')
}

// A cute little mark-and-sweep collector!
Expand Down
Loading

0 comments on commit c912a9d

Please sign in to comment.