Skip to content

Commit

Permalink
make dependency order stable
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Oct 19, 2018
1 parent 8a8111b commit 98b482e
Show file tree
Hide file tree
Showing 2 changed files with 885 additions and 875 deletions.
12 changes: 11 additions & 1 deletion lib/Compilation.js
Expand Up @@ -645,7 +645,15 @@ class Compilation extends Tapable {
war.dependencies = dependencies;
this.warnings.push(war);
}
module.dependencies.sort((a, b) => compareLocations(a.loc, b.loc));
const originalMap = module.dependencies.reduce((map, v, i) => {

This comment has been minimized.

Copy link
@pi0

pi0 Oct 22, 2018

@sokra I wonder why this pattern (Returning same reference (to map) with each reduce call) is preferred over simple forEach equivalent:

const originalMap = new Map();

module.dependencies.forEach((v, i) => {
  originalMap.set(v, i);
})

This comment has been minimized.

Copy link
@sokra

sokra Oct 23, 2018

Author Member

Both are valid. I used this because it's a single statement.

map.set(v, i);
return map;
}, new Map());
module.dependencies.sort((a, b) => {
const cmp = compareLocations(a.loc, b.loc);
if (cmp) return cmp;
return originalMap.get(a) - originalMap.get(b);
});
if (error) {
this.hooks.failedModule.call(module, error);
return callback(error);
Expand Down Expand Up @@ -2127,6 +2135,8 @@ class Compilation extends Tapable {
for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
chunks[indexChunk].sortItems();
}

chunks.sort((a, b) => a.compareTo(b));
}

sortItemsWithChunkIds() {
Expand Down

0 comments on commit 98b482e

Please sign in to comment.