Skip to content

Commit ba8e638

Browse files
angular-robotalan-agius4
authored andcommitted
build: update dependency webpack-dev-middleware to v8
See associated pull request for more information. Closes #32816 as a pr takeover
1 parent 685ebae commit ba8e638

File tree

7 files changed

+63
-45
lines changed

7 files changed

+63
-45
lines changed

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"tinyglobby": "0.2.15",
5656
"tslib": "2.8.1",
5757
"webpack": "5.105.4",
58-
"webpack-dev-middleware": "7.4.5",
58+
"webpack-dev-middleware": "8.0.2",
5959
"webpack-dev-server": "5.2.3",
6060
"webpack-merge": "6.0.1",
6161
"webpack-subresource-integrity": "5.1.0"

packages/angular_devkit/build_angular/src/builders/karma/browser_builder.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ export function execute(
7777
}),
7878
);
7979

80-
const KARMA_APPLICATION_PATH = '_karma_webpack_';
8180
webpackConfig.output ??= {};
82-
webpackConfig.output.path = `/${KARMA_APPLICATION_PATH}/`;
83-
webpackConfig.output.publicPath = `/${KARMA_APPLICATION_PATH}/`;
81+
webpackConfig.output.path = '/';
8482

8583
if (karmaOptions.singleRun) {
8684
webpackConfig.plugins.unshift({

packages/angular_devkit/build_angular/src/tools/webpack/plugins/karma/karma-context.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<!--
33
This is the execution context.
44
Loaded within the iframe.
@@ -9,7 +9,7 @@
99
<title></title>
1010
<base href="/" />
1111
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
12-
<link rel="stylesheet" href="_karma_webpack_/styles.css" crossorigin="anonymous" />
12+
<link rel="stylesheet" href="styles.css" crossorigin="anonymous" />
1313
<meta
1414
name="viewport"
1515
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
@@ -30,13 +30,13 @@
3030
// All served files with the latest timestamps
3131
%MAPPINGS%
3232
</script>
33-
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous"></script>
34-
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous"></script>
33+
<script src="runtime.js" crossorigin="anonymous"></script>
34+
<script src="polyfills.js" crossorigin="anonymous"></script>
3535
<!-- Dynamically replaced with <script> tags -->
3636
%SCRIPTS%
37-
<script src="_karma_webpack_/scripts.js" crossorigin="anonymous" defer></script>
38-
<script src="_karma_webpack_/vendor.js" crossorigin="anonymous" type="module"></script>
39-
<script src="_karma_webpack_/main.js" crossorigin="anonymous" type="module"></script>
37+
<script src="scripts.js" crossorigin="anonymous" defer></script>
38+
<script src="vendor.js" crossorigin="anonymous" type="module"></script>
39+
<script src="main.js" crossorigin="anonymous" type="module"></script>
4040
<script type="module">
4141
window.__karma__.loaded();
4242
</script>

packages/angular_devkit/build_angular/src/tools/webpack/plugins/karma/karma-debug.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<!--
33
This file is almost the same as context.html - loads all source files,
44
but its purpose is to be loaded in the main frame (not within an iframe),
@@ -10,7 +10,7 @@
1010
<title>Karma DEBUG RUNNER</title>
1111
<base href="/" />
1212
<link href="favicon.ico" rel="icon" type="image/x-icon" />
13-
<link rel="stylesheet" href="_karma_webpack_/styles.css" crossorigin="anonymous" />
13+
<link rel="stylesheet" href="styles.css" crossorigin="anonymous" />
1414
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
1515
<meta
1616
name="viewport"
@@ -32,13 +32,13 @@
3232
// All served files with the latest timestamps
3333
%MAPPINGS%
3434
</script>
35-
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous"></script>
36-
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous"></script>
35+
<script src="runtime.js" crossorigin="anonymous"></script>
36+
<script src="polyfills.js" crossorigin="anonymous"></script>
3737
<!-- Dynamically replaced with <script> tags -->
3838
%SCRIPTS%
39-
<script src="_karma_webpack_/scripts.js" crossorigin="anonymous" defer></script>
40-
<script src="_karma_webpack_/vendor.js" crossorigin="anonymous" type="module"></script>
41-
<script src="_karma_webpack_/main.js" crossorigin="anonymous" type="module"></script>
39+
<script src="scripts.js" crossorigin="anonymous" defer></script>
40+
<script src="vendor.js" crossorigin="anonymous" type="module"></script>
41+
<script src="main.js" crossorigin="anonymous" type="module"></script>
4242
<script type="module">
4343
window.__karma__.loaded();
4444
</script>

packages/angular_devkit/build_angular/src/tools/webpack/plugins/karma/karma.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import { logging } from '@angular-devkit/core';
1818
import { BuildOptions } from '../../../../utils/build-options';
1919
import { normalizeSourceMaps } from '../../../../utils/index';
2020

21-
const KARMA_APPLICATION_PATH = '_karma_webpack_';
22-
2321
let webpackMiddleware: webpackDevMiddleware.API<IncomingMessage, ServerResponse>;
2422

2523
const init: any = (config: any, emitter: any) => {
@@ -65,7 +63,6 @@ const init: any = (config: any, emitter: any) => {
6563
const webpackMiddlewareConfig = {
6664
// Hide webpack output because its noisy.
6765
stats: false,
68-
publicPath: `/${KARMA_APPLICATION_PATH}/`,
6966
};
7067

7168
config.webpackMiddleware = { ...webpackMiddlewareConfig, ...config.webpackMiddleware };
@@ -147,7 +144,7 @@ const sourceMapReporter: any = function (this: any, baseReporterDecorator: any,
147144
baseReporterDecorator(this);
148145
muteDuplicateReporterLogging(this, config);
149146

150-
const urlRegexp = /http:\/\/localhost:\d+\/_karma_webpack_\/(webpack:\/)?/gi;
147+
const urlRegexp = /http:\/\/localhost:\d+\/(webpack:\/)?/gi;
151148

152149
this.onSpecComplete = function (_browser: any, result: any) {
153150
if (!result.success) {
@@ -164,35 +161,37 @@ const sourceMapReporter: any = function (this: any, baseReporterDecorator: any,
164161

165162
sourceMapReporter.$inject = ['baseReporterDecorator', 'config'];
166163

164+
/**
165+
* List of files that are always served by the webpack server.
166+
*/
167+
const alwaysServe: ReadonlySet<string> = new Set([
168+
'/runtime.js',
169+
'/polyfills.js',
170+
'/scripts.js',
171+
'/styles.css',
172+
'/vendor.js',
173+
]);
174+
167175
// When a request is not found in the karma server, try looking for it from the webpack server root.
168176
function fallbackMiddleware() {
169177
return function (
170178
request: IncomingMessage,
171179
response: ServerResponse,
172180
next: (err?: unknown) => void,
173181
) {
174-
if (webpackMiddleware) {
175-
if (request.url && !new RegExp(`\\/${KARMA_APPLICATION_PATH}\\/.*`).test(request.url)) {
176-
request.url = '/' + KARMA_APPLICATION_PATH + request.url;
177-
}
178-
webpackMiddleware(request, response, () => {
179-
const alwaysServe = [
180-
`/${KARMA_APPLICATION_PATH}/runtime.js`,
181-
`/${KARMA_APPLICATION_PATH}/polyfills.js`,
182-
`/${KARMA_APPLICATION_PATH}/scripts.js`,
183-
`/${KARMA_APPLICATION_PATH}/styles.css`,
184-
`/${KARMA_APPLICATION_PATH}/vendor.js`,
185-
];
186-
if (request.url && alwaysServe.includes(request.url)) {
187-
response.statusCode = 200;
188-
response.end();
189-
} else {
190-
next();
191-
}
192-
});
193-
} else {
182+
if (!webpackMiddleware) {
194183
next();
184+
return;
195185
}
186+
187+
webpackMiddleware(request, response, () => {
188+
if (request.url && alwaysServe.has(request.url)) {
189+
response.statusCode = 200;
190+
response.end();
191+
} else {
192+
next();
193+
}
194+
});
196195
};
197196
}
198197

pnpm-lock.yaml

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/e2e/tests/test/test-sourcemap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default async function () {
3232
} catch (error) {
3333
assertIsError(error);
3434
assert.match(error.message, /\(src\/app\/app\.spec\.ts:3:27/);
35-
assert.doesNotMatch(error.message, /_karma_webpack_/);
35+
assert.doesNotMatch(error.message, /webpack/);
3636
}
3737

3838
// when sourcemaps are 'off' the stacktrace won't point to the spec.ts file.

0 commit comments

Comments
 (0)