Skip to content

Commit

Permalink
perf!: replace execa with tinyexec (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziebam authored Nov 26, 2024
1 parent 141a6a3 commit 73193d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"dependencies": {
"citty": "^0.1.6",
"consola": "^3.2.3",
"execa": "^8.0.1",
"pathe": "^1.1.2",
"tinyexec": "^0.3.0",
"pkg-types": "^1.2.1",
"ufo": "^1.5.4"
},
Expand Down
11 changes: 8 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions src/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,30 @@ function cached<T>(fn: () => Promise<T>): () => T | Promise<T> {
};
}

const importExeca = cached(() => import("execa").then((r) => r.execa));
const importTinyexec = cached(() => import("tinyexec").then((r) => r.x));
const hasCorepack = cached(async () => {
try {
const execa = await importExeca();
await execa("corepack", ["--version"]);
return true;
} catch {
return false;
}
const x = await importTinyexec();
const result = x("corepack", ["--version"]);
await result;
return result.exitCode === 0;
});

export async function executeCommand(
command: string,
args: string[],
options: Pick<OperationOptions, "cwd" | "silent"> = {},
): Promise<void> {
const execaArgs: [string, string[]] =
const xArgs: [string, string[]] =
command === "npm" || command === "bun" || !(await hasCorepack())
? [command, args]
: ["corepack", [command, ...args]];

const execa = await importExeca();
await execa(execaArgs[0], execaArgs[1], {
cwd: resolve(options.cwd || process.cwd()),
stdio: options.silent ? "pipe" : "inherit",
const x = await importTinyexec();
await x(xArgs[0], xArgs[1], {
nodeOptions: {
cwd: resolve(options.cwd || process.cwd()),
stdio: options.silent ? "pipe" : "inherit",
},
});
}

Expand Down

0 comments on commit 73193d6

Please sign in to comment.