fix(studio-server): a page follows a folder moved out of its own folder

This commit is contained in:
Miguel Angel Simon Sierra
2026-11-03 18:58:58 -05:00
parent ec0ea54063
commit b9978f772e
2 changed files with 16 additions and 1 deletions
@@ -791,6 +791,20 @@ describe("renaming a folder over the route", () => {
);
});
it("in HTML follows a folder moved out of the page's folder", async () => {
const project = mkdtempSync(join(tmpdir(), "hf-rename-refs-"));
dirs.push(project);
mkdirSync(join(project, "assets", "clips"), { recursive: true });
mkdirSync(join(project, "media"));
writeFileSync(join(project, "assets", "clips", "a.png"), "x");
writeFileSync(join(project, "assets", "i.html"), '<img src="clips/a.png">');
expect((await renameIn(project, "assets/clips", "media/clips")).status).toBe(200);
expect(readFileSync(join(project, "assets", "i.html"), "utf8")).toBe(
'<img src="../media/clips/a.png">',
);
});
it("in HTML gives a path the runtime reads from the root to the root pass, where both readings match", async () => {
const project = mkdtempSync(join(tmpdir(), "hf-rename-refs-"));
dirs.push(project);
+2 -1
View File
@@ -1126,9 +1126,10 @@ function updateReferences(
.filter((path) => path.startsWith(`${dir}/`))
.map((path) => path.slice(at + 1));
const [from, to] = [oldPath.slice(at + 1), posix.relative(dir, newPath)];
const everywhere = filesOnly(existing.map((path) => posix.relative(dir, path)));
parentFolderEdits.set(dir, {
css: referenceEdits(from, to, isDirectory, inside, { targets: null }),
html: referenceEdits(from, to, isDirectory, inside, { targets: filesOnly(inside) }),
html: referenceEdits(from, to, isDirectory, inside, { targets: everywhere }),
});
}
let updatedCount = 0;