Skip to content

Commit

Permalink
getSourceFileHash
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 15, 2024
1 parent a1946d5 commit 8069f6b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/dataloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class LoaderResolver {
return path;
}

getFileHash(name: string): string {
getSourceFileHash(name: string): string {
return getFileHash(this.root, this.getSourceFilePath(name));
}

Expand All @@ -170,7 +170,7 @@ export class LoaderResolver {
}

resolveFilePath(path: string): string {
return `/${join("_file", path)}?sha=${this.getFileHash(path)}`;
return `/${join("_file", path)}?sha=${this.getSourceFileHash(path)}`;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ export async function getResolvers(
}

// Compute the content hash.
for (const f of assets) hash.update(loaders.getFileHash(resolvePath(path, f)));
for (const f of files) hash.update(loaders.getFileHash(resolvePath(path, f)));
for (const f of assets) hash.update(loaders.getSourceFileHash(resolvePath(path, f)));
for (const f of files) hash.update(loaders.getSourceFileHash(resolvePath(path, f)));
for (const i of localImports) hash.update(getModuleHash(root, resolvePath(path, i)));
if (page.style && isPathImport(page.style)) hash.update(loaders.getFileHash(resolvePath(path, page.style)));
if (page.style && isPathImport(page.style)) hash.update(loaders.getSourceFileHash(resolvePath(path, page.style)));

// Collect transitively-attached files and local imports.
for (const i of localImports) {
Expand Down
14 changes: 7 additions & 7 deletions test/dataloaders-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ describe("LoaderResolver.find(path, {useStale: true})", () => {
});
});

describe("LoaderResolver.getFileHash(path)", () => {
describe("LoaderResolver.getSourceFileHash(path)", () => {
it("returns the content hash for the specified file’s data loader", async () => {
const loaders = new LoaderResolver({root: "test/input/build/archives.posix"});
assert.strictEqual(loaders.getFileHash("dynamic.zip.sh"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
assert.strictEqual(loaders.getFileHash("dynamic.zip"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
assert.strictEqual(loaders.getFileHash("dynamic/file.txt"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
assert.strictEqual(loaders.getFileHash("static.zip"), "e6afff224da77b900cfe3ab8789f2283883300e1497548c30af66dfe4c29b429"); // prettier-ignore
assert.strictEqual(loaders.getFileHash("static/file.txt"), "e6afff224da77b900cfe3ab8789f2283883300e1497548c30af66dfe4c29b429"); // prettier-ignore
assert.strictEqual(loaders.getSourceFileHash("dynamic.zip.sh"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
assert.strictEqual(loaders.getSourceFileHash("dynamic.zip"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
assert.strictEqual(loaders.getSourceFileHash("dynamic/file.txt"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
assert.strictEqual(loaders.getSourceFileHash("static.zip"), "e6afff224da77b900cfe3ab8789f2283883300e1497548c30af66dfe4c29b429"); // prettier-ignore
assert.strictEqual(loaders.getSourceFileHash("static/file.txt"), "e6afff224da77b900cfe3ab8789f2283883300e1497548c30af66dfe4c29b429"); // prettier-ignore
});
it("returns the empty hash if the specified file does not exist", async () => {
const loaders = new LoaderResolver({root: "test/input/build/files"});
assert.strictEqual(loaders.getFileHash("does-not-exist.csv"), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); // prettier-ignore
assert.strictEqual(loaders.getSourceFileHash("does-not-exist.csv"), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); // prettier-ignore
});
});

Expand Down

0 comments on commit 8069f6b

Please sign in to comment.