diff --git a/src/plugins/bundled-runtime-deps.test.ts b/src/plugins/bundled-runtime-deps.test.ts index 360a2978786..ce23de0f8ae 100644 --- a/src/plugins/bundled-runtime-deps.test.ts +++ b/src/plugins/bundled-runtime-deps.test.ts @@ -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(() => { diff --git a/src/plugins/bundled-runtime-deps.ts b/src/plugins/bundled-runtime-deps.ts index d3ba071d0f6..252ba6ec2e5 100644 --- a/src/plugins/bundled-runtime-deps.ts +++ b/src/plugins/bundled-runtime-deps.ts @@ -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 {