Skip to content

Commit 90e5c4a

Browse files
authored
Merge pull request #15426 from webpack/fix/issues-15360
fix node version for browserslist
2 parents dfdc8b1 + 9db496b commit 90e5c4a

4 files changed

Lines changed: 85 additions & 63 deletions

File tree

lib/config/browserslistTargetHandler.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ const resolve = browsers => {
121121
// baidu: Not supported
122122
// and_uc: Not supported
123123
// kaios: Not supported
124-
// Since Node.js 13.14.0 no warning about usage, but it was added 8.5.0 with some limitations and it was improved in 12.0.0 and 13.2.0
125-
node: [13, 14]
124+
node: [12, 17]
126125
});
127126

128127
return {
@@ -248,8 +247,7 @@ const resolve = browsers => {
248247
// baidu: Not supported
249248
// and_uc: Not supported
250249
// kaios: Not supported
251-
// Since Node.js 13.14.0 no warning about usage, but it was added 8.5.0 with some limitations and it was improved in 12.0.0 and 13.2.0
252-
node: [13, 14]
250+
node: [12, 17]
253251
}),
254252
dynamicImport: es6DynamicImport,
255253
dynamicImportInWorker: es6DynamicImport && !anyNode,
@@ -272,7 +270,7 @@ const resolve = browsers => {
272270
// baidu: Unknown support
273271
// and_uc: Unknown support
274272
// kaios: Unknown support
275-
node: [12, 0]
273+
node: 12
276274
}),
277275
optionalChaining: rawChecker({
278276
chrome: 80,

test/Defaults.unittest.js

Lines changed: 76 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,64 +13,64 @@ const quoteMeta = str => {
1313
return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
1414
};
1515

16-
describe("Defaults", () => {
17-
const cwd = process.cwd();
18-
const cwdRegExp = new RegExp(
19-
`${quoteMeta(cwd)}((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)`,
20-
"g"
21-
);
22-
const escapedCwd = JSON.stringify(cwd).slice(1, -1);
23-
const escapedCwdRegExp = new RegExp(
24-
`${quoteMeta(escapedCwd)}((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)`,
25-
"g"
26-
);
27-
const normalize = str => {
28-
if (cwd.startsWith("/")) {
29-
str = str.replace(new RegExp(quoteMeta(cwd), "g"), "<cwd>");
30-
} else {
31-
str = str.replace(cwdRegExp, (m, g) => `<cwd>${g.replace(/\\/g, "/")}`);
32-
str = str.replace(
33-
escapedCwdRegExp,
34-
(m, g) => `<cwd>${g.replace(/\\\\/g, "/")}`
35-
);
36-
}
37-
str = str.replace(/@@ -\d+,\d+ \+\d+,\d+ @@/g, "@@ ... @@");
38-
return str;
39-
};
16+
const cwd = process.cwd();
17+
const cwdRegExp = new RegExp(
18+
`${quoteMeta(cwd)}((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)`,
19+
"g"
20+
);
21+
const escapedCwd = JSON.stringify(cwd).slice(1, -1);
22+
const escapedCwdRegExp = new RegExp(
23+
`${quoteMeta(escapedCwd)}((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)`,
24+
"g"
25+
);
26+
const normalize = str => {
27+
if (cwd.startsWith("/")) {
28+
str = str.replace(new RegExp(quoteMeta(cwd), "g"), "<cwd>");
29+
} else {
30+
str = str.replace(cwdRegExp, (m, g) => `<cwd>${g.replace(/\\/g, "/")}`);
31+
str = str.replace(
32+
escapedCwdRegExp,
33+
(m, g) => `<cwd>${g.replace(/\\\\/g, "/")}`
34+
);
35+
}
36+
str = str.replace(/@@ -\d+,\d+ \+\d+,\d+ @@/g, "@@ ... @@");
37+
return str;
38+
};
4039

41-
class Diff {
42-
constructor(value) {
43-
this.value = value;
44-
}
40+
class Diff {
41+
constructor(value) {
42+
this.value = value;
4543
}
44+
}
4645

47-
expect.addSnapshotSerializer({
48-
test(value) {
49-
return value instanceof Diff;
50-
},
51-
print(received) {
52-
return normalize(received.value);
53-
}
54-
});
46+
expect.addSnapshotSerializer({
47+
test(value) {
48+
return value instanceof Diff;
49+
},
50+
print(received) {
51+
return normalize(received.value);
52+
}
53+
});
5554

56-
expect.addSnapshotSerializer({
57-
test(value) {
58-
return typeof value === "string";
59-
},
60-
print(received) {
61-
return JSON.stringify(normalize(received));
62-
}
63-
});
55+
expect.addSnapshotSerializer({
56+
test(value) {
57+
return typeof value === "string";
58+
},
59+
print(received) {
60+
return JSON.stringify(normalize(received));
61+
}
62+
});
6463

65-
const getDefaultConfig = config => {
66-
const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } =
67-
require("..").config;
68-
config = getNormalizedWebpackOptions(config);
69-
applyWebpackOptionsDefaults(config);
70-
process.chdir(cwd);
71-
return config;
72-
};
64+
const getDefaultConfig = config => {
65+
const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } =
66+
require("..").config;
67+
config = getNormalizedWebpackOptions(config);
68+
applyWebpackOptionsDefaults(config);
69+
process.chdir(cwd);
70+
return config;
71+
};
7372

73+
describe("snapshots", () => {
7474
const baseConfig = getDefaultConfig({ mode: "none" });
7575

7676
it("should have the correct base config", () => {
@@ -2018,3 +2018,27 @@ describe("Defaults", () => {
20182018
`)
20192019
);
20202020
});
2021+
2022+
it("should result in the same target options for same target", () => {
2023+
const inlineTarget = getDefaultConfig({ target: "node12.17" });
2024+
const browserslistTarget = getDefaultConfig({
2025+
target: "browserslist: node 12.17"
2026+
});
2027+
const diff = stripAnsi(
2028+
jestDiff(inlineTarget, browserslistTarget, {
2029+
expand: false,
2030+
contextLines: 0
2031+
})
2032+
);
2033+
2034+
expect(inlineTarget.output.environment.module).toBe(true);
2035+
expect(inlineTarget.output.environment.dynamicImport).toBe(true);
2036+
expect(new Diff(diff)).toMatchInlineSnapshot(`
2037+
- Expected
2038+
+ Received
2039+
2040+
@@ ... @@
2041+
- "target": "node12.17",
2042+
+ "target": "browserslist: node 12.17",
2043+
`);
2044+
});

test/__snapshots__/target-browserslist.unittest.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ Object {
298298
"const": true,
299299
"destructuring": true,
300300
"document": null,
301-
"dynamicImport": false,
301+
"dynamicImport": true,
302302
"dynamicImportInWorker": false,
303303
"electron": false,
304304
"fetchWasm": null,
@@ -307,7 +307,7 @@ Object {
307307
"globalThis": true,
308308
"importScripts": false,
309309
"importScriptsInWorker": true,
310-
"module": false,
310+
"module": true,
311311
"node": null,
312312
"nodeBuiltins": null,
313313
"nwjs": false,
@@ -675,7 +675,7 @@ Object {
675675
"const": true,
676676
"destructuring": true,
677677
"document": false,
678-
"dynamicImport": false,
678+
"dynamicImport": true,
679679
"dynamicImportInWorker": false,
680680
"electron": false,
681681
"fetchWasm": false,
@@ -684,7 +684,7 @@ Object {
684684
"globalThis": true,
685685
"importScripts": false,
686686
"importScriptsInWorker": true,
687-
"module": false,
687+
"module": true,
688688
"node": true,
689689
"nodeBuiltins": true,
690690
"nwjs": false,

test/configCases/ecmaVersion/browserslist/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ module.exports = {
1010
"bigIntLiteral": true,
1111
"const": true,
1212
"destructuring": true,
13-
"dynamicImport": false,
13+
"dynamicImport": true,
1414
"forOf": true,
15-
"module": false,
15+
"module": true,
1616
}
1717
`);
1818
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`

0 commit comments

Comments
 (0)