@@ -16,25 +16,25 @@ const debug = createDebugger('vite:external')
1616
1717const isExternalCache = new WeakMap <
1818 Environment ,
19- ( id : string , importer ?: string ) => boolean
19+ ( id : string , importer ?: string ) => Promise < boolean >
2020> ( )
2121
22- export function shouldExternalize (
22+ export async function shouldExternalize (
2323 environment : Environment ,
2424 id : string ,
2525 importer : string | undefined ,
26- ) : boolean {
26+ ) : Promise < boolean > {
2727 let isExternal = isExternalCache . get ( environment )
2828 if ( ! isExternal ) {
2929 isExternal = createIsExternal ( environment )
3030 isExternalCache . set ( environment , isExternal )
3131 }
32- return isExternal ( id , importer )
32+ return await isExternal ( id , importer )
3333}
3434
3535export function createIsConfiguredAsExternal (
3636 environment : PartialEnvironment ,
37- ) : ( id : string , importer ?: string ) => boolean {
37+ ) : ( id : string , importer ?: string ) => Promise < boolean > {
3838 const { config } = environment
3939 const { root, resolve } = config
4040 const { external, noExternal } = resolve
@@ -53,16 +53,16 @@ export function createIsConfiguredAsExternal(
5353 conditions : targetConditions ,
5454 }
5555
56- const isExternalizable = (
56+ const isExternalizable = async (
5757 id : string ,
5858 importer : string | undefined ,
5959 configuredAsExternal : boolean ,
60- ) : boolean => {
60+ ) : Promise < boolean > => {
6161 if ( ! bareImportRE . test ( id ) || id . includes ( '\0' ) ) {
6262 return false
6363 }
6464 try {
65- const resolved = tryNodeResolve (
65+ const resolved = await tryNodeResolve (
6666 id ,
6767 // Skip passing importer in build to avoid externalizing non-hoisted dependencies
6868 // unresolvable from root (which would be unresolvable from output bundles also)
@@ -91,7 +91,7 @@ export function createIsConfiguredAsExternal(
9191
9292 // Returns true if it is configured as external, false if it is filtered
9393 // by noExternal and undefined if it isn't affected by the explicit config
94- return ( id : string , importer ?: string ) => {
94+ return async ( id : string , importer ?: string ) => {
9595 if (
9696 // If this id is defined as external, force it as external
9797 // Note that individual package entries are allowed in `external`
@@ -120,26 +120,26 @@ export function createIsConfiguredAsExternal(
120120 }
121121 // If external is true, all will be externalized by default, regardless if
122122 // it's a linked package
123- return isExternalizable ( id , importer , external === true )
123+ return await isExternalizable ( id , importer , external === true )
124124 }
125125}
126126
127127function createIsExternal (
128128 environment : Environment ,
129- ) : ( id : string , importer ?: string ) => boolean {
129+ ) : ( id : string , importer ?: string ) => Promise < boolean > {
130130 const processedIds = new Map < string , boolean > ( )
131131
132132 const isConfiguredAsExternal = createIsConfiguredAsExternal ( environment )
133133
134- return ( id : string , importer ?: string ) => {
134+ return async ( id : string , importer ?: string ) => {
135135 if ( processedIds . has ( id ) ) {
136136 return processedIds . get ( id ) !
137137 }
138138 let isExternal = false
139139 if ( id [ 0 ] !== '.' && ! path . isAbsolute ( id ) ) {
140140 isExternal =
141141 isBuiltin ( environment . config . resolve . builtins , id ) ||
142- isConfiguredAsExternal ( id , importer )
142+ ( await isConfiguredAsExternal ( id , importer ) )
143143 }
144144 processedIds . set ( id , isExternal )
145145 return isExternal
0 commit comments