@@ -84,8 +84,8 @@ Plugin.init = function(head) {
84
84
85
85
const stats = cache . get ( h . KEYS . plugins ) || { } ;
86
86
87
- // 1. check installed plugins
88
- let plugins = [ ] ;
87
+ // 1. find installed plugins
88
+ let installed = [ ] ;
89
89
for ( let f of file . listCodeDir ( 'lib/plugins' ) ) {
90
90
const p = f . data ;
91
91
if ( ! p ) continue ;
@@ -98,39 +98,41 @@ Plugin.init = function(head) {
98
98
log . trace ( 'new plugin, enable by default' ) ;
99
99
p . enabled = true ;
100
100
}
101
+ installed . push ( p ) ;
102
+ }
103
+ // the one with bigger `id` comes first
104
+ installed = _ . sortBy ( installed , x => - x . id ) ;
101
105
106
+ // 2. init all in reversed order
107
+ for ( let i = installed . length - 1 ; i >= 0 ; -- i ) {
108
+ const p = installed [ i ] ;
102
109
if ( p . enabled ) {
103
110
p . init ( ) ;
104
111
log . trace ( 'inited plugin: ' + p . name ) ;
105
112
} else {
106
113
log . trace ( 'skipped plugin: ' + p . name ) ;
107
114
}
108
-
109
- plugins . push ( p ) ;
110
115
}
111
116
112
- // chain the plugins together
113
- // the one has bigger `id` comes first
114
- plugins = _ . sortBy ( plugins , x => - x . id ) ;
115
-
117
+ // 3. chain together
118
+ const plugins = installed . filter ( x => x . enabled ) ;
116
119
let last = head ;
117
120
for ( let p of plugins ) {
118
- if ( ! p . enabled ) continue ;
119
121
last . setNext ( p ) ;
120
122
last = p ;
121
123
}
122
124
123
- // 2 . check saved plugins
125
+ // 4 . check missing plugins
124
126
const missings = [ ] ;
125
127
for ( let k of _ . keys ( stats ) ) {
126
- if ( plugins . find ( x => x . name === k ) ) continue ;
128
+ if ( installed . find ( x => x . name === k ) ) continue ;
127
129
const p = new Plugin ( - 1 , k , 'missing' ) ;
128
130
p . enabled = stats [ k ] ;
129
131
missings . push ( p ) ;
132
+ log . trace ( 'missing plugin:' + p . name ) ;
130
133
}
131
- log . trace ( 'missing plugins: ' + missings . length ) ;
132
134
133
- Plugin . plugins = plugins . concat ( missings ) ;
135
+ Plugin . plugins = installed . concat ( missings ) ;
134
136
return missings . length === 0 ;
135
137
} ;
136
138
0 commit comments