From b0ea493986ac742920080cd6df53282ba94656d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 1 Dec 2026 18:16:22 +0000 Subject: [PATCH] fix(share): use forward-slash snapshot keys across platforms --- packages/share/src/projectSnapshot.mjs | 13 +++-- .../share/tests/projectSnapshotPosix.test.mjs | 49 +++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 packages/share/tests/projectSnapshotPosix.test.mjs diff --git a/packages/share/src/projectSnapshot.mjs b/packages/share/src/projectSnapshot.mjs index 1ba3caca308..586a7c8a367 100644 --- a/packages/share/src/projectSnapshot.mjs +++ b/packages/share/src/projectSnapshot.mjs @@ -137,7 +137,7 @@ export async function snapshotProject( if (kind?.isDirectory()) await walk(full, parents); else if (kind?.isFile()) { const key = await snapshotKey(full, byContent, fileTick); - if (key !== undefined) result.set(path.relative(dir, full), key); + if (key !== undefined) result.set(snapshotRelativePath(dir, full), key); } } } @@ -173,11 +173,11 @@ export async function snapshotFiles(dir, files, { lenientIgnore = false } = {}) const result = new Map(); const ignored = await ignoreFor(dir, lenientIgnore); for (const file of files) { - const full = path.join(dir, file); + const full = path.join(dir, file.replaceAll("\\", "/")); const stat = await fs.lstat(full).catch(() => null); if (stat?.isDirectory()) return null; const holds = stat?.isFile() && !excludedFromSnapshot(dir, full, ignored); - result.set(file, holds ? await snapshotKey(full, false) : undefined); + result.set(snapshotRelativePath(dir, full), holds ? await snapshotKey(full, false) : undefined); } return result; } @@ -204,8 +204,11 @@ export const projectFingerprint = async (projectPath, options) => /** @param {string} dir @param {boolean} lenient */ const ignoreFor = (dir, lenient) => (lenient ? readChangeIgnore(dir) : readSourceIgnore(dir)); +/** @param {string} dir @param {string} full */ +const snapshotRelativePath = (dir, full) => path.relative(dir, full).replaceAll("\\", "/"); + /** @param {string} dir @param {string} full @param {(path: string) => boolean} ignored */ function excludedFromSnapshot(dir, full, ignored) { - const relative = path.relative(dir, full); - return isOutsideFilm(relative) || ignored(relative.split(path.sep).join("/")); + const relative = snapshotRelativePath(dir, full); + return isOutsideFilm(relative) || ignored(relative); } diff --git a/packages/share/tests/projectSnapshotPosix.test.mjs b/packages/share/tests/projectSnapshotPosix.test.mjs new file mode 100644 index 00000000000..4ff15b8ee0c --- /dev/null +++ b/packages/share/tests/projectSnapshotPosix.test.mjs @@ -0,0 +1,49 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; +import { syncBuiltinESMExports } from "node:module"; +import { tmpdir } from "node:os"; +import path, { join } from "node:path"; +import { diffChangedFiles, snapshotFiles, snapshotProject } from "../src/projectSnapshot.mjs"; + +// fails without the fix: snapshotProject keyed entries with raw path.relative(), which emits backslashes on Windows, +// while excludedFromSnapshot normalized with path.sep. +test("snapshotProject, snapshotFiles, and ignore matching share forward-slash keys with Windows-style relative paths", async (t) => { + const dir = await mkdtemp(join(tmpdir(), "hf-share-win-snapshot-")); + const originalRelative = path.relative; + path.relative = (...args) => path.win32.relative(...args); + syncBuiltinESMExports(); + t.after(async () => { + path.relative = originalRelative; + syncBuiltinESMExports(); + await rm(dir, { recursive: true, force: true }); + }); + + await writeFile(join(dir, "index.html"), "

Film

"); + await writeFile(join(dir, ".hyperframesignore"), "assets/raw.mov\n"); + const before = await snapshotProject(dir); + + await mkdir(join(dir, "boards"), { recursive: true }); + await mkdir(join(dir, "compositions"), { recursive: true }); + await mkdir(join(dir, "assets"), { recursive: true }); + await writeFile(join(dir, "boards", "storyboard.html"), "

Board

"); + await writeFile(join(dir, "compositions", "title.html"), "

Title

"); + await writeFile(join(dir, "assets", "raw.mov"), "ignored"); + + const after = await snapshotProject(dir); + assert.deepEqual([...after.keys()].sort(), [ + "boards/storyboard.html", + "compositions/title.html", + "index.html", + ]); + assert.deepEqual(diffChangedFiles(before, after).sort(), [ + "boards/storyboard.html", + "compositions/title.html", + ]); + + const picked = await snapshotFiles(dir, ["boards\\storyboard.html", "assets\\raw.mov"]); + assert.ok(picked); + assert.deepEqual([...picked.keys()].sort(), ["assets/raw.mov", "boards/storyboard.html"]); + assert.notEqual(picked.get("boards/storyboard.html"), undefined); + assert.equal(picked.get("assets/raw.mov"), undefined); +});