From 613ff7ae5b7cd467a03c0c0409ac3f751e711614 Mon Sep 17 00:00:00 2001 From: Ajay Ghanwat Date: Mon, 24 Aug 2026 11:37:06 +0530 Subject: [PATCH] fix: invoke npm reliably from Bun on Windows --- scripts/release-changed.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/release-changed.ts b/scripts/release-changed.ts index 63db5cd5..4c076103 100644 --- a/scripts/release-changed.ts +++ b/scripts/release-changed.ts @@ -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 {