@@ -30,6 +30,7 @@ export interface RunnerOptions {
3030 innerObjects ?: Record < string , object > ;
3131
3232 innerObjectHandlers ?: Record < string , InnerObject [ ] > ;
33+ ModuleConfigUtil ?: typeof ModuleConfigUtil ;
3334}
3435
3536export class Runner {
@@ -46,27 +47,42 @@ export class Runner {
4647
4748 constructor ( cwd : string , options ?: RunnerOptions ) {
4849 this . cwd = cwd ;
49- this . moduleReferences = ModuleConfigUtil . readModuleReference ( this . cwd ) ;
50- this . moduleConfigs = { } ;
51- this . innerObjects = {
52- moduleConfigs : [ {
53- obj : new ModuleConfigs ( this . moduleConfigs ) ,
54- } ] ,
55- moduleConfig : [ ] ,
56- } ;
50+ this . moduleReferences = this . #loadModuleReferences( options ?. ModuleConfigUtil || ModuleConfigUtil ) ;
51+ this . moduleConfigs = this . #loadConfig( options ?. ModuleConfigUtil || ModuleConfigUtil ) ;
52+ this . #prepareInnerObjects( options ) ;
53+ this . loadUnitLoader = new EggModuleLoader ( this . moduleReferences ) ;
54+ const configSourceEggPrototypeHook = new ConfigSourceLoadUnitHook ( ) ;
55+ LoadUnitLifecycleUtil . registerLifecycle ( configSourceEggPrototypeHook ) ;
56+ }
57+
58+ #loadModuleReferences( moduleConfigUtil : typeof ModuleConfigUtil ) {
59+ return moduleConfigUtil . readModuleReference ( this . cwd ) ;
60+ }
5761
62+ #loadConfig( moduleConfigUtil : typeof ModuleConfigUtil ) {
63+ const moduleConfigs = { } ;
5864 for ( const reference of this . moduleReferences ) {
5965 const absoluteRef = {
60- path : ModuleConfigUtil . resolveModuleDir ( reference . path , this . cwd ) ,
66+ path : moduleConfigUtil . resolveModuleDir ( reference . path , this . cwd ) ,
6167 } ;
6268
63- const moduleName = ModuleConfigUtil . readModuleNameSync ( absoluteRef . path ) ;
64- this . moduleConfigs [ moduleName ] = {
69+ const moduleName = moduleConfigUtil . readModuleNameSync ( absoluteRef . path ) ;
70+ moduleConfigs [ moduleName ] = {
6571 name : moduleName ,
6672 reference : absoluteRef ,
67- config : ModuleConfigUtil . loadModuleConfigSync ( absoluteRef . path ) || { } ,
73+ config : moduleConfigUtil . loadModuleConfigSync ( absoluteRef . path ) || { } ,
6874 } ;
6975 }
76+ return moduleConfigs ;
77+ }
78+
79+ #prepareInnerObjects( options ?: RunnerOptions ) {
80+ this . innerObjects = {
81+ moduleConfigs : [ {
82+ obj : new ModuleConfigs ( this . moduleConfigs ) ,
83+ } ] ,
84+ moduleConfig : [ ] ,
85+ } ;
7086 for ( const moduleConfig of Object . values ( this . moduleConfigs ) ) {
7187 this . innerObjects . moduleConfig . push ( {
7288 obj : moduleConfig . config ,
@@ -76,6 +92,7 @@ export class Runner {
7692 } ] ,
7793 } ) ;
7894 }
95+
7996 if ( options ?. innerObjects ) {
8097 for ( const [ name , obj ] of Object . entries ( options . innerObjects ) ) {
8198 this . innerObjects [ name ] = [ {
@@ -85,9 +102,6 @@ export class Runner {
85102 } else if ( options ?. innerObjectHandlers ) {
86103 Object . assign ( this . innerObjects , options . innerObjectHandlers ) ;
87104 }
88- this . loadUnitLoader = new EggModuleLoader ( this . moduleReferences ) ;
89- const configSourceEggPrototypeHook = new ConfigSourceLoadUnitHook ( ) ;
90- LoadUnitLifecycleUtil . registerLifecycle ( configSourceEggPrototypeHook ) ;
91105 }
92106
93107 async init ( ) {
0 commit comments