Skip to content

Commit d78bf3d

Browse files
MajorBreakfastremy
authored andcommitted
fix: watch both js and mjs files if main file is JavaScript
1 parent 0d9a892 commit d78bf3d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/config/exec.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ function exec(nodemonOptions, execMap) {
113113

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

116-
var extension = options.ext !== undefined ?
117-
options.ext :
118-
(scriptExt ? scriptExt + ',json' : 'js,json');
116+
var extension = options.ext;
117+
if (extension === undefined) {
118+
var isJS = scriptExt === 'js' || scriptExt === 'mjs';
119+
extension = (isJS || !scriptExt) ? 'js,mjs' : scriptExt;
120+
extension += ',json'; // Always watch JSON files
121+
}
119122

120123
var execDefined = !!options.exec;
121124

@@ -184,7 +187,8 @@ function exec(nodemonOptions, execMap) {
184187
if (options.exec === 'coffee') {
185188
// don't override user specified extension tracking
186189
if (options.ext === undefined) {
187-
extension = 'coffee,litcoffee,js,json,mjs';
190+
if (extension) { extension += ','; }
191+
extension += 'coffee,litcoffee';
188192
}
189193

190194
// because windows can't find 'coffee', it needs the real file 'coffee.cmd'

test/cli/exec.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('nodemon exec', function () {
6363
var options = exec({ script: 'index.js' });
6464
var cmd = toCmd(options);
6565
assert.equal(options.exec, 'node', 'exec is node');
66-
assert.equal(options.ext, 'js,json');
66+
assert.equal(options.ext, 'js,mjs,json');
6767
assert.equal(cmd.string, 'node index.js', cmd.string);
6868
});
6969

0 commit comments

Comments
 (0)