mirror of
https://github.com/nexu-io/open-design.git
synced 2026-06-01 03:14:35 +07:00
Postinstall assumed `npm_execpath` always points to pnpm's JS entry and invoked it via `node $npm_execpath`. When pnpm is installed as a standalone binary (e.g. `@pnpm/exe` via mise / volta), `npm_execpath` points to an ELF/Mach-O/PE executable and Node fails with "Invalid or unexpected token" parsing the binary as JS. Branch on the executable's extension: keep wrapping `.js`/`.cjs`/`.mjs` entries with `node`, but spawn other paths directly so standalone pnpm binaries work too. Co-authored-by: decker <decker502@qq.com>
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
import { spawnSync } from "node:child_process";
|
|
import { dirname, extname, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
const repoRoot = resolve(scriptDir, "..");
|
|
|
|
const buildTargets = [
|
|
"packages/sidecar-proto",
|
|
"packages/sidecar",
|
|
"packages/platform",
|
|
"tools/dev",
|
|
];
|
|
|
|
const jsExtensions = new Set([".js", ".cjs", ".mjs"]);
|
|
|
|
function resolvePackageManagerInvocation() {
|
|
const pnpmExecPath = process.env.npm_execpath;
|
|
if (pnpmExecPath != null && pnpmExecPath.length > 0) {
|
|
if (jsExtensions.has(extname(pnpmExecPath).toLowerCase())) {
|
|
return { argsPrefix: [pnpmExecPath], command: process.execPath };
|
|
}
|
|
return { argsPrefix: [], command: pnpmExecPath };
|
|
}
|
|
|
|
return { argsPrefix: [], command: process.platform === "win32" ? "pnpm.cmd" : "pnpm" };
|
|
}
|
|
|
|
const packageManager = resolvePackageManagerInvocation();
|
|
|
|
for (const target of buildTargets) {
|
|
const result = spawnSync(
|
|
packageManager.command,
|
|
[...packageManager.argsPrefix, "-C", target, "run", "build"],
|
|
{
|
|
cwd: repoRoot,
|
|
stdio: "inherit",
|
|
},
|
|
);
|
|
|
|
if (result.error != null) {
|
|
throw result.error;
|
|
}
|
|
|
|
if (result.status !== 0) {
|
|
process.exit(result.status ?? 1);
|
|
}
|
|
}
|