From c2402e48c9da2b5bdd98591d80b5ad185b3097d3 Mon Sep 17 00:00:00 2001 From: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> Date: Wed, 18 Mar 2026 08:29:55 -0500 Subject: [PATCH] Build: narrow tsdown unresolved import guard --- scripts/tsdown-build.mjs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/tsdown-build.mjs b/scripts/tsdown-build.mjs index 5faa9799dbb..871e89ddbf0 100644 --- a/scripts/tsdown-build.mjs +++ b/scripts/tsdown-build.mjs @@ -6,6 +6,23 @@ const logLevel = process.env.OPENCLAW_BUILD_VERBOSE ? "info" : "warn"; const extraArgs = process.argv.slice(2); const INEFFECTIVE_DYNAMIC_IMPORT_RE = /\[INEFFECTIVE_DYNAMIC_IMPORT\]/; const UNRESOLVED_IMPORT_RE = /\[UNRESOLVED_IMPORT\]/; +const ANSI_ESCAPE_RE = new RegExp(String.raw`\u001B\[[0-9;]*m`, "g"); + +function findFatalUnresolvedImport(lines) { + for (const line of lines) { + if (!UNRESOLVED_IMPORT_RE.test(line)) { + continue; + } + + const normalizedLine = line.replace(ANSI_ESCAPE_RE, ""); + if (!normalizedLine.includes("extensions/")) { + return normalizedLine; + } + } + + return null; +} + const result = spawnSync( "pnpm", ["exec", "tsdown", "--config-loader", "unrun", "--logLevel", logLevel, ...extraArgs], @@ -32,10 +49,11 @@ if (result.status === 0 && INEFFECTIVE_DYNAMIC_IMPORT_RE.test(`${stdout}\n${stde process.exit(1); } -if (result.status === 0 && UNRESOLVED_IMPORT_RE.test(`${stdout}\n${stderr}`)) { - console.error( - "Build emitted [UNRESOLVED_IMPORT]. Declare or bundle the missing dependency instead of silently externalizing it.", - ); +const fatalUnresolvedImport = + result.status === 0 ? findFatalUnresolvedImport(`${stdout}\n${stderr}`.split("\n")) : null; + +if (fatalUnresolvedImport) { + console.error(`Build emitted [UNRESOLVED_IMPORT] outside extensions: ${fatalUnresolvedImport}`); process.exit(1); }