@@ -15,6 +15,29 @@ function inferOption(option, defaultValue) {
15
15
return option ? { } : defaultValue
16
16
}
17
17
18
+ /**
19
+ * Recursivly get the correct import order from rollup
20
+ * We only process a file once
21
+ *
22
+ * @param {string } id
23
+ * @param {Function } getModuleInfo
24
+ * @param {Set<string> } seen
25
+ */
26
+ function getRecursiveImportOrder ( id , getModuleInfo , seen = new Set ( ) ) {
27
+ if ( seen . has ( id ) ) {
28
+ return [ ]
29
+ }
30
+
31
+ seen . add ( id )
32
+
33
+ const result = [ id ]
34
+ getModuleInfo ( id ) . importedIds . forEach ( importFile => {
35
+ result . push ( ...getRecursiveImportOrder ( importFile , getModuleInfo , seen ) )
36
+ } )
37
+
38
+ return result
39
+ }
40
+
18
41
export default ( options = { } ) => {
19
42
const filter = createFilter ( options . include , options . exclude )
20
43
const postcssPlugins = Array . isArray ( options . plugins ) ?
@@ -149,10 +172,15 @@ export default (options = {}) => {
149
172
150
173
const concat = new Concat ( true , fileName , '\n' )
151
174
const entries = [ ...extracted . values ( ) ]
152
- const { modules } = bundle [ normalizePath ( path . relative ( dir , file ) ) ]
175
+ const { modules, facadeModuleId } = bundle [
176
+ normalizePath ( path . relative ( dir , file ) )
177
+ ]
153
178
154
179
if ( modules ) {
155
- const moduleIds = [ ...this . moduleIds ]
180
+ const moduleIds = getRecursiveImportOrder (
181
+ facadeModuleId ,
182
+ this . getModuleInfo
183
+ )
156
184
entries . sort (
157
185
( a , b ) => moduleIds . indexOf ( a . id ) - moduleIds . indexOf ( b . id )
158
186
)
0 commit comments