

















@@ -20,6 +20,7 @@ const HASHED_ROOT_JS_RE = /^(?<base>.+)-[A-Za-z0-9_-]+\.js$/u;
2020const DEFAULT_CAPTURE_BYTES = 8 * 1024 * 1024;
2121const DEFAULT_HEARTBEAT_MS = 30_000;
2222const DEFAULT_TSDOWN_NODE_OPTIONS = "--max-old-space-size=6144";
23+const DEFAULT_TSDOWN_MAX_OLD_SPACE_MB = 6144;
2324const TERMINATION_GRACE_MS = 5_000;
2425const TSDOWN_OUTPUT_ROOTS = ["dist", "dist-runtime"];
2526const GENERATED_SOURCE_DECLARATION_PATHSPEC = ":(glob)extensions/**/*.d.ts";
@@ -200,16 +201,50 @@ function parseNonNegativeInteger(value) {
200201return Math.trunc(parsed);
201202}
202203204+function normalizeTsdownNodeOptions(nodeOptions) {
205+const parts = nodeOptions.trim().split(/\s+/u).filter(Boolean);
206+const normalized = [];
207+let foundMaxOldSpaceSize = false;
208+209+for (let index = 0; index < parts.length; index += 1) {
210+const part = parts[index];
211+const inlineMatch = part.match(/^--max-old-space-size=(\d+)$/u);
212+if (inlineMatch) {
213+foundMaxOldSpaceSize = true;
214+const value = Math.max(Number(inlineMatch[1]), DEFAULT_TSDOWN_MAX_OLD_SPACE_MB);
215+normalized.push(`--max-old-space-size=${value}`);
216+continue;
217+}
218+219+if (part === "--max-old-space-size") {
220+foundMaxOldSpaceSize = true;
221+const next = parts[index + 1];
222+const parsed = next === undefined ? Number.NaN : Number(next);
223+const value = Number.isFinite(parsed)
224+ ? Math.max(Math.trunc(parsed), DEFAULT_TSDOWN_MAX_OLD_SPACE_MB)
225+ : DEFAULT_TSDOWN_MAX_OLD_SPACE_MB;
226+normalized.push(`--max-old-space-size=${value}`);
227+if (next !== undefined) {
228+index += 1;
229+}
230+continue;
231+}
232+233+normalized.push(part);
234+}
235+236+if (!foundMaxOldSpaceSize) {
237+normalized.push(DEFAULT_TSDOWN_NODE_OPTIONS);
238+}
239+240+return normalized.join(" ");
241+}
242+203243function resolveTsdownEnv(env) {
204244const nodeOptions = env.NODE_OPTIONS?.trim() ?? "";
205-if (/(?:^|\s)--max-old-space-size(?:=|\s+)/u.test(nodeOptions)) {
206-return env;
207-}
208245return {
209246 ...env,
210-NODE_OPTIONS: nodeOptions
211- ? `${nodeOptions} ${DEFAULT_TSDOWN_NODE_OPTIONS}`
212- : DEFAULT_TSDOWN_NODE_OPTIONS,
247+NODE_OPTIONS: normalizeTsdownNodeOptions(nodeOptions),
213248};
214249}
215250此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。