Skip to content

Commit 4cc59a0

Browse files
committed
perf: remove unnecessary hash cache
related: 0ee9d28#r159191471
1 parent 0ee9d28 commit 4cc59a0

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { isBuiltin } from 'node:module'
44
import { dirname } from 'node:path'
55
import { isNil, pickBy } from 'es-toolkit'
66
import { ResolverFactory } from 'oxc-resolver'
7+
import { stableHash } from 'stable-hash-x'
78
import { getBundlerConfig } from './bundler'
89
import { normalizeOptions } from './normalizeOptions'
9-
import { hashObject, removeQuerystring } from './utils'
10+
import { removeQuerystring } from './utils'
1011

1112
export * from './bundler/exports'
1213
export * from './typings'
@@ -20,7 +21,7 @@ export function resolve(source: string, file: string, options?: OxcResolverOptio
2021

2122
if (resolver == null) {
2223
options ??= {}
23-
const optionsHash = hashObject(options)
24+
const optionsHash = stableHash(options)
2425

2526
if (!cachedResolver || cachedOptionsHash !== optionsHash) {
2627
options = normalizeOptions(options)

src/utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
1-
import type { NapiResolveOptions } from 'oxc-resolver'
21
import { existsSync } from 'node:fs'
32
import { resolve } from 'node:path'
43
import { cwd } from 'node:process'
54
import { pathToFileURL } from 'node:url'
65
import { cloneDeep, isPlainObject, mergeWith } from 'es-toolkit'
7-
import { stableHash } from 'stable-hash-x'
8-
9-
export const hashCache: WeakMap<NapiResolveOptions, string> = new WeakMap<NapiResolveOptions, string>()
10-
11-
export function hashObject(obj: NapiResolveOptions): string {
12-
if (hashCache.has(obj)) {
13-
return hashCache.get(obj)!
14-
}
15-
16-
const hash = stableHash(obj)
17-
hashCache.set(obj, hash)
18-
return hash
19-
}
206

217
export function detectFile(files: string[]): string | undefined {
228
for (const file of files) {

0 commit comments

Comments
 (0)