Skip to content

Commit

Permalink
Replace spawndamnit with tinyexec (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
VanTanev authored Oct 16, 2024
1 parent 47b1dea commit 3c3198a
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-hornets-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@manypkg/cli": minor
---

Replace `spawndamnit` with `tinyexec` for fewer dependencies
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"picocolors": "^1.1.0",
"sembear": "^0.5.0",
"semver": "^6.3.0",
"spawndamnit": "^2.0.0",
"tinyexec": "^0.3.1",
"validate-npm-package-name": "^5.0.1"
},
"devDependencies": {
Expand Down
12 changes: 7 additions & 5 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { writePackage, install } from "./utils";
import { runCmd } from "./run";
import { upgradeDependency } from "./upgrade";
import { npmTagAll } from "./npm-tag";
import spawn from "spawndamnit";
import { exec } from "tinyexec";
import pLimit from "p-limit";

type RootPackage = Package & {
Expand Down Expand Up @@ -93,11 +93,13 @@ async function execCmd(args: string[]) {
await Promise.all(
packages.map((pkg) => {
return execLimit(async () => {
let { code } = await spawn(args[0], args.slice(1), {
cwd: pkg.dir,
stdio: "inherit",
const { exitCode } = await exec(args[0], args.slice(1), {
nodeOptions: {
cwd: pkg.dir,
stdio: "inherit",
},
});
highestExitCode = Math.max(code, highestExitCode);
highestExitCode = Math.max(exitCode ?? 1, highestExitCode);
});
})
);
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/npm-tag.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getPackages } from "@manypkg/get-packages";
import type { PackageJSON } from "@changesets/types";
import spawn from "spawndamnit";
import { exec } from "tinyexec";
import pLimit from "p-limit";

let npmLimit = pLimit(40);
Expand Down Expand Up @@ -30,7 +30,7 @@ async function tagApackage(
flags.push("--otp", otpCode);
}

return await spawn(
return await exec(
"npm",
[
"dist-tag",
Expand All @@ -40,8 +40,10 @@ async function tagApackage(
...flags,
],
{
stdio: "inherit",
env: Object.assign({}, process.env, envOverride),
nodeOptions: {
stdio: "inherit",
env: envOverride,
},
}
);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/run.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { runCmd } from "./run";
import fixturez from "fixturez";
import spawn from "spawndamnit";
import { exec } from "tinyexec";
import stripAnsi from "strip-ansi";

const f = fixturez(__dirname);
Expand All @@ -22,16 +22,16 @@ describe("Run command", () => {
// @ts-ignore
])(
'should execute "%s %s" and exit with %i',
async (arg0, arg1, exitCode) => {
const { stdout, stderr, code } = await spawn(
async (arg0, arg1, expectedExitCode) => {
const { exitCode, stdout, stderr } = await exec(
require.resolve("../bin"),
// @ts-ignore
["run", arg0, arg1],
{
cwd: f.find("basic-with-scripts"),
nodeOptions: { cwd: f.find("basic-with-scripts") },
}
);
expect(code).toBe(exitCode);
expect(exitCode).toBe(expectedExitCode);
expect(stripAnsi(stdout.toString())).toMatchSnapshot("stdout");
expect(stripAnsi(stderr.toString())).toMatchSnapshot("stderr");
}
Expand Down
23 changes: 13 additions & 10 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getPackages } from "@manypkg/get-packages";
import path from "path";
import spawn from "spawndamnit";
import { exec } from "tinyexec";
import * as logger from "./logger";
import { ExitError } from "./errors";

Expand All @@ -12,11 +11,13 @@ export async function runCmd(args: string[], cwd: string) {
});

if (exactMatchingPackage) {
const { code } = await spawn("yarn", args.slice(1), {
cwd: exactMatchingPackage.dir,
stdio: "inherit",
const { exitCode } = await exec("yarn", args.slice(1), {
nodeOptions: {
cwd: exactMatchingPackage.dir,
stdio: "inherit",
},
});
throw new ExitError(code);
throw new ExitError(exitCode ?? 1);
}

const matchingPackages = packages.filter((pkg) => {
Expand All @@ -39,10 +40,12 @@ export async function runCmd(args: string[], cwd: string) {
logger.error("No matching packages found");
throw new ExitError(1);
} else {
const { code } = await spawn("yarn", args.slice(1), {
cwd: matchingPackages[0].dir,
stdio: "inherit",
const { exitCode } = await exec("yarn", args.slice(1), {
nodeOptions: {
cwd: matchingPackages[0].dir,
stdio: "inherit",
},
});
throw new ExitError(code);
throw new ExitError(exitCode ?? 1);
}
}
6 changes: 3 additions & 3 deletions packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs/promises";
import { Package, Tool } from "@manypkg/get-packages";
import path from "path";
import spawn from "spawndamnit";
import { exec } from "tinyexec";
import detectIndent from "detect-indent";

export async function writePackage(pkg: Package) {
Expand All @@ -24,13 +24,13 @@ export async function install(toolType: string, cwd: string) {
yarn: "yarn",
};

await spawn(
await exec(
cliRunners[toolType],
toolType === "pnpm"
? ["install"]
: toolType === "lerna"
? ["bootstrap", "--since", "HEAD"]
: [],
{ cwd, stdio: "inherit" }
{ nodeOptions: { cwd, stdio: "inherit" } }
);
}
10 changes: 0 additions & 10 deletions types/spawndamnit.d.ts

This file was deleted.

5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14199,6 +14199,11 @@ timsort@^0.3.0:
resolved "https://registry.yarnpkg.com/timsort/-/timsort-0.3.0.tgz#405411a8e7e6339fe64db9a234de11dc31e02bd4"
integrity sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=

tinyexec@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/tinyexec/-/tinyexec-0.3.1.tgz#0ab0daf93b43e2c211212396bdb836b468c97c98"
integrity sha512-WiCJLEECkO18gwqIp6+hJg0//p23HXp4S+gGtAKu3mI2F2/sXC4FvHvXvB0zJVVaTPhx1/tOwdbRsa1sOBIKqQ==

title-case@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/title-case/-/title-case-2.1.1.tgz#3e127216da58d2bc5becf137ab91dae3a7cd8faa"
Expand Down

0 comments on commit 3c3198a

Please sign in to comment.