Skip to content

Commit 9b4c5ec

Browse files
fix: handle the auto value of the publicPath option
1 parent 37e23c8 commit 9b4c5ec

File tree

9 files changed

+1739
-2305
lines changed

9 files changed

+1739
-2305
lines changed

.github/workflows/nodejs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
matrix:
5757
os: [ubuntu-latest, windows-latest, macos-latest]
5858
node-version: [10.x, 12.x, 14.x]
59-
webpack-version: [latest, next]
59+
webpack-version: [4, latest]
6060

6161
runs-on: ${{ matrix.os }}
6262

package-lock.json

+1,665-2,221
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"url": "https://opencollective.com/webpack"
1414
},
1515
"engines": {
16-
"node": ">= 10.13"
16+
"node": ">= 10.13.0"
1717
},
1818
"scripts": {
1919
"commitlint": "commitlint --from=master",
@@ -38,11 +38,11 @@
3838
"webpack": "^4.0.0 || ^5.0.0"
3939
},
4040
"dependencies": {
41-
"mem": "^6.1.1",
41+
"mem": "^8.0.0",
4242
"memfs": "^3.2.0",
4343
"mime-types": "^2.1.27",
4444
"range-parser": "^1.2.1",
45-
"schema-utils": "^2.7.1"
45+
"schema-utils": "^3.0.0"
4646
},
4747
"devDependencies": {
4848
"@babel/cli": "^7.11.6",
@@ -52,25 +52,25 @@
5252
"@commitlint/config-conventional": "^11.0.0",
5353
"@webpack-contrib/defaults": "^6.3.0",
5454
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
55-
"babel-jest": "^26.3.0",
56-
"chokidar": "^3.4.2",
55+
"babel-jest": "^26.5.2",
56+
"chokidar": "^3.4.3",
5757
"cross-env": "^7.0.2",
58-
"del": "^5.1.0",
58+
"del": "^6.0.0",
5959
"del-cli": "^3.0.1",
60-
"eslint": "^7.8.1",
61-
"eslint-config-prettier": "^6.11.0",
62-
"eslint-plugin-import": "^2.22.0",
60+
"eslint": "^7.11.0",
61+
"eslint-config-prettier": "^6.12.0",
62+
"eslint-plugin-import": "^2.22.1",
6363
"eslint-plugin-prettier": "^3.1.4",
6464
"express": "^4.17.1",
65-
"file-loader": "^6.1.0",
65+
"file-loader": "^6.1.1",
6666
"husky": "^4.3.0",
67-
"jest": "^26.4.2",
68-
"lint-staged": "^10.3.0",
67+
"jest": "^26.5.3",
68+
"lint-staged": "^10.4.0",
6969
"npm-run-all": "^4.1.5",
70-
"prettier": "^2.1.1",
70+
"prettier": "^2.1.2",
7171
"standard-version": "^9.0.0",
72-
"supertest": "^4.0.2",
73-
"webpack": "^4.44.1"
72+
"supertest": "^5.0.0",
73+
"webpack": "^4.44.2"
7474
},
7575
"keywords": [
7676
"webpack",

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import validateOptions from 'schema-utils';
1+
import { validate } from 'schema-utils';
22
import mime from 'mime-types';
33

44
import middleware from './middleware';
@@ -11,7 +11,7 @@ import schema from './options.json';
1111
const noop = () => {};
1212

1313
export default function wdm(compiler, options = {}) {
14-
validateOptions(schema, options, {
14+
validate(schema, options, {
1515
name: 'Dev Middleware',
1616
baseDataPath: 'options',
1717
});

src/utils/getFilenameFromUrl.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export default function getFilenameFromUrl(context, url) {
2626
let publicPathObject;
2727

2828
try {
29-
publicPathObject = memoizedParse(publicPath || '/', false, true);
29+
publicPathObject = memoizedParse(
30+
publicPath !== 'auto' && publicPath ? publicPath : '/',
31+
false,
32+
true
33+
);
3034
} catch (_ignoreError) {
3135
// eslint-disable-next-line no-continue
3236
continue;

test/__snapshots__/middleware.test.js.snap

+22-56
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ Array [
1313
"webpack-dev-middleware",
1414
"error",
1515
Array [
16-
"Child \\"broken\\": ERROR in ./broken.js 1:3
17-
Module parse failed: Unexpected token (1:3)
18-
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
19-
> 1()2()3()
20-
|",
16+
"ERROR",
2117
],
2218
],
2319
Array [
@@ -31,7 +27,7 @@ You may need an appropriate loader to handle this file type, currently no loader
3127
"webpack-dev-middleware",
3228
"warn",
3329
Array [
34-
"Child \\"warning\\": WARNING in Warning",
30+
"WARNING",
3531
],
3632
],
3733
Array [
@@ -64,7 +60,7 @@ Array [
6460
"webpack-dev-middleware",
6561
"warn",
6662
Array [
67-
"WARNING in Warning",
63+
"WARNING",
6864
],
6965
],
7066
Array [
@@ -78,7 +74,7 @@ Array [
7874
"webpack-dev-middleware",
7975
"warn",
8076
Array [
81-
"WARNING in Warning",
77+
"WARNING",
8278
],
8379
],
8480
Array [
@@ -104,11 +100,7 @@ Array [
104100
"webpack-dev-middleware",
105101
"error",
106102
Array [
107-
"ERROR in ./broken.js 1:3
108-
Module parse failed: Unexpected token (1:3)
109-
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
110-
> 1()2()3()
111-
|",
103+
"ERROR",
112104
],
113105
],
114106
Array [
@@ -122,7 +114,7 @@ You may need an appropriate loader to handle this file type, currently no loader
122114
"webpack-dev-middleware",
123115
"warn",
124116
Array [
125-
"WARNING in Warning",
117+
"WARNING",
126118
],
127119
],
128120
Array [
@@ -200,7 +192,7 @@ Array [
200192
"webpack-dev-middleware",
201193
"info",
202194
Array [
203-
"X modules",
195+
"compiled successfully",
204196
],
205197
],
206198
Array [
@@ -242,8 +234,7 @@ Array [
242234
"webpack-dev-middleware",
243235
"error",
244236
Array [
245-
"Unable to write \\"/absolute/path/to/test/outputs/write-to-disk-mkdir-error\\" directory to disk:
246-
Error: Error in the \\"fs.mkdir\\" method.",
237+
"ERROR",
247238
],
248239
],
249240
]
@@ -255,8 +246,7 @@ Array [
255246
"webpack-dev-middleware",
256247
"error",
257248
Array [
258-
"Unable to write \\"/absolute/path/to/test/outputs/write-to-disk-writeFile-error/bundle.js\\" asset to disk:
259-
Error: Error in the \\"fs.writeFile\\" method.",
249+
"ERROR",
260250
],
261251
],
262252
]
@@ -268,7 +258,7 @@ Array [
268258
"webpack-dev-middleware",
269259
"error",
270260
Array [
271-
"Error: Error in Watch method",
261+
"ERROR",
272262
],
273263
],
274264
]
@@ -287,7 +277,7 @@ Array [
287277
"webpack-dev-middleware",
288278
"warn",
289279
Array [
290-
"WARNING in Warning",
280+
"WARNING",
291281
],
292282
],
293283
Array [
@@ -315,7 +305,7 @@ Array [
315305
"webpack-dev-middleware",
316306
"warn",
317307
Array [
318-
"WARNING in Warning",
308+
"WARNING",
319309
],
320310
],
321311
Array [
@@ -435,11 +425,7 @@ Array [
435425
"webpack-dev-middleware",
436426
"error",
437427
Array [
438-
"ERROR in ./broken.js 1:3
439-
Module parse failed: Unexpected token (1:3)
440-
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
441-
> 1()2()3()
442-
|",
428+
"ERROR",
443429
],
444430
],
445431
Array [
@@ -453,11 +439,7 @@ You may need an appropriate loader to handle this file type, currently no loader
453439
"webpack-dev-middleware",
454440
"error",
455441
Array [
456-
"ERROR in ./broken.js 1:3
457-
Module parse failed: Unexpected token (1:3)
458-
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
459-
> 1()2()3()
460-
|",
442+
"ERROR",
461443
],
462444
],
463445
Array [
@@ -485,11 +467,7 @@ You may need an appropriate loader to handle this file type, currently no loader
485467
"webpack-dev-middleware",
486468
"error",
487469
Array [
488-
"ERROR in ./broken.js 1:3
489-
Module parse failed: Unexpected token (1:3)
490-
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
491-
> 1()2()3()
492-
|",
470+
"ERROR",
493471
],
494472
],
495473
Array [
@@ -503,11 +481,7 @@ You may need an appropriate loader to handle this file type, currently no loader
503481
"webpack-dev-middleware",
504482
"error",
505483
Array [
506-
"ERROR in ./broken.js 1:3
507-
Module parse failed: Unexpected token (1:3)
508-
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
509-
> 1()2()3()
510-
|",
484+
"ERROR",
511485
],
512486
],
513487
Array [
@@ -533,11 +507,7 @@ Array [
533507
"webpack-dev-middleware",
534508
"error",
535509
Array [
536-
"ERROR in ./broken.js 1:3
537-
Module parse failed: Unexpected token (1:3)
538-
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
539-
> 1()2()3()
540-
|",
510+
"ERROR",
541511
],
542512
],
543513
Array [
@@ -565,11 +535,7 @@ You may need an appropriate loader to handle this file type, currently no loader
565535
"webpack-dev-middleware",
566536
"error",
567537
Array [
568-
"ERROR in ./broken.js 1:3
569-
Module parse failed: Unexpected token (1:3)
570-
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
571-
> 1()2()3()
572-
|",
538+
"ERROR",
573539
],
574540
],
575541
Array [
@@ -595,7 +561,7 @@ Array [
595561
"webpack-dev-middleware",
596562
"warn",
597563
Array [
598-
"WARNING in Warning",
564+
"WARNING",
599565
],
600566
],
601567
Array [
@@ -609,7 +575,7 @@ Array [
609575
"webpack-dev-middleware",
610576
"warn",
611577
Array [
612-
"WARNING in Warning",
578+
"WARNING",
613579
],
614580
],
615581
Array [
@@ -637,7 +603,7 @@ Array [
637603
"webpack-dev-middleware",
638604
"warn",
639605
Array [
640-
"WARNING in Warning",
606+
"WARNING",
641607
],
642608
],
643609
Array [
@@ -651,7 +617,7 @@ Array [
651617
"webpack-dev-middleware",
652618
"warn",
653619
Array [
654-
"WARNING in Warning",
620+
"WARNING",
655621
],
656622
],
657623
Array [

test/helpers/GetLogsPlugin.js

+26-7
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,46 @@ export default class GetLogsPlugin {
33
this.logs = [];
44
}
55

6-
static normalizeLogs(log) {
6+
static normalizeLogs(log, type) {
77
if (Array.isArray(log)) {
8-
return log.map((nestedLog) => GetLogsPlugin.normalizeLogs(nestedLog));
8+
return log.map((nestedLog) =>
9+
GetLogsPlugin.normalizeLogs(nestedLog, type)
10+
);
11+
}
12+
13+
// TODO remove after webpack@4 dropping
14+
if (type === 'error') {
15+
return 'ERROR';
16+
}
17+
18+
// TODO remove after webpack@4 dropping
19+
if (type === 'warn') {
20+
return 'WARNING';
21+
}
22+
23+
// TODO remove after webpack@4 dropping
24+
if (log.includes('modules')) {
25+
return 'compiled successfully';
26+
}
27+
28+
// TODO remove after webpack@4 dropping
29+
if (log.includes('Entrypoint')) {
30+
return 'Entrypoint main = bundle.js';
931
}
1032

1133
return log
1234
.toString()
1335
.trim()
1436
.replace(process.cwd(), '/absolute/path/to')
15-
.replace(/\\/g, '/')
16-
.replace(/\d+ modules/, 'X modules')
17-
.replace(/Entrypoint (\w+) = ([\w.]+)( (\(.*\)))?/, 'Entrypoint $1 = $2')
18-
.replace(/Child "(\w+)":\s+/, 'Child "$1": ');
37+
.replace(/\\/g, '/');
1938
}
2039

2140
apply(compiler) {
2241
const hook =
2342
compiler.hooks.infrastructurelog || compiler.hooks.infrastructureLog;
2443

2544
hook.tap('GetLogsPlugin', (name, type, args) => {
26-
this.logs.push([name, type, GetLogsPlugin.normalizeLogs(args)]);
45+
this.logs.push([name, type, GetLogsPlugin.normalizeLogs(args, type)]);
2746

2847
return false;
2948
});

test/middleware.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ describe('middleware', () => {
216216
it('should return the "416" code for the "GET" request with the invalid range header', (done) => {
217217
request(app)
218218
.get('/bundle.js')
219-
.set('Range', 'bytes=6000-')
219+
.set('Range', 'bytes=9999999-')
220220
.expect(416, done);
221221
});
222222

0 commit comments

Comments
 (0)