Merge pull request #25 from rstacruz/node-gyp

node-gyp support
This commit is contained in:
Rico Sta. Cruz
2016-01-30 05:32:09 +08:00
5 changed files with 35 additions and 5 deletions

1
.aoeu/package.json Normal file
View File

@@ -0,0 +1 @@
{}

View File

@@ -18,6 +18,6 @@ module.exports = function obliterate (path) {
}
})
.catch(err => {
if (err !== 'ENOENT') throw err
if (err.code !== 'ENOENT') throw err
})
}

View File

@@ -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.
*/

View File

@@ -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",

View File

@@ -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)
})