From c9789cf5ee0a3736d28ae95e30374ca9ba157800 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Sat, 30 Jan 2016 05:24:26 +0800 Subject: [PATCH 1/3] Add node-gyp support --- lib/fs/obliterate.js | 2 +- lib/install/post_install.js | 14 ++++++++++++++ package.json | 1 + test/index.js | 8 ++++---- 4 files changed, 20 insertions(+), 5 deletions(-) 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..405d1600c4 100644 --- a/lib/install/post_install.js +++ b/lib/install/post_install.js @@ -4,16 +4,30 @@ 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(_ => checkBindingGyp(root, log)) .then(_ => runScript(root, scripts.preinstall, log)) .then(_ => runScript(root, scripts.install, log)) .then(_ => runScript(root, scripts.postinstall, log)) } +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 + }) +} + +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..2e1584df18 100644 --- a/test/index.js +++ b/test/index.js @@ -105,12 +105,12 @@ 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) { 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 === 'function', 'ursa() is available') t.end() }, t.end) }) From 9d6581e6d3f6c6e350f7c57b17946999d59f52fb Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Sat, 30 Jan 2016 05:29:15 +0800 Subject: [PATCH 2/3] Only support node-gyp when scripts.install isn't available --- .aoeu/package.json | 1 + lib/install/post_install.js | 11 ++++++++++- test/index.js | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .aoeu/package.json 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/install/post_install.js b/lib/install/post_install.js index 405d1600c4..05757aa8ad 100644 --- a/lib/install/post_install.js +++ b/lib/install/post_install.js @@ -10,12 +10,17 @@ module.exports = function postInstall (root, pkg, log) { debug('postinstall', pkg) var scripts = pkg && pkg.scripts || {} return Promise.resolve() - .then(_ => checkBindingGyp(root, log)) + .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)) @@ -24,6 +29,10 @@ function checkBindingGyp (root, log) { }) } +/* + * Returns the bin for node-gyp + */ + function nodeGypBin () { return JSON.stringify(require.resolve('node-gyp/bin/node-gyp')) } diff --git a/test/index.js b/test/index.js index 2e1584df18..dc8e217f81 100644 --- a/test/index.js +++ b/test/index.js @@ -106,6 +106,11 @@ test('bundleDependencies (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') + t.end() + } + prepare() install({ input: ['ursa@0.9.1'], flags: { quiet: true } }) .then(function () { From 1bb8a3a723b3e58e6f96640779c991a89d8f912f Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Sat, 30 Jan 2016 05:31:36 +0800 Subject: [PATCH 3/3] Update tests --- test/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.js b/test/index.js index dc8e217f81..10e388da8a 100644 --- a/test/index.js +++ b/test/index.js @@ -108,14 +108,14 @@ test('bundleDependencies (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') - t.end() + return t.end() } prepare() install({ input: ['ursa@0.9.1'], flags: { quiet: true } }) .then(function () { var ursa = require(join(process.cwd(), 'node_modules', 'ursa')) - t.ok(typeof ursa === 'function', 'ursa() is available') + t.ok(typeof ursa === 'object', 'ursa() is available') t.end() }, t.end) })