Skip to content

Commit fc4b923

Browse files
committed
fix(@angular-devkit/build-angular): update webpack to 5.105.0
This the below security security issues: GHSA-8fgc-7cc6-rx7x GHSA-38r7-794h-5758 Closes: #32465
1 parent 399c3ec commit fc4b923

File tree

15 files changed

+283
-86
lines changed

15 files changed

+283
-86
lines changed

goldens/public-api/angular_devkit/build_webpack/index.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import { BuilderContext } from '@angular-devkit/architect';
88
import { BuilderOutput } from '@angular-devkit/architect';
99
import { Observable } from 'rxjs';
10-
import webpack from 'webpack';
11-
import WebpackDevServer from 'webpack-dev-server';
10+
import type webpack from 'webpack';
11+
import type WebpackDevServer from 'webpack-dev-server';
1212

1313
// @public (undocumented)
1414
export type BuildResult = BuilderOutput & {
@@ -65,7 +65,7 @@ export type WebpackDevServerFactory = typeof WebpackDevServer;
6565
// @public (undocumented)
6666
export interface WebpackFactory {
6767
// (undocumented)
68-
(config: webpack.Configuration): Observable<webpack.Compiler> | webpack.Compiler;
68+
(config: webpack.Configuration): Observable<webpack.Compiler | null> | webpack.Compiler | null;
6969
}
7070

7171
// @public (undocumented)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
"verdaccio-auth-memory": "^10.0.0",
204204
"vite": "6.4.1",
205205
"watchpack": "2.4.2",
206-
"webpack": "5.98.0",
206+
"webpack": "5.105.0",
207207
"webpack-dev-middleware": "7.4.2",
208208
"webpack-dev-server": "5.2.2",
209209
"webpack-merge": "6.0.1",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"terser": "5.39.0",
5757
"tree-kill": "1.2.2",
5858
"tslib": "2.8.1",
59-
"webpack": "5.98.0",
59+
"webpack": "5.105.0",
6060
"webpack-dev-middleware": "7.4.2",
6161
"webpack-dev-server": "5.2.2",
6262
"webpack-merge": "6.0.1",

packages/angular_devkit/build_angular/src/tools/webpack/plugins/css-optimizer-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class CssOptimizerPlugin {
131131
private optimize(
132132
input: string,
133133
name: string,
134-
inputMap: object,
134+
inputMap: object | null,
135135
target: string[] | undefined,
136136
): Promise<TransformResult> {
137137
let sourceMapLine;

packages/angular_devkit/build_angular/src/tools/webpack/plugins/index-html-webpack-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class IndexHtmlWebpackPlugin extends IndexHtmlGenerator {
6060
}
6161

6262
files.push({
63-
name: chunk.name,
63+
name: chunk.name ?? undefined,
6464
file,
6565
extension: extname(file),
6666
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// TODO: cleanup this file, it's copied as is from Angular CLI.
1111
import * as http from 'http';
1212
import * as path from 'path';
13+
import assert from 'node:assert';
1314
import webpack from 'webpack';
1415
import webpackDevMiddleware from 'webpack-dev-middleware';
1516

@@ -142,6 +143,8 @@ const init: any = (config: any, emitter: any) => {
142143
callback?.();
143144
}
144145

146+
assert(compiler, 'Compiler cannot be undefined.');
147+
145148
compiler.hooks.invalid.tap('karma', () => handler());
146149
compiler.hooks.watchRun.tapAsync('karma', (_: any, callback: () => void) => handler(callback));
147150
compiler.hooks.run.tapAsync('karma', (_: any, callback: () => void) => handler(callback));

packages/angular_devkit/build_angular/src/tools/webpack/plugins/remove-hash-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class RemoveHashPlugin {
1919

2020
apply(compiler: Compiler): void {
2121
compiler.hooks.compilation.tap('remove-hash-plugin', (compilation) => {
22-
const assetPath = (path: string, data: { chunk?: { name: string } }) => {
22+
const assetPath = (path: string, data: { chunk?: { name?: string | null } }) => {
2323
const chunkName = data.chunk?.name;
2424
const { chunkNames, hashFormat } = this.options;
2525

packages/angular_devkit/build_angular/src/utils/process-bundle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
240240
for (const locale of i18n.inlineLocales) {
241241
const content = new ReplaceSource(
242242
inputMap
243-
? new SourceMapSource(options.code, options.filename, inputMap)
243+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
244+
new SourceMapSource(options.code, options.filename, inputMap as any)
244245
: new OriginalSource(options.code, options.filename),
245246
);
246247

packages/angular_devkit/build_webpack/src/builders/webpack-dev-server/index.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
*/
88

99
import { Builder, BuilderContext, createBuilder } from '@angular-devkit/architect';
10+
import assert from 'node:assert';
1011
import { resolve as pathResolve } from 'node:path';
1112
import { Observable, from, isObservable, of, switchMap } from 'rxjs';
12-
import webpack from 'webpack';
13-
import WebpackDevServer from 'webpack-dev-server';
13+
import type webpack from 'webpack';
14+
import type WebpackDevServer from 'webpack-dev-server';
1415
import { getEmittedFiles, getWebpackConfig } from '../../utils';
1516
import { BuildResult, WebpackFactory, WebpackLoggingCallback } from '../webpack';
1617
import { Schema as WebpackDevServerBuilderSchema } from './schema';
@@ -43,7 +44,7 @@ export function runWebpackDevServer(
4344
return of(result);
4445
}
4546
} else {
46-
return of(webpack(c));
47+
return from(import('webpack').then((mod) => mod.default(c)));
4748
}
4849
};
4950

@@ -53,9 +54,9 @@ export function runWebpackDevServer(
5354
) => {
5455
if (options.webpackDevServerFactory) {
5556
return new options.webpackDevServerFactory(config, webpack);
57+
} else {
58+
return from(import('webpack-dev-server').then((mod) => new mod.default(config, webpack)));
5659
}
57-
58-
return new WebpackDevServer(config, webpack);
5960
};
6061

6162
const {
@@ -69,14 +70,21 @@ export function runWebpackDevServer(
6970
} = options;
7071

7172
return createWebpack({ ...config, watch: false }).pipe(
73+
switchMap(async (webpackCompiler) => {
74+
return [
75+
webpackCompiler,
76+
options.webpackDevServerFactory ?? (await import('webpack-dev-server')).default,
77+
] as unknown as [webpack.Compiler | null, WebpackDevServerFactory];
78+
}),
7279
switchMap(
73-
(webpackCompiler) =>
80+
([webpackCompiler, webpackDevServerFactory]) =>
7481
new Observable<DevServerBuildOutput>((obs) => {
82+
assert(webpackCompiler, 'Webpack compiler factory did not return a compiler instance.');
83+
7584
const devServerConfig = options.devServerConfig || config.devServer || {};
7685
devServerConfig.host ??= 'localhost';
7786

7887
let result: Partial<DevServerBuildOutput>;
79-
8088
const statsOptions = typeof config.stats === 'boolean' ? undefined : config.stats;
8189

8290
webpackCompiler.hooks.done.tap('build-webpack', (stats) => {
@@ -91,7 +99,7 @@ export function runWebpackDevServer(
9199
} as unknown as DevServerBuildOutput);
92100
});
93101

94-
const devServer = createWebpackDevServer(webpackCompiler, devServerConfig);
102+
const devServer = new webpackDevServerFactory(devServerConfig, webpackCompiler);
95103
devServer.startCallback((err) => {
96104
if (err) {
97105
obs.error(err);

packages/angular_devkit/build_webpack/src/builders/webpack/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88

99
import { Builder, BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
10+
import assert from 'node:assert';
1011
import { resolve as pathResolve } from 'node:path';
1112
import { Observable, from, isObservable, of, switchMap } from 'rxjs';
12-
import webpack from 'webpack';
13+
import type webpack from 'webpack';
1314
import { EmittedFiles, getEmittedFiles, getWebpackConfig } from '../../utils';
1415
import { Schema as RealWebpackBuilderSchema } from './schema';
1516

@@ -19,7 +20,7 @@ export interface WebpackLoggingCallback {
1920
(stats: webpack.Stats, config: webpack.Configuration): void;
2021
}
2122
export interface WebpackFactory {
22-
(config: webpack.Configuration): Observable<webpack.Compiler> | webpack.Compiler;
23+
(config: webpack.Configuration): Observable<webpack.Compiler | null> | webpack.Compiler | null;
2324
}
2425

2526
export type BuildResult = BuilderOutput & {
@@ -56,14 +57,16 @@ export function runWebpack(
5657
return of(result);
5758
}
5859
} else {
59-
return of(webpack(c));
60+
return from(import('webpack').then((mod) => mod.default(c)));
6061
}
6162
};
6263

6364
return createWebpack({ ...config, watch: false }).pipe(
6465
switchMap(
6566
(webpackCompiler) =>
6667
new Observable<BuildResult>((obs) => {
68+
assert(webpackCompiler, 'Webpack compiler factory did not return a compiler instance.');
69+
6770
const callback = (err?: Error | null, stats?: webpack.Stats) => {
6871
if (err) {
6972
return obs.error(err);
@@ -101,7 +104,7 @@ export function runWebpack(
101104

102105
// Teardown logic. Close the watcher when unsubscribed from.
103106
return () => {
104-
watching.close(() => {});
107+
watching?.close(() => {});
105108
webpackCompiler.close(() => {});
106109
};
107110
} else {

0 commit comments

Comments
 (0)