Skip to content

Commit 8069f6b

Browse files
committed
getSourceFileHash
1 parent a1946d5 commit 8069f6b

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/dataloader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class LoaderResolver {
155155
return path;
156156
}
157157

158-
getFileHash(name: string): string {
158+
getSourceFileHash(name: string): string {
159159
return getFileHash(this.root, this.getSourceFilePath(name));
160160
}
161161

@@ -170,7 +170,7 @@ export class LoaderResolver {
170170
}
171171

172172
resolveFilePath(path: string): string {
173-
return `/${join("_file", path)}?sha=${this.getFileHash(path)}`;
173+
return `/${join("_file", path)}?sha=${this.getSourceFileHash(path)}`;
174174
}
175175
}
176176

src/resolvers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ export async function getResolvers(
116116
}
117117

118118
// Compute the content hash.
119-
for (const f of assets) hash.update(loaders.getFileHash(resolvePath(path, f)));
120-
for (const f of files) hash.update(loaders.getFileHash(resolvePath(path, f)));
119+
for (const f of assets) hash.update(loaders.getSourceFileHash(resolvePath(path, f)));
120+
for (const f of files) hash.update(loaders.getSourceFileHash(resolvePath(path, f)));
121121
for (const i of localImports) hash.update(getModuleHash(root, resolvePath(path, i)));
122-
if (page.style && isPathImport(page.style)) hash.update(loaders.getFileHash(resolvePath(path, page.style)));
122+
if (page.style && isPathImport(page.style)) hash.update(loaders.getSourceFileHash(resolvePath(path, page.style)));
123123

124124
// Collect transitively-attached files and local imports.
125125
for (const i of localImports) {

test/dataloaders-test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,18 @@ describe("LoaderResolver.find(path, {useStale: true})", () => {
9999
});
100100
});
101101

102-
describe("LoaderResolver.getFileHash(path)", () => {
102+
describe("LoaderResolver.getSourceFileHash(path)", () => {
103103
it("returns the content hash for the specified file’s data loader", async () => {
104104
const loaders = new LoaderResolver({root: "test/input/build/archives.posix"});
105-
assert.strictEqual(loaders.getFileHash("dynamic.zip.sh"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
106-
assert.strictEqual(loaders.getFileHash("dynamic.zip"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
107-
assert.strictEqual(loaders.getFileHash("dynamic/file.txt"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
108-
assert.strictEqual(loaders.getFileHash("static.zip"), "e6afff224da77b900cfe3ab8789f2283883300e1497548c30af66dfe4c29b429"); // prettier-ignore
109-
assert.strictEqual(loaders.getFileHash("static/file.txt"), "e6afff224da77b900cfe3ab8789f2283883300e1497548c30af66dfe4c29b429"); // prettier-ignore
105+
assert.strictEqual(loaders.getSourceFileHash("dynamic.zip.sh"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
106+
assert.strictEqual(loaders.getSourceFileHash("dynamic.zip"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
107+
assert.strictEqual(loaders.getSourceFileHash("dynamic/file.txt"), "516cec2431ce8f1181a7a2a161db8bdfcaea132d3b2c37f863ea6f05d64d1d10"); // prettier-ignore
108+
assert.strictEqual(loaders.getSourceFileHash("static.zip"), "e6afff224da77b900cfe3ab8789f2283883300e1497548c30af66dfe4c29b429"); // prettier-ignore
109+
assert.strictEqual(loaders.getSourceFileHash("static/file.txt"), "e6afff224da77b900cfe3ab8789f2283883300e1497548c30af66dfe4c29b429"); // prettier-ignore
110110
});
111111
it("returns the empty hash if the specified file does not exist", async () => {
112112
const loaders = new LoaderResolver({root: "test/input/build/files"});
113-
assert.strictEqual(loaders.getFileHash("does-not-exist.csv"), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); // prettier-ignore
113+
assert.strictEqual(loaders.getSourceFileHash("does-not-exist.csv"), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); // prettier-ignore
114114
});
115115
});
116116

0 commit comments

Comments
 (0)