Skip to content

Commit f845565

Browse files
committed
Sort the usedIds array in records
This prevents unnecessary churn when version-controlling your records
1 parent 3605035 commit f845565

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

lib/RecordIdsPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class RecordIdsPlugin {
118118
}
119119
usedIds.add(chunk.id);
120120
}
121-
records.chunks.usedIds = Array.from(usedIds);
121+
records.chunks.usedIds = Array.from(usedIds).sort();
122122
}
123123
);
124124
compilation.hooks.reviveChunks.tap(

test/configCases/records/stable-sort/split-2.js

Whitespace-only changes.

test/configCases/records/stable-sort/split.js

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require.ensure([], function(require) {
2+
require('./split.js')
3+
})
4+
5+
require.ensure([], function(require) {
6+
require('./split-2.js')
7+
}, "split")
8+
9+
it("sorts the usedIds array to prevent churn", function() {
10+
var fs = require("fs");
11+
var path = require("path");
12+
var records = JSON.parse(fs.readFileSync(path.join(__dirname, "records.json"), "utf-8"));
13+
expect(records.chunks.usedIds).toEqual([0, "main", "split"]);
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var path = require("path");
2+
3+
module.exports = {
4+
mode: "development",
5+
entry: "./test",
6+
recordsOutputPath: path.resolve(
7+
__dirname,
8+
"../../../js/config/records/stable-sort/records.json"
9+
),
10+
target: "node",
11+
node: {
12+
__dirname: false
13+
}
14+
};

0 commit comments

Comments
 (0)