1
1
// @ts -check
2
+ const { warn } = require ( './logger' )
2
3
const DEFAULT_STAGE = 100
3
4
4
5
/** @typedef {{after?: string|Array<string>, stage?: number} } Apply */
@@ -93,20 +94,19 @@ function topologicalSorting (plugins) {
93
94
plugins . forEach ( p => {
94
95
const after = getOrderParams ( p ) . after
95
96
indegrees . set ( p , after . size )
96
- if ( after . size > 0 ) {
97
- for ( const id of after ) {
98
- const prerequisite = pluginsMap . get ( id )
99
- // remove invalid data
100
- if ( ! prerequisite ) {
101
- indegrees . set ( p , indegrees . get ( p ) - 1 )
102
- continue
103
- }
104
-
105
- if ( ! graph . has ( prerequisite ) ) {
106
- graph . set ( prerequisite , [ ] )
107
- }
108
- graph . get ( prerequisite ) . push ( p )
97
+ if ( after . size === 0 ) return
98
+ for ( const id of after ) {
99
+ const prerequisite = pluginsMap . get ( id )
100
+ // remove invalid data
101
+ if ( ! prerequisite ) {
102
+ indegrees . set ( p , indegrees . get ( p ) - 1 )
103
+ continue
109
104
}
105
+
106
+ if ( ! graph . has ( prerequisite ) ) {
107
+ graph . set ( prerequisite , [ ] )
108
+ }
109
+ graph . get ( prerequisite ) . push ( p )
110
110
}
111
111
} )
112
112
@@ -130,9 +130,11 @@ function topologicalSorting (plugins) {
130
130
} )
131
131
}
132
132
const valid = res . length === plugins . length
133
- // TODO: show warning to user when invalid? or return plugins directly
134
- // return valid ? res : []
135
- return valid ? res : plugins
133
+ if ( ! valid ) {
134
+ warn ( `No proper plugin execution order found.` )
135
+ return plugins
136
+ }
137
+ return res
136
138
}
137
139
138
140
/**
0 commit comments