Skip to content

Commit

Permalink
when running a coffee file, use --nodejs correctly
Browse files Browse the repository at this point in the history
Previously, the --nodejs flag was being prepended if you had any
arguments prefixed with '--', even if they were intended for your
application. There is an additional problem where arguments intended for
node js need to be grouped into a single argument passed after --nodejs.

After this patch, any flag before your script is considered a nodejs
argument. These, along with any other exec arguments are bundled into a
single argument separated by spaces.

Fixes #530
  • Loading branch information
dpatti committed Apr 22, 2015
1 parent 55320b7 commit a71db72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions lib/config/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,18 @@ function exec(nodemonOptions, execMap) {
// note: indexOf('coffee') handles both .coffee and .litcoffee
if (!execDefined && options.exec === 'node' && scriptExt.indexOf('coffee') !== -1) {
options.exec = 'coffee';
// ensure that we call: `coffee --nodejs ...`
if (options.execArgs === undefined) {
options.execArgs = [];
}
// if there's a leading argument to the exec that starts with `--` then
// it could be --debug or --debug-brk or something else intended for node
// so we'll add the --nodejs switch.
if ((options.args || []).join(' ').indexOf('--') === 0) {
options.execArgs.unshift('--nodejs');

// we need to get execArgs set before the script
// for example, in `nodemon --debug my-script.coffee --my-flag`, debug is an
// execArg, while my-flag is a script arg
var leadingArgs = (options.args || []).splice(0, options.scriptPosition);
options.execArgs = options.execArgs.concat(leadingArgs);
options.scriptPosition = 0;

if (options.execArgs.length > 0) {
// because this is the coffee executable, we need to combine the exec args
// into a single argument after the nodejs flag
options.execArgs = ['--nodejs', options.execArgs.join(' ')];
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/cli/exec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('nodemon exec', function () {
var options = exec({ script: 'app.coffee', nodeArgs: [ '--debug' ] });

assert(options.exec.indexOf('coffee') === 0, 'using coffeescript to execute');
assert(options.execArgs.indexOf('--debug') !== -1);
assert(options.execArgs[1].indexOf('--debug') !== -1);
assert(options.ext.indexOf('coffee') !== -1);
});

Expand Down

0 comments on commit a71db72

Please sign in to comment.