@@ -25,6 +25,7 @@ import { MidwayTraceService } from './service/traceService';
2525import { ComponentConfigurationLoader } from './context/componentLoader' ;
2626import { findProjectEntryFile , findProjectEntryFileSync } from './util' ;
2727import { AsyncLocalStorageContextManager } from './common/asyncContextManager' ;
28+ import { MODULE_LOADER_KEY } from './constants' ;
2829import {
2930 MidwayInitializerPerformanceManager ,
3031 MidwayPerformanceManager ,
@@ -199,6 +200,14 @@ export async function prepareGlobalApplicationContextAsync(
199200 // register baseDir and appDir
200201 applicationContext . registerObject ( 'baseDir' , baseDir ) ;
201202 applicationContext . registerObject ( 'appDir' , appDir ) ;
203+ if ( globalOptions . moduleLoader ) {
204+ // Keep the custom loader on the container so later module discovery
205+ // phases (for example file detectors) can follow the same load strategy.
206+ applicationContext . registerObject (
207+ MODULE_LOADER_KEY ,
208+ globalOptions . moduleLoader
209+ ) ;
210+ }
202211
203212 if ( ! globalOptions . asyncContextManager ) {
204213 globalOptions . asyncContextManager = new AsyncLocalStorageContextManager ( ) ;
@@ -224,7 +233,12 @@ export async function prepareGlobalApplicationContextAsync(
224233 // set entry file
225234 globalOptions . imports = [
226235 ...( globalOptions . imports ?? [ ] ) ,
227- await findProjectEntryFile ( appDir , baseDir , globalOptions . moduleLoadType ) ,
236+ await findProjectEntryFile (
237+ appDir ,
238+ baseDir ,
239+ globalOptions . moduleLoadType ,
240+ globalOptions . moduleLoader
241+ ) ,
228242 ] ;
229243
230244 MidwayInitializerPerformanceManager . markEnd (
@@ -366,6 +380,14 @@ export function prepareGlobalApplicationContext(
366380 // register baseDir and appDir
367381 applicationContext . registerObject ( 'baseDir' , baseDir ) ;
368382 applicationContext . registerObject ( 'appDir' , appDir ) ;
383+ if ( globalOptions . moduleLoader ) {
384+ // Keep the custom loader on the container so later module discovery
385+ // phases (for example file detectors) can follow the same load strategy.
386+ applicationContext . registerObject (
387+ MODULE_LOADER_KEY ,
388+ globalOptions . moduleLoader
389+ ) ;
390+ }
369391
370392 if ( ! globalOptions . asyncContextManager ) {
371393 globalOptions . asyncContextManager = new AsyncLocalStorageContextManager ( ) ;
0 commit comments