fix(build): preserve the selected tsdown runtime (#151735)

This commit is contained in:
Peter Steinberger 2026-09-18 04:32:35 -07:00 • committed by GitHub
parent b9fc4fe10c
commit bae8ef078e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 60 deletions

View file

@ -40,7 +40,6 @@ import {
TSDOWN_PACKAGE_OUTPUT_ROOTS,
tsdownPackageOutputRoot,
} from "./lib/tsdown-output-roots.mts";
import { resolvePnpmRunner } from "./pnpm-runner.mts";
const logLevel = process.env.OPENCLAW_BUILD_VERBOSE ? "info" : "warn";
const INEFFECTIVE_DYNAMIC_IMPORT_MARKER = "[INEFFECTIVE_DYNAMIC_IMPORT]";
@ -137,9 +136,7 @@ type ResolvedMemoryLimitParams = MemoryLimitParams & { resolvedMaxOldSpaceMb?: n
type TsdownBuildParams = ResolvedMemoryLimitParams & {
args?: string[];
comSpec?: string;
nodeExecPath?: string;
npmExecPath?: string;
};
type TsdownBuildResult = ReturnType<ReturnType<typeof createTsdownOutputScanner>["finish"]> & {
@ -925,33 +922,15 @@ export function resolveTsdownBuildInvocation(
"--no-clean",
...forwardedArgs,
];
if (env.OPENCLAW_BUILD_ALL_NO_PNPM === "1") {
return {
command: params.nodeExecPath ?? process.execPath,
args: ["node_modules/tsdown/dist/run.mjs", ...tsdownArgs],
options: {
stdio: tsdownStdio(),
shell: false,
windowsVerbatimArguments: undefined,
env,
},
};
}
const runner = resolvePnpmRunner({
env,
pnpmArgs: ["exec", "tsdown", ...tsdownArgs],
nodeExecPath: params.nodeExecPath ?? process.execPath,
npmExecPath: params.npmExecPath ?? env.npm_execpath,
comSpec: params.comSpec,
platform: (params.platform ?? process.platform) === "win32" ? "win32" : "linux",
});
// A package-manager bin shim can select a different runtime from PATH.
// Keep the compiler on the runtime chosen by its build owner.
return {
command: runner.command,
args: runner.args,
command: params.nodeExecPath ?? process.execPath,
args: ["node_modules/tsdown/dist/run.mjs", ...tsdownArgs],
options: {
stdio: tsdownStdio(),
shell: runner.shell,
windowsVerbatimArguments: runner.windowsVerbatimArguments,
shell: false,
windowsVerbatimArguments: undefined,
env,
},
};

View file

@ -95,7 +95,6 @@ type TsdownInvocationParams = NonNullable<Parameters<typeof resolveTsdownBuildIn
function resolveTestNodeOptions(params: TsdownInvocationParams) {
return resolveTsdownBuildInvocation({
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env: {},
...params,
}).options.env.NODE_OPTIONS;
@ -146,12 +145,11 @@ describe("resolveTsdownBuildInvocation", () => {
args: ["--format", "esm"],
platform: "linux",
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env: {},
...NO_MEMORY_LIMIT,
});
expect(result.args).toContain("tsdown");
expect(result.args[0]).toBe("node_modules/tsdown/dist/run.mjs");
expect(result.args).toEqual(expect.arrayContaining(["--config-loader", "unrun", "--no-clean"]));
expect(result.args.slice(-2)).toEqual(["--format", "esm"]);
});
@ -161,7 +159,6 @@ describe("resolveTsdownBuildInvocation", () => {
args: ["--format", "esm"],
platform: "linux",
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env: {},
...NO_MEMORY_LIMIT,
});
@ -192,7 +189,6 @@ describe("resolveTsdownBuildInvocation", () => {
args,
platform: "linux",
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env,
...NO_MEMORY_LIMIT,
});
@ -207,7 +203,6 @@ describe("resolveTsdownBuildInvocation", () => {
args: ["--dts"],
platform: "linux",
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env: { OPENCLAW_RUN_NODE_SKIP_DTS_BUILD: "1" },
...NO_MEMORY_LIMIT,
});
@ -244,7 +239,6 @@ describe("resolveTsdownBuildInvocation", () => {
],
platform: "linux",
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env: {},
...NO_MEMORY_LIMIT,
});
@ -340,7 +334,6 @@ describe("resolveTsdownBuildInvocation", () => {
args,
platform: "linux",
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env: {},
...NO_MEMORY_LIMIT,
});
@ -361,7 +354,6 @@ describe("resolveTsdownBuildInvocation", () => {
args,
platform: "linux",
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env: {},
...NO_MEMORY_LIMIT,
});
@ -434,7 +426,6 @@ describe("resolveTsdownBuildInvocation", () => {
const result = resolveTsdownBuildPlan({
platform: "linux",
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env: {},
cgroupMemoryLimitPaths: ["/test/memory.max"],
fs: {
@ -465,7 +456,6 @@ describe("resolveTsdownBuildInvocation", () => {
args,
platform: "linux",
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env: {},
cgroupMemoryLimitBytes: 4 * 1024 * 1024 * 1024,
});
@ -662,7 +652,6 @@ describe("resolveTsdownBuildInvocation", () => {
args,
platform: "linux",
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env,
cgroupMemoryLimitBytes: 2 * 1024 * 1024 * 1024,
});
@ -682,15 +671,10 @@ describe("resolveTsdownBuildInvocation", () => {
expect(result.heapShortfall?.fatal).toBe(true);
});
it("routes Windows tsdown builds through the pnpm runner instead of shell=true", () => {
const rootDir = createTempDir("openclaw-pnpm-runner-");
const npmExecPath = path.join(rootDir, "pnpm.cjs");
fs.writeFileSync(npmExecPath, "console.log('pnpm');\n");
it("keeps the selected Windows runtime and literal compiler arguments", () => {
const result = resolveTsdownBuildInvocation({
platform: "win32",
nodeExecPath: "C:\\Program Files\\nodejs\\node.exe",
npmExecPath,
env: {},
...NO_MEMORY_LIMIT,
});
@ -698,9 +682,7 @@ describe("resolveTsdownBuildInvocation", () => {
expect(result).toEqual({
command: "C:\\Program Files\\nodejs\\node.exe",
args: [
npmExecPath,
"exec",
"tsdown",
"node_modules/tsdown/dist/run.mjs",
"--config-loader",
"unrun",
"--logLevel",
@ -721,7 +703,6 @@ describe("resolveTsdownBuildInvocation", () => {
title: "keeps inherited Windows tsdown heap settings at the Windows build cap",
platform: "win32",
execPath: "C:\\Program Files\\nodejs\\node.exe",
pnpmPath: "C:\\repo\\pnpm.cjs",
nodeOptions: "--trace-warnings --max-old-space-size=8192",
expectedNodeOptions: "--trace-warnings --max-old-space-size=8192",
},
@ -729,7 +710,6 @@ describe("resolveTsdownBuildInvocation", () => {
title: "clamps explicit Windows tsdown heap settings to the Windows build cap",
platform: "win32",
execPath: "C:\\Program Files\\nodejs\\node.exe",
pnpmPath: "C:\\repo\\pnpm.cjs",
nodeOptions: "--trace-warnings --max-old-space-size=12288",
expectedNodeOptions: "--trace-warnings --max-old-space-size=8192",
},
@ -737,7 +717,6 @@ describe("resolveTsdownBuildInvocation", () => {
title: "preserves explicit tsdown heap settings",
platform: "linux",
execPath: "/usr/bin/node",
pnpmPath: "/tmp/pnpm.cjs",
nodeOptions: "--trace-warnings --max-old-space-size=12288",
expectedNodeOptions: "--trace-warnings --max-old-space-size=12288",
},
@ -745,7 +724,6 @@ describe("resolveTsdownBuildInvocation", () => {
title: "raises inherited lower tsdown heap settings to the build default",
platform: "linux",
execPath: "/usr/bin/node",
pnpmPath: "/tmp/pnpm.cjs",
nodeOptions: "--trace-warnings --max-old-space-size=4096",
expectedNodeOptions: "--trace-warnings --max-old-space-size=12288",
},
@ -753,15 +731,13 @@ describe("resolveTsdownBuildInvocation", () => {
title: "raises split inherited lower tsdown heap settings to the build default",
platform: "linux",
execPath: "/usr/bin/node",
pnpmPath: "/tmp/pnpm.cjs",
nodeOptions: "--trace-warnings --max-old-space-size 4096",
expectedNodeOptions: "--trace-warnings --max-old-space-size=12288",
},
])("$title", ({ platform, execPath, pnpmPath, nodeOptions, expectedNodeOptions }) => {
])("$title", ({ platform, execPath, nodeOptions, expectedNodeOptions }) => {
const result = resolveTsdownBuildInvocation({
platform,
nodeExecPath: execPath,
npmExecPath: pnpmPath,
env: { NODE_OPTIONS: nodeOptions },
...NO_MEMORY_LIMIT,
});
@ -1700,7 +1676,6 @@ describe("resolveTsdownBuildInvocation", () => {
const result = resolveTsdownBuildInvocation({
platform: "win32",
nodeExecPath: "C:\\Program Files\\nodejs\\node.exe",
npmExecPath: "C:\\repo\\pnpm.cjs",
env: {
NODE_OPTIONS: "--trace-warnings --max-old-space-size=12288",
OPENCLAW_TSDOWN_MAX_OLD_SPACE_MB: "4096",
@ -1716,7 +1691,6 @@ describe("resolveTsdownBuildInvocation", () => {
expect(() =>
resolveTsdownBuildInvocation({
nodeExecPath: "/usr/bin/node",
npmExecPath: "/tmp/pnpm.cjs",
env: { OPENCLAW_TSDOWN_MAX_OLD_SPACE_MB: value },
...NO_MEMORY_LIMIT,
}),
@ -1739,11 +1713,11 @@ describe("resolveTsdownBuildInvocation", () => {
expect(nodeOptions).toBe("--max-old-space-size=6400");
});
it("can run tsdown without invoking pnpm", () => {
it("preserves the selected compiler runtime despite inherited package-manager state", () => {
const result = resolveTsdownBuildInvocation({
platform: "linux",
nodeExecPath: "/usr/bin/node",
env: { OPENCLAW_BUILD_ALL_NO_PNPM: "1" },
env: { npm_execpath: "/unrelated/pnpm.cjs" },
...NO_MEMORY_LIMIT,
});
@ -1763,7 +1737,7 @@ describe("resolveTsdownBuildInvocation", () => {
windowsVerbatimArguments: undefined,
env: {
NODE_OPTIONS: "--max-old-space-size=12288",
OPENCLAW_BUILD_ALL_NO_PNPM: "1",
npm_execpath: "/unrelated/pnpm.cjs",
},
},
});