From ad226afc13f4480bc6c942785571ec10fdf8b293 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Fri, 22 Dec 2017 22:34:18 +0000 Subject: [PATCH] fix: ensure non-slurp is passed to script The `--` argument now passes all arguments after the script (if omitted in the nodemon call), rather than the exec command. Fixes #750 --- lib/cli/parse.js | 3 ++- test/cli/parse.test.js | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/cli/parse.js b/lib/cli/parse.js index bff13e3a..789fe6ea 100644 --- a/lib/cli/parse.js +++ b/lib/cli/parse.js @@ -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--; @@ -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; diff --git a/test/cli/parse.test.js b/test/cli/parse.test.js index b01b8622..c5813707 100644 --- a/test/cli/parse.test.js +++ b/test/cli/parse.test.js @@ -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 () {