MCPcopy Create free account
hub / github.com/observablehq/framework / getModuleHashInternal

Function getModuleHashInternal

src/javascript/module.ts:63–85  ·  view source on GitHub ↗
(root: string, path: string, getHash = (p: string) => getFileHash(root, p))

Source from the content-addressed store, hash-verified

61}
62
63function getModuleHashInternal(root: string, path: string, getHash = (p: string) => getFileHash(root, p)): Hash {
64 const hash = createHash("sha256");
65 const paths = new Set([path]);
66 for (const path of paths) {
67 if (path.endsWith(".js")) {
68 const info = getModuleInfo(root, path);
69 if (!info) continue; // ignore missing file
70 hash.update(info.hash);
71 for (const i of info.localStaticImports) {
72 paths.add(resolvePath(path, i));
73 }
74 for (const i of info.localDynamicImports) {
75 paths.add(resolvePath(path, i));
76 }
77 for (const i of info.files) {
78 hash.update(getHash(resolvePath(path, i)));
79 }
80 } else {
81 hash.update(getHash(path)); // e.g., import.meta.resolve("foo.json")
82 }
83 }
84 return hash;
85}
86
87/**
88 * Like getModuleHash, but further takes into consideration the resolved exact

Callers 2

getModuleHashFunction · 0.85
getLocalModuleHashFunction · 0.85

Calls 3

getFileHashFunction · 0.85
getModuleInfoFunction · 0.85
resolvePathFunction · 0.50

Tested by

no test coverage detected