Skip to content

Commit

Permalink
fix: read config file before defaulting script parameter (#1110)
Browse files Browse the repository at this point in the history
If I have a nodemon.json config file with an `exec` property, then this is automatically appended with ` index.js` when running `nodemon` standalone.

I would expect this to be equivalent to running `nodemon --exec "my cmd"` - that is providing an `exec` prevents defaulting of `script` to index.js.

To resolve, move the code which defaults the `script` property when `exec` is undefined to after the config files have been read, so that the behaviour is the same irrespective of whether properties are set in CLI flags or in nodemon.json.
  • Loading branch information
lennym authored and remy committed Dec 4, 2017
1 parent d0c515a commit f3e0c29
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
21 changes: 0 additions & 21 deletions lib/cli/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,6 @@ function parse(argv) {
}
}

if (script === null && !nodemonOptions.exec) {
var found = findAppScript();
if (found !== null) {
if (found.exec) {
nodemonOptions.exec = found.exec;
}
script = found.script;
nodemonOptions.scriptPosition = args.length;
}
}

nodemonOptions.script = script;
nodemonOptions.args = args;

Expand Down Expand Up @@ -212,16 +201,6 @@ function nodemonOption(options, arg, eatNext) {
}
}

function findAppScript() {
// nodemon has been run alone, so try to read the package file
// or try to read the index.js file
if (existsSync('./index.js')) {
return { exec: null, script: 'index.js' };
}

return null;
}

/**
* Given an argument (ie. from nodemonOption()), will parse and return the
* equivalent millisecond value or 0 if the argument cannot be parsed
Expand Down
17 changes: 17 additions & 0 deletions lib/config/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ var defaults = require('./defaults');

module.exports = load;

var existsSync = fs.existsSync || path.existsSync;

function findAppScript() {
// nodemon has been run alone, so try to read the package file
// or try to read the index.js file
if (existsSync('./index.js')) {
return 'index.js';
}
}

/**
* Load the nodemon config, first reading the global root/nodemon.json, then
* the local nodemon.json to the exec and then overwritting using any user
Expand Down Expand Up @@ -55,6 +65,13 @@ function load(settings, options, config, callback) {
// add in any missing defaults
options = utils.merge(options, defaults);

if (!options.script && !options.exec) {
var found = findAppScript();
if (found) {
options.script = found;
}
}

// work out the execOptions based on the final config we have
options.execOptions = exec({
script: options.script,
Expand Down

0 comments on commit f3e0c29

Please sign in to comment.