fix: keep runtime model auth alias after build

This commit is contained in:
Peter Steinberger
2026-05-02 23:54:57 +01:00
parent 61349d6bdc
commit f352caf07e
5 changed files with 61 additions and 10 deletions

View File

@@ -122,13 +122,38 @@ export function writeStableRootRuntimeAliases(params = {}) {
candidatesByAlias.set(aliasFileName, candidates);
}
const resolveAliasCandidate = (candidates) => {
if (candidates.length === 1) {
return candidates[0];
}
const candidateSet = new Set(candidates);
const wrappers = candidates.filter((candidate) => {
const filePath = path.join(distDir, candidate);
let source;
try {
source = fsImpl.readFileSync(filePath, "utf8");
} catch {
return false;
}
return candidates.some(
(target) =>
target !== candidate &&
candidateSet.has(target) &&
source.includes(`"./${target}"`) &&
!source.includes("\n//#region "),
);
});
return wrappers.length === 1 ? wrappers[0] : null;
};
for (const [aliasFileName, candidates] of candidatesByAlias) {
const aliasPath = path.join(distDir, aliasFileName);
if (candidates.length !== 1) {
const candidate = resolveAliasCandidate(candidates);
if (!candidate) {
fsImpl.rmSync?.(aliasPath, { force: true });
continue;
}
writeTextFileIfChanged(aliasPath, `export * from "./${candidates[0]}";\n`);
writeTextFileIfChanged(aliasPath, `export * from "./${candidate}";\n`);
}
}