{"name":"spawn-rx","version":"5.0.2","keywords":["spawn","rx"],"author":{"name":"Anaïs Betts","email":"anais@anaisbetts.org"},"license":"MIT","_id":"spawn-rx@5.0.2","maintainers":[{"name":"paulcbetts","email":"paul@paulbetts.org"}],"homepage":"https://github.com/anaisbetts/spawn-rx","bugs":{"url":"https://github.com/anaisbetts/spawn-rx/issues"},"dist":{"shasum":"3901e8f581b41f4f5dd5e666a9a1f888d20705e9","tarball":"http://registry-npm.ywwl.com/spawn-rx/download/spawn-rx-5.0.2.tgz","fileCount":19,"integrity":"sha512-Hh3F5NG11lYIEae6t2rgxg00P3boCESFT8A1NOuAaC72GEL8HuoiE/a2PwSCzLlWx5Bx6+nBGrH1RXv1VPcqvQ==","signatures":[{"sig":"MEUCICm/K+sPBJPfhH6OH2z+36ziZlqe/VKLgjcstCb9NawcAiEA9eRw5fcYGluRBTfQc8+wS+Ml3zyCVvbxtUoX2OG1OU4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":154684,"size":57932,"noattachment":false,"key":"/spawn-rx/-/spawn-rx-5.0.2.tgz"},"main":"lib/src/index.js","gitHead":"03d61e931d1fae8c0fbff00ffe0959aeff192fd7","scripts":{"doc":"echo \"esdoc may not work correctly\" && esdoc -c ./esdoc.json","lint":"npx eslint .","test":"mocha --compilers ts:ts-node/register ./test/*","build":"npm-run-all compile test","compile":"tsc -p ./tsconfig.json","prepublishOnly":"npm run build"},"typings":"lib/src/index.d.ts","_npmUser":{"name":"paulcbetts","email":"paul@paulbetts.org"},"repository":{"url":"git+https://github.com/anaisbetts/spawn-rx.git","type":"git"},"_npmVersion":"10.9.0","description":"An Rx-version of child_process.spawn","directories":{},"_nodeVersion":"23.1.0","dependencies":{"rxjs":"^7.8.1","debug":"^4.3.7","lodash.assign":"^4.2.0"},"_hasShrinkwrap":false,"devDependencies":{"chai":"^4.5.0","uuid":"3.0.1","esdoc":"^1.1.0","mocha":"^4.0.0","eslint":"^9.14.0","marked":"^0.5.0","ts-node":"^3.3.0","prettier":"^3.3.3","@eslint/js":"^9.14.0","typescript":"^5.6.3","@types/chai":"^4.3.20","@types/node":"^8.10.66","npm-run-all":"^4.0.2","@types/debug":"^4.1.12","@types/mocha":"^2.2.48","babel-register":"^6.23.0","@eslint/eslintrc":"^3.1.0","chai-as-promised":"^7.1.2","esdoc-es7-plugin":"0.0.3","typescript-eslint":"^8.14.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@types/chai-as-promised":"^7.1.8","esdoc-plugin-async-to-sync":"^0.5.0"},"_npmOperationalInternal":{"tmp":"tmp/spawn-rx_5.0.2_1732446003316_0.7677028792814395","host":"s3://npm-registry-packages"},"readme":"# spawn-rx: A better version of spawn\n\n| Linux/OSX | Windows |\n| --- | --- |\n| [![Build Status](https://travis-ci.org/tools-rx/spawn-rx.svg?branch=master)](https://travis-ci.org/tools-rx/spawn-rx) | [![Build status](https://ci.appveyor.com/api/projects/status/xm9xpgma4jwy3xns?svg=true)](https://ci.appveyor.com/project/dfbaskin/spawn-rx) |\n\n`spawn-rx` is a package that adds an Observable as well as a Promise version of \nthe `child_process.spawn` API, and fixes some deficiencies in `spawn` that come \nup especially on Windows. For example:\n\n* `spawn` searches PATH on POSIX platforms but will not on Windows, you need to\n  provide an exact path. spawn-rx makes Windows act like other platforms.\n  \n* On Windows, `{detached: true}` doesn't actually create a process group properly.\n  `spawn-rx` provides a `spawnDetached` method that allows you to spawn a detached\n  process and kill the entire process group if needed.\n  \n* POSIX platforms allow you to directly execute scripts that have a shebang at \n  the top of the file, whereas Windows can only natively `spawn` EXE files, which\n  makes executing npm binaries annoying. `spawn-rx` automatically rewrites your\n  `cmd` and `args` parameters for CMD scripts, PowerShell scripts, and node.js\n  files.\n\n## Examples\n\nspawn-as-promise:\n\n```js\n// Will run down path to find C:\\Windows\\System32\\wmic.exe, whereas normal \n// 'spawn' would require an absolute path.\nspawnPromise('wmic', [])\n  .then((result) => console.log(result));\n```\n\nHandle failed processes as errors:\n\n```js\ntry {\n  await spawnPromise('exit', ['-1']);\n} catch (e) {\n  console.log(\"Processes that return non-zero exit codes throw\")\n}\n```\n\nKill running process trees:\n\n```js\nlet disp = spawnDetached('takesALongTime', []).subscribe();\nawait Promise.delay(1000);\n\n// Kill the process and its children by unsubscribing.\ndisp.dispose();\n```\n\nStream process output:\n\n```js\nspawn('ls', ['-r'])\n  .subscribe(\n    (x) => console.log(x), \n    (e) => console.log(\"Process exited with an error\"));\n```\n\nExecute scripts:\n\n```js\n// Executes ./node_modules/.bin/uuid.cmd on Windows if invoked via `npm run`\nlet result = await spawnPromise('uuid');\n```\n\n\n## What's Jobber?\n\nJobber is a Windows executable that will execute a command in a process group,\nand if signaled via a named pipe, will terminate that process group. It's used\nin the implementation of `spawnDetached`. Jobber was written by me, and its license\nis the same as `spawn-rx`, it is not a third-party dependency.\n\n## Spawn output\n\nBy default spawn will merge stdout and stderr into the returned observable.\nYou can exclude one or the other by passing `ignore` in the `stdio` option of spawn.\n\nAlternatively if you call it with `{ split: true }` option, the observable output\nwill be an object `{ source: 'stdout', text: '...' }` so you can distinguish\nthe outputs.\n\n## Stdin support\n\nIf you provide an `Observable<string>` in `opts.stdin`, it'll be subscribed upon\n and fed into the child process stdin. Its completion will terminate stdin stream.\n\n## Methods\n\n```typescript\n/**\n * Spawns a process attached as a child of the current process.\n *\n * @param  {string} exe               The executable to run\n * @param  {string[]} params     The parameters to pass to the child\n * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.\n *\n * @return {Observable<OutputLine>}       Returns an Observable that when subscribed\n *                                    to, will create a child process. The\n *                                    process output will be streamed to this\n *                                    Observable, and if unsubscribed from, the\n *                                    process will be terminated early. If the\n *                                    process terminates with a non-zero value,\n *                                    the Observable will terminate with onError.\n */\nfunction spawn(\n  exe: string,\n  params: string[],\n  opts: SpawnOptions & SpawnRxExtras & { split: true }\n): Observable<OutputLine>;\n\nfunction spawn(\n  exe: string,\n  params: string[],\n  opts?: SpawnOptions & SpawnRxExtras & { split: false | undefined }\n): Observable<string>;\n\n/**\n * Spawns a process but detached from the current process. The process is put\n * into its own Process Group.\n *\n * @param  {string} exe               The executable to run\n * @param  {string[]} params     The parameters to pass to the child\n * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.\n *\n * @return {Observable<OutputLine>}       Returns an Observable that when subscribed\n *                                    to, will create a detached process. The\n *                                    process output will be streamed to this\n *                                    Observable, and if unsubscribed from, the\n *                                    process will be terminated early. If the\n *                                    process terminates with a non-zero value,\n *                                    the Observable will terminate with onError.\n */\nfunction spawnDetached(\n  exe: string,\n  params: string[],\n  opts: SpawnOptions & SpawnRxExtras & { split: true }\n): Observable<OutputLine>;\n\nfunction spawnDetached(\n  exe: string,\n  params: string[],\n  opts?: SpawnOptions & SpawnRxExtras & { split: false | undefined }\n): Observable<string>;\n\n/**\n * Spawns a process as a child process.\n *\n * @param  {string} exe               The executable to run\n * @param  {string[]} params     The parameters to pass to the child\n * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.\n *\n * @return {Promise<[string, string]>}       Returns a Promise that represents a child\n *                                 process. The value returned is the process\n *                                 output. If the process terminates with a\n *                                 non-zero value, the Promise will resolve with\n *                                 an Error.\n */\nfunction spawnPromise(\n  exe: string,\n  params: string[],\n  opts: SpawnOptions & SpawnRxExtras & { split: true }\n): Promise<[string, string]>;\n\nfunction spawnPromise(\n  exe: string,\n  params: string[],\n  opts?: SpawnOptions & SpawnRxExtras\n): Promise<string>;\n\n/**\n * Spawns a process but detached from the current process. The process is put\n * into its own Process Group.\n *\n * @param  {string} exe               The executable to run\n * @param  {string[]} params     The parameters to pass to the child\n * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.\n *\n * @return {Promise<[string, string]>}       Returns a Promise that represents a detached\n *                                 process. The value returned is the process\n *                                 output. If the process terminates with a\n *                                 non-zero value, the Promise will resolve with\n *                                 an Error.\n */\nfunction spawnDetachedPromise(\n  exe: string,\n  params: string[],\n  opts: SpawnOptions & SpawnRxExtras & { split: true }\n): Promise<[string, string]>;\n\nfunction spawnDetachedPromise(\n  exe: string,\n  params: string[],\n  opts?: SpawnOptions & SpawnRxExtras\n): Promise<string>;\n\n/**\n * Finds the actual executable and parameters to run on Windows. This method\n * mimics the POSIX behavior of being able to run scripts as executables by\n * replacing the passed-in executable with the script runner, for PowerShell,\n * CMD, and node scripts.\n *\n * This method also does the work of running down PATH, which spawn on Windows\n * also doesn't do, unlike on POSIX.\n *\n * @param  {string} exe           The executable to run\n * @param  {string[]} args   The arguments to run\n *\n * @return {Object}               The cmd and args to run\n * @property {string} cmd         The command to pass to spawn\n * @property {string[]} args The arguments to pass to spawn\n */\nfunction findActualExecutable(\n  exe: string,\n  args: string[]\n): {\n  cmd: string;\n  args: string[];\n};\n","publish_time":1732446003492,"_cnpm_publish_time":1732446003492,"dist-tags":{"beta":"4.0.0-beta.1","latest":"6.0.1"}}