Skip to content

Commit

Permalink
Merge pull request #7721 from webpack/bugfix/occurence-order
Browse files Browse the repository at this point in the history
fix order of occurrence order plugin
  • Loading branch information
sokra committed Jul 15, 2018
2 parents 2c4ba6c + 753dcce commit aae20a8
Show file tree
Hide file tree
Showing 13 changed files with 1,195 additions and 1,189 deletions.
2 changes: 1 addition & 1 deletion lib/optimize/OccurrenceChunkOrderPlugin.js
Expand Up @@ -49,7 +49,7 @@ class OccurrenceOrderChunkIdsPlugin {
if (aOccurs < bOccurs) return 1;
const orgA = originalOrder.get(a);
const orgB = originalOrder.get(b);
return orgB - orgA;
return orgA - orgB;
});
}
);
Expand Down
2 changes: 1 addition & 1 deletion lib/optimize/OccurrenceModuleOrderPlugin.js
Expand Up @@ -91,7 +91,7 @@ class OccurrenceOrderModuleIdsPlugin {
if (aOccurs < bOccurs) return 1;
const orgA = originalOrder.get(a);
const orgB = originalOrder.get(b);
return orgB - orgA;
return orgA - orgB;
});
}
);
Expand Down
4 changes: 2 additions & 2 deletions lib/optimize/OccurrenceOrderPlugin.js
Expand Up @@ -91,7 +91,7 @@ class OccurrenceOrderPlugin {
if (aOccurs < bOccurs) return 1;
const orgA = originalOrder.get(a);
const orgB = originalOrder.get(b);
return orgB - orgA;
return orgA - orgB;
});
}
);
Expand Down Expand Up @@ -124,7 +124,7 @@ class OccurrenceOrderPlugin {
if (aOccurs < bOccurs) return 1;
const orgA = originalOrder.get(a);
const orgB = originalOrder.get(b);
return orgB - orgA;
return orgA - orgB;
});
}
);
Expand Down
6 changes: 3 additions & 3 deletions test/Compiler.test.js
Expand Up @@ -85,7 +85,7 @@ describe("Compiler", () => {
expect(Object.keys(files)).toEqual(["/main.js"]);
const bundle = files["/main.js"];
expect(bundle).toMatch("function __webpack_require__(");
expect(bundle).toMatch("__webpack_require__(/*! ./a */ 0);");
expect(bundle).toMatch(/__webpack_require__\(\/\*! \.\/a \*\/ \d\);/);
expect(bundle).toMatch("./c.js");
expect(bundle).toMatch("./a.js");
expect(bundle).toMatch("This is a");
Expand Down Expand Up @@ -145,9 +145,9 @@ describe("Compiler", () => {
it("should compile a file with multiple chunks", done => {
compile("./chunks", {}, (stats, files) => {
expect(stats.chunks).toHaveLength(2);
expect(Object.keys(files)).toEqual(["/0.js", "/main.js"]);
expect(Object.keys(files)).toEqual(["/main.js", "/1.js"]);
const bundle = files["/main.js"];
const chunk = files["/0.js"];
const chunk = files["/1.js"];
expect(bundle).toMatch("function __webpack_require__(");
expect(bundle).toMatch("__webpack_require__(/*! ./b */");
expect(chunk).not.toMatch("__webpack_require__(/* ./b */");
Expand Down
9 changes: 5 additions & 4 deletions test/HotModuleReplacementPlugin.test.js
Expand Up @@ -50,10 +50,11 @@ describe("HotModuleReplacementPlugin", () => {
output: {
path: path.join(__dirname, "js", "HotModuleReplacementPlugin")
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
]
plugins: [new webpack.HotModuleReplacementPlugin()],
optimization: {
moduleIds: "size",
chunkIds: "size"
}
});
fs.writeFileSync(entryFile, "1", "utf-8");
compiler.run((err, stats) => {
Expand Down
1 change: 0 additions & 1 deletion test/StatsTestCases.test.js
Expand Up @@ -75,7 +75,6 @@ describe("StatsTestCases", () => {
])
);
};
new webpack.optimize.OccurrenceOrderPlugin().apply(c);
});
c.run((err, stats) => {
if (err) return done(err);
Expand Down
20 changes: 10 additions & 10 deletions test/__snapshots__/ConfigTestCases.test.js.snap
Expand Up @@ -4,10 +4,10 @@ exports[`ConfigTestCases records issue-2991 exported tests should write relative
"{
\\"modules\\": {
\\"byIdentifier\\": {
\\"external \\\\\\"path\\\\\\"\\": 0,
\\"external \\\\\\"fs\\\\\\"\\": 1,
\\"ignored pkgs/somepackage/foo\\": 2,
\\"test.js\\": 3
\\"test.js\\": 0,
\\"ignored pkgs/somepackage/foo\\": 1,
\\"external \\\\\\"fs\\\\\\"\\": 2,
\\"external \\\\\\"path\\\\\\"\\": 3
},
\\"usedIds\\": {
\\"0\\": 0,
Expand All @@ -32,12 +32,12 @@ exports[`ConfigTestCases records issue-7339 exported tests should write relative
"{
\\"modules\\": {
\\"byIdentifier\\": {
\\"dependencies/foo.js\\": 0,
\\"dependencies/bar.js\\": 1,
\\"external \\\\\\"path\\\\\\"\\": 2,
\\"external \\\\\\"fs\\\\\\"\\": 3,
\\"dependencies sync /^\\\\\\\\.\\\\\\\\/.*$/\\": 4,
\\"test.js\\": 5
\\"dependencies/bar.js\\": 0,
\\"dependencies/foo.js\\": 1,
\\"test.js\\": 2,
\\"dependencies sync /^\\\\\\\\.\\\\\\\\/.*$/\\": 3,
\\"external \\\\\\"fs\\\\\\"\\": 4,
\\"external \\\\\\"path\\\\\\"\\": 5
},
\\"usedIds\\": {
\\"0\\": 0,
Expand Down
2,322 changes: 1,161 additions & 1,161 deletions test/__snapshots__/StatsTestCases.test.js.snap

Large diffs are not rendered by default.

Expand Up @@ -66,6 +66,8 @@ module.exports = {
asyncIndex2: "0: ./async.js"
});
const indicies = compilation.modules
.slice()
.sort((a, b) => a.index - b.index)
.map(
m =>
`${m.index}: ${m.readableIdentifier(
Expand All @@ -74,6 +76,8 @@ module.exports = {
)
.join(", ");
const indicies2 = compilation.modules
.slice()
.sort((a, b) => a.index2 - b.index2)
.map(
m =>
`${m.index2}: ${m.readableIdentifier(
Expand All @@ -82,10 +86,10 @@ module.exports = {
)
.join(", ");
expect(indicies).toEqual(
"2: ./shared.js, 4: ./c.js, 3: ./b.js, 1: ./a.js, 6: ./async.js, 5: ./entry2.js, 0: ./entry1.js"
"0: ./entry1.js, 1: ./a.js, 2: ./shared.js, 3: ./b.js, 4: ./c.js, 5: ./entry2.js, 6: ./async.js"
);
expect(indicies2).toEqual(
"0: ./shared.js, 3: ./c.js, 2: ./b.js, 1: ./a.js, 6: ./async.js, 5: ./entry2.js, 4: ./entry1.js"
"0: ./shared.js, 1: ./a.js, 2: ./b.js, 3: ./c.js, 4: ./entry1.js, 5: ./entry2.js, 6: ./async.js"
);
});
};
Expand Down
4 changes: 3 additions & 1 deletion test/configCases/code-generation/use-strict/index.js
Expand Up @@ -15,12 +15,14 @@ it("should include only one use strict per module", function() {
match = regExp.exec(source);
}

matches.sort();

expect(matches).toEqual([
"__webpack_require__.r(__webpack_exports__);",
"/* unused harmony default export */ var _unused_webpack_default_export = (\"a\");",
"__webpack_require__.r(__webpack_exports__);",
"__webpack_require__.r(__webpack_exports__);",
"__webpack_require__.r(__webpack_exports__);",
"__webpack_require__.r(__webpack_exports__);",
"it(\"should include only one use strict per module\", function() {",
]);
});
Expand Up @@ -18,7 +18,7 @@ module.exports = {

var bundleDetects = [
options.amd.expectedChunkFilenameLength && {
regex: new RegExp("^0.bundle" + i, "i"),
regex: new RegExp("^\\d+.bundle" + i, "i"),
expectedNameLength: options.amd.expectedChunkFilenameLength
},
{
Expand Down
2 changes: 1 addition & 1 deletion test/configCases/plugins/banner-plugin/index.js
Expand Up @@ -6,7 +6,7 @@ it("should contain banner in bundle0 chunk", () => {
expect(source).toMatch("A test value");
expect(source).toMatch("banner is a string");
expect(source).toMatch("banner is a function");
expect(source).toMatch("/*!\n * multiline\n * banner\n * 1\n */");
expect(source).toMatch("/*!\n * multiline\n * banner\n * bundle0\n */");
});

it("should not contain banner in vendors chunk", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/configCases/plugins/banner-plugin/webpack.config.js
Expand Up @@ -19,7 +19,7 @@ module.exports = {
exclude: ["vendors.js"]
}),
new webpack.BannerPlugin({
banner: ({ chunk }) => `multiline\nbanner\n${chunk.id}`
banner: ({ chunk }) => `multiline\nbanner\n${chunk.name}`
})
]
};

0 comments on commit aae20a8

Please sign in to comment.