diff --git a/docs/modules/cross-spawn.md b/docs/modules/cross-spawn.md new file mode 100644 index 00000000..0f3ebb82 --- /dev/null +++ b/docs/modules/cross-spawn.md @@ -0,0 +1,27 @@ +--- +description: Modern alternatives to the cross-spawn package for spawning child processes +--- + +# Replacements for `cross-spawn` + +> [!NOTE] +> If your application does not need to support Windows, you can likely drop `cross-spawn` entirely as it solely exists to provide Windows spawn compatibility. You can use the built-in `node:child_process` in that case. + +## `tinyexec` + +[`tinyexec`](https://github.com/tinylibs/tinyexec) is a minimal, dependency-free process execution library. + +`cross-spawn` follows the Node.js `spawn` API and returns a `ChildProcess`. In comparison, `tinyexec` returns an awaitable result containing the process output and exit code. + +Example: + +```ts +import spawn from 'cross-spawn' // [!code --] +import { x } from 'tinyexec' // [!code ++] + +const child = spawn('npm', ['list', '-g']) // [!code --] +const { stdout, exitCode } = await x('npm', ['list', '-g']) // [!code ++] + +child.stdout?.on('data', (output) => console.log(output.toString())) // [!code --] +console.log(stdout, exitCode) // [!code ++] +``` diff --git a/manifests/preferred.json b/manifests/preferred.json index 80a7525d..f3a0b56e 100644 --- a/manifests/preferred.json +++ b/manifests/preferred.json @@ -196,6 +196,12 @@ "replacements": ["fetch", "ofetch", "ky"], "url": {"type": "e18e", "id": "fetch"} }, + "cross-spawn": { + "type": "module", + "moduleName": "cross-spawn", + "replacements": ["tinyexec"], + "url": {"type": "e18e", "id": "cross-spawn"} + }, "crypto-js": { "type": "module", "moduleName": "crypto-js",