fix: invoke npm reliably from Bun on Windows
Quality / quality (windows-latest) (push) Waiting to run
Quality / quality (ubuntu-latest) (push) Failing after 9m51s

This commit is contained in:
2026-08-24 11:37:06 +05:30
parent e372ae571a
commit 613ff7ae5b
+14 -4
View File
@@ -4,7 +4,6 @@ import { join, resolve } from "node:path";
import { spawnSync } from "node:child_process";
const root = resolve(import.meta.dir, "..");
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
const mode = process.argv[2] ?? "plan";
const requested = process.argv.slice(3).filter((arg) => !arg.startsWith("--"));
@@ -28,6 +27,17 @@ function run(command: string, args: string[], capture = false, allowFailure = fa
return result;
}
function runNpm(args: string[], capture = false, allowFailure = false) {
return process.platform === "win32"
? run(
process.env.ComSpec ?? "cmd.exe",
["/d", "/s", "/c", "npm", ...args],
capture,
allowFailure,
)
: run("npm", args, capture, allowFailure);
}
function allPackages(): PackageInfo[] {
return readdirSync(join(root, "packages"), { withFileTypes: true }).flatMap((entry) => {
const file = join(root, "packages", entry.name, "package.json");
@@ -80,7 +90,7 @@ function syncWorkspaceLock(pkgs: PackageInfo[]): void {
function registryHas(pkg: PackageInfo): boolean {
return (
run(npm, ["view", `${pkg.name}@${pkg.manifest.version}`, "version", "--json"], true, true)
runNpm(["view", `${pkg.name}@${pkg.manifest.version}`, "version", "--json"], true, true)
.status === 0
);
}
@@ -127,10 +137,10 @@ if (mode === "plan") {
run(process.execPath, ["run", "check:component-imports"]);
run(process.execPath, ["test", ...selected.map((pkg) => `packages/${pkg.dir}`)]);
run(process.execPath, ["run", "scripts/publish-packages.ts", ...selected.map((pkg) => pkg.name)]);
run(npm, ["whoami"]);
runNpm(["whoami"]);
for (const pkg of selected) {
const stage = join(root, ".publish", pkg.dir);
if (!registryHas(pkg)) run(npm, ["publish", stage, "--access", "restricted"]);
if (!registryHas(pkg)) runNpm(["publish", stage, "--access", "restricted"]);
console.log(`${pkg.name}@${pkg.manifest.version}`);
}
} else {