Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: feed args to exec when detecting script #1273

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/config/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ function load(settings, options, config, callback) {
if (!options.script && !options.exec) {
var found = findAppScript();
if (found) {
// if the script is found as a result of not being on the command
// line, then we move any of the pre double-dash args in execArgs
const n = options.scriptPosition || options.args.length;
options.execArgs = (options.execArgs || [])
.concat(options.args.splice(0, n));
options.scriptPosition = null;

options.script = found;
}
}
Expand Down
15 changes: 8 additions & 7 deletions test/cli/exec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ describe('nodemon exec', function () {
});

it('should support --debug', function () {
var options = exec({ script: 'app.js', nodeArgs: [ '--debug' ]});
var options = exec({ script: 'app.js', nodeArgs: ['--debug'] });
var cmd = toCmd(options);
assert(cmd.string === 'node --debug app.js', cmd.string);
assert(options.ext.indexOf('js') !== -1, 'extension watched is .js');
});

it('should support --debug=XXXX', function () {
var options = exec({ script: 'app.js', nodeArgs: [ '--debug=9999' ]});
var options = exec({ script: 'app.js', nodeArgs: ['--debug=9999'] });
var cmd = toCmd(options);
assert(cmd.string === 'node --debug=9999 app.js', cmd.string);
assert(options.exec === 'node');
Expand Down Expand Up @@ -140,30 +140,30 @@ describe('nodemon exec', function () {
});

it('should support coffeescript in debug mode', function () {
var options = exec({ script: 'app.coffee', nodeArgs: [ '--debug' ] });
var options = exec({ script: 'app.coffee', nodeArgs: ['--debug'] });

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

it('should support custom execs', function () {
var options = exec({ script: 'app.py', exec: 'python'});
var options = exec({ script: 'app.py', exec: 'python' });

assert(options.exec === 'python');
assert(options.ext.indexOf('py') !== -1);
});

it('should support custom executables with arguments', function () {
var options = exec({ script: 'app.py', exec: 'python --debug'});
var options = exec({ script: 'app.py', exec: 'python --debug' });
var cmd = toCmd(options);

assert(cmd.string === 'python --debug app.py', cmd.string);
assert(options.ext.indexOf('py') !== -1);
});

it('should support an array of exec arguments', function() {
var options = exec({script: 'app.js', exec: ['/path to node', '-v']});
it('should support an array of exec arguments', function () {
var options = exec({ script: 'app.js', exec: ['/path to node', '-v'] });

assert(options.exec === '/path to node', options.exec);
assert(options.execArgs.length === 1, options.execArgs.length);
Expand Down Expand Up @@ -219,4 +219,5 @@ describe('nodemon exec', function () {
var cmd = toCmd(options);
assert(cmd.string === 'node index', cmd.string);
});

});