Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/share/src/projectSnapshot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
49 changes: 49 additions & 0 deletions packages/share/tests/projectSnapshotPosix.test.mjs
Original file line number Diff line number Diff line change
@@ -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"), "<h1>Film</h1>");
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"), "<h1>Board</h1>");
await writeFile(join(dir, "compositions", "title.html"), "<h1>Title</h1>");
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);
});
Loading