diff options
Diffstat (limited to 'deps/npm/node_modules/libnpx/index.js')
-rw-r--r-- | deps/npm/node_modules/libnpx/index.js | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/deps/npm/node_modules/libnpx/index.js b/deps/npm/node_modules/libnpx/index.js index 3033e9cd06..21f44b3710 100644 --- a/deps/npm/node_modules/libnpx/index.js +++ b/deps/npm/node_modules/libnpx/index.js @@ -86,6 +86,9 @@ function npx (argv) { if (process.platform === 'win32') { bins = bins.filter(b => b !== 'etc' && b !== 'node_modules') } + if (bins.length < 1) { + throw new Error(Y()`command not found: ${argv.command}`) + } const cmd = new RegExp(`^${argv.command}(?:\\.cmd)?$`, 'i') const matching = bins.find(b => b.match(cmd)) return path.resolve(results.bin, bins[matching] || bins[0]) @@ -116,11 +119,7 @@ function npx (argv) { module.exports._localBinPath = localBinPath function localBinPath (cwd) { return require('./get-prefix.js')(cwd).then(prefix => { - const pkgjson = path.join(prefix, 'package.json') - return promisify(fs.stat)(pkgjson).then( - () => path.join(prefix, 'node_modules', '.bin'), - err => { if (err.code !== 'ENOENT') throw err } - ) + return prefix && path.join(prefix, 'node_modules', '.bin') }) } @@ -146,8 +145,8 @@ function ensurePackages (specs, opts) { ).then(cache => { const prefix = path.join(cache, '_npx', process.pid.toString()) const bins = process.platform === 'win32' - ? prefix - : path.join(prefix, 'bin') + ? prefix + : path.join(prefix, 'bin') const rimraf = require('rimraf') process.on('exit', () => rimraf.sync(prefix)) return promisify(rimraf)(bins).then(() => { @@ -224,8 +223,8 @@ function installPackages (specs, prefix, opts) { if (npmPath) { args.unshift( process.platform === 'win32' - ? child.escapeArg(opts.npm) - : opts.npm + ? child.escapeArg(opts.npm) + : opts.npm ) return process.argv[0] } else { @@ -254,7 +253,8 @@ function installPackages (specs, prefix, opts) { module.exports._execCommand = execCommand function execCommand (_existing, argv) { return findNodeScript(_existing, argv).then(existing => { - if (existing && !argv.nodeArg && !argv.shell && existing !== process.argv[1]) { + const argvCmdOpts = argv.cmdOpts || [] + if (existing && !argv.alwaysSpawn && !argv.nodeArg && !argv.shell && existing !== process.argv[1]) { const Module = require('module') // let it take over the process. This means we can skip node startup! if (!argv.noYargs) { @@ -264,31 +264,35 @@ function execCommand (_existing, argv) { process.argv = [ process.argv[0], // Current node binary existing // node script path. `runMain()` will set this as the new main - ].concat(argv.cmdOpts) // options for the cmd itself + ].concat(argvCmdOpts) // options for the cmd itself Module.runMain() // ✨MAGIC✨. Sorry-not-sorry } else if (!existing && argv.nodeArg && argv.nodeArg.length) { throw new Error(Y()`ERROR: --node-arg/-n can only be used on packages with node scripts.`) } else { let cmd = existing - let opts = argv - if (existing && argv.nodeArg && argv.nodeArg.length) { + let cmdOpts = argvCmdOpts + if (existing) { + cmd = process.argv[0] + if (process.platform === 'win32') { + cmd = child.escapeArg(cmd, true) + } // If we know we're running a run script and we got a --node-arg, // we need to fudge things a bit to get them working right. - let nargs = argv.nodeArg - if (typeof nargs === 'string') { - nargs = [nargs] + cmdOpts = argv.nodeArg + if (cmdOpts) { + cmdOpts = Array.isArray(cmdOpts) ? cmdOpts : [cmdOpts] + } else { + cmdOpts = [] } // It's valid for a single arg to be a string of multiple // space-separated node args. // Example: `$ npx -n '--inspect --harmony --debug' ...` - nargs = nargs.reduce((acc, arg) => { + cmdOpts = cmdOpts.reduce((acc, arg) => { return acc.concat(arg.split(/\s+/)) }, []) - cmd = process.argv[0] - opts = Object.assign({}, argv, { - cmdOpts: nargs.concat([existing], argv.cmdOpts || []) - }) + cmdOpts = cmdOpts.concat(existing, argvCmdOpts) } + const opts = Object.assign({}, argv, { cmdOpts }) return child.runCommand(cmd, opts).catch(err => { if (err.isOperational && err.exitCode) { // At this point, we want to treat errors from the child as if @@ -355,7 +359,7 @@ function findNodeScript (existing, opts) { return str.match(cmd) || str.match(mingw) }).then(match => { return match && path.join(path.dirname(existing), match[1]) - }).then(x => console.log(x) || x) + }) } }) } |