Skip to content

Commit

Permalink
fix: ensure non-slurp is passed to script
Browse files Browse the repository at this point in the history
The `--` argument now passes all arguments after the script (if omitted in the nodemon call), rather than the exec command.

Fixes #750
  • Loading branch information
remy committed Dec 22, 2017
1 parent 0bb1eec commit ad226af
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/cli/parse.js
Expand Up @@ -67,6 +67,7 @@ function parse(argv) {
// respect the standard way of saying: hereafter belongs to my script
if (args[i] === '--') {
args.splice(i, 1);
nodemonOptions.scriptPosition = i;
// cycle back one argument, as we just ate this one up
i--;

Expand Down Expand Up @@ -102,7 +103,7 @@ function parse(argv) {
* @return {Boolean} false if argument was not a nodemon arg
*/
function nodemonOption(options, arg, eatNext) {
// line seperation on purpose to help legibility
// line separation on purpose to help legibility
if (arg === '--help' || arg === '-h' || arg === '-?') {
var help = eatNext();
options.help = help ? help : true;
Expand Down
35 changes: 34 additions & 1 deletion test/cli/parse.test.js
Expand Up @@ -274,12 +274,45 @@ describe('nodemon respects custom "ext" and "execMap"', function () {
});
});

describe('nodemon should slurp properly', () => {
describe.only('nodemon should slurp properly', () => {
it('should read quotes as a single entity', () => {
const settings = parse(asCLI('notindex.js -- -b "hello - world"'));
assert(settings.execOptions.exec === 'node', 'node is exec');
assert(settings.args.length === 3, 'only has 3 arguments to node');
});

it('should pass non-slurped args to script', () => {
const settings = parse(asCLI('-- --log'));
var cmd = commandToString(command(settings));
assert.equal(cmd, 'node ./lib/nodemon.js --log', 'args passed to script');
});

it('should pass non-slurped args to explicit script', () => {
const settings = parse(asCLI('./lib/nodemon.js -- --log'));
var cmd = commandToString(command(settings));
assert.equal(cmd, 'node ./lib/nodemon.js --log', 'args passed to script');
});

it('should pass slurped args to explicit script', () => {
const settings = parse(asCLI('./lib/nodemon.js --log'));
var cmd = commandToString(command(settings));
assert.equal(cmd, 'node ./lib/nodemon.js --log', 'args passed to script');
});

it('should handle a mix of slurps', () => {
var cmd;
var settings;

cmd = commandToString(command(parse(asCLI('--inspect -- --log'))));
assert.equal(cmd, 'node --inspect ./lib/nodemon.js --log', 'args passed to script');

cmd = commandToString(command(parse(asCLI('--inspect ./lib/nodemon.js -- --log'))));
assert.equal(cmd, 'node --inspect ./lib/nodemon.js --log', 'args passed to script');

cmd = commandToString(command(parse(asCLI('--inspect --log ./lib/nodemon.js'))));
assert.equal(cmd, 'node --inspect --log ./lib/nodemon.js', 'args passed to script');
});

});

describe('nodemon with CoffeeScript', function () {
Expand Down

0 comments on commit ad226af

Please sign in to comment.