@@ -43,15 +43,6 @@ export interface ResolverOptions {
43
43
}
44
44
45
45
export interface Resolver {
46
- /**
47
- * Sets up the PnP API if it is available such that globals like `require`
48
- * have been monkey-patched to use PnP resolution.
49
- *
50
- * This function does nothing if PnP resolution is not enabled or if the PnP
51
- * API is not available.
52
- */
53
- setupPnP ( ) : Promise < void >
54
-
55
46
/**
56
47
* Resolves a JavaScript module to a file path.
57
48
*
@@ -98,6 +89,11 @@ export interface Resolver {
98
89
*/
99
90
child ( opts : Partial < ResolverOptions > ) : Promise < Resolver >
100
91
92
+ /**
93
+ * Whether or not the PnP API is being used by the resolver
94
+ */
95
+ hasPnP ( ) : Promise < boolean >
96
+
101
97
/**
102
98
* Refresh information the resolver may have cached
103
99
*
@@ -107,17 +103,18 @@ export interface Resolver {
107
103
}
108
104
109
105
export async function createResolver ( opts : ResolverOptions ) : Promise < Resolver > {
110
- let fileSystem = opts . fileSystem ? opts . fileSystem : new CachedInputFileSystem ( fs , 4000 )
111
-
112
106
let pnpApi : PnpApi | null = null
113
107
114
108
// Load PnP API if requested
109
+ // This MUST be done before `CachedInputFileSystem` is created
115
110
if ( typeof opts . pnp === 'object' ) {
116
111
pnpApi = opts . pnp
117
112
} else if ( opts . pnp ) {
118
113
pnpApi = await loadPnPApi ( opts . root )
119
114
}
120
115
116
+ let fileSystem = opts . fileSystem ? opts . fileSystem : new CachedInputFileSystem ( fs , 4000 )
117
+
121
118
let tsconfig : TSConfigApi | null = null
122
119
123
120
// Load TSConfig path mappings
@@ -217,10 +214,6 @@ export async function createResolver(opts: ResolverOptions): Promise<Resolver> {
217
214
return ( await tsconfig ?. substituteId ( id , base ) ) ?? id
218
215
}
219
216
220
- async function setupPnP ( ) {
221
- pnpApi ?. setup ( )
222
- }
223
-
224
217
async function aliases ( base : string ) {
225
218
if ( ! tsconfig ) return { }
226
219
@@ -231,12 +224,16 @@ export async function createResolver(opts: ResolverOptions): Promise<Resolver> {
231
224
await tsconfig ?. refresh ( )
232
225
}
233
226
227
+ async function hasPnP ( ) {
228
+ return ! ! pnpApi
229
+ }
230
+
234
231
return {
235
- setupPnP,
236
232
resolveJsId,
237
233
resolveCssId,
238
234
substituteId,
239
235
refresh,
236
+ hasPnP,
240
237
241
238
aliases,
242
239
0 commit comments