(root: string, path: string, getHash = (p: string) => getFileHash(root, p))
| 61 | } |
| 62 | |
| 63 | function 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 |
no test coverage detected