{"name":"flagged-respawn","description":"A tool for respawning node binaries when special flags are present.","version":"1.0.0","homepage":"https://github.com/js-cli/js-flagged-respawn","author":{"name":"Tyler Kellen","url":"http://goingslowly.com/"},"repository":{"type":"git","url":"git://github.com/js-cli/js-flagged-respawn.git"},"bugs":{"url":"https://github.com/js-cli/js-flagged-respawn/issues"},"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":"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"},"keywords":["respawn flags"],"devDependencies":{"chai":"^3.5.0","jscs":"^3.0.7","jshint":"^2.9.5","mocha":"^3.5.3","nyc":"^11.3.0","v8flags":"^3.0.1"},"gitHead":"81d23e8973c7f2c69dccf313a320628bd068a721","_id":"flagged-respawn@1.0.0","_shasum":"4e79ae9b2eb38bf86b3bb56bf3e0a56aa5fcabd7","_from":".","_npmVersion":"2.15.1","_nodeVersion":"0.10.48","_npmUser":{"name":"phated","email":"blaine.bublitz@gmail.com"},"maintainers":[{"email":"blaine.bublitz@gmail.com","name":"phated"},{"email":"bertrand.marron@gmail.com","name":"tusbar"},{"email":"tyler@sleekcode.net","name":"tkellen"}],"dist":{"shasum":"4e79ae9b2eb38bf86b3bb56bf3e0a56aa5fcabd7","tarball":"http://registry-npm.ywwl.com/flagged-respawn/download/flagged-respawn-1.0.0.tgz","integrity":"sha512-uEIeQj2Z4a7Jzpb682FYsKc4YWHKaykTndikWrRtoWhOc1w3/97An5RcLhwBSq7phxokzK5kFHEKRKT0raGgTg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB9E+Jh3Zu8t6kH0pzbKegXUjM0o2wieVox06HiKUBcsAiA3h9YDKT7rHZR6vwVwYxg1yOEGNH18w/XKShZ37DGdLA=="}],"size":4193,"noattachment":false,"key":"/flagged-respawn/-/flagged-respawn-1.0.0.tgz"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/flagged-respawn-1.0.0.tgz_1513468186583_0.7541352626867592"},"directories":{},"readme":"<p align=\"center\">\n  <a href=\"http://gulpjs.com\">\n    <img height=\"257\" width=\"114\" src=\"https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png\">\n  </a>\n</p>\n\n# flagged-respawn\n\n[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]\n\nA tool for respawning node binaries when special flags are present.\n\n## What is it?\n\nSay you wrote a command line tool that runs arbitrary javascript (e.g. task runner, test framework, etc). For the sake of discussion, let's pretend it's a testing harness you've named `testify`.\n\nEverything is going splendidly until one day you decide to test some code that relies on a feature behind a v8 flag in node (`--harmony`, for example). Without much thought, you run `testify --harmony spec tests.js`.\n\nIt doesn't work. After digging around for a bit, you realize this produces a [`process.argv`](http://nodejs.org/docs/latest/api/process.html#process_process_argv) of:\n\n`['node', '/usr/local/bin/test', '--harmony', 'spec', 'tests.js']`\n\nCrap. The `--harmony` flag is in the wrong place! It should be applied to the **node** command, not our binary. What we actually wanted was this:\n\n`['node', '--harmony', '/usr/local/bin/test', 'spec', 'tests.js']`\n\nFlagged-respawn fixes this problem and handles all the edge cases respawning creates, such as:\n\n- Providing a method to determine if a respawn is needed.\n- Piping stderr/stdout from the child into the parent.\n- Making the parent process exit with the same code as the child.\n- If the child is killed, making the parent exit with the same signal.\n\nTo see it in action, clone this repository and run `npm install` / `npm run respawn` / `npm run nospawn`.\n\n## Sample Usage\n\n```js\n#!/usr/bin/env node\n\nconst flaggedRespawn = require('flagged-respawn');\n\n// get a list of all possible v8 flags for the running version of node\nconst v8flags = require('v8flags').fetch();\n\nflaggedRespawn(v8flags, process.argv, function (ready, child) {\n  if (ready) {\n    console.log('Running!');\n    // your cli code here\n  } else {\n    console.log('Special flags found, respawning.');\n  }\n  if (process.pid !== child.pid) {\n    console.log('Respawned to PID:', child.pid);\n  }\n});\n```\n\n## API\n\n### <u>flaggedRespawn(flags, argv, [ forcedFlags, ] callback) : Void</u>\n\nRespawns 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.\n\n#### Forbid respawning\n\nIf `--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).\n\n#### Parameter:\n\n| Parameter     |      Type       | Description                                                                              |\n| :------------ | :-------------: | :--------------------------------------------------------------------------------------- |\n| _flags_       |      Array      | An array of node flags and V8 flags which are available when present in _argv_.          |\n| _argv_        |      Array      | Command line arguments to respawn.                                                       |\n| _forcedFlags_ | Array or String | An array of node flags or a string of a single flag and V8 flags for respawning forcely. |\n| _callback_    |    function     | A called function when not respawning or after respawned.                                |\n\n- **<u><i>callback</i>(ready, proc, argv) : Void</u>**\n\n  _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.)\n\n  _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).\n\n  **Parameter:**\n\n  | Parameter |  Type   | Description                                                          |\n  | :-------- | :-----: | :------------------------------------------------------------------- |\n  | _ready_   | boolean | True, if not respawning and is ready to execute main function.       |\n  | _proc_    | object  | Child process object if respawned, otherwise current process object. |\n  | _argv_    |  Array  | An array of command line arguments.                                  |\n\n## License\n\nMIT\n\n<!-- prettier-ignore-start -->\n[downloads-image]: https://img.shields.io/npm/dm/flagged-respawn.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/flagged-respawn\n[npm-image]: https://img.shields.io/npm/v/flagged-respawn.svg?style=flat-square\n\n[ci-url]: https://github.com/gulpjs/flagged-respawn/actions?query=workflow:dev\n[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/flagged-respawn/dev?style=flat-square\n\n[coveralls-url]: https://coveralls.io/r/gulpjs/flagged-respawn\n[coveralls-image]: https://img.shields.io/coveralls/gulpjs/flagged-respawn/master.svg?style=flat-square\n<!-- prettier-ignore-end -->\n","publish_time":1513468187568,"_cnpm_publish_time":1513468187568,"dist-tags":{"latest":"2.0.0"}}