Skip to content

Commit

Permalink
solve tj#306, and bin in $PATH make sense now
Browse files Browse the repository at this point in the history
Almost revert tj#173 which lead to the bug in tj#306
  • Loading branch information
zhiyelee committed Dec 14, 2014
1 parent 1444cf3 commit 6c33af8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var spawn = require('child_process').spawn;
var path = require('path');
var dirname = path.dirname;
var basename = path.basename;
var fs = require('fs');

/**
* Expose the root command.
Expand Down Expand Up @@ -449,13 +450,14 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
var dir = dirname(argv[1]);
var bin = basename(argv[1], '.js') + '-' + args[0];

// check for ./<bin> first
// prefer local `./<bin>` to bin in the $PATH
var local = path.join(dir, bin);
if (fs.existsSync(local)) bin = local;

// run it
args = args.slice(1);
args.unshift(local);
var proc = spawn('node', args, { stdio: 'inherit', customFds: [0, 1, 2] });

var proc = spawn(bin, args, { stdio: 'inherit'} );
proc.on('error', function(err) {
if (err.code == "ENOENT") {
console.error('\n %s(1) does not exist, try --help\n', bin);
Expand Down

0 comments on commit 6c33af8

Please sign in to comment.