@@ -133,30 +133,35 @@ async function findEggCore(options: LoaderOptions): Promise<{ EggCore?: object;
133
133
debug ( '[findEggCore] import "egg" from paths:%o error: %o' , paths , err ) ;
134
134
}
135
135
136
- const name = '@eggjs/core' ;
137
- // egg => egg-core
138
- try {
139
- const { EggCore, EggLoader } = await importModule ( name , { paths } ) ;
140
- if ( EggLoader ) {
141
- return { EggCore, EggLoader } ;
136
+ // egg-core 在 6.2.3 版本中更名为 @eggjs/core,为兼容老版本,支持同时查找两个包,优先使用新名字
137
+ const names = [ '@eggjs/core' , 'egg-core' ] ;
138
+ for ( const name of names ) {
139
+ try {
140
+ const { EggCore, EggLoader } = await importModule ( name , { paths } ) ;
141
+ if ( EggLoader ) {
142
+ return { EggCore, EggLoader } ;
143
+ }
144
+ } catch ( err : any ) {
145
+ debug ( '[findEggCore] import "%s" from paths:%o error: %o' , name , paths , err ) ;
142
146
}
143
- } catch ( err : any ) {
144
- debug ( '[findEggCore] import "%s" from paths:%o error: %o' , name , paths , err ) ;
145
- }
146
147
147
- try {
148
- const { EggCore, EggLoader } = await importModule ( name ) ;
149
- if ( EggLoader ) {
150
- return { EggCore, EggLoader } ;
148
+ try {
149
+ const { EggCore, EggLoader } = await importModule ( name ) ;
150
+ if ( EggLoader ) {
151
+ return { EggCore, EggLoader } ;
152
+ }
153
+ } catch ( err : any ) {
154
+ debug ( '[findEggCore] import "%s" error: %o' , name , err ) ;
151
155
}
152
- } catch ( err : any ) {
153
- debug ( '[findEggCore] import "%s" error: %o' , name , err ) ;
154
- }
155
156
156
- let eggCorePath = path . join ( options . baseDir , `node_modules/${ name } ` ) ;
157
- if ( ! ( await exists ( eggCorePath ) ) ) {
158
- eggCorePath = path . join ( options . framework , `node_modules/${ name } ` ) ;
157
+ let eggCorePath = path . join ( options . baseDir , `node_modules/${ name } ` ) ;
158
+ if ( ! ( await exists ( eggCorePath ) ) ) {
159
+ eggCorePath = path . join ( options . framework , `node_modules/${ name } ` ) ;
160
+ }
161
+ if ( await exists ( eggCorePath ) ) {
162
+ return await importModule ( eggCorePath ) ;
163
+ }
159
164
}
160
- assert ( await exists ( eggCorePath ) , `Can't find ${ name } from ${ options . baseDir } and ${ options . framework } ` ) ;
161
- return await importModule ( eggCorePath ) ;
165
+
166
+ assert ( false , `Can't find ${ names . join ( ' or ' ) } from ${ options . baseDir } and ${ options . framework } ` ) ;
162
167
}
0 commit comments