Skip to content

Commit ad226af

Browse files
authored
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
1 parent 0bb1eec commit ad226af

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/cli/parse.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function parse(argv) {
6767
// respect the standard way of saying: hereafter belongs to my script
6868
if (args[i] === '--') {
6969
args.splice(i, 1);
70+
nodemonOptions.scriptPosition = i;
7071
// cycle back one argument, as we just ate this one up
7172
i--;
7273

@@ -102,7 +103,7 @@ function parse(argv) {
102103
* @return {Boolean} false if argument was not a nodemon arg
103104
*/
104105
function nodemonOption(options, arg, eatNext) {
105-
// line seperation on purpose to help legibility
106+
// line separation on purpose to help legibility
106107
if (arg === '--help' || arg === '-h' || arg === '-?') {
107108
var help = eatNext();
108109
options.help = help ? help : true;

test/cli/parse.test.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,45 @@ describe('nodemon respects custom "ext" and "execMap"', function () {
274274
});
275275
});
276276

277-
describe('nodemon should slurp properly', () => {
277+
describe.only('nodemon should slurp properly', () => {
278278
it('should read quotes as a single entity', () => {
279279
const settings = parse(asCLI('notindex.js -- -b "hello - world"'));
280280
assert(settings.execOptions.exec === 'node', 'node is exec');
281281
assert(settings.args.length === 3, 'only has 3 arguments to node');
282282
});
283+
284+
it('should pass non-slurped args to script', () => {
285+
const settings = parse(asCLI('-- --log'));
286+
var cmd = commandToString(command(settings));
287+
assert.equal(cmd, 'node ./lib/nodemon.js --log', 'args passed to script');
288+
});
289+
290+
it('should pass non-slurped args to explicit script', () => {
291+
const settings = parse(asCLI('./lib/nodemon.js -- --log'));
292+
var cmd = commandToString(command(settings));
293+
assert.equal(cmd, 'node ./lib/nodemon.js --log', 'args passed to script');
294+
});
295+
296+
it('should pass slurped args to explicit script', () => {
297+
const settings = parse(asCLI('./lib/nodemon.js --log'));
298+
var cmd = commandToString(command(settings));
299+
assert.equal(cmd, 'node ./lib/nodemon.js --log', 'args passed to script');
300+
});
301+
302+
it('should handle a mix of slurps', () => {
303+
var cmd;
304+
var settings;
305+
306+
cmd = commandToString(command(parse(asCLI('--inspect -- --log'))));
307+
assert.equal(cmd, 'node --inspect ./lib/nodemon.js --log', 'args passed to script');
308+
309+
cmd = commandToString(command(parse(asCLI('--inspect ./lib/nodemon.js -- --log'))));
310+
assert.equal(cmd, 'node --inspect ./lib/nodemon.js --log', 'args passed to script');
311+
312+
cmd = commandToString(command(parse(asCLI('--inspect --log ./lib/nodemon.js'))));
313+
assert.equal(cmd, 'node --inspect --log ./lib/nodemon.js', 'args passed to script');
314+
});
315+
283316
});
284317

285318
describe('nodemon with CoffeeScript', function () {

0 commit comments

Comments
 (0)