Skip to content

Commit

Permalink
fix: occasional wrong order in extract mode
Browse files Browse the repository at this point in the history
Closes #153
  • Loading branch information
Anidetrix committed Jan 11, 2021
1 parent 77b858e commit 52cb377
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,25 @@ export default (options: Options = {}): Plugin => {

const getImports = (chunk: OutputChunk): string[] => {
const ordered: string[] = [];
let ids: string[] = [];

for (const module of Object.keys(chunk.modules)) {
const traversed: string[] = [];
ids.push(module);
while (ids.length > 0) {
let ids = [module];
do {
const imports: string[] = [];
for (const id of ids) {
if (traversed.includes(id) || !isIncluded(id)) continue;
if (loaders.isSupported(id)) ordered.push(id);
else traversed.push(id);
if (loaders.isSupported(id)) {
imports.push(id);
continue;
}
traversed.push(id);
const i = this.getModuleInfo(id);
i && imports.push(...i.importedIds);
}
ids = imports;
}
} while (ids.some(id => !loaders.isSupported(id)));
ordered.push(...ids);
}

return ordered;
Expand Down

0 comments on commit 52cb377

Please sign in to comment.