diff --git a/lib/make-spawn-args.js b/lib/make-spawn-args.js index 8a32d71..1c9f02c 100644 --- a/lib/make-spawn-args.js +++ b/lib/make-spawn-args.js @@ -1,21 +1,34 @@ /* eslint camelcase: "off" */ const setPATH = require('./set-path.js') const { resolve } = require('path') -const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js') + +let npm_config_node_gyp const makeSpawnArgs = options => { const { + args, + binPaths, + cmd, + env, event, + nodeGyp, path, scriptShell = true, - binPaths, - env, stdio, - cmd, - args, stdioString, } = options + if (nodeGyp) { + // npm already pulled this from env and passes it in to options + npm_config_node_gyp = nodeGyp + } else if (env.npm_config_node_gyp) { + // legacy mode for standalone user + npm_config_node_gyp = env.npm_config_node_gyp + } else { + // default + npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js') + } + const spawnEnv = setPATH(path, binPaths, { // we need to at least save the PATH environment var ...process.env, diff --git a/lib/run-script-pkg.js b/lib/run-script-pkg.js index 9900c96..161caeb 100644 --- a/lib/run-script-pkg.js +++ b/lib/run-script-pkg.js @@ -7,18 +7,19 @@ const isServerPackage = require('./is-server-package.js') const runScriptPkg = async options => { const { - event, - path, - scriptShell, + args = [], binPaths = false, env = {}, - stdio = 'pipe', + event, + nodeGyp, + path, pkg, - args = [], - stdioString, + scriptShell, // how long to wait for a process.kill signal // only exposed here so that we can make the test go a bit faster. signalTimeout = 500, + stdio = 'pipe', + stdioString, } = options const { scripts = {}, gypfile } = pkg @@ -63,14 +64,15 @@ const runScriptPkg = async options => { } const [spawnShell, spawnArgs, spawnOpts] = makeSpawnArgs({ + args, + binPaths, + cmd, + env: { ...env, ...packageEnvs(pkg) }, event, + nodeGyp, path, scriptShell, - binPaths, - env: { ...env, ...packageEnvs(pkg) }, stdio, - cmd, - args, stdioString, }) diff --git a/test/make-spawn-args.js b/test/make-spawn-args.js index 83e90a0..110f28f 100644 --- a/test/make-spawn-args.js +++ b/test/make-spawn-args.js @@ -62,13 +62,15 @@ t.test('spawn args', async t => { /.*/, a => a.includes('echo test'), e => { - return e.env.test_fixture === 'a string' + return e.env.test_fixture === 'a string' && + e.env.npm_config_node_gyp === '/test/path.js' } ) await t.resolves(() => runScript({ pkg, path: testdir, env: { + npm_config_node_gyp: '/test/path.js', test_fixture: 'a string', }, event: 'test', @@ -76,6 +78,23 @@ t.test('spawn args', async t => { t.ok(spawk.done()) }) + await t.test('provided options.nodeGyp', async t => { + spawk.spawn( + /.*/, + a => a.includes('echo test'), + e => { + return e.env.npm_config_node_gyp === '/test/path.js' + } + ) + await t.resolves(() => runScript({ + pkg, + path: testdir, + nodeGyp: '/test/path.js', + event: 'test', + })) + t.ok(spawk.done()) + }) + await t.test('provided args', async t => { spawk.spawn( /.*/,