Skip to content

Commit 9595d94

Browse files
committed
chore: merge
* 'master' of github.com:remy/nodemon: fix: postinstall hide message in CI chore: change test targets (#1788) chore: Switch from JSCS to ESLint fix: ignore ./<path> on cwd (#1787) fix: runOnChangeOnly=true
2 parents a12cc4d + 3d2320f commit 9595d94

11 files changed

+841
-1151
lines changed

.eslintrc.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es2021": true
6+
},
7+
"parserOptions": {
8+
"ecmaVersion": 12
9+
},
10+
"rules": {
11+
"space-before-function-paren": [
12+
2,
13+
{
14+
"anonymous": "ignore",
15+
"named": "never"
16+
}
17+
]
18+
}
19+
}

.github/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This will allow for the automatic changelog to generate correctly.
1616

1717
## Code standards
1818

19-
Ensure that your code adheres to the included `.jshintrc` and `.jscsrc` configs.
19+
Ensure that your code adheres to the included `.jshintrc` and `.eslintrc.json` configs.
2020

2121
## Sending pull requests
2222

.jscsrc

-13
This file was deleted.

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ cache:
55
notifications:
66
email: false
77
node_js:
8+
- '14'
89
- '12'
9-
- '11'
1010
- '10'
11-
- '8'
1211
before_install:
1312
- if [ "$TRAVIS_PULL_REQUEST_BRANCH" == "" ]; then echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" >> .npmrc; fi
1413
after_success:

bin/postinstall.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
function main() {
4-
if (process.env.SUPPRESS_SUPPORT || process.env.OPENCOLLECTIVE_HIDE) {
4+
if (process.env.SUPPRESS_SUPPORT || process.env.OPENCOLLECTIVE_HIDE || process.env.CI) {
55
return;
66
}
77

lib/monitor/match.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ function match(files, monitor, ext) {
157157
if (s.indexOf('!' + cwd) === 0) {
158158
return s;
159159
}
160+
161+
// if it starts with a period, then let's get the relative path
162+
if (s.indexOf('!.') === 0) {
163+
return '!' + path.resolve(cwd, s.substring(1));
164+
}
165+
160166
return '!**' + (prefix !== path.sep ? path.sep : '') + s.slice(1);
161167
}
162168

@@ -195,12 +201,13 @@ function match(files, monitor, ext) {
195201
for (var i = 0; i < rules.length; i++) {
196202
if (rules[i].slice(0, 1) === '!') {
197203
if (!minimatch(file, rules[i], minimatchOpts)) {
204+
debug('ignored', file, 'rule:', rules[i]);
198205
ignored++;
199206
matched = true;
200207
break;
201208
}
202209
} else {
203-
debug('match', file, minimatch(file, rules[i], minimatchOpts));
210+
debug('matched', file, 'rule:', rules[i]);
204211
if (minimatch(file, rules[i], minimatchOpts)) {
205212
watched++;
206213

lib/monitor/run.js

+67-54
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,31 @@ var signals = require('./signals');
1818

1919
function run(options) {
2020
var cmd = config.command.raw;
21+
// moved up
22+
// we need restart function below in the global scope for run.kill
23+
/*jshint validthis:true*/
24+
restart = run.bind(this, options);
25+
run.restart = restart;
26+
27+
// binding options with instance of run
28+
// so that we can use it in run.kill
29+
run.options = options;
2130

2231
var runCmd = !options.runOnChangeOnly || config.lastStarted !== 0;
2332
if (runCmd) {
2433
utils.log.status('starting `' + config.command.string + '`');
34+
} else {
35+
// should just watch file if command is not to be run
36+
// had another alternate approach
37+
// to stop process being forked/spawned in the below code
38+
// but this approach does early exit and makes code cleaner
39+
debug('start watch on: %s', config.options.watch);
40+
if (config.options.watch !== false) {
41+
watch();
42+
return;
43+
}
2544
}
2645

27-
/*jshint validthis:true*/
28-
restart = run.bind(this, options);
29-
run.restart = restart;
30-
3146
config.lastStarted = Date.now();
3247

3348
var stdio = ['pipe', 'pipe', 'pipe'];
@@ -237,53 +252,9 @@ function run(options) {
237252
}
238253
});
239254

240-
run.kill = function (noRestart, callback) {
241-
// I hate code like this :( - Remy (author of said code)
242-
if (typeof noRestart === 'function') {
243-
callback = noRestart;
244-
noRestart = false;
245-
}
246-
247-
if (!callback) {
248-
callback = noop;
249-
}
250-
251-
if (child !== null) {
252-
// if the stdin piping is on, we need to unpipe, but also close stdin on
253-
// the child, otherwise linux can throw EPIPE or ECONNRESET errors.
254-
if (options.stdin) {
255-
process.stdin.unpipe(child.stdin);
256-
}
257-
258-
// For the on('exit', ...) handler above the following looks like a
259-
// crash, so we set the killedAfterChange flag if a restart is planned
260-
if (!noRestart) {
261-
killedAfterChange = true;
262-
}
263-
264-
/* Now kill the entire subtree of processes belonging to nodemon */
265-
var oldPid = child.pid;
266-
if (child) {
267-
kill(child, config.signal, function () {
268-
// this seems to fix the 0.11.x issue with the "rs" restart command,
269-
// though I'm unsure why. it seems like more data is streamed in to
270-
// stdin after we close.
271-
if (child && options.stdin && child.stdin && oldPid === child.pid) {
272-
child.stdin.end();
273-
}
274-
callback();
275-
});
276-
}
277-
} else if (!noRestart) {
278-
// if there's no child, then we need to manually start the process
279-
// this is because as there was no child, the child.on('exit') event
280-
// handler doesn't exist which would normally trigger the restart.
281-
bus.once('start', callback);
282-
restart();
283-
} else {
284-
callback();
285-
}
286-
};
255+
// moved the run.kill outside to handle both the cases
256+
// intial start
257+
// no start
287258

288259
// connect stdin to the child process (options.stdin is on by default)
289260
if (options.stdin) {
@@ -381,12 +352,54 @@ function kill(child, signal, callback) {
381352
}
382353
}
383354

384-
// stubbed out for now, filled in during run
385-
run.kill = function (flag, callback) {
386-
if (callback) {
355+
run.kill = function (noRestart, callback) {
356+
// I hate code like this :( - Remy (author of said code)
357+
if (typeof noRestart === 'function') {
358+
callback = noRestart;
359+
noRestart = false;
360+
}
361+
362+
if (!callback) {
363+
callback = noop;
364+
}
365+
366+
if (child !== null) {
367+
// if the stdin piping is on, we need to unpipe, but also close stdin on
368+
// the child, otherwise linux can throw EPIPE or ECONNRESET errors.
369+
if (run.options.stdin) {
370+
process.stdin.unpipe(child.stdin);
371+
}
372+
373+
// For the on('exit', ...) handler above the following looks like a
374+
// crash, so we set the killedAfterChange flag if a restart is planned
375+
if (!noRestart) {
376+
killedAfterChange = true;
377+
}
378+
379+
/* Now kill the entire subtree of processes belonging to nodemon */
380+
var oldPid = child.pid;
381+
if (child) {
382+
kill(child, config.signal, function () {
383+
// this seems to fix the 0.11.x issue with the "rs" restart command,
384+
// though I'm unsure why. it seems like more data is streamed in to
385+
// stdin after we close.
386+
if (child && run.options.stdin && child.stdin && oldPid === child.pid) {
387+
child.stdin.end();
388+
}
389+
callback();
390+
});
391+
}
392+
} else if (!noRestart) {
393+
// if there's no child, then we need to manually start the process
394+
// this is because as there was no child, the child.on('exit') event
395+
// handler doesn't exist which would normally trigger the restart.
396+
bus.once('start', callback);
397+
run.restart();
398+
} else {
387399
callback();
388400
}
389401
};
402+
390403
run.restart = noop;
391404

392405
bus.on('quit', function onQuit(code) {

0 commit comments

Comments
 (0)