fix: materialize stale runtime mirror symlinks

This commit is contained in:
Peter Steinberger
2026-04-27 07:42:42 +01:00
parent 04be516926
commit 566295cd34
2 changed files with 28 additions and 1 deletions

View File

@@ -240,6 +240,30 @@ describe("installBundledRuntimeDeps", () => {
expect(fs.readFileSync(chunkPath, "utf8")).toContain("same-file");
});
it("replaces stale mirror symlinks when materializing chunks", () => {
const tempDir = makeTempDir();
const sourcePath = path.join(tempDir, "dist", "accounts.js");
const targetPath = path.join(tempDir, "stage", "dist", "accounts.js");
fs.mkdirSync(path.dirname(sourcePath), { recursive: true });
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
fs.writeFileSync(
sourcePath,
[
`//#region extensions/slack/src/accounts.ts`,
`export const marker = "source";`,
`//#endregion`,
"",
].join("\n"),
"utf8",
);
fs.symlinkSync(sourcePath, targetPath, "file");
materializeBundledRuntimeMirrorDistFile(sourcePath, targetPath);
expect(fs.lstatSync(targetPath).isSymbolicLink()).toBe(false);
expect(fs.readFileSync(targetPath, "utf8")).toContain("source");
});
it("uses a real write probe for runtime dependency roots", () => {
const accessSpy = vi.spyOn(fs, "accessSync").mockImplementation(() => undefined);
const mkdirSpy = vi.spyOn(fs, "mkdtempSync").mockImplementation(() => {

View File

@@ -91,7 +91,10 @@ export function materializeBundledRuntimeMirrorDistFile(
return;
}
try {
if (fs.realpathSync(sourcePath) === fs.realpathSync(targetPath)) {
if (
fs.realpathSync(sourcePath) === fs.realpathSync(targetPath) &&
!fs.lstatSync(targetPath).isSymbolicLink()
) {
return;
}
} catch {