@@ -21,7 +21,7 @@ import {
21
21
22
22
const root = cwd ( ) ;
23
23
24
- let resolverCache : ResolverFactory | null = null ;
24
+ let relativeResolver : ResolverFactory | null = null ;
25
25
26
26
/**
27
27
* Resolves relative path imports
@@ -36,13 +36,13 @@ function resolveRelativePath(
36
36
modulePath : string ,
37
37
options : NapiResolveOptions ,
38
38
) : ResolvedResult {
39
- if ( ! resolverCache ) {
40
- resolverCache = new ResolverFactory ( options ) ;
39
+ if ( ! relativeResolver ) {
40
+ relativeResolver = new ResolverFactory ( options ) ;
41
41
}
42
42
43
43
const sourceFileDir = path . dirname ( sourceFile ) ;
44
44
45
- const result = resolverCache . sync ( sourceFileDir , modulePath ) ;
45
+ const result = relativeResolver . sync ( sourceFileDir , modulePath ) ;
46
46
47
47
if ( result . path ) {
48
48
return { found : true , path : result . path } ;
@@ -52,6 +52,7 @@ function resolveRelativePath(
52
52
}
53
53
54
54
const pathToPackagesMap = new Map < string , string [ ] > ( ) ;
55
+ let resolver : ResolverFactory | null = null ;
55
56
56
57
export default function resolve (
57
58
modulePath : string ,
@@ -137,12 +138,25 @@ export default function resolve(
137
138
}
138
139
}
139
140
140
- const resolver = new ResolverFactory ( {
141
- alias : resolveAlias ,
142
- tsconfig : configFileOptions ,
143
- roots : resolveRoots ,
144
- ...restOptions ,
145
- } ) ;
141
+ if ( ! resolver ) {
142
+ resolver = new ResolverFactory ( {
143
+ alias : resolveAlias ,
144
+ tsconfig : configFileOptions ,
145
+ roots : resolveRoots ,
146
+ ...restOptions ,
147
+ } ) ;
148
+ } else {
149
+ const oldResolver = resolver ;
150
+
151
+ resolver = oldResolver . cloneWithOptions ( {
152
+ alias : resolveAlias ,
153
+ tsconfig : configFileOptions ,
154
+ roots : resolveRoots ,
155
+ ...restOptions ,
156
+ } ) ;
157
+
158
+ oldResolver . clearCache ( ) ;
159
+ }
146
160
147
161
const result = resolver . sync ( path . dirname ( sourceFile ) , modulePath ) ;
148
162
if ( result . path ) {
0 commit comments