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

Function getLocalModuleHash

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

Source from the content-addressed store, hash-verified

91 * version of an imported npm package changes.
92 */
93export async function getLocalModuleHash(root: string, path: string, getHash?: (p: string) => string): Promise<string> {
94 const hash = getModuleHashInternal(root, path, getHash);
95 const info = getModuleInfo(root, path);
96 if (info) {
97 const globalPaths = new Set<string>();
98 for (const i of [...info.globalStaticImports, ...info.globalDynamicImports]) {
99 if (builtins.has(i) || i.startsWith("observablehq:")) {
100 hash.update(`${resolveBuiltin(i)}?version=${process.env.npm_package_version}`); // change hash when Framework changes
101 } else if (i.startsWith("npm:")) {
102 globalPaths.add(await resolveNpmImport(root, i.slice("npm:".length)));
103 } else if (i.startsWith("jsr:")) {
104 globalPaths.add(await resolveJsrImport(root, i.slice("jsr:".length)));
105 } else if (!/^\w+:/.test(i)) {
106 globalPaths.add(await resolveNodeImport(root, i));
107 }
108 }
109 for (const p of globalPaths) {
110 hash.update(p);
111 for (const i of await parseImports(join(root, ".observablehq", "cache"), p)) {
112 if (i.type === "local") {
113 globalPaths.add(resolvePath(p, i.name));
114 }
115 }
116 }
117 }
118 return hash.digest("hex");
119}
120
121/**
122 * Returns the information for the module at the specified path within the

Callers 1

getLocalModuleHashMethod · 0.85

Calls 8

resolveJsrImportFunction · 0.90
getModuleHashInternalFunction · 0.85
getModuleInfoFunction · 0.85
resolveBuiltinFunction · 0.85
resolveNpmImportFunction · 0.85
resolveNodeImportFunction · 0.85
parseImportsFunction · 0.85
resolvePathFunction · 0.50

Tested by

no test coverage detected