Skip to content

Commit 009d868

Browse files
dominykasremy
authored andcommitted
feat: support wildcard extension matching
1 parent 76f825e commit 009d868

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

lib/config/exec.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ function exec(nodemonOptions, execMap) {
9797
var script = path.basename(options.script || '');
9898

9999
var scriptExt = path.extname(script).slice(1);
100-
var extension = options.ext || (scriptExt ? scriptExt + ',json' : 'js,json');
100+
101+
var extension = options.ext !== undefined ?
102+
options.ext :
103+
(scriptExt ? scriptExt + ',json' : 'js,json');
104+
101105
var execDefined = !!options.exec;
102106

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

165169
if (options.exec === 'coffee') {
166170
// don't override user specified extension tracking
167-
if (!options.ext) {
171+
if (options.ext === undefined) {
168172
extension = 'coffee,litcoffee,js,json,mjs';
169173
}
170174

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

188192
if (options.script) {
189-
options.script = expandScript(options.script, '.' +
190-
extension.split(',')[0]);
193+
options.script = expandScript(options.script,
194+
extension && ('.' + extension.split(',')[0]));
191195
}
192196

193197
options.env = {};

lib/nodemon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function nodemon(settings) {
150150
return rule.slice(0, 1) !== '!' ? rule : false;
151151
}).filter(Boolean).join(' '));
152152

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

155155
if (config.options.dump) {
156156
utils.log._log('log', '--------------');

test/cli/exec.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ describe('nodemon exec', function () {
9393
assert(options.ext.indexOf('jade') !== -1, 'pipe separated string');
9494
});
9595

96+
it('should support watching all extensions', function () {
97+
var options = exec({ script: 'app.js', ext: '' });
98+
assert.equal(options.ext, '', 'does not set default extensions when empty extension requested');
99+
100+
options = exec({ script: 'app.js', ext: '.' });
101+
assert.equal(options.ext, '', 'treats `.` as wildcard extension');
102+
103+
options = exec({ script: 'app.js', ext: '*' });
104+
assert.equal(options.ext, '', 'treats `*` as wildcard extension');
105+
106+
options = exec({ script: 'app.coffee', exec: 'coffee', ext: '' });
107+
assert.equal(options.ext, '', 'does not set default extensions when empty extension requested');
108+
});
109+
96110
it('should replace {{filename}}', function () {
97111
var options = exec({ script: 'app.js', exec: 'node {{filename}}.tmp --somethingElse' });
98112

@@ -182,6 +196,10 @@ describe('nodemon exec', function () {
182196
var options = exec({ script: 'app' });
183197
var cmd = toCmd(options);
184198
assert(cmd.string === 'node app.js', cmd.string);
199+
200+
options = exec({ script: 'app', ext: '' });
201+
cmd = toCmd(options);
202+
assert(cmd.string === 'node app.js', cmd.string);
185203
});
186204

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

0 commit comments

Comments
 (0)