aboutsummaryrefslogtreecommitdiff
path: root/node_modules/flagged-respawn
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/flagged-respawn')
-rw-r--r--node_modules/flagged-respawn/.npmignore1
-rw-r--r--node_modules/flagged-respawn/.travis.yml9
-rw-r--r--node_modules/flagged-respawn/README.md35
-rw-r--r--node_modules/flagged-respawn/index.js38
-rw-r--r--node_modules/flagged-respawn/lib/reorder.js4
-rw-r--r--node_modules/flagged-respawn/lib/respawn.js1
-rw-r--r--node_modules/flagged-respawn/package.json26
-rw-r--r--node_modules/flagged-respawn/test/bin/exit_code.js13
-rw-r--r--node_modules/flagged-respawn/test/bin/respawner.js17
-rw-r--r--node_modules/flagged-respawn/test/bin/signal.js16
-rw-r--r--node_modules/flagged-respawn/test/index.js99
11 files changed, 90 insertions, 169 deletions
diff --git a/node_modules/flagged-respawn/.npmignore b/node_modules/flagged-respawn/.npmignore
deleted file mode 100644
index a1dca7a54..000000000
--- a/node_modules/flagged-respawn/.npmignore
+++ /dev/null
@@ -1 +0,0 @@
-*.flags.json
diff --git a/node_modules/flagged-respawn/.travis.yml b/node_modules/flagged-respawn/.travis.yml
deleted file mode 100644
index e37da77f8..000000000
--- a/node_modules/flagged-respawn/.travis.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-language: node_js
-node_js:
- - "0.8"
- - "0.10"
- - "0.11"
-matrix:
- fast_finish: true
- allow_failures:
- - node_js: 0.11
diff --git a/node_modules/flagged-respawn/README.md b/node_modules/flagged-respawn/README.md
index a431fe36e..a281f0806 100644
--- a/node_modules/flagged-respawn/README.md
+++ b/node_modules/flagged-respawn/README.md
@@ -49,8 +49,43 @@ flaggedRespawn(v8flags, process.argv, function (ready, child) {
```
+
+## API
+
+### <u>flaggedRespawn(flags, argv, [ forcedFlags, ] callback) : Void</u>
+
+Respawns the script itself when *argv* has special flag contained in *flags* and/or *forcedFlags* is not empty. Because members of *flags* and *forcedFlags* are passed to `node` command, each of them needs to be a node flag or a V8 flag.
+
+#### Forbid respawning
+
+If `--no-respawning` flag is given in *argv*, this function does not respawned even if *argv* contains members of flags or *forcedFlags* is not empty. (This flag is also used internally to prevent from respawning more than once).
+
+#### Parameter:
+
+| Parameter | Type | Description |
+|:--------------|:------:|:----------------------------------------------------|
+| *flags* | Array | An array of node flags and V8 flags which are available when present in *argv*. |
+| *argv* | Array | Command line arguments to respawn. |
+| *forcedFlags* | Array or String | An array of node flags or a string of a single flag and V8 flags for respawning forcely. |
+| *callback* | function | A called function when not respawning or after respawned. |
+
+* **<u><i>callback</i>(ready, proc, argv) : Void</u>**
+
+ *callback* function is called both when respawned or not, and it can be distinguished by callback's argument: *ready*. (*ready* indicates whether a process spawned its child process (false) or not (true), but it does not indicate whether a process is a spawned child process or not. *ready* for a spawned child process is true.)
+
+ *argv* is an array of command line arguments which is respawned (when *ready* is false) or is passed current process except flags within *flags* and `--no-respawning` (when *ready* is true).
+
+ **Parameter:**
+
+ | Parameter | Type | Description |
+ |:----------|:-------:|:--------------------------|
+ | *ready* | boolean | True, if not respawning and is ready to execute main function. |
+ | *proc* | object | Child process object if respawned, otherwise current process object. |
+ | *argv* | Array | An array of command line arguments. |
+
## Release History
+* 2017-12-16 - v1.0.0 - Force/Forbid respawn, Improved API & testing
* 2016-03-22 - v0.3.2 - fix issue with v8 flags values being dropped
* 2014-09-12 - v0.3.1 - use `{ stdio: 'inherit' }` for spawn to maintain colors
* 2014-09-11 - v0.3.0 - for real this time
diff --git a/node_modules/flagged-respawn/index.js b/node_modules/flagged-respawn/index.js
index b1234003e..15b4bf70d 100644
--- a/node_modules/flagged-respawn/index.js
+++ b/node_modules/flagged-respawn/index.js
@@ -1,18 +1,52 @@
const reorder = require('./lib/reorder');
const respawn = require('./lib/respawn');
+const remover = require('./lib/remover');
-module.exports = function (flags, argv, execute) {
+const FORBID_RESPAWNING_FLAG = '--no-respawning';
+
+module.exports = function (flags, argv, forcedFlags, execute) {
if (!flags) {
throw new Error('You must specify flags to respawn with.');
}
if (!argv) {
throw new Error('You must specify an argv array.');
}
+
+ if (typeof forcedFlags === 'function') {
+ execute = forcedFlags;
+ forcedFlags = [];
+ }
+
+ if (typeof forcedFlags === 'string') {
+ forcedFlags = [forcedFlags];
+ }
+
+ if (!Array.isArray(forcedFlags)) {
+ forcedFlags = [];
+ }
+
+ var index = argv.indexOf(FORBID_RESPAWNING_FLAG);
+ if (index >= 0) {
+ argv = argv.slice(0, index).concat(argv.slice(index + 1));
+ argv = remover(flags, argv);
+ execute(true, process, argv);
+ return;
+ }
+
var proc = process;
var reordered = reorder(flags, argv);
var ready = JSON.stringify(argv) === JSON.stringify(reordered);
+
+ if (forcedFlags.length) {
+ reordered = reordered.slice(0, 1)
+ .concat(forcedFlags)
+ .concat(reordered.slice(1));
+ ready = false;
+ }
+
if (!ready) {
+ reordered.push(FORBID_RESPAWNING_FLAG);
proc = respawn(reordered);
}
- execute(ready, proc);
+ execute(ready, proc, reordered);
};
diff --git a/node_modules/flagged-respawn/lib/reorder.js b/node_modules/flagged-respawn/lib/reorder.js
index 556a7d13b..5c72772d2 100644
--- a/node_modules/flagged-respawn/lib/reorder.js
+++ b/node_modules/flagged-respawn/lib/reorder.js
@@ -1,3 +1,5 @@
+const isV8flags = require('./is-v8flags');
+
module.exports = function (flags, argv) {
if (!argv) {
argv = process.argv;
@@ -5,7 +7,7 @@ module.exports = function (flags, argv) {
var args = [argv[1]];
argv.slice(2).forEach(function (arg) {
var flag = arg.split('=')[0];
- if (flags.indexOf(flag) !== -1) {
+ if (isV8flags(flag, flags)) {
args.unshift(arg);
} else {
args.push(arg);
diff --git a/node_modules/flagged-respawn/lib/respawn.js b/node_modules/flagged-respawn/lib/respawn.js
index 086585300..c5dd4047c 100644
--- a/node_modules/flagged-respawn/lib/respawn.js
+++ b/node_modules/flagged-respawn/lib/respawn.js
@@ -4,6 +4,7 @@ module.exports = function (argv) {
var child = spawn(argv[0], argv.slice(1), { stdio: 'inherit' });
child.on('exit', function (code, signal) {
process.on('exit', function () {
+ /* istanbul ignore if */
if (signal) {
process.kill(process.pid, signal);
} else {
diff --git a/node_modules/flagged-respawn/package.json b/node_modules/flagged-respawn/package.json
index dee61c0c6..f3a88ec87 100644
--- a/node_modules/flagged-respawn/package.json
+++ b/node_modules/flagged-respawn/package.json
@@ -1,7 +1,7 @@
{
"name": "flagged-respawn",
"description": "A tool for respawning node binaries when special flags are present.",
- "version": "0.3.2",
+ "version": "1.0.0",
"homepage": "https://github.com/js-cli/js-flagged-respawn",
"author": {
"name": "Tyler Kellen",
@@ -14,18 +14,19 @@
"bugs": {
"url": "https://github.com/js-cli/js-flagged-respawn/issues"
},
- "licenses": [
- {
- "type": "MIT",
- "url": "https://github.com/js-cli/js-flagged-respawn/blob/master/LICENSE"
- }
- ],
+ "license": "MIT",
"scripts": {
+ "lint": "jshint index.js lib/ && jscs index.js lib/",
"respawn": "node test/bin/respawner --harmony test",
"nospawn": "node test/bin/respawner test",
- "test": "mocha -R spec test"
+ "test": "npm run lint && mocha -R spec test",
+ "cover": "nyc --reporter=lcov --reporter=text-summary npm test"
},
"main": "index.js",
+ "files": [
+ "index.js",
+ "lib/"
+ ],
"engines": {
"node": ">= 0.8.0"
},
@@ -33,8 +34,11 @@
"respawn flags"
],
"devDependencies": {
- "chai": "~1.9.1",
- "mocha": "~1.21.4",
- "v8flags": "~1.0.1"
+ "chai": "^3.5.0",
+ "jscs": "^3.0.7",
+ "jshint": "^2.9.5",
+ "mocha": "^3.5.3",
+ "nyc": "^11.3.0",
+ "v8flags": "^3.0.1"
}
}
diff --git a/node_modules/flagged-respawn/test/bin/exit_code.js b/node_modules/flagged-respawn/test/bin/exit_code.js
deleted file mode 100644
index f2fff2d52..000000000
--- a/node_modules/flagged-respawn/test/bin/exit_code.js
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env node
-
-const flaggedRespawn = require('../../');
-
-flaggedRespawn(['--harmony'], process.argv, function (ready) {
-
- if (ready) {
- setTimeout(function () {
- process.exit(100);
- }, 100);
- }
-
-});
diff --git a/node_modules/flagged-respawn/test/bin/respawner.js b/node_modules/flagged-respawn/test/bin/respawner.js
deleted file mode 100644
index 71348ba67..000000000
--- a/node_modules/flagged-respawn/test/bin/respawner.js
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/env node
-
-const flaggedRespawn = require('../../');
-
-// get a list of all possible v8 flags for the running version of node
-const v8flags = require('v8flags').fetch();
-
-flaggedRespawn(v8flags, process.argv, function (ready, child) {
- if (ready) {
- console.log('Running!');
- } else {
- console.log('Special flags found, respawning.');
- }
- if (child.pid !== process.pid) {
- console.log('Respawned to PID:', child.pid);
- }
-});
diff --git a/node_modules/flagged-respawn/test/bin/signal.js b/node_modules/flagged-respawn/test/bin/signal.js
deleted file mode 100644
index f4a1edf1a..000000000
--- a/node_modules/flagged-respawn/test/bin/signal.js
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/env node
-
-const flaggedRespawn = require('../../');
-
-flaggedRespawn(['--harmony'], process.argv, function (ready, child) {
-
- if (ready) {
- setTimeout(function() {
- process.exit();
- }, 100);
- } else {
- console.log('got child!');
- child.kill('SIGHUP');
- }
-
-});
diff --git a/node_modules/flagged-respawn/test/index.js b/node_modules/flagged-respawn/test/index.js
deleted file mode 100644
index d83fce3aa..000000000
--- a/node_modules/flagged-respawn/test/index.js
+++ /dev/null
@@ -1,99 +0,0 @@
-const expect = require('chai').expect;
-const exec = require('child_process').exec;
-
-const reorder = require('../lib/reorder');
-const flaggedRespawn = require('../');
-
-describe('flaggedRespawn', function () {
- var flags = ['--harmony', '--use_strict', '--stack_size']
-
- describe('reorder', function () {
-
- it('should re-order args, placing special flags first', function () {
- var needsRespawn = ['node', 'file.js', '--flag', '--harmony', 'command'];
- var noRespawnNeeded = ['node', 'bin/flagged-respawn', 'thing'];
- expect(reorder(flags, needsRespawn))
- .to.deep.equal(['node', '--harmony', 'file.js', '--flag', 'command']);
- expect(reorder(flags, noRespawnNeeded))
- .to.deep.equal(noRespawnNeeded);
- });
-
- it('should keep flags values when not placed first', function () {
- var args = ['node', 'file.js', '--stack_size=2048'];
- var expected = ['node', '--stack_size=2048', 'file.js'];
- expect(reorder(flags, args)).to.deep.equal(expected);
- });
-
- it('should ignore special flags when they are in the correct position', function () {
- var args = ['node', '--harmony', 'file.js', '--flag'];
- expect(reorder(flags, reorder(flags, args))).to.deep.equal(args);
- });
-
- });
-
- describe('execute', function () {
-
- it('should throw if no flags are specified', function () {
- expect(function () { flaggedRespawn.execute(); }).to.throw;
- });
-
- it('should throw if no argv is specified', function () {
- expect(function () { flaggedRespawn.execute(flags); }).to.throw;
- });
-
- it('should respawn and pipe stderr/stdout to parent', function (done) {
- exec('node ./test/bin/respawner.js --harmony', function (err, stdout, stderr) {
- expect(stdout.replace(/[0-9]/g, '')).to.equal('Special flags found, respawning.\nRespawned to PID: \nRunning!\n');
- done();
- });
- });
-
- it('should respawn and pass exit code from child to parent', function (done) {
- exec('node ./test/bin/exit_code.js --harmony', function (err, stdout, stderr) {
- expect(err.code).to.equal(100);
- done();
- });
- });
-
- it.skip('should respawn; if child is killed, parent should exit with same signal', function (done) {
- // TODO: figure out why travis hates this
- exec('node ./test/bin/signal.js --harmony', function (err, stdout, stderr) {
- console.log('err', err);
- console.log('stdout', stdout);
- console.log('stderr', stderr);
- expect(err.signal).to.equal('SIGHUP');
- done();
- });
- });
-
- it('should call back with ready as true when respawn is not needed', function () {
- var argv = ['node', './test/bin/respawner'];
- flaggedRespawn(flags, argv, function (ready) {
- expect(ready).to.be.true;
- });
- });
-
- it('should call back with ready as false when respawn is needed', function () {
- var argv = ['node', './test/bin/respawner', '--harmony'];
- flaggedRespawn(flags, argv, function (ready) {
- expect(ready).to.be.false;
- });
- });
-
- it('should call back with the child process when ready', function () {
- var argv = ['node', './test/bin/respawner', '--harmony'];
- flaggedRespawn(flags, argv, function (ready, child) {
- expect(child.pid).to.not.equal(process.pid);
- });
- });
-
- it('should call back with own process when respawn not needed', function () {
- var argv = ['node', './test/bin/respawner'];
- flaggedRespawn(flags, argv, function (ready, child) {
- expect(child.pid).to.equal(process.pid);
- });
- });
-
- });
-
-});