@@ -7,6 +7,8 @@ const PluginAPI = require('../../PluginAPI');
77const DEFAULT_METHODS = require ( '../methods' ) ;
88const PreLoadPlugins = require ( '../../../plugins/register' ) ;
99const { API_TYPE , SHARED_PROPS : { BEFORE_INIT_METHODS } } = require ( '../../Constants' ) ;
10+ const parsePlugin = require ( '../../../utils/parsePlugin' ) ;
11+
1012const SYMBOL_BEFORE_INIT_METHODS = Symbol ( '$$beforeInitMethods$$' ) ;
1113
1214class PluginService extends MethodService {
@@ -31,14 +33,18 @@ class PluginService extends MethodService {
3133 const allplugins = micros . map ( key => {
3234 return this . microsConfig [ key ] . plugins || [ ] ;
3335 } ) . concat ( plugins ) ;
34- const pluginsObj = allplugins . reduce ( ( arr , item ) => {
35- if ( Array . isArray ( item ) ) {
36- return arr . concat ( item . reduce ( ( _arr , _item ) => {
37- return _arr . concat ( this . resolvePlugin ( _item ) ) ;
38- } , [ ] ) ) ;
36+ const pluginsObj = [ ] ;
37+ while ( allplugins . length ) {
38+ const item = allplugins . shift ( ) ;
39+ if ( Array . isArray ( item ) ) { // presets
40+ allplugins . unshift ( ...item ) ;
41+ } else {
42+ const res = this . resolvePlugin ( item ) ;
43+ if ( res ) {
44+ pluginsObj . push ( ...[ ] . concat ( res ) ) ;
45+ }
3946 }
40- return arr . concat ( this . resolvePlugin ( item ) ) ;
41- } , [ ] ) . filter ( item => ! ! item ) ;
47+ }
4248 const collection = new Set ( ) ;
4349 const result = pluginsObj . filter ( item => {
4450 // 去除已经注册的插件
@@ -578,12 +584,17 @@ class PluginService extends MethodService {
578584 if ( apply ) {
579585 const _apply = apply . default || apply ;
580586 if ( Array . isArray ( _apply ) ) { // 支持数组模式
581- return _apply . map ( _applyItem => {
582- if ( _applyItem ) {
583- return this . _resolvePluginResult ( item , { apply : _applyItem , link, opts } ) ;
587+ return _apply . reduce ( ( arr , _applyItem ) => {
588+ if ( _ . isFunction ( _applyItem ) ) {
589+ const res = this . _resolvePluginResult ( item , { apply : _applyItem , link, opts } ) ;
590+ return arr . concat ( res || [ ] ) ;
591+ } else if ( _applyItem ) {
592+ const _parsePlugin = parsePlugin ( _applyItem ) ;
593+ const res = this . resolvePlugin ( Object . assign ( item , _parsePlugin ) ) ;
594+ return arr . concat ( res || [ ] ) ;
584595 }
585- return false ;
586- } ) . filter ( _it => ! ! _it ) ;
596+ return arr ;
597+ } , [ ] ) . filter ( _it => ! ! _it ) ;
587598 }
588599 return this . _resolvePluginResult ( item , { apply, link, opts } ) ;
589600 }
0 commit comments