From 8069f6b57d01d5f544374ee0271d6f7e930b7e68 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Fri, 15 Mar 2024 16:16:58 -0700 Subject: [PATCH] getSourceFileHash --- src/dataloader.ts | 4 ++-- src/resolvers.ts | 6 +++--- test/dataloaders-test.ts | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/dataloader.ts b/src/dataloader.ts index e427240b5..a1daf35be 100644 --- a/src/dataloader.ts +++ b/src/dataloader.ts @@ -155,7 +155,7 @@ export class LoaderResolver { return path; } - getFileHash(name: string): string { + getSourceFileHash(name: string): string { return getFileHash(this.root, this.getSourceFilePath(name)); } @@ -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)}`; } } diff --git a/src/resolvers.ts b/src/resolvers.ts index cc817a94c..34da9ac63 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -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) { diff --git a/test/dataloaders-test.ts b/test/dataloaders-test.ts index 24970cee0..8e15c8139 100644 --- a/test/dataloaders-test.ts +++ b/test/dataloaders-test.ts @@ -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 }); });