diff --git a/lib/config/exec.js b/lib/config/exec.js index 3a4f7f7d..65ec7bdb 100644 --- a/lib/config/exec.js +++ b/lib/config/exec.js @@ -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; @@ -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' diff --git a/test/cli/exec.test.js b/test/cli/exec.test.js index 6765b8bf..50fba622 100644 --- a/test/cli/exec.test.js +++ b/test/cli/exec.test.js @@ -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); });