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

fix: read config file before defaulting script parameter #1110

Merged
merged 1 commit into from
Dec 4, 2017
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
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