Skip to content

Commit 9cb0f41

Browse files
committed
fix: make sidecar bundling windows-safe
1 parent 37c8b2d commit 9cb0f41

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

packages/sidecar/scripts/prepare-bundle.mjs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ const scriptDir = dirname(fileURLToPath(import.meta.url));
77
const packageDir = resolve(scriptDir, "..");
88
const workspaceRoot = resolve(packageDir, "../..");
99
const bundleDir = resolve(packageDir, ".bundle");
10-
const bundledNodePath = join(bundleDir, "node", "bin", "node");
10+
const packageManagerExecPath = process.env.npm_execpath;
11+
const pnpmHome = process.env.PNPM_HOME;
12+
const pnpmExecutable = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
13+
const bundledNodePath = join(
14+
bundleDir,
15+
"node",
16+
"bin",
17+
process.platform === "win32" ? "node.exe" : "node",
18+
);
1119

1220
async function run(command, args, cwd) {
1321
await new Promise((resolvePromise, rejectPromise) => {
@@ -17,6 +25,10 @@ async function run(command, args, cwd) {
1725
stdio: "inherit",
1826
});
1927

28+
child.once("error", (error) => {
29+
rejectPromise(error);
30+
});
31+
2032
child.once("exit", (code, signal) => {
2133
if (code === 0) {
2234
resolvePromise();
@@ -32,12 +44,33 @@ async function run(command, args, cwd) {
3244
});
3345
}
3446

47+
async function runPnpm(args, cwd) {
48+
if (packageManagerExecPath && /\.(c?js|mjs)$/i.test(packageManagerExecPath)) {
49+
await run(process.execPath, [packageManagerExecPath, ...args], cwd);
50+
return;
51+
}
52+
53+
const packageManagerCommand = pnpmHome
54+
? join(pnpmHome, pnpmExecutable)
55+
: pnpmExecutable;
56+
await run(packageManagerCommand, args, cwd);
57+
}
58+
3559
await rm(bundleDir, { force: true, recursive: true });
36-
await run(
37-
"pnpm",
38-
["deploy", "--legacy", "--filter", "@opengoat/sidecar", "--prod", bundleDir],
60+
await runPnpm(
61+
[
62+
"deploy",
63+
"--legacy",
64+
"--filter",
65+
"@opengoat/sidecar",
66+
"--prod",
67+
"--config.node-linker=hoisted",
68+
bundleDir,
69+
],
3970
workspaceRoot,
4071
);
4172
await mkdir(dirname(bundledNodePath), { recursive: true });
4273
await cp(process.execPath, bundledNodePath);
43-
await chmod(bundledNodePath, 0o755);
74+
if (process.platform !== "win32") {
75+
await chmod(bundledNodePath, 0o755);
76+
}

0 commit comments

Comments
 (0)