Skip to content

Commit

Permalink
feat: support wildcard extension matching
Browse files Browse the repository at this point in the history
  • Loading branch information
dominykas authored and remy committed Dec 20, 2017
1 parent 76f825e commit 009d868
Show file tree
Hide file tree
Showing 3 changed files with 27 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 @@ -97,7 +97,11 @@ function exec(nodemonOptions, execMap) {
var script = path.basename(options.script || '');

var scriptExt = path.extname(script).slice(1);
var extension = options.ext || (scriptExt ? scriptExt + ',json' : 'js,json');

var extension = options.ext !== undefined ?
options.ext :
(scriptExt ? scriptExt + ',json' : 'js,json');

var execDefined = !!options.exec;

// allows the user to simplify cli usage:
Expand Down Expand Up @@ -164,7 +168,7 @@ function exec(nodemonOptions, execMap) {

if (options.exec === 'coffee') {
// don't override user specified extension tracking
if (!options.ext) {
if (options.ext === undefined) {
extension = 'coffee,litcoffee,js,json,mjs';
}

Expand All @@ -186,8 +190,8 @@ function exec(nodemonOptions, execMap) {
options.ext = extension;

if (options.script) {
options.script = expandScript(options.script, '.' +
extension.split(',')[0]);
options.script = expandScript(options.script,
extension && ('.' + extension.split(',')[0]));
}

options.env = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function nodemon(settings) {
return rule.slice(0, 1) !== '!' ? rule : false;
}).filter(Boolean).join(' '));

utils.log.detail('watching extensions: ' + config.options.execOptions.ext);
utils.log.detail('watching extensions: ' + (config.options.execOptions.ext || '(all)'));

if (config.options.dump) {
utils.log._log('log', '--------------');
Expand Down
18 changes: 18 additions & 0 deletions test/cli/exec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ describe('nodemon exec', function () {
assert(options.ext.indexOf('jade') !== -1, 'pipe separated string');
});

it('should support watching all extensions', function () {
var options = exec({ script: 'app.js', ext: '' });
assert.equal(options.ext, '', 'does not set default extensions when empty extension requested');

options = exec({ script: 'app.js', ext: '.' });
assert.equal(options.ext, '', 'treats `.` as wildcard extension');

options = exec({ script: 'app.js', ext: '*' });
assert.equal(options.ext, '', 'treats `*` as wildcard extension');

options = exec({ script: 'app.coffee', exec: 'coffee', ext: '' });
assert.equal(options.ext, '', 'does not set default extensions when empty extension requested');
});

it('should replace {{filename}}', function () {
var options = exec({ script: 'app.js', exec: 'node {{filename}}.tmp --somethingElse' });

Expand Down Expand Up @@ -182,6 +196,10 @@ describe('nodemon exec', function () {
var options = exec({ script: 'app' });
var cmd = toCmd(options);
assert(cmd.string === 'node app.js', cmd.string);

options = exec({ script: 'app', ext: '' });
cmd = toCmd(options);
assert(cmd.string === 'node app.js', cmd.string);
});

it('should expand based on custom extensions to hello.py', function () {
Expand Down

0 comments on commit 009d868

Please sign in to comment.