Skip to content

Commit

Permalink
fix(bundle): sort bundle files by path
Browse files Browse the repository at this point in the history
This way we are be sure they will alway be concatenated in the same
order. This is meant to prevent the hash of bundles to change due to an
unexpected order of file inclusion.
  • Loading branch information
Jenselme committed Feb 4, 2018
1 parent 5ed65ce commit 77697b1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,18 @@ exports.Bundle = class {
});
}

work = work.then(() => files = files.concat(this.getBundledFiles()));
// Sort files by path to be sure they will alway be concatenated in the same order.
let bundleFiles = this.getBundledFiles()
.sort((a, b) => {
if (a.path > b.path) {
return -1
} else if (b.path > a.path) {
return 1
} else {
return 0
}
});
work = work.then(() => files = files.concat(bundleFiles));

if (this.append.length) {
work = work.then(() => addFilesInOrder(this, this.append, files));
Expand Down Expand Up @@ -211,7 +222,6 @@ exports.Bundle = class {
content = Convert.removeMapFileComments(currentFile.contents);
}
}

concat.add(currentFile.path, content, sourceMap ? JSON.stringify(sourceMap) : undefined);
}

Expand Down

0 comments on commit 77697b1

Please sign in to comment.