@@ -4,17 +4,18 @@ import { CachedInputFileSystem, ResolverFactory } from 'enhanced-resolve'
4
4
5
5
import { defaultConditionNames , defaultExtensionAlias , defaultExtensions , defaultMainFields } from './default'
6
6
import { digestHashObject } from './helpers'
7
+ import { init } from './init'
7
8
import { logger } from './logger'
8
9
import { resolveImport } from './resolveImport'
9
10
10
- import type { InternalResolverOptions , ResolvedResult , ResolverOptions } from './types'
11
+ import type { InternalResolverOptions , Matcher , ResolvedResult , ResolverOptions } from './types'
11
12
import type { Resolver } from 'enhanced-resolve'
12
13
13
14
const times = [ ]
14
15
15
16
let cachedOptions : InternalResolverOptions
16
- let previousOptionsHash : ReturnType < typeof digestHashObject >
17
- let optionsHash : ReturnType < typeof digestHashObject >
17
+ let previousOptionsHash : ReturnType < typeof digestHashObject > | undefined
18
+ let optionsHash : ReturnType < typeof digestHashObject > | undefined
18
19
let resolverCachedOptions : InternalResolverOptions
19
20
let resolver : Resolver | undefined
20
21
@@ -25,7 +26,7 @@ export const interfaceVersion = 2
25
26
* @param file the importing file's full path; i.e. '/usr/local/bin/file.js'
26
27
* @param options
27
28
*/
28
- export function resolve ( specifier : string , file : string , options ?: ResolverOptions | undefined | null ) : ResolvedResult {
29
+ export function resolve ( specifier : string , file : string , options ?: ResolverOptions ) : ResolvedResult {
29
30
let t0 : DOMHighResTimeStamp = 0
30
31
31
32
if ( options ?. performanceToLog ) t0 = performance . now ( )
@@ -43,12 +44,14 @@ export function resolve(specifier: string, file: string, options?: ResolverOptio
43
44
}
44
45
}
45
46
47
+ const matchers : Matcher [ ] = init ( options ?? { } , optionsHash ?? digestHashObject ( options ) )
48
+
46
49
if ( ! resolver || resolverCachedOptions !== cachedOptions ) {
47
50
resolver = ResolverFactory . createResolver ( cachedOptions )
48
51
resolverCachedOptions = cachedOptions
49
52
}
50
53
51
- const result = resolveImport ( specifier , file , cachedOptions , resolver )
54
+ const result = resolveImport ( matchers , specifier , file , cachedOptions , resolver )
52
55
53
56
if ( options ?. performanceToLog ) {
54
57
const t1 = performance . now ( )
@@ -60,15 +63,21 @@ export function resolve(specifier: string, file: string, options?: ResolverOptio
60
63
}
61
64
62
65
export function createImportResolver ( options : ResolverOptions ) {
63
- const resolver = ResolverFactory . createResolver ( {
64
- ...options ,
65
- conditionNames : options ?. conditionNames ?? defaultConditionNames ,
66
- extensions : options ?. extensions ?? defaultExtensions ,
67
- extensionAlias : options ?. extensionAlias ?? defaultExtensionAlias ,
68
- mainFields : options ?. mainFields ?? defaultMainFields ,
69
- fileSystem : new CachedInputFileSystem ( fs , 5 * 1000 ) ,
70
- useSyncFileSystemCalls : true ,
71
- } )
66
+ if ( ! cachedOptions || previousOptionsHash !== ( optionsHash = digestHashObject ( options ) ) ) {
67
+ previousOptionsHash = optionsHash
68
+ cachedOptions = {
69
+ ...options ,
70
+ conditionNames : options ?. conditionNames ?? defaultConditionNames ,
71
+ extensions : options ?. extensions ?? defaultExtensions ,
72
+ extensionAlias : options ?. extensionAlias ?? defaultExtensionAlias ,
73
+ mainFields : options ?. mainFields ?? defaultMainFields ,
74
+ fileSystem : new CachedInputFileSystem ( fs , 5 * 1000 ) ,
75
+ useSyncFileSystemCalls : true ,
76
+ }
77
+ }
78
+
79
+ const matchers : Matcher [ ] = init ( options , optionsHash ?? digestHashObject ( options ) )
80
+ const resolver = ResolverFactory . createResolver ( cachedOptions )
72
81
73
82
return {
74
83
name : 'eslint-import-resolver-x' ,
@@ -78,7 +87,7 @@ export function createImportResolver(options: ResolverOptions) {
78
87
79
88
if ( options ?. performanceToLog ) t0 = performance . now ( )
80
89
81
- const result = resolveImport ( modulePath , source , cachedOptions , resolver )
90
+ const result = resolveImport ( matchers , modulePath , source , cachedOptions , resolver )
82
91
83
92
if ( options ?. performanceToLog ) {
84
93
const t1 = performance . now ( )
0 commit comments