Skip to content

Commit 695b618

Browse files
authored
chore: support WDS v5 (#837)
1 parent 46efb13 commit 695b618

File tree

11 files changed

+1276
-928
lines changed

11 files changed

+1276
-928
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ version: 2.1
22

33
anchors:
44
- &node-version-enum
5-
- '14.20'
6-
- '16.17'
7-
- '18.9'
5+
- '18.20'
6+
- '20.12'
7+
- '22.0'
88
- &webpack-version-enum
99
- '4'
1010
- '5'
1111
- &node-version-param
1212
node-version:
13-
default: '16.17'
13+
default: '20.12'
1414
enum: *node-version-enum
1515
type: enum
1616
- &webpack-version-param
@@ -45,7 +45,7 @@ executors:
4545
parameters:
4646
<<: *node-version-param
4747
docker:
48-
- image: pmmmwh/puppeteer:<< parameters.node-version >>
48+
- image: cimg/node:<< parameters.node-version >>-browsers
4949
auth:
5050
username: $DOCKER_LOGIN
5151
password: $DOCKER_PASSWORD

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@
101101
"type-fest": "^4.0.0",
102102
"typescript": "~5.1.6",
103103
"webpack": "^5.76.0",
104-
"webpack-cli": "^4.7.2",
105-
"webpack-cli.legacy": "npm:[email protected]",
106-
"webpack-dev-server": "^4.2.1",
107-
"webpack-dev-server.legacy": "npm:[email protected]",
104+
"webpack-cli": "^5.1.4",
105+
"webpack-cli-v4": "npm:[email protected]",
106+
"webpack-dev-server": "^5.0.4",
107+
"webpack-dev-server-v3": "npm:[email protected]",
108+
"webpack-dev-server-v4": "npm:[email protected]",
108109
"webpack-hot-middleware": "^2.25.0",
109110
"webpack-plugin-serve": "^1.4.1",
110-
"webpack.legacy": "npm:[email protected]",
111+
"webpack-v4": "npm:[email protected]",
111112
"yalc": "^1.0.0-pre.53",
112113
"yn": "^4.0.0"
113114
},
@@ -117,7 +118,7 @@
117118
"sockjs-client": "^1.4.0",
118119
"type-fest": ">=0.17.0 <5.0.0",
119120
"webpack": ">=4.43.0 <6.0.0",
120-
"webpack-dev-server": "3.x || 4.x",
121+
"webpack-dev-server": "3.x || 4.x || 5.x",
121122
"webpack-hot-middleware": "2.x",
122123
"webpack-plugin-serve": "0.x || 1.x"
123124
},
@@ -146,5 +147,6 @@
146147
},
147148
"engines": {
148149
"node": ">= 10.13"
149-
}
150+
},
151+
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
150152
}

scripts/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (yn(process.env.DEBUG)) {
3232

3333
if (parseInt(process.env.WEBPACK_VERSION || 5, 10) === 4) {
3434
// Apply Webpack npm aliases in Jest's module system
35-
argv.push(`--moduleNameMapper="${JSON.stringify({ '^webpack($|/.*)': 'webpack.legacy$1' })}"`);
35+
argv.push(`--moduleNameMapper="${JSON.stringify({ '^webpack($|/.*)': 'webpack-v4$1' })}"`);
3636
}
3737

3838
void jest.run(argv);

test/helpers/sandbox/aliasLegacyWebpack.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const moduleAlias = require('module-alias');
22

3-
moduleAlias.addAliases({ 'webpack-dev-server': 'webpack-dev-server.legacy' });
3+
moduleAlias.addAliases({ 'webpack-dev-server': 'webpack-dev-server-v3' });

test/helpers/sandbox/aliasWDSv4.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const moduleAlias = require('module-alias');
2+
3+
moduleAlias.addAliases({ 'webpack-dev-server': 'webpack-dev-server-v4' });
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const moduleAlias = require('module-alias');
2+
3+
moduleAlias.addAliases({ webpack: 'webpack-v4' });

test/helpers/sandbox/configs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ module.exports = {
8585
resolve: {
8686
alias: ${JSON.stringify(
8787
{
88-
...(WEBPACK_VERSION === 4 && { webpack: 'webpack.legacy' }),
89-
...(WDS_VERSION === 3 && { 'webpack-dev-server': 'webpack-dev-server.legacy' }),
88+
...(WEBPACK_VERSION === 4 && { webpack: 'webpack-v4' }),
89+
...(WDS_VERSION === 3 && { 'webpack-dev-server': 'webpack-dev-server-v3' }),
90+
...(WDS_VERSION === 4 && { 'webpack-dev-server': 'webpack-dev-server-v4' }),
9091
},
9192
null,
9293
2

test/helpers/sandbox/spawn.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ const isOpenSSL3 = semver.gte(process.versions.node, '17.0.0');
88
* @param {string} packageName
99
* @returns {string}
1010
*/
11-
function getPackageExecutable(packageName) {
11+
function getPackageExecutable(packageName, binName) {
1212
let { bin: binPath } = require(`${packageName}/package.json`);
13-
if (!binPath) {
14-
throw new Error(`Package ${packageName} does not have an executable!`);
15-
}
16-
1713
// "bin": { "package": "bin.js" }
1814
if (typeof binPath === 'object') {
19-
binPath = binPath[packageName];
15+
binPath = binPath[binName || packageName];
16+
}
17+
if (!binPath) {
18+
throw new Error(`Package ${packageName} does not have an executable!`);
2019
}
2120

2221
return require.resolve(path.join(packageName, binPath));
@@ -133,13 +132,21 @@ function spawnTestProcess(processPath, argv, options = {}) {
133132
* @returns {Promise<import('child_process').ChildProcess | void>}
134133
*/
135134
function spawnWebpackServe(port, dirs, options = {}) {
136-
const webpackBin = getPackageExecutable('webpack-cli');
135+
const webpackBin = getPackageExecutable(
136+
WDS_VERSION === 4 ? 'webpack-cli-v4' : 'webpack-cli',
137+
'webpack-cli'
138+
);
137139

138140
const NODE_OPTIONS = [
139-
// This requires a script to alias `webpack` and `webpack-cli` -
140-
// both v4 and v5 is installed side by side,
141-
// so we have to ensure that they resolve to the `legacy` variant.
142-
WEBPACK_VERSION === 4 && `--require "${require.resolve('./aliasLegacyWebpack')}"`,
141+
// This requires a script to alias `webpack` -
142+
// both v4 and v5 are installed,
143+
// so we have to ensure that they resolve to the correct variant.
144+
WEBPACK_VERSION === 4 && `--require "${require.resolve('./aliasWebpackv4')}"`,
145+
// This requires a script to alias `webpack-dev-server` -
146+
// both v3, v4 and v5 are installed,
147+
// so we have to ensure that they resolve to the correct variant.
148+
WDS_VERSION === 3 && `--require "${require.resolve('./aliasWDSv3')}"`,
149+
WDS_VERSION === 4 && `--require "${require.resolve('./aliasWDSv4')}"`,
143150
// This make Node.js use the legacy OpenSSL provider -
144151
// it is necessary as OpenSSL 3.0 removed support for MD4,
145152
// which is the default hashing algorithm used in Webpack 4.

test/jest-environment.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ class SandboxEnvironment extends NodeEnvironment {
99

1010
this.global.__DEBUG__ = yn(process.env.DEBUG);
1111
this.global.WEBPACK_VERSION = parseInt(process.env.WEBPACK_VERSION || '5', 10);
12-
this.global.WDS_VERSION = semver.major(process.version) < 12 ? 3 : 4;
12+
this.global.WDS_VERSION =
13+
semver.major(process.version) < 12
14+
? 3
15+
: semver.major(process.version) < 18 || this.global.WEBPACK_VERSION === 4
16+
? 4
17+
: 5;
1318

1419
const wsEndpoint = process.env.PUPPETEER_WS_ENDPOINT;
1520
if (!wsEndpoint) {

0 commit comments

Comments
 (0)