Skip to content

Commit

Permalink
Add documentation about nano-spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 15, 2024
1 parent 3fc8049 commit 60cb78e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,6 @@ await pRetry(
<hr>
[**Next**: πŸ€“ TypeScript](typescript.md)\
[**Next**: 🐭 Small package size](small.md)\
[**Previous**: πŸ“Ž Windows](windows.md)\
[**Top**: Table of contents](../readme.md#documentation)
38 changes: 38 additions & 0 deletions docs/small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<picture>
<source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">
<img alt="execa logo" src="../media/logo.svg" width="400">
</picture>
<br>

# 🐭 Small package size

## `nano-spawn`

Execa aims to be the best way to run commands on Node.js. It is [very widely used](../../../network/dependents), [battle-tested](../../../graphs/contributors) and has a bunch of [features](../readme.md#features).

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.

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).

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).

### `node:child_process`

Both Execa and nano-spawn are built on top of the [`node:child_process`](https://nodejs.org/api/child_process.html) core module.

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).

```js
import {execFile} from 'node:child_process';
import {promisify} from 'node:util';

const pExecFile = promisify(execFile);

const result = await pExecFile('npm', ['run', 'build']);
```

<hr>

[**Next**: πŸ€“ TypeScript](typescript.md)\
[**Previous**: πŸ” Differences with Bash and zx](bash.md)\
[**Top**: Table of contents](../readme.md#documentation)
2 changes: 1 addition & 1 deletion docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,5 @@ await execa(options)`npm run build`;
<hr>

[**Next**: πŸ“” API reference](api.md)\
[**Previous**: πŸ” Differences with Bash and zx](bash.md)\
[**Previous**: 🐭 Small package size](small.md)\
[**Top**: Table of contents](../readme.md#documentation)
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Advanced usage:
- πŸ› [Debugging](docs/debugging.md)
- πŸ“Ž [Windows](docs/windows.md)
- πŸ” [Difference with Bash and zx](docs/bash.md)
- 🐭 [Small package size](docs/small.md)
- πŸ€“ [TypeScript](docs/typescript.md)
- πŸ“” [API reference](docs/api.md)

Expand Down Expand Up @@ -440,6 +441,7 @@ await execa`npm run test`;

## Related

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

Expand Down

0 comments on commit 60cb78e

Please sign in to comment.