From 8de57351f7be3fe89f077fcff5f5ec6e50fd5d8d Mon Sep 17 00:00:00 2001 From: "openclaw-clownfish[bot]" <280122609+openclaw-clownfish[bot]@users.noreply.github.com> Date: Mon, 22 Jun 2026 12:22:25 +0000 Subject: [PATCH] fix(build): allow tsdown heap override --- scripts/tsdown-build.mjs | 11 ++--------- test/scripts/tsdown-build.test.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/tsdown-build.mjs b/scripts/tsdown-build.mjs index 7438085b0fb7..60a3bcc1b7ee 100644 --- a/scripts/tsdown-build.mjs +++ b/scripts/tsdown-build.mjs @@ -7,6 +7,7 @@ import fs from "node:fs"; import path from "node:path"; import { pathToFileURL } from "node:url"; import { BUNDLED_PLUGIN_PATH_PREFIX } from "./lib/bundled-plugin-paths.mjs"; +import { parsePositiveInt } from "./lib/numeric-options.mjs"; import { TSDOWN_PACKAGE_OUTPUT_ROOTS } from "./lib/tsdown-output-roots.mjs"; import { resolveWindowsTaskkillPath } from "./lib/windows-taskkill.mjs"; import { resolvePnpmRunner } from "./pnpm-runner.mjs"; @@ -307,15 +308,7 @@ function parsePositiveIntegerEnv(value, name) { if (typeof value !== "string" || value.trim() === "") { return null; } - const text = value.trim(); - if (!/^\d+$/u.test(text)) { - throw new Error(`${name} must be a positive integer`); - } - const parsed = Number(text); - if (!Number.isSafeInteger(parsed) || parsed <= 0) { - throw new Error(`${name} must be a positive safe integer`); - } - return parsed; + return parsePositiveInt(value, name); } function parseNonNegativeIntegerEnv(value, name) { diff --git a/test/scripts/tsdown-build.test.ts b/test/scripts/tsdown-build.test.ts index f984ffcefa01..8ab9900f74b2 100644 --- a/test/scripts/tsdown-build.test.ts +++ b/test/scripts/tsdown-build.test.ts @@ -260,6 +260,17 @@ describe("resolveTsdownBuildInvocation", () => { expect(result.options.env.NODE_OPTIONS).toBe("--max-old-space-size=3072"); }); + it("keeps memory detection when OPENCLAW_TSDOWN_MAX_OLD_SPACE_MB is blank", () => { + const result = resolveTsdownBuildInvocation({ + nodeExecPath: "/usr/bin/node", + npmExecPath: "/tmp/pnpm.cjs", + env: { OPENCLAW_TSDOWN_MAX_OLD_SPACE_MB: " " }, + cgroupMemoryLimitBytes: 7 * 1024 * 1024 * 1024, + }); + + expect(result.options.env.NODE_OPTIONS).toBe("--max-old-space-size=6400"); + }); + it("uses OPENCLAW_TSDOWN_MAX_OLD_SPACE_MB to normalize inherited NODE_OPTIONS", () => { const result = resolveTsdownBuildInvocation({ platform: "win32",