|
1 | 1 | import type { NapiResolveOptions } from 'oxc-resolver'
|
2 |
| -import { createHash } from 'node:crypto' |
3 | 2 | import { existsSync } from 'node:fs'
|
4 | 3 | import { resolve } from 'node:path'
|
5 | 4 | import { cwd } from 'node:process'
|
6 | 5 | import { pathToFileURL } from 'node:url'
|
7 | 6 | import { cloneDeep, isPlainObject, mergeWith } from 'es-toolkit'
|
8 | 7 |
|
9 |
| -export const hashCache: WeakMap<NapiResolveOptions, string> = new WeakMap<NapiResolveOptions, string>() |
10 |
| - |
11 |
| -export function generateHash(obj: any): string { |
12 |
| - function normalize(obj: any): string { |
13 |
| - if (obj === null || obj === 'undefined') { |
14 |
| - return 'null' |
15 |
| - } else if (typeof obj !== 'object') { |
16 |
| - return obj.toString() |
17 |
| - } else if (Array.isArray(obj)) { |
18 |
| - return `[${obj.map(normalize).sort().join(',')}]` |
19 |
| - } |
20 |
| - const sortedKeys = Object.keys(obj).sort() |
21 |
| - return `{${sortedKeys.map((key) => `${key}:${normalize(obj[key])}`).join(',')}}` |
22 |
| - } |
| 8 | +import { stableHash as generateHash } from 'stable-hash' |
23 | 9 |
|
24 |
| - const normalizedString = normalize(obj) |
25 |
| - return createHash('md5').update(normalizedString).digest('hex') |
26 |
| -} |
| 10 | +export const hashCache: WeakMap<NapiResolveOptions, string> = new WeakMap<NapiResolveOptions, string>() |
27 | 11 |
|
28 | 12 | export function hashObject(obj: NapiResolveOptions): string {
|
29 | 13 | if (hashCache.has(obj)) {
|
|
0 commit comments