Skip to content

Commit eb3cfba

Browse files
authored
Add documentation about nano-spawn (#1157)
1 parent 3fc8049 commit eb3cfba

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

β€Ždocs/bash.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,6 @@ await pRetry(
12691269
12701270
<hr>
12711271
1272-
[**Next**: πŸ€“ TypeScript](typescript.md)\
1272+
[**Next**: 🐭 Small packages](small.md)\
12731273
[**Previous**: πŸ“Ž Windows](windows.md)\
12741274
[**Top**: Table of contents](../readme.md#documentation)

β€Ždocs/small.mdβ€Ž

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<picture>
2+
<source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">
3+
<img alt="execa logo" src="../media/logo.svg" width="400">
4+
</picture>
5+
<br>
6+
7+
# 🐭 Small packages
8+
9+
## `nano-spawn`
10+
11+
Execa aims to be the best way to run commands on Node.js. It is [very widely used](https://github.com/sindresorhus/execa/network/dependents), [battle-tested](https://github.com/sindresorhus/execa/graphs/contributors) and has a bunch of [features](../readme.md#features).
12+
13+
However, this means it has a relatively big package size: [![Install size](https://packagephobia.com/badge?p=execa)](https://packagephobia.com/result?p=execa). This should not be a problem in a server-side context, such as a script, a server, or an app. But you might be in an environment requiring small packages, such as a library or a serverless function.
14+
15+
If so, you can use [nano-spawn](https://github.com/sindresorhus/nano-spawn). It is similar, is maintained by the [same people](https://github.com/sindresorhus/nano-spawn#maintainers), has no dependencies, and a smaller package size: ![npm package minzipped size](https://img.shields.io/bundlejs/size/nano-spawn) [![Install size](https://packagephobia.com/badge?p=nano-spawn)](https://packagephobia.com/result?p=nano-spawn).
16+
17+
On the other hand, please note `nano-spawn` lacks many features from Execa: [scripts](scripts.md), [template string syntax](execution.md#template-string-syntax), [synchronous execution](execution.md#synchronous-execution), [file input/output](output.md#file-output), [binary input/output](binary.md), [advanced piping](pipe.md), [verbose mode](debugging.md#verbose-mode), [graceful](termination.md#graceful-termination) or [forceful termination](termination.md#forceful-termination), [IPC](ipc.md), [shebangs on Windows](windows.md), [and much more](https://github.com/sindresorhus/nano-spawn/issues/14).
18+
19+
```js
20+
import spawn from 'nano-spawn';
21+
22+
const result = await spawn('npm', ['run', 'build']);
23+
```
24+
25+
### `node:child_process`
26+
27+
Both Execa and nano-spawn are built on top of the [`node:child_process`](https://nodejs.org/api/child_process.html) core module.
28+
29+
If you'd prefer avoiding adding any dependency, you may use `node:child_process` directly. However, you might miss some basic [features](https://github.com/sindresorhus/nano-spawn#features) that both Execa and nano-spawn provide: [proper error handling](https://github.com/sindresorhus/nano-spawn#subprocesserror), [full Windows support](https://github.com/sindresorhus/nano-spawn#windows-support), [local binaries](https://github.com/sindresorhus/nano-spawn#optionspreferlocal), [piping](https://github.com/sindresorhus/nano-spawn#subprocesspipefile-arguments-options), [lines iteration](https://github.com/sindresorhus/nano-spawn#subprocesssymbolasynciterator), [interleaved output](https://github.com/sindresorhus/nano-spawn#resultoutput), [and more](https://github.com/sindresorhus/nano-spawn#features).
30+
31+
```js
32+
import {execFile} from 'node:child_process';
33+
import {promisify} from 'node:util';
34+
35+
const pExecFile = promisify(execFile);
36+
37+
const result = await pExecFile('npm', ['run', 'build']);
38+
```
39+
40+
<hr>
41+
42+
[**Next**: πŸ€“ TypeScript](typescript.md)\
43+
[**Previous**: πŸ” Differences with Bash and zx](bash.md)\
44+
[**Top**: Table of contents](../readme.md#documentation)

β€Ždocs/typescript.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,5 @@ await execa(options)`npm run build`;
187187
<hr>
188188

189189
[**Next**: πŸ“” API reference](api.md)\
190-
[**Previous**: πŸ” Differences with Bash and zx](bash.md)\
190+
[**Previous**: 🐭 Small packages](small.md)\
191191
[**Top**: Table of contents](../readme.md#documentation)

β€Žreadme.mdβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Advanced usage:
103103
- πŸ› [Debugging](docs/debugging.md)
104104
- πŸ“Ž [Windows](docs/windows.md)
105105
- πŸ” [Difference with Bash and zx](docs/bash.md)
106+
- 🐭 [Small packages](docs/small.md)
106107
- πŸ€“ [TypeScript](docs/typescript.md)
107108
- πŸ“” [API reference](docs/api.md)
108109

@@ -440,6 +441,7 @@ await execa`npm run test`;
440441

441442
## Related
442443

444+
- [nano-spawn](https://github.com/sindresorhus/nano-spawn) - Like Execa but [smaller](docs/small.md)
443445
- [gulp-execa](https://github.com/ehmicky/gulp-execa) - Gulp plugin for Execa
444446
- [nvexeca](https://github.com/ehmicky/nvexeca) - Run Execa using any Node.js version
445447

0 commit comments

Comments
Β (0)