Skip to content
Myr

solve #306, and bin in $PATH make sense

Before adoption: this commit came in with the history the project adopted, so no landing records it.

solve #306, and bin in $PATH make sense now #196 Almost revert #173 which lead to the bug in #306 Also remove deprecated customFds option in spawn

authored by zhiyelee · committed by zhiyelee · parent c6807fd · Browse files · 1 file+17 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−3 removed

  • other:+17 added−3 removed

1 file+17 added−3 removed

modified:index.js+17 added-3 removed
6 unmodified lines
7var spawn = require('child_process').spawn;8var path = require('path');9var dirname = path.dirname;10var basename = path.basename;11var fs = require('fs');1213/**14 * Expose the root command.15 */
444 unmodified lines
460 // executable461 var dir = dirname(argv[1]);462 var bin = basename(argv[1], '.js') + '-' + args[0];463463 // check for ./<bin> first464 // prefer local `./<bin>` to bin in the $PATH465 var local = path.join(dir, bin);466 try {467 // for versions before node v0.8 when there weren't `fs.existsSync`468 if (fs.statSync(local).isFile()) {469 bin = local;470 }471 } catch (e) {}472473 // run it474 args = args.slice(1);468 args.unshift(local);469 var proc = spawn('node', args, { stdio: 'inherit', customFds: [0, 1, 2] });475476 var proc;477 if (process.platform !== 'win32') {478 proc = spawn(bin, args, { stdio: 'inherit'});479 } else {480 args.unshift(local);481 proc = spawn(process.execPath, args, { stdio: 'inherit'});482 }483484 proc.on('error', function(err) {485 if (err.code == "ENOENT") {486 console.error('\n %s(1) does not exist, try --help\n', bin);487 } else if (err.code == "EACCES") {
547 unmodified lines