From e90f15aa8a2afffe67fa7a86208587b8cdc34f3e Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Tue, 9 Jan 2018 13:18:08 +0000 Subject: [PATCH] fix: node < 6.4.0 causing crash on 'rs' trigger * fix: node < 6.4.0 can't connect to stdin * fix: child stdio when spawn is similar to fork Fixes #1218 --- lib/monitor/match.js | 1 - lib/monitor/run.js | 47 ++++++------ lib/spawn.js | 29 +++---- lib/utils/index.js | 3 + package-lock.json | 132 ++++++++++++++++---------------- package.json | 2 + test/events/complete.test.js | 21 ----- test/fork/change-detect.test.js | 29 +++---- test/monitor/match.test.js | 75 ++++++++++-------- 9 files changed, 163 insertions(+), 176 deletions(-) diff --git a/lib/monitor/match.js b/lib/monitor/match.js index 603c8fe3..ed34c72d 100644 --- a/lib/monitor/match.js +++ b/lib/monitor/match.js @@ -131,7 +131,6 @@ function tryBaseDir(dir) { function match(files, monitor, ext) { // sort the rules by highest specificity (based on number of slashes) // ignore rules (!) get sorted highest as they take precedent - // TODO actually check separator rules work on windows const cwd = process.cwd(); var rules = monitor.sort(function (a, b) { var r = b.split(path.sep).length - a.split(path.sep).length; diff --git a/lib/monitor/run.js b/lib/monitor/run.js index fc5e7162..59657506 100644 --- a/lib/monitor/run.js +++ b/lib/monitor/run.js @@ -68,24 +68,22 @@ function run(options) { var args = runCmd ? utils.stringify(executable, cmd.args) : ':'; var spawnArgs = [sh, [shFlag, args]]; - if (utils.version.major === 0 && utils.version.minor < 8) { - // use the old spawn args :-\ - } else { - spawnArgs.push({ - env: utils.merge(options.execOptions.env, process.env), - stdio: stdio, - }); - } + spawnArgs.push({ + env: utils.merge(options.execOptions.env, process.env), + stdio: stdio, + }); const firstArg = cmd.args[0] || ''; + // hasStdio allows us to correctly handle stdin piping + // see: https://git.io/vNtX3 + const hasStdio = utils.satisfies('>= 6.4.0 || < 5'); + if ( - // this is a hack to avoid forking if there's a node argument being passed - // it's a short term fix, and I'm not 100% sure that `fork` is the right way - firstArg.indexOf('-') === -1 && - firstArg !== 'inspect' && - executable === 'node' && - utils.version.major > 4 + firstArg.indexOf('-') === -1 && // don't fork if there's a node arg + firstArg !== 'inspect' && // don't fork it's `inspect` debugger + executable === 'node' && // only fork if node + utils.version.major > 4 // only fork if node version > 4 ) { var forkArgs = cmd.args.slice(1); var env = utils.merge(options.execOptions.env, process.env); @@ -93,6 +91,7 @@ function run(options) { child = fork(options.execOptions.script, forkArgs, { env: env, stdio: stdio, + silent: !hasStdio, }); utils.log.detail('forking'); debug(forkArgs); @@ -216,9 +215,7 @@ function run(options) { // 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) { - if (process.stdin.unpipe) { // node > 0.8 - process.stdin.unpipe(child.stdin); - } + process.stdin.unpipe(child.stdin); } if (utils.isWindows) { @@ -234,12 +231,8 @@ function run(options) { // 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 && oldPid === child.pid) { - // this is stupid and horrible, but node 0.12 on windows blows up - // with this line, so we'll skip it entirely. - if (!utils.isWindows) { - child.stdin.end(); - } + if (child && options.stdin && child.stdin && oldPid === child.pid) { + child.stdin.end(); } callback(); }); @@ -263,8 +256,12 @@ function run(options) { // swallow the stdin error if it happens // ref: https://github.com/remy/nodemon/issues/1195 - child.stdin.on('error', () => { }); - process.stdin.pipe(child.stdin); + if (hasStdio) { + child.stdin.on('error', () => { }); + process.stdin.pipe(child.stdin); + } else { + child.stdout.pipe(process.stdout); + } bus.once('exit', function () { if (child && process.stdin.unpipe) { // node > 0.8 diff --git a/lib/spawn.js b/lib/spawn.js index e098f213..d0adaeb1 100644 --- a/lib/spawn.js +++ b/lib/spawn.js @@ -1,12 +1,10 @@ -var utils = require('./utils'); -var merge = utils.merge; -var bus = utils.bus; -var childProcess = require('child_process'); -var _spawn = childProcess.spawn; +const utils = require('./utils'); +const merge = utils.merge; +const bus = utils.bus; +const spawn = require('child_process').spawn; -module.exports = function spawn(command, config, eventArgs) { +module.exports = function spawnCommand(command, config, eventArgs) { var stdio = ['pipe', 'pipe', 'pipe']; - var child = null; if (config.options.stdout) { stdio = ['pipe', process.stdout, process.stderr]; @@ -20,23 +18,18 @@ module.exports = function spawn(command, config, eventArgs) { shFlag = '/c'; } - var args = ''; if (!Array.isArray(command)) { command = [command]; } - args = command.join(' '); + const args = command.join(' '); - if (utils.version.major >= 1 || utils.version.minor >= 8) { - var env = merge(process.env, { FILENAME: eventArgs[0] }); - child = _spawn(sh, [shFlag, args], { - env: merge(config.options.execOptions.env, env), - stdio: stdio, - }); - } else { - child = spawn(sh, args); - } + const env = merge(process.env, { FILENAME: eventArgs[0] }); + const child = spawn(sh, [shFlag, args], { + env: merge(config.options.execOptions.env, env), + stdio: stdio, + }); if (config.required) { var emit = { diff --git a/lib/utils/index.js b/lib/utils/index.js index b6cde7b5..5f1f857b 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -1,8 +1,11 @@ var noop = function () { }; var path = require('path'); +const semver = require('semver'); var version = process.versions.node.split('.') || [null, null, null]; var utils = (module.exports = { + semver: semver, + satisfies: test => semver.satisfies(process.versions.node, test), version: { major: parseInt(version[0] || 0, 10), minor: parseInt(version[1] || 0, 10), diff --git a/package-lock.json b/package-lock.json index aaee6f47..29e63004 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ "@commitlint/core": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/@commitlint/core/-/core-3.2.0.tgz", - "integrity": "sha512-VnBRqhcB+zaFhNpNuMAMtanDUICVKR4t2pJBgB+1VjuHtSJIj6TBrUYs/FHpI65RDwvfpjNM/OPFa0FyqzN8PA==", + "integrity": "sha1-MXU+dy0JS3LKmKXwWP5WFeVMeac=", "dev": true, "requires": { "babel-runtime": "6.26.0", @@ -50,7 +50,7 @@ "@semantic-release/commit-analyzer": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/@semantic-release/commit-analyzer/-/commit-analyzer-3.0.7.tgz", - "integrity": "sha512-bxCvvDsZeQp6Fvev8CdAV4pu9rEt8NOuLIFS0E8RLjKRnqQVL/fGAwpQWnRQ5hc08UZroguBNEENWpKBubWmKQ==", + "integrity": "sha1-3JVURKbT0q6bjiH5DCyAxOkUKy8=", "dev": true, "requires": { "@semantic-release/error": "2.1.0", @@ -81,7 +81,7 @@ "@semantic-release/condition-travis": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/@semantic-release/condition-travis/-/condition-travis-6.2.1.tgz", - "integrity": "sha512-0g8O/OObhqjAotztjPjMJ43I6oX05z/Ffdu6HMsScDgLX1+QQzq5w0HnUxjmiXUGNwqi5M6s7BF65ZKHbGOytQ==", + "integrity": "sha1-40IeW85H8nBX1mq6155DI4JCeYI=", "dev": true, "requires": { "@semantic-release/error": "2.1.0", @@ -110,13 +110,13 @@ "@semantic-release/error": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@semantic-release/error/-/error-2.1.0.tgz", - "integrity": "sha512-r3pcw7lhzoSalM55O7L8R3gNq8AnZ7OS7RReHqJDTIuyRaQbtfZ+9S8Krvh/BSnTMYYhs4TgZctb6pOamegUtQ==", + "integrity": "sha1-RHcfZ29bFI2jCREShal5AaqVpuA=", "dev": true }, "@semantic-release/last-release-npm": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@semantic-release/last-release-npm/-/last-release-npm-2.0.2.tgz", - "integrity": "sha512-ge5AWWtcrEd6GeG4tsv8gx774G9aPNrrornjBBqNDqN7Eg/xI914ftcnmSgnsbmKcqmq4g+QElIJhNMvsfpOkQ==", + "integrity": "sha1-yRscy0iw1wlbEHvm68LAwIvYjCc=", "dev": true, "requires": { "@semantic-release/error": "2.1.0", @@ -127,7 +127,7 @@ "@semantic-release/release-notes-generator": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/@semantic-release/release-notes-generator/-/release-notes-generator-4.0.5.tgz", - "integrity": "sha512-LznqPnifl8jtQkV5ZXnQbqMLx9QROoX5d/FLteLyKy3AznLSubm5rH0LndKvf9ZI8XU8jwgLYu+wbLAEIR2PPg==", + "integrity": "sha1-RswvFr22D+lnS7zWFr/g+Ls1NHw=", "dev": true, "requires": { "@semantic-release/error": "2.1.0", @@ -158,12 +158,12 @@ "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" + "integrity": "sha1-+PLIh60Qv2f2NPAFtph/7TF5qsg=" }, "agent-base": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.1.2.tgz", - "integrity": "sha512-VE6QoEdaugY86BohRtfGmTDabxdU5sCKOkbcPA6PXKJsRzEi/7A3RCTxJal1ft/4qSfPht5/iQLhMh/wzSkkNw==", + "integrity": "sha1-gPps3kQPTc+a8mF88kYJm12Z8Mg=", "dev": true, "requires": { "es6-promisify": "5.0.0" @@ -202,7 +202,7 @@ "ansi-styles": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", - "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", + "integrity": "sha1-wVm41b4PnlpvNG2rlPFs4CIWG4g=", "requires": { "color-convert": "1.9.1" } @@ -213,19 +213,10 @@ "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8=", "dev": true }, - "anymatch": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.2.tgz", - "integrity": "sha512-0XNayC8lTHQ2OI8aljNCN3sSx6hsr/1+rlcDAotXJR7C1oZZHCNsfpbKwMjRA3Uqb5tF1Rae2oloTr4xpq+WjA==", - "requires": { - "micromatch": "2.3.11", - "normalize-path": "2.1.1" - } - }, "aproba": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "integrity": "sha1-aALmJk79GMeQobDVF/DyYnvyyUo=", "dev": true }, "are-we-there-yet": { @@ -258,7 +249,7 @@ "arr-flatten": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.1.0.tgz", - "integrity": "sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg==" + "integrity": "sha1-NgSLv/TntH4TZkQxbJlmnqWukfE=" }, "array-find-index": { "version": "1.0.2", @@ -338,7 +329,7 @@ "babylon": { "version": "6.18.0", "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz", - "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==", + "integrity": "sha1-ry87iPpvXB5MY00aD46sT1WzleM=", "dev": true }, "balanced-match": { @@ -404,7 +395,7 @@ "boxen": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/boxen/-/boxen-1.3.0.tgz", - "integrity": "sha512-TNPjfTr432qx7yOjQyaXm3dSR0MH9vXp7eT1BFSl/C51g+EFnOR9hTg1IreahGBmDNCehscshe45f+C1TBZbLw==", + "integrity": "sha1-VcbDmouljZxhrSLNh3Uy3rZlogs=", "requires": { "ansi-align": "2.0.0", "camelcase": "4.1.0", @@ -494,7 +485,7 @@ "chalk": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz", - "integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==", + "integrity": "sha1-tepI78nBeT3MybR2fJORTT8tUro=", "requires": { "ansi-styles": "3.2.0", "escape-string-regexp": "1.0.5", @@ -515,12 +506,23 @@ "is-glob": "2.0.1", "path-is-absolute": "1.0.1", "readdirp": "2.1.0" + }, + "dependencies": { + "anymatch": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.2.tgz", + "integrity": "sha512-0XNayC8lTHQ2OI8aljNCN3sSx6hsr/1+rlcDAotXJR7C1oZZHCNsfpbKwMjRA3Uqb5tF1Rae2oloTr4xpq+WjA==", + "requires": { + "micromatch": "2.3.11", + "normalize-path": "2.1.1" + } + } } }, "ci-info": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-1.1.2.tgz", - "integrity": "sha512-uTGIPNx/nSpBdsF6xnseRXLLtfr9VLqkz8ZqHXr3Y7b6SftyRxBGjwMtJj1OhNbmlc1wZzLNAlAcvyIiE8a6ZA==", + "integrity": "sha1-A1YSWdtI0EdMi9yQ9bR7Botrv7Q=", "dev": true }, "cli-boxes": { @@ -576,7 +578,7 @@ "color-convert": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz", - "integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==", + "integrity": "sha1-wSYRB66y8pTr/+ye2eytUppgl+0=", "requires": { "color-name": "1.1.3" } @@ -669,7 +671,7 @@ "configstore": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/configstore/-/configstore-3.1.1.tgz", - "integrity": "sha512-5oNkD/L++l0O6xGXxb1EWS7SivtjfGQlRyxJsYgE0Z495/L81e2h4/d3r969hoPXuFItzNOKMtsXgYG4c7dYvw==", + "integrity": "sha1-CU7mYquD+tmRdnjeEU+q6o/NypA=", "requires": { "dot-prop": "4.2.0", "graceful-fs": "4.1.11", @@ -833,7 +835,7 @@ "cst": { "version": "0.4.10", "resolved": "https://registry.npmjs.org/cst/-/cst-0.4.10.tgz", - "integrity": "sha512-U5ETe1IOjq2h56ZcBE3oe9rT7XryCH6IKgPMv0L7sSk6w29yR3p5egCK0T3BDNHHV95OoUBgXsqiVG+3a900Ag==", + "integrity": "sha1-nAXIJSkKdi8KhcCqu4wP4DWuhRY=", "dev": true, "requires": { "babel-runtime": "6.26.0", @@ -1001,7 +1003,7 @@ "dot-prop": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", - "integrity": "sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ==", + "integrity": "sha1-HxngwuGqDjJ5fEl5nyg3rGr2nFc=", "requires": { "is-obj": "1.0.1" } @@ -1211,7 +1213,7 @@ "follow-redirects": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.2.6.tgz", - "integrity": "sha512-FrMqZ/FONtHnbqO651UPpfRUVukIEwJhXMfdr/JWAmrDbeYBu773b1J6gdWDyRIj4hvvzQEHoEOTrdR8o6KLYA==", + "integrity": "sha1-Tc3H5Ks91nZal/+Jw7TCWBF8eb8=", "dev": true, "requires": { "debug": "3.1.0" @@ -1220,7 +1222,7 @@ "debug": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "integrity": "sha1-W7WgZyYotkFJVmuhaBnmFRjGcmE=", "dev": true, "requires": { "ms": "2.0.0" @@ -1309,7 +1311,7 @@ "fsevents": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz", - "integrity": "sha512-WIr7iDkdmdbxu/Gh6eKEZJL6KPE74/5MEsf2whTOFNxbIoIixogroLdKYqB6FDav4Wavh/lZdzzd3b2KxIXC5Q==", + "integrity": "sha1-EfgjGPX+e7LNIpZaEI6TBiCCFtg=", "optional": true, "requires": { "nan": "2.8.0", @@ -2536,7 +2538,7 @@ "hosted-git-info": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.5.0.tgz", - "integrity": "sha512-pNgbURSuab90KbTqvRPsseaTxOJCZBD0a7t+haSN33piP9cCM4l0CqdzAif2hUqm716UovKB2ROmiabGAKVXyg==", + "integrity": "sha1-bWDjSzq7yDEwYsO3mO+NkBoHrzw=", "dev": true }, "htmlparser2": { @@ -2600,7 +2602,7 @@ "https-proxy-agent": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.1.1.tgz", - "integrity": "sha512-LK6tQUR/VOkTI6ygAfWUKKP95I+e6M1h7N3PncGu1CATHCnex+CAv9ttR0lbHu1Uk2PXm/WoAHFo6JCGwMjVMw==", + "integrity": "sha1-p85DgqG6gmbuhIV4d4Ei1JEmD9k=", "dev": true, "requires": { "agent-base": "4.1.2", @@ -2610,7 +2612,7 @@ "debug": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "integrity": "sha1-W7WgZyYotkFJVmuhaBnmFRjGcmE=", "dev": true, "requires": { "ms": "2.0.0" @@ -2706,7 +2708,7 @@ "ini": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" + "integrity": "sha1-7uJfVtscnsYIXgwid4CD9Zar+Sc=" }, "is-arrayish": { "version": "0.2.1", @@ -2725,7 +2727,7 @@ "is-buffer": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", - "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==" + "integrity": "sha1-76ouqdqg16suoTqXsritUf776L4=" }, "is-builtin-module": { "version": "1.0.0", @@ -3021,7 +3023,7 @@ "js-yaml": { "version": "3.10.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz", - "integrity": "sha512-O2v52ffjLa9VeM43J4XocZE//WT9N0IiwDa3KSHH7Tu8CtH+1qM8SIZvnsTh6v+4yFy5KUY3BHUVwjpfAWsjIA==", + "integrity": "sha1-LnhEFka9RoLpY/IrbpKCPDCcYtw=", "dev": true, "requires": { "argparse": "1.0.9", @@ -3031,7 +3033,7 @@ "esprima": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", - "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==", + "integrity": "sha1-RJnt3NERDgshi6zy+n9/WfVcqAQ=", "dev": true } } @@ -3448,7 +3450,7 @@ "lru-cache": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.1.tgz", - "integrity": "sha512-q4spe4KTfsAS1SUHLO0wz8Qiyf1+vMIAgpRYioFYDMNqKfHQbg+AVDH3i4fvpl71/P1L0dBl+fQi+P37UYf0ew==", + "integrity": "sha1-Yi4y6CSItJJ5EUpPns9F581rulU=", "requires": { "pseudomap": "1.0.2", "yallist": "2.1.2" @@ -3457,7 +3459,7 @@ "make-dir": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.1.0.tgz", - "integrity": "sha512-0Pkui4wLJ7rxvmfUvs87skoEaxmu0hCUApF8nonzpl7q//FWp9zu8W61Scz4sd/kUiqDxvUhtoam2efDyiBzcA==", + "integrity": "sha1-GbQ2n+SMEW9Twq+VrRAsDjnoXVE=", "requires": { "pify": "3.0.0" } @@ -3671,7 +3673,7 @@ "mz": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", - "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", + "integrity": "sha1-lQCAV6Vsr63CvGPd5/n/aVWUjjI=", "dev": true, "requires": { "any-promise": "1.3.0", @@ -3767,7 +3769,7 @@ "normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", - "integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==", + "integrity": "sha1-EvlaMH1YNSB1oEkHuErIvpisAS8=", "dev": true, "requires": { "hosted-git-info": "2.5.0", @@ -3787,7 +3789,7 @@ "npm-package-arg": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/npm-package-arg/-/npm-package-arg-5.1.2.tgz", - "integrity": "sha512-wJBsrf0qpypPT7A0LART18hCdyhpCMxeTtcb0X4IZO2jsP6Om7EHN1d9KSKiqD+KVH030RVNpWS9thk+pb7wzA==", + "integrity": "sha1-+xjRe7YeYJANYxJhmRm9dTdVqzc=", "dev": true, "requires": { "hosted-git-info": "2.5.0", @@ -3799,7 +3801,7 @@ "npm-registry-client": { "version": "8.5.0", "resolved": "https://registry.npmjs.org/npm-registry-client/-/npm-registry-client-8.5.0.tgz", - "integrity": "sha512-Nkcw24bfECKFNt0FLDQ+PjVqSlKxMggcboXiUBIvjbCnA15xjRO4kCwRDluGNXZjHFLx/vPjN4+ESXyVjpXLbQ==", + "integrity": "sha1-SHj7b6Hxil3Aiug6z5TQ0BEtftA=", "dev": true, "requires": { "concat-stream": "1.6.0", @@ -3884,7 +3886,7 @@ "npmlog": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", - "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "integrity": "sha1-CKfyqL9zRgR3mp76StXMcXq7lUs=", "dev": true, "requires": { "are-we-there-yet": "1.1.4", @@ -4224,7 +4226,7 @@ "pstree.remy": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.0.tgz", - "integrity": "sha512-q5I5vLRMVtdWa8n/3UEzZX7Lfghzrg9eG2IKk2ENLSofKRCXVqMvMUHxCKgXNaqH/8ebhBxrqftHWnyTFweJ5Q==", + "integrity": "sha1-8q8nJlvT5bMrv8wQ6AusVbp4aIs=", "requires": { "ps-tree": "1.1.0" } @@ -4250,7 +4252,7 @@ "randomatic": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz", - "integrity": "sha512-D5JUjPyJbaJDkuAazpVnSfVkLlpeO3wDlPROTMLGKG1zMFNFRgrciKo1ltz/AzNTkqE0HzDx655QOL51N06how==", + "integrity": "sha1-x6vpzIuHwLqodrGf3oP9RkeX44w=", "requires": { "is-number": "3.0.0", "kind-of": "4.0.0" @@ -4349,7 +4351,7 @@ "readable-stream": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", - "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==", + "integrity": "sha1-No8lEtefnUb9/HE0mueHi7weuVw=", "requires": { "core-util-is": "1.0.2", "inherits": "2.0.3", @@ -4390,7 +4392,7 @@ "regex-cache": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/regex-cache/-/regex-cache-0.4.4.tgz", - "integrity": "sha512-nVIZwtCjkC9YgvWkpM55B5rBhBYRZhAaJbgcFYXXsHnbZ9UZI9nnVWYZpBlCqv9ho2eZryPnWrZGsOdPwVWXWQ==", + "integrity": "sha1-db3FiioUls7EihKDW8VMjVYjNt0=", "requires": { "is-equal-shallow": "0.1.3" } @@ -4514,7 +4516,7 @@ "rimraf": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", - "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "integrity": "sha1-LtgVDSShbqhlHm1u8PR8QVjOejY=", "dev": true, "requires": { "glob": "7.1.2" @@ -4523,7 +4525,7 @@ "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=", "dev": true, "requires": { "fs.realpath": "1.0.0", @@ -4539,7 +4541,7 @@ "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + "integrity": "sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=" }, "semantic-release": { "version": "8.2.0", @@ -4598,7 +4600,7 @@ "semver": { "version": "5.4.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", - "integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg==" + "integrity": "sha1-4FnAnYVx8FQII3M0M1BdOi8AsY4=" }, "semver-diff": { "version": "2.1.0", @@ -4683,7 +4685,7 @@ "source-map-support": { "version": "0.4.18", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", - "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", + "integrity": "sha1-Aoam3ovkJkEzhZTpfM6nXwosWF8=", "dev": true, "requires": { "source-map": "0.5.7" @@ -4729,7 +4731,7 @@ "split2": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/split2/-/split2-2.2.0.tgz", - "integrity": "sha512-RAb22TG39LhI31MbreBgIuKiIKhVsawfTgEGqKHTK87aG+ul/PB8Sqoi3I7kVdRWiCfrKxK3uo4/YUkpNvhPbw==", + "integrity": "sha1-GGsldbz4PoW30YRldWI47k7kJJM=", "dev": true, "requires": { "through2": "2.0.3" @@ -4768,7 +4770,7 @@ "ssri": { "version": "4.1.6", "resolved": "https://registry.npmjs.org/ssri/-/ssri-4.1.6.tgz", - "integrity": "sha512-WUbCdgSAMQjTFZRWvSPpauryvREEA+Krn19rx67UlJEJx/M192ZHxMmJXjZ4tkdFm+Sb0SXGlENeQVlA5wY7kA==", + "integrity": "sha1-DLSbashEV+e91GbLcww8tiPpols=", "dev": true, "requires": { "safe-buffer": "5.1.1" @@ -4797,7 +4799,7 @@ "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "integrity": "sha1-q5Pyeo3BPSjKyBXEYhQ6bZASrp4=", "requires": { "is-fullwidth-code-point": "2.0.0", "strip-ansi": "4.0.0" @@ -4806,7 +4808,7 @@ "string_decoder": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "integrity": "sha1-D8Z9fBQYJd6UKC3VNr7GubzoYKs=", "requires": { "safe-buffer": "5.1.1" } @@ -4880,7 +4882,7 @@ "text-extensions": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/text-extensions/-/text-extensions-1.7.0.tgz", - "integrity": "sha512-AKXZeDq230UaSzaO5s3qQUZOaC7iKbzq0jOFL614R7d9R593HLqAOL0cYoqLdkNrjBSOdmoQI06yigq1TSBXAg==", + "integrity": "sha1-+qq6JiXtdG1WiiPk0KrNm/CKizk=", "dev": true }, "thenify": { @@ -5232,7 +5234,7 @@ "vow": { "version": "0.4.17", "resolved": "https://registry.npmjs.org/vow/-/vow-0.4.17.tgz", - "integrity": "sha512-A3/9bWFqf6gT0jLR4/+bT+IPTe1mQf+tdsW6+WI5geP9smAp8Kbbu4R6QQCDKZN/8TSCqTlXVQm12QliB4rHfg==", + "integrity": "sha1-sW4I+uWMUvPrxodfJEGyapJoKQQ=", "dev": true }, "vow-fs": { @@ -5250,7 +5252,7 @@ "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=", "dev": true, "requires": { "fs.realpath": "1.0.0", @@ -5266,7 +5268,7 @@ "vow-queue": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/vow-queue/-/vow-queue-0.4.3.tgz", - "integrity": "sha512-/poAKDTFL3zYbeQg7cl4BGcfP4sGgXKrHnRFSKj97dteUFu8oyXMwIcdwu8NSx/RmPGIuYx1Bik/y5vU4H/VKw==", + "integrity": "sha1-S6j2S1bpISwNvlfxQFruvVTM540=", "dev": true, "requires": { "vow": "0.4.17" @@ -5284,7 +5286,7 @@ "which": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz", - "integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==", + "integrity": "sha1-/wS9/AEO5UfXgL7DjhrBwnd9JTo=", "requires": { "isexe": "2.0.0" } @@ -5292,7 +5294,7 @@ "wide-align": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz", - "integrity": "sha512-ijDLlyQ7s6x1JgCLur53osjm/UXUYD9+0PbYKrBsYisYXzCxN+HC3mYDNy/dWdmf3AwqwU3CXwDCvsNgGK1S0w==", + "integrity": "sha1-Vx4PGwYEY268DfwhsDObvjE0FxA=", "dev": true, "requires": { "string-width": "1.0.2" @@ -5393,7 +5395,7 @@ "write-file-atomic": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.3.0.tgz", - "integrity": "sha512-xuPeK4OdjWqtfi59ylvVL0Yn35SF3zgcAcv7rBPFHVaEapaDr4GdGgm3j7ckTwH9wHL7fGmgfAnb0+THrHb8tA==", + "integrity": "sha1-H/YVdcLipOjlENb6TiQ8zhg5mas=", "requires": { "graceful-fs": "4.1.11", "imurmurhash": "0.1.4", diff --git a/package.json b/package.json index a4f0434b..7ef081bd 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "web": "node web", "semantic-release": "semantic-release pre && npm publish && semantic-release post", "prepush": "npm run lint", + "killall": "ps auxww | grep node | grep -v grep | awk '{ print $2 }' | xargs kill -9", "postinstall": "node -e \"console.log('\\u001b[32mLove nodemon? You can now support the project via the open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[96m\\u001b[1mhttps://opencollective.com/nodemon/donate\\u001b[0m\\n')\" || exit 0" }, "devDependencies": { @@ -58,6 +59,7 @@ "ignore-by-default": "^1.0.1", "minimatch": "^3.0.4", "pstree.remy": "^1.1.0", + "semver": "^5.4.1", "touch": "^3.1.0", "undefsafe": "0.0.3", "update-notifier": "^2.3.0" diff --git a/test/events/complete.test.js b/test/events/complete.test.js index 039b60d7..46aba41b 100644 --- a/test/events/complete.test.js +++ b/test/events/complete.test.js @@ -89,27 +89,6 @@ describe('events should follow normal flow on user triggered change', }); }); - // it('quit', function (done) { - // var cmd = asCLI('env.js'); - // cmd.exec = path.join('..', '..', '..', cmd.exec); - // var p = fork(cmd.exec, cmd.args, { - // cwd: dir, - // silent: true, - // detached: true, - // }); - // p.stdout.on('data', function (m) { - // m = m.toString().trim(); - // if (m === 'STOPPED') { - // p.kill('SIGINT'); - // } - // if (m === 'QUIT') { - // assert(true, '"quit" event'); - // done(); - // } - // }); - // }); - - it('stdout', function (done) { nodemon(conf()).once('stdout', function (data) { assert(true, '"stdout" event with: ' + data); diff --git a/test/fork/change-detect.test.js b/test/fork/change-detect.test.js index 961f3af2..840a8a92 100644 --- a/test/fork/change-detect.test.js +++ b/test/fork/change-detect.test.js @@ -1,14 +1,14 @@ 'use strict'; /*global describe:true, it: true */ var utils = require('../utils'), - colour = require('../../lib/utils/colour'), - assert = require('assert'), - touch = require('touch'), - appjs = utils.appjs, - appcoffee = utils.appcoffee, - match = utils.match, - cleanup = utils.cleanup, - run = utils.run; + colour = require('../../lib/utils/colour'), + assert = require('assert'), + touch = require('touch'), + appjs = utils.appjs, + appcoffee = utils.appcoffee, + match = utils.match, + cleanup = utils.cleanup, + run = utils.run; describe('nodemon fork simply running', function () { it('should start', function (done) { @@ -39,13 +39,13 @@ describe('nodemon fork monitor', function () { if (startWatch && match(data, 'changes after filters')) { var changes = colour.strip(data.trim()); var restartedOn = null; - changes.replace(/changes after filters \(before\/after\): \d+\/(\d+)/, function (all, m) { + changes.replace(/changes after filters \(before\/after\): \d+\/(\d+)/, (_, m) => { restartedOn = m; }); // .split('changes after filters').pop().split('/'); // var restartedOn = changes.pop().trim(); - assert(restartedOn === '1', 'nodemon restarted on 1 file: ' + restartedOn + ' / ' + data.toString()); + assert.equal(restartedOn, '1', 'nodemon restarted on 1 file: ' + restartedOn + ' / ' + data.toString()); } }, error: function (data) { @@ -59,7 +59,7 @@ describe('nodemon fork monitor', function () { } else if (event.type === 'start') { setTimeout(function () { touch.sync(appjs); - }, 2500); + }, 1000); } }); }); @@ -69,10 +69,11 @@ describe('nodemon fork monitor', function () { var p = run(appjs, { output: function (data) { if (match(data, 'changes after filters')) { - var changes = colour.strip(data.trim()).slice(-5).split('/'); + data = colour.strip(data.toString().trim()); + var changes = data.split('/'); var restartedOn = changes.pop(); - assert(restartedOn === '0', 'expects to not have restarted'); + assert.equal(restartedOn, '0', 'expects to not have restarted'); utils.cleanup(p, done); } }, @@ -91,6 +92,6 @@ describe('nodemon fork monitor', function () { utils.cleanup(p, done, new Error('nodemon restarted')); } }); - }, 2000); + }, 1000); }); }); diff --git a/test/monitor/match.test.js b/test/monitor/match.test.js index 1a114d6a..8e784b61 100644 --- a/test/monitor/match.test.js +++ b/test/monitor/match.test.js @@ -1,15 +1,15 @@ 'use strict'; /*global describe:true, it: true */ var assert = require('assert'), - match = require('../../lib/monitor/match'), - config = require('../../lib/config'), - path = require('path'), - fs = require('fs'), - nodemonUtils = require('../../lib/utils'), - defaults = require('../../lib/config/defaults'), - utils = require('../utils'), - watch = require('../../lib/monitor/watch'), - merge = nodemonUtils.merge; + match = require('../../lib/monitor/match'), + config = require('../../lib/config'), + path = require('path'), + fs = require('fs'), + nodemonUtils = require('../../lib/utils'), + defaults = require('../../lib/config/defaults'), + utils = require('../utils'), + watch = require('../../lib/monitor/watch'), + merge = nodemonUtils.merge; describe('match', function () { var monitor = [ @@ -22,6 +22,17 @@ describe('match', function () { '!*.coffee', ]; + it('should handle lots of **s!', () => { + const res = match(['test/fixtures/app.js'], ['*.*', + '!**/.git/**', + '!**/.nyc_output/**', + '!**/.sass-cache/**', + '!**/bower_components/**', + '!**/coverage/**'], 'js,mjs,json'); + + assert.equal(res.result.length, 1, JSON.stringify(res)); + }) + it('should match zero files', function () { var files = [ 'views/server/remy.coffee', @@ -144,7 +155,7 @@ describe('match', function () { it('should support old .nodemonignore', function (done) { // prevents our test from finding the nodemon.json files var pwd = process.cwd(), - old = nodemonUtils.home; + old = nodemonUtils.home; process.chdir(path.resolve(pwd, 'test/fixtures/legacy')); nodemonUtils.home = path.resolve(pwd, 'test/fixtures/legacy'); @@ -356,10 +367,10 @@ describe('watcher', function () { ignoreRoot: [] }, function (config) { return watch.watch() - .then(function () { - done(); - }) - .catch(done) + .then(function () { + done(); + }) + .catch(done) }) }); @@ -368,14 +379,14 @@ describe('watcher', function () { watch: ['test/fixtures/*'] }, function (config) { return watch.watch() - .then(function (files) { - var withDotfile = files.filter(function (file) { - return /test\/fixtures\/\.dotfile$/.test(file); - }); - assert.deepEqual(withDotfile.length, 0, 'should not contain .dotfile'); - done(); - }) - .catch(done); + .then(function (files) { + var withDotfile = files.filter(function (file) { + return /test\/fixtures\/\.dotfile$/.test(file); + }); + assert.deepEqual(withDotfile.length, 0, 'should not contain .dotfile'); + done(); + }) + .catch(done); }) }); @@ -384,11 +395,11 @@ describe('watcher', function () { watch: ['test/fixtures/.dotfile'] }, function (config) { return watch.watch() - .then(function (files) { - assert.deepEqual(files.length, 1, 'should contain .dotfile'); - done(); - }) - .catch(done); + .then(function (files) { + assert.deepEqual(files.length, 1, 'should contain .dotfile'); + done(); + }) + .catch(done); }) }); @@ -397,11 +408,11 @@ describe('watcher', function () { watch: ['test/fixtures/.dotfolder'] }, function (config) { return watch.watch() - .then(function (files) { - assert.deepEqual(files.length, 3, 'file lists should contain .dotfolder files'); - done(); - }) - .catch(done); + .then(function (files) { + assert.deepEqual(files.length, 3, 'file lists should contain .dotfolder files'); + done(); + }) + .catch(done); }) }); });