Skip to content

refactor: replace execa w/ ezspawn#115

Merged
antfu merged 2 commits intoantfu-collective:mainfrom
SukkaW:replace-execa
Apr 25, 2024
Merged

refactor: replace execa w/ ezspawn#115
antfu merged 2 commits intoantfu-collective:mainfrom
SukkaW:replace-execa

Conversation

@SukkaW
Copy link
Copy Markdown
Contributor

@SukkaW SukkaW commented Apr 25, 2024

I first encountered the package @jsdevtools/ez-spawn through bumpp, which uses exspawn under the hood.

Though no longer being actively maintained, ezspawn already fulfills almost every use case and doesn't suffer from breaking bugs.

@jsdevtools/ez-spawn has fewer dependencies than execa and takes up only 47% of the disk space (the installation size of @jsdevtools/ez-spawn is 142 KiB compared to execa at 301 KiB). Moreover, its usage is extremely straightforward. Unlike execa, which has separated execa and execCommand, ezspawn's single method can perform both functions.

Comment thread src/commands/check/checkGlobal.ts Outdated
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import { execa, execaCommand } from 'execa'
import { async as ezspawnAsync } from '@jsdevtools/ez-spawn'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { async as ezspawnAsync } from '@jsdevtools/ez-spawn'
import { async as execute } from '@jsdevtools/ez-spawn'

A bit nitpicking, but how about just making the name easy by describing what it does than what it is made?

I don't even mind NTR it to be execa 🤣

Copy link
Copy Markdown
Contributor Author

@SukkaW SukkaW Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only use the async method anyway, I am going to alias it to a simple name.

Just like how execa exports a named method execa, let's use ezspawn.

@antfu antfu merged commit 5c7aa67 into antfu-collective:main Apr 25, 2024
@zanminkian
Copy link
Copy Markdown

This cli tool do not need third-party package to execute command. Just use childProcess.execSync is enough.

import childProcess from "node:child_process";
const config= JSON.parse(
  childProcess.execSync(`echo '{"hello":"world"}'`).toString("utf8"),
);
console.log(config); // {hello: 'world'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants