{"name":"@expo/spawn-async","version":"1.8.0","keywords":["spawn","child_process","async","promise","process"],"author":{"name":"Expo"},"license":"MIT","_id":"@expo/spawn-async@1.8.0","maintainers":[{"name":"ide","email":"ide+npm@jameside.com"},{"name":"brentvatne","email":"brentvatne@gmail.com"},{"name":"evanbacon","email":"baconbrix@gmail.com"},{"name":"expoadmin","email":"support@expo.io"},{"name":"exponent","email":"exponent.team@gmail.com"},{"name":"bycedric","email":"me@bycedric.com"},{"name":"kudochien","email":"ckchien@gmail.com"},{"name":"alanhughes","email":"hughesno1@gmail.com"},{"name":"tsapeta","email":"npm@tsapeta.com"},{"name":"expo-bot","email":"brent+expobotnpm@expo.io"},{"name":"philpl","email":"phil@kitten.sh"},{"name":"wschurman","email":"wschurman@gmail.com"}],"homepage":"https://github.com/expo/spawn-async#readme","bugs":{"url":"https://github.com/expo/spawn-async/issues"},"dist":{"shasum":"915e2ab38554fca7d788e16032078554dee633cf","tarball":"http://registry-npm.ywwl.com/@expo/spawn-async/download/@expo/spawn-async-1.8.0.tgz","fileCount":6,"integrity":"sha512-eb9xxd/LbuEGSdua4NumCu/McVB9EM+F/JxB9pWgnERw4HQ9XyTNH1KapG6oqLWR8TuRK2LQfzJlmNi94CVobw==","signatures":[{"sig":"MEQCIARz0AVGpq8A+SttKWwZBMjXxDhl2cL88qIeIddCacyGAiASqPM+rkwiruccHXJdHIvC5wCca+NtJ1FnZkWFa7NbQQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":28306,"size":7477,"noattachment":false,"key":"/@expo/spawn-async/-/@expo/spawn-async-1.8.0.tgz"},"jest":{"preset":"ts-jest","rootDir":"src"},"main":"./build/spawnAsync.js","types":"./build/spawnAsync.d.ts","engines":{"node":">=12"},"gitHead":"5a3013e49d2161bc5beb6b7c8e236c5d7bd38547","scripts":{"test":"jest","build":"tsc","clean":"rm -rf build","start":"tsc --watch","prepare":"yarn clean && yarn build"},"_npmUser":{"name":"philpl","email":"phil@kitten.sh"},"repository":{"url":"git+https://github.com/expo/spawn-async.git","type":"git"},"_npmVersion":"10.9.7","description":"A Promise-based interface into processes created by child_process.spawn","directories":{},"_nodeVersion":"22.22.2","dependencies":{"cross-spawn":"^7.0.6"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.5.0","ts-jest":"^29.0.5","typescript":"^5.0.2","@types/jest":"^29.5.0","@types/node":"^18.15.3","@types/cross-spawn":"^6.0.2"},"_npmOperationalInternal":{"tmp":"tmp/spawn-async_1.8.0_1779209154562_0.7103595858700329","host":"s3://npm-registry-packages-npm-production"},"readme":"# spawn-async [![Tests](https://github.com/expo/spawn-async/actions/workflows/main.yml/badge.svg)](https://github.com/expo/spawn-async/actions/workflows/main.yml)\n\nA cross-platform version of Node's `child_process.spawn` as an async function that returns a promise. Supports Node 12 LTS and up.\n\n## Usage:\n```js\nimport spawnAsync from '@expo/spawn-async';\n\n(async function () {\n  let resultPromise = spawnAsync('echo', ['hello', 'world']);\n  let spawnedChildProcess = resultPromise.child;\n  try {\n    let {\n      pid,\n      output: [stdout, stderr],\n      stdout,\n      stderr,\n      status,\n      signal,\n    } = await resultPromise;\n  } catch (e) {\n    console.error(e.stack);\n    // The error object also has the same properties as the result object\n  }\n})();\n```\n\n## API\n\n`spawnAsync` takes the same arguments as [`child_process.spawn`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options). Its options are the same as those of `child_process.spawn` plus:\n\n- `ignoreStdio`: whether to ignore waiting for the child process's stdio streams to close before resolving the result promise. When ignoring stdio, the returned values for `stdout` and `stderr` will be empty strings. The default value of this option is `false`.\n- `maxBuffer`: the maximum bytes retained from `stdout` and `stderr` (independently). Output is collected with a sliding window. When set explicitly, exceeding it rejects the promise with an error whose `code` is `ERR_CHILD_PROCESS_STDIO_MAXBUFFER` and whose `stdout`/`stderr` carry the truncated tail. When omitted, the default is `buffer.constants.MAX_STRING_LENGTH` (~512 MiB).\n\nIt returns a promise whose result is an object with these properties:\n\n- `pid`: the process ID of the spawned child process\n- `output`: an array with stdout and stderr's output\n- `stdout`: a string of what the child process wrote to stdout\n- `stderr`: a string of what the child process wrote to stderr\n- `status`: the exit code of the child process\n- `signal`: the signal (ex: `SIGTERM`) used to stop the child process if it did not exit on its own\n\nIf there's an error running the child process or it exits with a non-zero status code, `spawnAsync` rejects the returned promise. The Error object also has the properties listed above.\n\n### Accessing the child process\n\nSometimes you may want to access the child process object--for example, if you wanted to attach event handlers to `stdio` or `stderr` and process data as it is available instead of waiting for the process to be resolved.\n\nYou can do this by accessing `.child` on the Promise that is returned by `spawnAsync`.\n\nHere is an example:\n```js\n(async () => {\n  let ffmpeg$ = spawnAsync('ffmpeg', ['-i', 'path/to/source.flac', '-codec:a', 'libmp3lame', '-b:a', '320k', '-ar', '44100', 'path/to/output.mp3']);\n  let childProcess = ffmpeg$.child;\n  childProcess.stdout.on('data', (data) => {\n    console.log(`ffmpeg stdout: ${data}`);\n  });\n  childProcess.stderr.on('data', (data) => {\n    console.error(`ffmpeg stderr: ${data}`);\n  });\n  let result = await ffmpeg$;\n  console.log(`ffmpeg pid ${result.pid} exited with code ${result.code}`);\n})();\n\n```\n\n## Notes\n\n### `maxBuffer`\n\n`maxBuffer` is a later addition to the API. Set it when child output could exhaust memory and crash the parent process, or when the command or arguments are influenced by untrusted input — an attacker can otherwise force unbounded output to crash the parent.\n\nThe default of `buffer.constants.MAX_STRING_LENGTH` (~512 MiB) is a crash-safe floor, not a memory bound: at that size the materialized string itself can still exhaust process memory.\n\nWhen `maxBuffer` is set explicitly, exceeding it rejects the promise immediately with `ERR_CHILD_PROCESS_STDIO_MAXBUFFER`. When left at the default, exceeding it doesn't reject; the sliding-window tail is still readable, but reading `stdout`/`stderr` throws `ERR_CHILD_PROCESS_STDIO_MAXBUFFER` with the truncated tail attached.\n","publish_time":1779209154705,"_cnpm_publish_time":1779209154705,"dist-tags":{"latest":"1.8.0","next":"1.4.0"}}