fix: invoke npm reliably from Bun on Windows
This commit is contained in:
@@ -4,7 +4,6 @@ import { join, resolve } from "node:path";
|
|||||||
import { spawnSync } from "node:child_process";
|
import { spawnSync } from "node:child_process";
|
||||||
|
|
||||||
const root = resolve(import.meta.dir, "..");
|
const root = resolve(import.meta.dir, "..");
|
||||||
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
||||||
const mode = process.argv[2] ?? "plan";
|
const mode = process.argv[2] ?? "plan";
|
||||||
const requested = process.argv.slice(3).filter((arg) => !arg.startsWith("--"));
|
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;
|
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[] {
|
function allPackages(): PackageInfo[] {
|
||||||
return readdirSync(join(root, "packages"), { withFileTypes: true }).flatMap((entry) => {
|
return readdirSync(join(root, "packages"), { withFileTypes: true }).flatMap((entry) => {
|
||||||
const file = join(root, "packages", entry.name, "package.json");
|
const file = join(root, "packages", entry.name, "package.json");
|
||||||
@@ -80,7 +90,7 @@ function syncWorkspaceLock(pkgs: PackageInfo[]): void {
|
|||||||
|
|
||||||
function registryHas(pkg: PackageInfo): boolean {
|
function registryHas(pkg: PackageInfo): boolean {
|
||||||
return (
|
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
|
.status === 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -127,10 +137,10 @@ if (mode === "plan") {
|
|||||||
run(process.execPath, ["run", "check:component-imports"]);
|
run(process.execPath, ["run", "check:component-imports"]);
|
||||||
run(process.execPath, ["test", ...selected.map((pkg) => `packages/${pkg.dir}`)]);
|
run(process.execPath, ["test", ...selected.map((pkg) => `packages/${pkg.dir}`)]);
|
||||||
run(process.execPath, ["run", "scripts/publish-packages.ts", ...selected.map((pkg) => pkg.name)]);
|
run(process.execPath, ["run", "scripts/publish-packages.ts", ...selected.map((pkg) => pkg.name)]);
|
||||||
run(npm, ["whoami"]);
|
runNpm(["whoami"]);
|
||||||
for (const pkg of selected) {
|
for (const pkg of selected) {
|
||||||
const stage = join(root, ".publish", pkg.dir);
|
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}`);
|
console.log(` ✓ ${pkg.name}@${pkg.manifest.version}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user