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); }