{"id":14982044,"url":"https://github.com/gulpjs/flagged-respawn","last_synced_at":"2025-05-07T13:21:36.637Z","repository":{"id":20377754,"uuid":"23653296","full_name":"gulpjs/flagged-respawn","owner":"gulpjs","description":"A tool for respawning node binaries when special flags are present.","archived":false,"fork":false,"pushed_at":"2021-11-21T22:03:19.000Z","size":45,"stargazers_count":21,"open_issues_count":0,"forks_count":6,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-27T15:25:08.641Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gulpjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-04T07:44:27.000Z","updated_at":"2023-11-12T03:41:39.000Z","dependencies_parsed_at":"2022-07-26T02:47:10.920Z","dependency_job_id":null,"html_url":"https://github.com/gulpjs/flagged-respawn","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fflagged-respawn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fflagged-respawn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fflagged-respawn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fflagged-respawn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gulpjs","download_url":"https://codeload.github.com/gulpjs/flagged-respawn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252665040,"owners_count":21785010,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T14:04:41.462Z","updated_at":"2025-05-07T13:21:36.610Z","avatar_url":"https://github.com/gulpjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://gulpjs.com\"\u003e\n    \u003cimg height=\"257\" width=\"114\" src=\"https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\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### \u003cu\u003eflaggedRespawn(flags, argv, [ forcedFlags, ] callback) : Void\u003c/u\u003e\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- **\u003cu\u003e\u003ci\u003ecallback\u003c/i\u003e(ready, proc, argv) : Void\u003c/u\u003e**\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\u003c!-- prettier-ignore-start --\u003e\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\u003c!-- prettier-ignore-end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgulpjs%2Fflagged-respawn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgulpjs%2Fflagged-respawn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgulpjs%2Fflagged-respawn/lists"}