From d78bf3d5d17bf3be73d98bd7d500f3d5b5021659 Mon Sep 17 00:00:00 2001 From: Josef Brandl Date: Fri, 29 Dec 2017 15:44:54 +0100 Subject: [PATCH] fix: watch both js and mjs files if main file is JavaScript --- lib/config/exec.js | 12 ++++++++---- test/cli/exec.test.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) 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); });