(root: string, path: string, getHash?: (p: string) => string)
| 91 | * version of an imported npm package changes. |
| 92 | */ |
| 93 | export 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 |
no test coverage detected