diff --git a/.aoeu/package.json b/.aoeu/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/.aoeu/package.json @@ -0,0 +1 @@ +{} diff --git a/lib/fs/obliterate.js b/lib/fs/obliterate.js index 93478cd2f5..57fb4bad62 100644 --- a/lib/fs/obliterate.js +++ b/lib/fs/obliterate.js @@ -18,6 +18,6 @@ module.exports = function obliterate (path) { } }) .catch(err => { - if (err !== 'ENOENT') throw err + if (err.code !== 'ENOENT') throw err }) } diff --git a/lib/install/post_install.js b/lib/install/post_install.js index 2296103656..05757aa8ad 100644 --- a/lib/install/post_install.js +++ b/lib/install/post_install.js @@ -4,16 +4,39 @@ var spawn = require('child_process').spawn var debug = require('debug')('pnpm:post_install') var delimiter = require('path').delimiter var byline = require('byline') +var fs = require('mz/fs') module.exports = function postInstall (root, pkg, log) { debug('postinstall', pkg) var scripts = pkg && pkg.scripts || {} return Promise.resolve() + .then(_ => !scripts.install && checkBindingGyp(root, log)) .then(_ => runScript(root, scripts.preinstall, log)) .then(_ => runScript(root, scripts.install, log)) .then(_ => runScript(root, scripts.postinstall, log)) } +/* + * Run node-gyp when binding.gyp is available. Only do this when there's no + * `install` script (see `npm help scripts`). + */ + +function checkBindingGyp (root, log) { + return fs.stat(join(root, 'binding.gyp')) + .then(_ => runScript(root, 'node ' + nodeGypBin() + ' rebuild', log)) + .catch(err => { + if (err.code !== 'ENOENT') throw err + }) +} + +/* + * Returns the bin for node-gyp + */ + +function nodeGypBin () { + return JSON.stringify(require.resolve('node-gyp/bin/node-gyp')) +} + /* * Runs an npm script. */ diff --git a/package.json b/package.json index ac48323a8d..db64818e92 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "meow": "3.7.0", "mkdirp": "0.5.1", "mz": "2.2.0", + "node-gyp": "3.2.1", "node-uuid": "1.4.7", "npm-package-arg": "4.1.0", "object-assign": "4.0.1", diff --git a/test/index.js b/test/index.js index 9a06bc0645..10e388da8a 100644 --- a/test/index.js +++ b/test/index.js @@ -105,12 +105,17 @@ test('bundleDependencies (fsevents@1.0.6)', function (t) { }, t.end) }) -test('compiled modules (fsevents@1.0.6)', function (t) { +test('compiled modules (ursa@0.9.1)', function (t) { + if (!process.env.CI) { + t.skip('only ran on CI') + return t.end() + } + prepare() - install({ input: ['fsevents@1.0.6'], flags: { quiet: true } }) + install({ input: ['ursa@0.9.1'], flags: { quiet: true } }) .then(function () { - var fsevents = require(join(process.cwd(), 'node_modules', 'fsevents')) - t.ok(typeof fsevents === 'function', 'fsevents() is available') + var ursa = require(join(process.cwd(), 'node_modules', 'ursa')) + t.ok(typeof ursa === 'object', 'ursa() is available') t.end() }, t.end) })