@@ -59,9 +59,10 @@ module.exports = {
5959 loadPlugin ( ) {
6060 this . timing . start ( 'Load Plugin' ) ;
6161
62+ this . lookupDirs = this . getLookupDirs ( ) ;
6263 this . allPlugins = { } ;
63- this . appPlugins = this . loadAppPlugins ( ) ;
6464 this . eggPlugins = this . loadEggPlugins ( ) ;
65+ this . appPlugins = this . loadAppPlugins ( ) ;
6566 this . customPlugins = this . loadCustomPlugins ( ) ;
6667
6768 this . _extendPlugins ( this . allPlugins , this . eggPlugins ) ;
@@ -336,17 +337,7 @@ module.exports = {
336337 return result . sequence . map ( name => allPlugins [ name ] ) ;
337338 } ,
338339
339- // Get the real plugin path
340- getPluginPath ( plugin ) {
341- if ( plugin . path ) {
342- return plugin . path ;
343- }
344-
345- if ( plugin . package ) {
346- assert ( isValidatePackageName ( plugin . package ) , `plugin ${ plugin . name } invalid, use 'path' instead of package: "${ plugin . package } "` ) ;
347- }
348-
349- const name = plugin . package || plugin . name ;
340+ getLookupDirs ( ) {
350341 const lookupDirs = new Set ( ) ;
351342
352343 // try to locate the plugin in the following directories's node_modules
@@ -362,17 +353,36 @@ module.exports = {
362353 // should find the $cwd when test the plugins under npm3
363354 lookupDirs . add ( process . cwd ( ) ) ;
364355
356+ return lookupDirs ;
357+ } ,
358+
359+ // Get the real plugin path
360+ getPluginPath ( plugin ) {
361+ if ( plugin . path ) {
362+ return plugin . path ;
363+ }
364+
365+ if ( plugin . package ) {
366+ assert ( isValidatePackageName ( plugin . package ) , `plugin ${ plugin . name } invalid, use 'path' instead of package: "${ plugin . package } "` ) ;
367+ }
368+
369+ return this . _resolvePluginPath ( plugin ) ;
370+ } ,
371+
372+ _resolvePluginPath ( plugin ) {
373+ const name = plugin . package || plugin . name ;
374+
365375 try {
366376 // should find the plugin directory
367377 // pnpm will lift the node_modules to the sibling directory
368378 // 'node_modules/.pnpm/yadan@2.0.0/node_modules/yadan/node_modules',
369379 // 'node_modules/.pnpm/yadan@2.0.0/node_modules', <- this is the sibling directory
370380 // 'node_modules/.pnpm/egg@2.33.1/node_modules/egg/node_modules',
371381 // 'node_modules/.pnpm/egg@2.33.1/node_modules', <- this is the sibling directory
372- const filePath = require . resolve ( `${ name } /package.json` , { paths : [ ...lookupDirs ] } ) ;
382+ const filePath = require . resolve ( `${ name } /package.json` , { paths : [ ...this . lookupDirs ] } ) ;
373383 return path . dirname ( filePath ) ;
374384 } catch ( _ ) {
375- throw new Error ( `Can not find plugin ${ name } in "${ [ ...lookupDirs ] . join ( ', ' ) } "` ) ;
385+ throw new Error ( `Can not find plugin ${ name } in "${ [ ...this . lookupDirs ] . join ( ', ' ) } "` ) ;
376386 }
377387 } ,
378388
0 commit comments