Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/modules/cross-spawn.md
Original file line number Diff line number Diff line change
@@ -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 ++]
```
6 changes: 6 additions & 0 deletions manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down