@@ -140,7 +140,9 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre
140140 if ( isWrappedId ( resolved . id , ES_IMPORT_SUFFIX ) ) {
141141 return (
142142 ( await getTypeForImportedModule (
143- ( await this . load ( { id : resolved . id } ) ) . meta . commonjs . resolved ,
143+ (
144+ await this . load ( { id : resolved . id } )
145+ ) . meta . commonjs . resolved ,
144146 this . load
145147 ) ) !== IS_WRAPPED_COMMONJS
146148 ) ;
@@ -151,61 +153,56 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre
151153 ) . some ( ( shouldTransform ) => shouldTransform ) ;
152154 } ,
153155 /* eslint-disable no-param-reassign */
154- resolveRequireSourcesAndUpdateMeta : ( rollupContext ) => async (
155- parentId ,
156- isParentCommonJS ,
157- parentMeta ,
158- sources
159- ) => {
160- parentMeta . initialCommonJSType = isParentCommonJS ;
161- parentMeta . requires = [ ] ;
162- parentMeta . isRequiredCommonJS = Object . create ( null ) ;
163- setInitialParentType ( parentId , isParentCommonJS ) ;
164- const currentlyResolvingForParent = currentlyResolving . get ( parentId ) || new Set ( ) ;
165- currentlyResolving . set ( parentId , currentlyResolvingForParent ) ;
166- const requireTargets = await Promise . all (
167- sources . map ( async ( { source, isConditional } ) => {
168- // Never analyze or proxy internal modules
169- if ( source . startsWith ( '\0' ) ) {
170- return { id : source , allowProxy : false } ;
171- }
172- currentlyResolvingForParent . add ( source ) ;
173- const resolved =
174- ( await rollupContext . resolve ( source , parentId , {
175- custom : { 'node-resolve' : { isRequire : true } }
176- } ) ) || resolveExtensions ( source , parentId , extensions ) ;
177- currentlyResolvingForParent . delete ( source ) ;
178- if ( ! resolved ) {
179- return { id : wrapId ( source , EXTERNAL_SUFFIX ) , allowProxy : false } ;
180- }
181- const childId = resolved . id ;
182- if ( resolved . external ) {
183- return { id : wrapId ( childId , EXTERNAL_SUFFIX ) , allowProxy : false } ;
184- }
185- parentMeta . requires . push ( { resolved, isConditional } ) ;
186- await analyzeRequiredModule ( parentId , resolved , isConditional , rollupContext . load ) ;
187- return { id : childId , allowProxy : true } ;
188- } )
189- ) ;
190- parentMeta . isCommonJS = getTypeForFullyAnalyzedModule ( parentId ) ;
191- fullyAnalyzedModules [ parentId ] = true ;
192- return requireTargets . map ( ( { id : dependencyId , allowProxy } , index ) => {
193- // eslint-disable-next-line no-multi-assign
194- const isCommonJS = ( parentMeta . isRequiredCommonJS [
195- dependencyId
196- ] = getTypeForFullyAnalyzedModule ( dependencyId ) ) ;
197- fullyAnalyzedModules [ dependencyId ] = true ;
198- return {
199- source : sources [ index ] . source ,
200- id : allowProxy
201- ? isCommonJS === IS_WRAPPED_COMMONJS
202- ? wrapId ( dependencyId , WRAPPED_SUFFIX )
203- : wrapId ( dependencyId , PROXY_SUFFIX )
204- : dependencyId ,
205- isCommonJS
206- } ;
207- } ) ;
208- } ,
156+ resolveRequireSourcesAndUpdateMeta :
157+ ( rollupContext ) => async ( parentId , isParentCommonJS , parentMeta , sources ) => {
158+ parentMeta . initialCommonJSType = isParentCommonJS ;
159+ parentMeta . requires = [ ] ;
160+ parentMeta . isRequiredCommonJS = Object . create ( null ) ;
161+ setInitialParentType ( parentId , isParentCommonJS ) ;
162+ const currentlyResolvingForParent = currentlyResolving . get ( parentId ) || new Set ( ) ;
163+ currentlyResolving . set ( parentId , currentlyResolvingForParent ) ;
164+ const requireTargets = await Promise . all (
165+ sources . map ( async ( { source, isConditional } ) => {
166+ // Never analyze or proxy internal modules
167+ if ( source . startsWith ( '\0' ) ) {
168+ return { id : source , allowProxy : false } ;
169+ }
170+ currentlyResolvingForParent . add ( source ) ;
171+ const resolved =
172+ ( await rollupContext . resolve ( source , parentId , {
173+ custom : { 'node-resolve' : { isRequire : true } }
174+ } ) ) || resolveExtensions ( source , parentId , extensions ) ;
175+ currentlyResolvingForParent . delete ( source ) ;
176+ if ( ! resolved ) {
177+ return { id : wrapId ( source , EXTERNAL_SUFFIX ) , allowProxy : false } ;
178+ }
179+ const childId = resolved . id ;
180+ if ( resolved . external ) {
181+ return { id : wrapId ( childId , EXTERNAL_SUFFIX ) , allowProxy : false } ;
182+ }
183+ parentMeta . requires . push ( { resolved, isConditional } ) ;
184+ await analyzeRequiredModule ( parentId , resolved , isConditional , rollupContext . load ) ;
185+ return { id : childId , allowProxy : true } ;
186+ } )
187+ ) ;
188+ parentMeta . isCommonJS = getTypeForFullyAnalyzedModule ( parentId ) ;
189+ fullyAnalyzedModules [ parentId ] = true ;
190+ return requireTargets . map ( ( { id : dependencyId , allowProxy } , index ) => {
191+ // eslint-disable-next-line no-multi-assign
192+ const isCommonJS = ( parentMeta . isRequiredCommonJS [ dependencyId ] =
193+ getTypeForFullyAnalyzedModule ( dependencyId ) ) ;
194+ fullyAnalyzedModules [ dependencyId ] = true ;
195+ return {
196+ source : sources [ index ] . source ,
197+ id : allowProxy
198+ ? isCommonJS === IS_WRAPPED_COMMONJS
199+ ? wrapId ( dependencyId , WRAPPED_SUFFIX )
200+ : wrapId ( dependencyId , PROXY_SUFFIX )
201+ : dependencyId ,
202+ isCommonJS
203+ } ;
204+ } ) ;
205+ } ,
209206 isCurrentlyResolving ( source , parentId ) {
210207 const currentlyResolvingForParent = currentlyResolving . get ( parentId ) ;
211208 return currentlyResolvingForParent && currentlyResolvingForParent . has ( source ) ;
0 commit comments