@@ -101,6 +101,7 @@ export class ModuleLinker {
101101 const exports = this . loadCommonJSModule (
102102 errorBase ,
103103 identifier ,
104+ spec ,
104105 referencing . context
105106 ) ;
106107 module = new vm . SyntheticModule < { default : Context } > (
@@ -151,13 +152,24 @@ export class ModuleLinker {
151152 private loadCommonJSModule (
152153 errorBase : string ,
153154 identifier : string ,
155+ spec : string ,
154156 context : vm . Context
155157 ) : any {
156158 // If we've already seen a module with the same identifier, return it, to
157159 // handle import cycles
158160 const cached = this . #cjsModuleCache. get ( identifier ) ;
159161 if ( cached ) return cached . exports ;
160162
163+ const additionalModule = this . additionalModules [ spec ] ;
164+ const module : CommonJSModule = { exports : { } } ;
165+
166+ // If this is an additional module, return it immediately
167+ if ( additionalModule ) {
168+ module . exports . default = additionalModule . default ;
169+ this . #cjsModuleCache. set ( identifier , module ) ;
170+ return module . exports ;
171+ }
172+
161173 // Find first matching module rule ("ignore" requires relative paths)
162174 const relativeIdentifier = path . relative ( "" , identifier ) ;
163175 const rule = this . moduleRules . find ( ( rule ) =>
@@ -170,9 +182,8 @@ export class ModuleLinker {
170182 ) ;
171183 }
172184
173- // Create module and store in cache now as require is sync, so may load
174- // this module again before this function returns
175- const module : CommonJSModule = { exports : { } } ;
185+ // Store in cache now as require is sync, so may load this module again
186+ // before this function returns
176187 this . #cjsModuleCache. set ( identifier , module ) ;
177188
178189 // Load module based on rule type
@@ -221,7 +232,7 @@ export class ModuleLinker {
221232 const errorBase = `Unable to resolve "${ relative } " dependency "${ spec } "` ;
222233 // Get path to specified module relative to referencing module
223234 const identifier = path . resolve ( referencingDirname , spec ) ;
224- return this . loadCommonJSModule ( errorBase , identifier , context ) ;
235+ return this . loadCommonJSModule ( errorBase , identifier , spec , context ) ;
225236 } ;
226237 }
227238}
0 commit comments