Skip to content

Commit

Permalink
fix: watch both js and mjs files if main file is JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorBreakfast authored and remy committed Dec 29, 2017
1 parent 0d9a892 commit d78bf3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/config/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ function exec(nodemonOptions, execMap) {

var scriptExt = path.extname(script).slice(1);

var extension = options.ext !== undefined ?
options.ext :
(scriptExt ? scriptExt + ',json' : 'js,json');
var extension = options.ext;
if (extension === undefined) {
var isJS = scriptExt === 'js' || scriptExt === 'mjs';
extension = (isJS || !scriptExt) ? 'js,mjs' : scriptExt;
extension += ',json'; // Always watch JSON files
}

var execDefined = !!options.exec;

Expand Down Expand Up @@ -184,7 +187,8 @@ function exec(nodemonOptions, execMap) {
if (options.exec === 'coffee') {
// don't override user specified extension tracking
if (options.ext === undefined) {
extension = 'coffee,litcoffee,js,json,mjs';
if (extension) { extension += ','; }
extension += 'coffee,litcoffee';
}

// because windows can't find 'coffee', it needs the real file 'coffee.cmd'
Expand Down
2 changes: 1 addition & 1 deletion test/cli/exec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('nodemon exec', function () {
var options = exec({ script: 'index.js' });
var cmd = toCmd(options);
assert.equal(options.exec, 'node', 'exec is node');
assert.equal(options.ext, 'js,json');
assert.equal(options.ext, 'js,mjs,json');
assert.equal(cmd.string, 'node index.js', cmd.string);
});

Expand Down

0 comments on commit d78bf3d

Please sign in to comment.