Build: narrow tsdown unresolved import guard
This commit is contained in:
parent
13f396b395
commit
c2402e48c9
@ -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);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user