diff options
Diffstat (limited to 'node_modules/foreground-child')
-rw-r--r-- | node_modules/foreground-child/CHANGELOG.md | 93 | ||||
-rw-r--r-- | node_modules/foreground-child/LICENSE | 15 | ||||
-rw-r--r-- | node_modules/foreground-child/README.md | 52 | ||||
-rw-r--r-- | node_modules/foreground-child/changelog.sh | 10 | ||||
-rw-r--r-- | node_modules/foreground-child/index.js | 102 | ||||
-rw-r--r-- | node_modules/foreground-child/package.json | 34 |
6 files changed, 306 insertions, 0 deletions
diff --git a/node_modules/foreground-child/CHANGELOG.md b/node_modules/foreground-child/CHANGELOG.md new file mode 100644 index 000000000..dc5a25082 --- /dev/null +++ b/node_modules/foreground-child/CHANGELOG.md @@ -0,0 +1,93 @@ +# Changes + + +## v1.5.6 + +* Fix 'childHangup is undefined' + +## v1.5.5 + +* add files list to package.json +* neveragain.tech pledge request + +## v1.5.4 + +* update tap to v8 +* Let the child decide if signals should be fatal + +## v1.5.3 + +* bump deps + +## v1.5.2 + +* add an automatic changelog script +* replace cross-spawn-async with cross-spawn +* test: stay alive long enough to be signaled + +## v1.5.1 + +* avoid race condition in test +* Use fd numbers instead of 'inherit' for Node v0.10 compatibility + +## v1.5.0 + +* add caveats re IPC and arbitrary FDs +* Forward IPC messages to foregrounded child process + +## v1.4.0 + +* Set `process.exitCode` based on the child’s exit code + +## v1.3.5 + +* Better testing for when cross-spawn-async needed +* appveyor: node v0.10 on windows is too flaky + +## v1.3.4 + +* Only use cross-spawn-async for shebangs +* update vanity badges and package.json for repo move +* appveyor + +## v1.3.3 + +* Skip signals in tests on Windows +* update to tap@4 +* use cross-spawn-async on windows + +## v1.3.2 + +* Revert "switch to win-spawn" +* Revert "Transparently translate high-order exit code to appropriate signal" +* update travis versions +* Transparently translate high-order exit code to appropriate signal +* ignore coverage folder + +## v1.3.1 + +* switch to win-spawn + +## v1.3.0 + +* note skipped test in test output +* left an unused var c in +* slice arguments, added documentation +* added a unit test, because I strive to be a good open-source-citizen +* make travis also work on 0.12 and iojs again +* added badge +* patch for travis exit weirdness +* fix typo in .gitignore +* beforeExit hook + +## v1.2.0 + +* Use signal-exit, fix kill(process.pid) race + +## v1.1.0 + +* Enforce that parent always gets a 'exit' event + +## v1.0.0 + +* first diff --git a/node_modules/foreground-child/LICENSE b/node_modules/foreground-child/LICENSE new file mode 100644 index 000000000..19129e315 --- /dev/null +++ b/node_modules/foreground-child/LICENSE @@ -0,0 +1,15 @@ +The ISC License + +Copyright (c) Isaac Z. Schlueter and Contributors + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/node_modules/foreground-child/README.md b/node_modules/foreground-child/README.md new file mode 100644 index 000000000..d388f9500 --- /dev/null +++ b/node_modules/foreground-child/README.md @@ -0,0 +1,52 @@ +# foreground-child + +[](https://travis-ci.org/tapjs/foreground-child) [](https://ci.appveyor.com/project/isaacs/foreground-child) + +Run a child as if it's the foreground process. Give it stdio. Exit +when it exits. + +Mostly this module is here to support some use cases around wrapping +child processes for test coverage and such. + +## USAGE + +```js +var foreground = require('foreground-child') + +// cats out this file +var child = foreground('cat', [__filename]) + +// At this point, it's best to just do nothing else. +// return or whatever. +// If the child gets a signal, or just exits, then this +// parent process will exit in the same way. +``` + +A callback can optionally be provided, if you want to perform an action +before your foreground-child exits: + +```js +var child = foreground('cat', [__filename], function (done) { + // perform an action. + return done() +}) +``` + +## Caveats + +The "normal" standard IO file descriptors (0, 1, and 2 for stdin, +stdout, and stderr respectively) are shared with the child process. +Additionally, if there is an IPC channel set up in the parent, then +messages are proxied to the child on file descriptor 3. + +However, in Node, it's possible to also map arbitrary file descriptors +into a child process. In these cases, foreground-child will not map +the file descriptors into the child. If file descriptors 0, 1, or 2 +are used for the IPC channel, then strange behavior may happen (like +printing IPC messages to stderr, for example). + +Note that a SIGKILL will always kill the parent process, _and never +the child process_, because SIGKILL cannot be caught or proxied. The +only way to do this would be if Node provided a way to truly exec a +process as the new foreground program in the same process space, +without forking a separate child process. diff --git a/node_modules/foreground-child/changelog.sh b/node_modules/foreground-child/changelog.sh new file mode 100644 index 000000000..be61b4f70 --- /dev/null +++ b/node_modules/foreground-child/changelog.sh @@ -0,0 +1,10 @@ +#!/bin/bash +( + echo '# Changes' + echo '' + git log --first-parent --pretty=format:'%s' \ + | grep -v '^update changelog' \ + | grep -v 'beta' \ + | perl -p -e 's/^((v?[0-9]+\.?)+)?$/\n## \1\n/g' \ + | perl -p -e 's/^([^#\s].*)$/* \1/g' +)> CHANGELOG.md diff --git a/node_modules/foreground-child/index.js b/node_modules/foreground-child/index.js new file mode 100644 index 000000000..32ae9ff57 --- /dev/null +++ b/node_modules/foreground-child/index.js @@ -0,0 +1,102 @@ +var signalExit = require('signal-exit') +var spawn = require('child_process').spawn +if (process.platform === 'win32') { + spawn = require('cross-spawn') +} + +module.exports = function (program, args, cb) { + var arrayIndex = arguments.length + + if (typeof args === 'function') { + cb = args + args = undefined + } else { + cb = Array.prototype.slice.call(arguments).filter(function (arg, i) { + if (typeof arg === 'function') { + arrayIndex = i + return true + } + })[0] + } + + cb = cb || function (done) { + return done() + } + + if (Array.isArray(program)) { + args = program.slice(1) + program = program[0] + } else if (!Array.isArray(args)) { + args = [].slice.call(arguments, 1, arrayIndex) + } + + var spawnOpts = { stdio: [0, 1, 2] } + + if (process.send) { + spawnOpts.stdio.push('ipc') + } + + var child = spawn(program, args, spawnOpts) + + var childExited = false + var unproxySignals = proxySignals(child) + process.on('exit', childHangup) + function childHangup () { + child.kill('SIGHUP') + } + + child.on('close', function (code, signal) { + // Allow the callback to inspect the child’s exit code and/or modify it. + process.exitCode = signal ? 128 + signal : code + + cb(function () { + unproxySignals() + process.removeListener('exit', childHangup) + childExited = true + if (signal) { + // If there is nothing else keeping the event loop alive, + // then there's a race between a graceful exit and getting + // the signal to this process. Put this timeout here to + // make sure we're still alive to get the signal, and thus + // exit with the intended signal code. + setTimeout(function () {}, 200) + process.kill(process.pid, signal) + } else { + // Equivalent to process.exit() on Node.js >= 0.11.8 + process.exit(process.exitCode) + } + }) + }) + + if (process.send) { + process.removeAllListeners('message') + + child.on('message', function (message, sendHandle) { + process.send(message, sendHandle) + }) + + process.on('message', function (message, sendHandle) { + child.send(message, sendHandle) + }) + } + + return child +} + +function proxySignals (child) { + var listeners = {} + signalExit.signals().forEach(function (sig) { + listeners[sig] = function () { + child.kill(sig) + } + process.on(sig, listeners[sig]) + }) + + return unproxySignals + + function unproxySignals () { + for (var sig in listeners) { + process.removeListener(sig, listeners[sig]) + } + } +} diff --git a/node_modules/foreground-child/package.json b/node_modules/foreground-child/package.json new file mode 100644 index 000000000..d0921683f --- /dev/null +++ b/node_modules/foreground-child/package.json @@ -0,0 +1,34 @@ +{ + "name": "foreground-child", + "version": "1.5.6", + "description": "Run a child as if it's the foreground process. Give it stdio. Exit when it exits.", + "main": "index.js", + "directories": { + "test": "test" + }, + "dependencies": { + "cross-spawn": "^4", + "signal-exit": "^3.0.0" + }, + "devDependencies": { + "tap": "^8.0.1" + }, + "scripts": { + "test": "tap --coverage test/*.js", + "changelog": "bash changelog.sh", + "postversion": "npm run changelog && git add CHANGELOG.md && git commit -m 'update changelog - '${npm_package_version}" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/tapjs/foreground-child.git" + }, + "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", + "license": "ISC", + "bugs": { + "url": "https://github.com/tapjs/foreground-child/issues" + }, + "homepage": "https://github.com/tapjs/foreground-child#readme", + "files": [ + "index.js" + ] +} |