Skip to content

Commit

Permalink
fix: handle the auto value of the publicPath option
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Oct 14, 2020
1 parent 37e23c8 commit 9b4c5ec
Show file tree
Hide file tree
Showing 9 changed files with 1,739 additions and 2,305 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [10.x, 12.x, 14.x]
webpack-version: [latest, next]
webpack-version: [4, latest]

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

Expand Down
3,886 changes: 1,665 additions & 2,221 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"url": "https://opencollective.com/webpack"
},
"engines": {
"node": ">= 10.13"
"node": ">= 10.13.0"
},
"scripts": {
"commitlint": "commitlint --from=master",
Expand All @@ -38,11 +38,11 @@
"webpack": "^4.0.0 || ^5.0.0"
},
"dependencies": {
"mem": "^6.1.1",
"mem": "^8.0.0",
"memfs": "^3.2.0",
"mime-types": "^2.1.27",
"range-parser": "^1.2.1",
"schema-utils": "^2.7.1"
"schema-utils": "^3.0.0"
},
"devDependencies": {
"@babel/cli": "^7.11.6",
Expand All @@ -52,25 +52,25 @@
"@commitlint/config-conventional": "^11.0.0",
"@webpack-contrib/defaults": "^6.3.0",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^26.3.0",
"chokidar": "^3.4.2",
"babel-jest": "^26.5.2",
"chokidar": "^3.4.3",
"cross-env": "^7.0.2",
"del": "^5.1.0",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"eslint": "^7.8.1",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint": "^7.11.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.4",
"express": "^4.17.1",
"file-loader": "^6.1.0",
"file-loader": "^6.1.1",
"husky": "^4.3.0",
"jest": "^26.4.2",
"lint-staged": "^10.3.0",
"jest": "^26.5.3",
"lint-staged": "^10.4.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.1",
"prettier": "^2.1.2",
"standard-version": "^9.0.0",
"supertest": "^4.0.2",
"webpack": "^4.44.1"
"supertest": "^5.0.0",
"webpack": "^4.44.2"
},
"keywords": [
"webpack",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import validateOptions from 'schema-utils';
import { validate } from 'schema-utils';
import mime from 'mime-types';

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

export default function wdm(compiler, options = {}) {
validateOptions(schema, options, {
validate(schema, options, {
name: 'Dev Middleware',
baseDataPath: 'options',
});
Expand Down
6 changes: 5 additions & 1 deletion src/utils/getFilenameFromUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export default function getFilenameFromUrl(context, url) {
let publicPathObject;

try {
publicPathObject = memoizedParse(publicPath || '/', false, true);
publicPathObject = memoizedParse(
publicPath !== 'auto' && publicPath ? publicPath : '/',
false,
true
);
} catch (_ignoreError) {
// eslint-disable-next-line no-continue
continue;
Expand Down
78 changes: 22 additions & 56 deletions test/__snapshots__/middleware.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ Array [
"webpack-dev-middleware",
"error",
Array [
"Child \\"broken\\": ERROR in ./broken.js 1:3
Module parse failed: Unexpected token (1:3)
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
> 1()2()3()
|",
"ERROR",
],
],
Array [
Expand All @@ -31,7 +27,7 @@ You may need an appropriate loader to handle this file type, currently no loader
"webpack-dev-middleware",
"warn",
Array [
"Child \\"warning\\": WARNING in Warning",
"WARNING",
],
],
Array [
Expand Down Expand Up @@ -64,7 +60,7 @@ Array [
"webpack-dev-middleware",
"warn",
Array [
"WARNING in Warning",
"WARNING",
],
],
Array [
Expand All @@ -78,7 +74,7 @@ Array [
"webpack-dev-middleware",
"warn",
Array [
"WARNING in Warning",
"WARNING",
],
],
Array [
Expand All @@ -104,11 +100,7 @@ Array [
"webpack-dev-middleware",
"error",
Array [
"ERROR in ./broken.js 1:3
Module parse failed: Unexpected token (1:3)
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
> 1()2()3()
|",
"ERROR",
],
],
Array [
Expand All @@ -122,7 +114,7 @@ You may need an appropriate loader to handle this file type, currently no loader
"webpack-dev-middleware",
"warn",
Array [
"WARNING in Warning",
"WARNING",
],
],
Array [
Expand Down Expand Up @@ -200,7 +192,7 @@ Array [
"webpack-dev-middleware",
"info",
Array [
"X modules",
"compiled successfully",
],
],
Array [
Expand Down Expand Up @@ -242,8 +234,7 @@ Array [
"webpack-dev-middleware",
"error",
Array [
"Unable to write \\"/absolute/path/to/test/outputs/write-to-disk-mkdir-error\\" directory to disk:
Error: Error in the \\"fs.mkdir\\" method.",
"ERROR",
],
],
]
Expand All @@ -255,8 +246,7 @@ Array [
"webpack-dev-middleware",
"error",
Array [
"Unable to write \\"/absolute/path/to/test/outputs/write-to-disk-writeFile-error/bundle.js\\" asset to disk:
Error: Error in the \\"fs.writeFile\\" method.",
"ERROR",
],
],
]
Expand All @@ -268,7 +258,7 @@ Array [
"webpack-dev-middleware",
"error",
Array [
"Error: Error in Watch method",
"ERROR",
],
],
]
Expand All @@ -287,7 +277,7 @@ Array [
"webpack-dev-middleware",
"warn",
Array [
"WARNING in Warning",
"WARNING",
],
],
Array [
Expand Down Expand Up @@ -315,7 +305,7 @@ Array [
"webpack-dev-middleware",
"warn",
Array [
"WARNING in Warning",
"WARNING",
],
],
Array [
Expand Down Expand Up @@ -435,11 +425,7 @@ Array [
"webpack-dev-middleware",
"error",
Array [
"ERROR in ./broken.js 1:3
Module parse failed: Unexpected token (1:3)
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
> 1()2()3()
|",
"ERROR",
],
],
Array [
Expand All @@ -453,11 +439,7 @@ You may need an appropriate loader to handle this file type, currently no loader
"webpack-dev-middleware",
"error",
Array [
"ERROR in ./broken.js 1:3
Module parse failed: Unexpected token (1:3)
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
> 1()2()3()
|",
"ERROR",
],
],
Array [
Expand Down Expand Up @@ -485,11 +467,7 @@ You may need an appropriate loader to handle this file type, currently no loader
"webpack-dev-middleware",
"error",
Array [
"ERROR in ./broken.js 1:3
Module parse failed: Unexpected token (1:3)
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
> 1()2()3()
|",
"ERROR",
],
],
Array [
Expand All @@ -503,11 +481,7 @@ You may need an appropriate loader to handle this file type, currently no loader
"webpack-dev-middleware",
"error",
Array [
"ERROR in ./broken.js 1:3
Module parse failed: Unexpected token (1:3)
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
> 1()2()3()
|",
"ERROR",
],
],
Array [
Expand All @@ -533,11 +507,7 @@ Array [
"webpack-dev-middleware",
"error",
Array [
"ERROR in ./broken.js 1:3
Module parse failed: Unexpected token (1:3)
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
> 1()2()3()
|",
"ERROR",
],
],
Array [
Expand Down Expand Up @@ -565,11 +535,7 @@ You may need an appropriate loader to handle this file type, currently no loader
"webpack-dev-middleware",
"error",
Array [
"ERROR in ./broken.js 1:3
Module parse failed: Unexpected token (1:3)
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
> 1()2()3()
|",
"ERROR",
],
],
Array [
Expand All @@ -595,7 +561,7 @@ Array [
"webpack-dev-middleware",
"warn",
Array [
"WARNING in Warning",
"WARNING",
],
],
Array [
Expand All @@ -609,7 +575,7 @@ Array [
"webpack-dev-middleware",
"warn",
Array [
"WARNING in Warning",
"WARNING",
],
],
Array [
Expand Down Expand Up @@ -637,7 +603,7 @@ Array [
"webpack-dev-middleware",
"warn",
Array [
"WARNING in Warning",
"WARNING",
],
],
Array [
Expand All @@ -651,7 +617,7 @@ Array [
"webpack-dev-middleware",
"warn",
Array [
"WARNING in Warning",
"WARNING",
],
],
Array [
Expand Down
33 changes: 26 additions & 7 deletions test/helpers/GetLogsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,46 @@ export default class GetLogsPlugin {
this.logs = [];
}

static normalizeLogs(log) {
static normalizeLogs(log, type) {
if (Array.isArray(log)) {
return log.map((nestedLog) => GetLogsPlugin.normalizeLogs(nestedLog));
return log.map((nestedLog) =>
GetLogsPlugin.normalizeLogs(nestedLog, type)
);
}

// TODO remove after webpack@4 dropping
if (type === 'error') {
return 'ERROR';
}

// TODO remove after webpack@4 dropping
if (type === 'warn') {
return 'WARNING';
}

// TODO remove after webpack@4 dropping
if (log.includes('modules')) {
return 'compiled successfully';
}

// TODO remove after webpack@4 dropping
if (log.includes('Entrypoint')) {
return 'Entrypoint main = bundle.js';
}

return log
.toString()
.trim()
.replace(process.cwd(), '/absolute/path/to')
.replace(/\\/g, '/')
.replace(/\d+ modules/, 'X modules')
.replace(/Entrypoint (\w+) = ([\w.]+)( (\(.*\)))?/, 'Entrypoint $1 = $2')
.replace(/Child "(\w+)":\s+/, 'Child "$1": ');
.replace(/\\/g, '/');
}

apply(compiler) {
const hook =
compiler.hooks.infrastructurelog || compiler.hooks.infrastructureLog;

hook.tap('GetLogsPlugin', (name, type, args) => {
this.logs.push([name, type, GetLogsPlugin.normalizeLogs(args)]);
this.logs.push([name, type, GetLogsPlugin.normalizeLogs(args, type)]);

return false;
});
Expand Down
2 changes: 1 addition & 1 deletion test/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('middleware', () => {
it('should return the "416" code for the "GET" request with the invalid range header', (done) => {
request(app)
.get('/bundle.js')
.set('Range', 'bytes=6000-')
.set('Range', 'bytes=9999999-')
.expect(416, done);
});

Expand Down
Loading

0 comments on commit 9b4c5ec

Please sign in to comment.