Skip to content

Commit 0f4bbb5

Browse files
alan-agius4clydin
authored andcommitted
refactor(@angular-devkit/build-angular): remove webpack 4 checks
These are no longer needed as we don't support Webpack 4 any longer
1 parent bd0aba7 commit 0f4bbb5

24 files changed

+104
-322
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@
183183
"parse5-html-rewriting-stream": "6.0.1",
184184
"pidtree": "^0.5.0",
185185
"pidusage": "^2.0.17",
186-
"pnp-webpack-plugin": "1.6.4",
187186
"popper.js": "^1.14.1",
188187
"postcss": "8.2.10",
189188
"postcss-import": "14.0.1",
@@ -226,7 +225,7 @@
226225
"typescript": "4.2.4",
227226
"verdaccio": "4.12.0",
228227
"verdaccio-auth-memory": "^10.0.0",
229-
"webpack": "5.30.0",
228+
"webpack": "5.31.0",
230229
"webpack-dev-middleware": "4.1.0",
231230
"webpack-dev-server": "3.11.2",
232231
"webpack-merge": "5.7.3",

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ ts_library(
166166
"@npm//open",
167167
"@npm//ora",
168168
"@npm//parse5-html-rewriting-stream",
169-
"@npm//pnp-webpack-plugin",
170169
"@npm//postcss",
171170
"@npm//postcss-import",
172171
"@npm//postcss-loader",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"open": "8.0.5",
4848
"ora": "5.4.0",
4949
"parse5-html-rewriting-stream": "6.0.1",
50-
"pnp-webpack-plugin": "1.6.4",
5150
"postcss": "8.2.10",
5251
"postcss-import": "14.0.1",
5352
"postcss-loader": "5.2.0",
@@ -70,7 +69,7 @@
7069
"terser-webpack-plugin": "4.2.3",
7170
"text-table": "0.2.0",
7271
"tree-kill": "1.2.2",
73-
"webpack": "5.30.0",
72+
"webpack": "5.31.0",
7473
"webpack-dev-middleware": "4.1.0",
7574
"webpack-dev-server": "3.11.2",
7675
"webpack-merge": "5.7.3",

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ import { I18nOptions } from './i18n-options';
3535

3636
type LocalizeUtilities = typeof import('@angular/localize/src/tools/src/source_file_utils');
3737

38-
const deserialize = ((v8 as unknown) as { deserialize(buffer: Buffer): unknown }).deserialize;
39-
4038
// If code size is larger than 500KB, consider lower fidelity but faster sourcemap merge
4139
const FAST_SOURCEMAP_THRESHOLD = 500 * 1024;
4240

@@ -88,7 +86,7 @@ let i18n: I18nOptions | undefined;
8886

8987
export function setup(data: number[] | { cachePath: string; i18n: I18nOptions }): void {
9088
const options = Array.isArray(data)
91-
? (deserialize(Buffer.from(data)) as { cachePath: string; i18n: I18nOptions })
89+
? (v8.deserialize(Buffer.from(data)) as { cachePath: string; i18n: I18nOptions })
9290
: data;
9391
cachePath = options.cachePath;
9492
i18n = options.i18n;

packages/angular_devkit/build_angular/src/utils/webpack-diagnostics.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,15 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import * as webpack from 'webpack';
9-
import { isWebpackFiveOrHigher } from './webpack-version';
109

1110
const WebpackError = require('webpack/lib/WebpackError');
1211

1312
export function addWarning(compilation: webpack.compilation.Compilation, message: string): void {
14-
if (isWebpackFiveOrHigher()) {
15-
compilation.warnings.push(new WebpackError(message));
16-
} else {
17-
// Allows building with either Webpack 4 or 5+ types
18-
// tslint:disable-next-line: no-any
19-
compilation.warnings.push(message as any);
20-
}
13+
compilation.warnings.push(new WebpackError(message));
14+
2115
}
2216

2317
export function addError(compilation: webpack.compilation.Compilation, message: string): void {
24-
if (isWebpackFiveOrHigher()) {
25-
compilation.errors.push(new WebpackError(message));
26-
} else {
27-
// Allows building with either Webpack 4 or 5+ types
28-
// tslint:disable-next-line: no-any
29-
compilation.errors.push(new Error(message) as any);
30-
}
18+
compilation.errors.push(new WebpackError(message));
19+
3120
}

packages/angular_devkit/build_angular/src/utils/webpack-version.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,3 @@ export function isWebpackFiveOrHigher(): boolean {
2121

2222
return cachedIsWebpackFiveOrHigher;
2323
}
24-
25-
// tslint:disable-next-line: no-any
26-
export function withWebpackFourOrFive<T, R>(webpackFourValue: T, webpackFiveValue: R): any {
27-
return isWebpackFiveOrHigher() ? webpackFiveValue : webpackFourValue;
28-
}

packages/angular_devkit/build_angular/src/webpack.d.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,6 @@ import { loader as webpack4Loader } from '@types/webpack';
1010

1111
// Webpack 5 transition support types
1212
declare module 'webpack' {
13-
export interface Configuration extends webpack.Configuration {
14-
devServer?: import('webpack-dev-server').Configuration;
15-
}
16-
17-
export namespace sources {
18-
export class RawSource extends webpack.sources.RawSource {
19-
constructor(source: string);
20-
}
21-
export class SourceMapSource extends webpack.sources.SourceMapSource {
22-
constructor(
23-
source: string,
24-
name: string,
25-
sourceMap: string,
26-
originalSource: string,
27-
innerSourceMap: string,
28-
);
29-
}
30-
}
31-
32-
export namespace compilation {
33-
export type Compilation = webpack.Compilation;
34-
export type Module = webpack.Module;
35-
}
3613

3714
export namespace loader {
3815
export type LoaderContext = webpack4Loader.LoaderContext;

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,15 @@ import {
3535
import { findAllNodeModules } from '../../utils/find-up';
3636
import { Spinner } from '../../utils/spinner';
3737
import { addError } from '../../utils/webpack-diagnostics';
38-
import { isWebpackFiveOrHigher, withWebpackFourOrFive } from '../../utils/webpack-version';
3938
import {
4039
DedupeModuleResolvePlugin,
41-
NamedLazyChunksPlugin,
4240
OptimizeCssWebpackPlugin,
4341
ScriptsWebpackPlugin,
4442
} from '../plugins';
4543
import { getEsVersionForFileName, getOutputHashFormat, getWatchOptions, normalizeExtraEntryPoints } from '../utils/helpers';
4644
import { IGNORE_WARNINGS } from '../utils/stats';
4745

4846
const TerserPlugin = require('terser-webpack-plugin');
49-
const PnpWebpackPlugin = require('pnp-webpack-plugin');
5047

5148
// tslint:disable-next-line:no-big-function
5249
export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
@@ -288,18 +285,6 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
288285
);
289286
}
290287

291-
if (buildOptions.namedChunks && !isWebpackFiveOrHigher()) {
292-
extraPlugins.push(new NamedLazyChunksPlugin());
293-
294-
// Provide full names for lazy routes that use the deprecated string format
295-
extraPlugins.push(
296-
new ContextReplacementPlugin(
297-
/\@angular[\\\/]core[\\\/]/,
298-
(data: { chunkName?: string }) => (data.chunkName = '[request]'),
299-
),
300-
);
301-
}
302-
303288
if ((scriptsSourceMap || stylesSourceMap)) {
304289
extraRules.push({
305290
test: /\.m?js$/,
@@ -422,7 +407,6 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
422407
extensions: ['.ts', '.tsx', '.mjs', '.js'],
423408
symlinks: !buildOptions.preserveSymlinks,
424409
modules: [wco.tsConfig.options.baseUrl || projectRoot, 'node_modules'],
425-
plugins: isWebpackFiveOrHigher() ? [] : [PnpWebpackPlugin],
426410
},
427411
resolveLoader: {
428412
symlinks: !buildOptions.preserveSymlinks,
@@ -433,12 +417,10 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
433417
'node_modules',
434418
...findAllNodeModules(__dirname, projectRoot),
435419
],
436-
plugins: isWebpackFiveOrHigher() ? [] : [PnpWebpackPlugin.moduleLoader(module)],
437420
},
438421
context: root,
439422
entry: entryPoints,
440423
output: {
441-
...withWebpackFourOrFive({ futureEmitAssets: true }, {}),
442424
path: path.resolve(root, buildOptions.outputPath),
443425
publicPath: buildOptions.deployUrl,
444426
filename: ({ chunk }) => {
@@ -455,7 +437,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
455437
performance: {
456438
hints: false,
457439
},
458-
...withWebpackFourOrFive({}, { ignoreWarnings: IGNORE_WARNINGS }),
440+
ignoreWarnings: IGNORE_WARNINGS,
459441
module: {
460442
// Show an error for missing exports instead of a warning.
461443
strictExportPresence: true,
@@ -494,9 +476,9 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
494476
cache: !!buildOptions.watch && !cachingDisabled,
495477
optimization: {
496478
minimizer: extraMinimizers,
497-
moduleIds: withWebpackFourOrFive('hashed', 'deterministic'),
479+
moduleIds: 'deterministic',
498480
chunkIds: buildOptions.namedChunks ? 'named' : 'deterministic',
499-
...withWebpackFourOrFive({ noEmitOnErrors: true }, { emitOnErrors: false }),
481+
emitOnErrors: false,
500482
},
501483
plugins: [
502484
// Always replace the context for the System.import in angular/core to prevent warnings.

packages/angular_devkit/build_angular/src/webpack/configs/stats.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import { WebpackConfigOptions } from '../../utils/build-options';
10-
import { isWebpackFiveOrHigher } from '../../utils/webpack-version';
1110

1211
const webpackOutputOptions = {
1312
all: false, // Fallback value for stats options when an option is not defined. It has precedence over local webpack defaults.
@@ -43,11 +42,7 @@ const verboseWebpackOutputOptions: Record<string, boolean | string | number> =
4342
logging: 'verbose',
4443
};
4544

46-
if (isWebpackFiveOrHigher()) {
47-
verboseWebpackOutputOptions['modulesSpace'] = Infinity;
48-
} else {
49-
verboseWebpackOutputOptions['maxModules'] = Infinity;
50-
}
45+
verboseWebpackOutputOptions['modulesSpace'] = Infinity;
5146

5247
export function getWebpackStatsConfig(verbose = false) {
5348
return verbose

packages/angular_devkit/build_angular/src/webpack/plugins/analytics.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88
import { analytics } from '@angular-devkit/core';
99
import {
10+
Compilation,
1011
Compiler,
1112
Module,
1213
Stats,
13-
compilation,
1414
} from 'webpack';
1515
import { OriginalSource } from 'webpack-sources';
1616

@@ -182,7 +182,7 @@ export class NgBuildAnalyticsPlugin {
182182
}
183183
}
184184

185-
protected _collectBundleStats(compilation: compilation.Compilation) {
185+
protected _collectBundleStats(compilation: Compilation) {
186186
const chunkAssets = new Set<string>();
187187
for (const chunk of compilation.chunks) {
188188
if (!chunk.rendered) {
@@ -231,7 +231,7 @@ export class NgBuildAnalyticsPlugin {
231231
* Reports a succeed module.
232232
* @private
233233
*/
234-
protected _succeedModule(mod: compilation.Module) {
234+
protected _succeedModule(mod: Module) {
235235
// Only report NormalModule instances.
236236
if (mod.constructor !== NormalModule) {
237237
return;
@@ -253,7 +253,7 @@ export class NgBuildAnalyticsPlugin {
253253
}
254254
}
255255

256-
protected _compilation(compiler: Compiler, compilation: compilation.Compilation) {
256+
protected _compilation(compiler: Compiler, compilation: Compilation) {
257257
this._reset();
258258
compilation.hooks.succeedModule.tap('NgBuildAnalyticsPlugin', this._succeedModule.bind(this));
259259
}

0 commit comments

Comments
 (0)