Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"tinyglobby": "0.2.15",
"tslib": "2.8.1",
"webpack": "5.105.4",
"webpack-dev-middleware": "7.4.5",
"webpack-dev-middleware": "8.0.2",
"webpack-dev-server": "5.2.3",
"webpack-merge": "6.0.1",
"webpack-subresource-integrity": "5.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ export function execute(
}),
);

const KARMA_APPLICATION_PATH = '_karma_webpack_';
webpackConfig.output ??= {};
webpackConfig.output.path = `/${KARMA_APPLICATION_PATH}/`;
webpackConfig.output.publicPath = `/${KARMA_APPLICATION_PATH}/`;
webpackConfig.output.path = '/';

if (karmaOptions.singleRun) {
webpackConfig.plugins.unshift({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<!--
This is the execution context.
Loaded within the iframe.
Expand All @@ -9,7 +9,7 @@
<title></title>
<base href="/" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="_karma_webpack_/styles.css" crossorigin="anonymous" />
<link rel="stylesheet" href="styles.css" crossorigin="anonymous" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
Expand All @@ -30,13 +30,13 @@
// All served files with the latest timestamps
%MAPPINGS%
</script>
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous"></script>
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous"></script>
<script src="runtime.js" crossorigin="anonymous"></script>
<script src="polyfills.js" crossorigin="anonymous"></script>
<!-- Dynamically replaced with <script> tags -->
%SCRIPTS%
<script src="_karma_webpack_/scripts.js" crossorigin="anonymous" defer></script>
<script src="_karma_webpack_/vendor.js" crossorigin="anonymous" type="module"></script>
<script src="_karma_webpack_/main.js" crossorigin="anonymous" type="module"></script>
<script src="scripts.js" crossorigin="anonymous" defer></script>
<script src="vendor.js" crossorigin="anonymous" type="module"></script>
<script src="main.js" crossorigin="anonymous" type="module"></script>
<script type="module">
window.__karma__.loaded();
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<!--
This file is almost the same as context.html - loads all source files,
but its purpose is to be loaded in the main frame (not within an iframe),
Expand All @@ -10,7 +10,7 @@
<title>Karma DEBUG RUNNER</title>
<base href="/" />
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link rel="stylesheet" href="_karma_webpack_/styles.css" crossorigin="anonymous" />
<link rel="stylesheet" href="styles.css" crossorigin="anonymous" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta
name="viewport"
Expand All @@ -32,13 +32,13 @@
// All served files with the latest timestamps
%MAPPINGS%
</script>
<script src="_karma_webpack_/runtime.js" crossorigin="anonymous"></script>
<script src="_karma_webpack_/polyfills.js" crossorigin="anonymous"></script>
<script src="runtime.js" crossorigin="anonymous"></script>
<script src="polyfills.js" crossorigin="anonymous"></script>
<!-- Dynamically replaced with <script> tags -->
%SCRIPTS%
<script src="_karma_webpack_/scripts.js" crossorigin="anonymous" defer></script>
<script src="_karma_webpack_/vendor.js" crossorigin="anonymous" type="module"></script>
<script src="_karma_webpack_/main.js" crossorigin="anonymous" type="module"></script>
<script src="scripts.js" crossorigin="anonymous" defer></script>
<script src="vendor.js" crossorigin="anonymous" type="module"></script>
<script src="main.js" crossorigin="anonymous" type="module"></script>
<script type="module">
window.__karma__.loaded();
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { logging } from '@angular-devkit/core';
import { BuildOptions } from '../../../../utils/build-options';
import { normalizeSourceMaps } from '../../../../utils/index';

const KARMA_APPLICATION_PATH = '_karma_webpack_';

let webpackMiddleware: webpackDevMiddleware.API<IncomingMessage, ServerResponse>;

const init: any = (config: any, emitter: any) => {
Expand Down Expand Up @@ -65,7 +63,6 @@ const init: any = (config: any, emitter: any) => {
const webpackMiddlewareConfig = {
// Hide webpack output because its noisy.
stats: false,
publicPath: `/${KARMA_APPLICATION_PATH}/`,
};

config.webpackMiddleware = { ...webpackMiddlewareConfig, ...config.webpackMiddleware };
Expand Down Expand Up @@ -147,7 +144,7 @@ const sourceMapReporter: any = function (this: any, baseReporterDecorator: any,
baseReporterDecorator(this);
muteDuplicateReporterLogging(this, config);

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

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

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

/**
* List of files that are always served by the webpack server.
*/
const alwaysServe: ReadonlySet<string> = new Set([
'/runtime.js',
'/polyfills.js',
'/scripts.js',
'/styles.css',
'/vendor.js',
]);

// When a request is not found in the karma server, try looking for it from the webpack server root.
function fallbackMiddleware() {
return function (
request: IncomingMessage,
response: ServerResponse,
next: (err?: unknown) => void,
) {
if (webpackMiddleware) {
if (request.url && !new RegExp(`\\/${KARMA_APPLICATION_PATH}\\/.*`).test(request.url)) {
request.url = '/' + KARMA_APPLICATION_PATH + request.url;
}
webpackMiddleware(request, response, () => {
const alwaysServe = [
`/${KARMA_APPLICATION_PATH}/runtime.js`,
`/${KARMA_APPLICATION_PATH}/polyfills.js`,
`/${KARMA_APPLICATION_PATH}/scripts.js`,
`/${KARMA_APPLICATION_PATH}/styles.css`,
`/${KARMA_APPLICATION_PATH}/vendor.js`,
];
if (request.url && alwaysServe.includes(request.url)) {
response.statusCode = 200;
response.end();
} else {
next();
}
});
} else {
if (!webpackMiddleware) {
next();
return;
}

webpackMiddleware(request, response, () => {
if (request.url && alwaysServe.has(request.url)) {
response.statusCode = 200;
response.end();
} else {
next();
}
});
};
}

Expand Down
25 changes: 23 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/e2e/tests/test/test-sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async function () {
} catch (error) {
assertIsError(error);
assert.match(error.message, /\(src\/app\/app\.spec\.ts:3:27/);
assert.doesNotMatch(error.message, /_karma_webpack_/);
assert.doesNotMatch(error.message, /webpack/);
}

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