1+ import { stableHash } from 'stable-hash-x'
12import { globSync , isDynamicPattern } from 'tinyglobby'
23import type { TsconfigOptions } from 'unrs-resolver'
34
@@ -16,7 +17,7 @@ import type { TypeScriptResolverOptions } from './types.js'
1617
1718export let defaultConfigFile : string
1819
19- const configFileMapping = new Map < string , string > ( )
20+ const configFileMapping = new Map < string , TypeScriptResolverOptions > ( )
2021
2122let warned : boolean | undefined
2223
@@ -76,18 +77,24 @@ export function normalizeOptions(
7677 ensured = true
7778 }
7879
80+ const optionsHash = stableHash ( options )
7981 if ( configFile ) {
80- let cachedConfigFile : string | undefined = configFileMapping . get ( configFile )
81- if ( cachedConfigFile ) {
82- log ( 'using cached config file for' , configFile )
83- configFile = cachedConfigFile
84- } else if ( ! ensured && configFile !== defaultConfigFile ) {
85- cachedConfigFile = tryFile ( DEFAULT_TRY_PATHS , false , configFile )
86- configFileMapping . set ( configFile , cachedConfigFile )
87- configFile = cachedConfigFile
82+ const cachedOptions = configFileMapping . get ( `${ configFile } \0${ optionsHash } ` )
83+ if ( cachedOptions ) {
84+ log (
85+ 'using cached options for' ,
86+ configFile ,
87+ 'with options hash' ,
88+ optionsHash ,
89+ )
90+ return cachedOptions
8891 }
8992 }
9093
94+ if ( ! ensured && configFile && configFile !== defaultConfigFile ) {
95+ configFile = tryFile ( DEFAULT_TRY_PATHS , false , configFile )
96+ }
97+
9198 options = {
9299 conditionNames : defaultConditionNames ,
93100 extensions : defaultExtensions ,
@@ -100,5 +107,9 @@ export function normalizeOptions(
100107 : undefined ,
101108 }
102109
110+ if ( configFile ) {
111+ configFileMapping . set ( `${ configFile } \0${ optionsHash } ` , options )
112+ }
113+
103114 return options
104115}
0 commit comments