@@ -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 */
135134function 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.
0 commit comments