Skip to content

Commit

Permalink
chore: merge
Browse files Browse the repository at this point in the history
* '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
  • Loading branch information
remy committed Jan 6, 2021
2 parents a12cc4d + 3d2320f commit 9595d94
Show file tree
Hide file tree
Showing 11 changed files with 841 additions and 1,151 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,19 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"space-before-function-paren": [
2,
{
"anonymous": "ignore",
"named": "never"
}
]
}
}
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Expand Up @@ -16,7 +16,7 @@ This will allow for the automatic changelog to generate correctly.

## Code standards

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

## Sending pull requests

Expand Down
13 changes: 0 additions & 13 deletions .jscsrc

This file was deleted.

3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -5,10 +5,9 @@ cache:
notifications:
email: false
node_js:
- '14'
- '12'
- '11'
- '10'
- '8'
before_install:
- if [ "$TRAVIS_PULL_REQUEST_BRANCH" == "" ]; then echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" >> .npmrc; fi
after_success:
Expand Down
2 changes: 1 addition & 1 deletion bin/postinstall.js
@@ -1,7 +1,7 @@
#!/usr/bin/env node

function main() {
if (process.env.SUPPRESS_SUPPORT || process.env.OPENCOLLECTIVE_HIDE) {
if (process.env.SUPPRESS_SUPPORT || process.env.OPENCOLLECTIVE_HIDE || process.env.CI) {
return;
}

Expand Down
9 changes: 8 additions & 1 deletion lib/monitor/match.js
Expand Up @@ -157,6 +157,12 @@ function match(files, monitor, ext) {
if (s.indexOf('!' + cwd) === 0) {
return s;
}

// if it starts with a period, then let's get the relative path
if (s.indexOf('!.') === 0) {
return '!' + path.resolve(cwd, s.substring(1));
}

return '!**' + (prefix !== path.sep ? path.sep : '') + s.slice(1);
}

Expand Down Expand Up @@ -195,12 +201,13 @@ function match(files, monitor, ext) {
for (var i = 0; i < rules.length; i++) {
if (rules[i].slice(0, 1) === '!') {
if (!minimatch(file, rules[i], minimatchOpts)) {
debug('ignored', file, 'rule:', rules[i]);
ignored++;
matched = true;
break;
}
} else {
debug('match', file, minimatch(file, rules[i], minimatchOpts));
debug('matched', file, 'rule:', rules[i]);
if (minimatch(file, rules[i], minimatchOpts)) {
watched++;

Expand Down
121 changes: 67 additions & 54 deletions lib/monitor/run.js
Expand Up @@ -18,16 +18,31 @@ var signals = require('./signals');

function run(options) {
var cmd = config.command.raw;
// moved up
// we need restart function below in the global scope for run.kill
/*jshint validthis:true*/
restart = run.bind(this, options);
run.restart = restart;

// binding options with instance of run
// so that we can use it in run.kill
run.options = options;

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

/*jshint validthis:true*/
restart = run.bind(this, options);
run.restart = restart;

config.lastStarted = Date.now();

var stdio = ['pipe', 'pipe', 'pipe'];
Expand Down Expand Up @@ -237,53 +252,9 @@ function run(options) {
}
});

run.kill = function (noRestart, callback) {
// I hate code like this :( - Remy (author of said code)
if (typeof noRestart === 'function') {
callback = noRestart;
noRestart = false;
}

if (!callback) {
callback = noop;
}

if (child !== null) {
// if the stdin piping is on, we need to unpipe, but also close stdin on
// the child, otherwise linux can throw EPIPE or ECONNRESET errors.
if (options.stdin) {
process.stdin.unpipe(child.stdin);
}

// For the on('exit', ...) handler above the following looks like a
// crash, so we set the killedAfterChange flag if a restart is planned
if (!noRestart) {
killedAfterChange = true;
}

/* Now kill the entire subtree of processes belonging to nodemon */
var oldPid = child.pid;
if (child) {
kill(child, config.signal, function () {
// this seems to fix the 0.11.x issue with the "rs" restart command,
// though I'm unsure why. it seems like more data is streamed in to
// stdin after we close.
if (child && options.stdin && child.stdin && oldPid === child.pid) {
child.stdin.end();
}
callback();
});
}
} else if (!noRestart) {
// if there's no child, then we need to manually start the process
// this is because as there was no child, the child.on('exit') event
// handler doesn't exist which would normally trigger the restart.
bus.once('start', callback);
restart();
} else {
callback();
}
};
// moved the run.kill outside to handle both the cases
// intial start
// no start

// connect stdin to the child process (options.stdin is on by default)
if (options.stdin) {
Expand Down Expand Up @@ -381,12 +352,54 @@ function kill(child, signal, callback) {
}
}

// stubbed out for now, filled in during run
run.kill = function (flag, callback) {
if (callback) {
run.kill = function (noRestart, callback) {
// I hate code like this :( - Remy (author of said code)
if (typeof noRestart === 'function') {
callback = noRestart;
noRestart = false;
}

if (!callback) {
callback = noop;
}

if (child !== null) {
// if the stdin piping is on, we need to unpipe, but also close stdin on
// the child, otherwise linux can throw EPIPE or ECONNRESET errors.
if (run.options.stdin) {
process.stdin.unpipe(child.stdin);
}

// For the on('exit', ...) handler above the following looks like a
// crash, so we set the killedAfterChange flag if a restart is planned
if (!noRestart) {
killedAfterChange = true;
}

/* Now kill the entire subtree of processes belonging to nodemon */
var oldPid = child.pid;
if (child) {
kill(child, config.signal, function () {
// this seems to fix the 0.11.x issue with the "rs" restart command,
// though I'm unsure why. it seems like more data is streamed in to
// stdin after we close.
if (child && run.options.stdin && child.stdin && oldPid === child.pid) {
child.stdin.end();
}
callback();
});
}
} else if (!noRestart) {
// if there's no child, then we need to manually start the process
// this is because as there was no child, the child.on('exit') event
// handler doesn't exist which would normally trigger the restart.
bus.once('start', callback);
run.restart();
} else {
callback();
}
};

run.restart = noop;

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

0 comments on commit 9595d94

Please sign in to comment.