Skip to content

Commit

Permalink
[FIX] Bundler: Sort raw modules by default
Browse files Browse the repository at this point in the history
Unlike the documentation states, topological sorting of modules within
'raw' sections was not enabled by default.

Sorting is based on dependencies only, so enabling it by default should
only solve issues in case dependencies are declared but sort was not
enabled.
If no dependencies are defined, the order will not change.

This could only break use cases where dependencies have been wrongly
declared and a user relies on the current unsorted order.
  • Loading branch information
matz3 committed Dec 9, 2021
1 parent 7207bab commit 0e11b69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/lbt/bundle/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class BundleResolver {

return collectModulesForSection(section).
then( (modules) => {
if ( section.mode == SectionType.Raw && section.sort ) {
if ( section.mode == SectionType.Raw && section.sort !== false ) {
// sort the modules in topological order
return topologicalSort(pool, modules).then( (modules) => {
log.verbose(" resolved modules (sorted): %s", modules);
Expand Down
9 changes: 8 additions & 1 deletion test/lib/lbt/graph/topologicalSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ test("topologicalSort", async (t) => {
t.deepEqual(topologicalSortResult, ["mydep", "myroot"]);
});


test("cyclic dependencies", async (t) => {
const pool = createMockPool({"third": "mydep", "mydep": "third"});
const roots = ["myroot", "mydep", "third"];
const error = await t.throwsAsync(topologicalSort(pool, roots));
t.deepEqual(error.message, "failed to resolve cyclic dependencies: mydep,third");
});

test("no dependencies", async (t) => {
const pool = createMockPool({});
const roots = ["module4", "module2", "module3", "module1"];
const topologicalSortResult = await topologicalSort(pool, roots);
// Modules should not be sorted by any means as no dependencies are defined
t.deepEqual(topologicalSortResult, ["module4", "module2", "module3", "module1"]);
});

0 comments on commit 0e11b69

Please sign in to comment.