Skip to content

Commit 3db2787

Browse files
clydinmgechev
authored andcommitted
refactor(@angular-devkit/build-angular): update webpack typings (#15334)
1 parent 26f66fe commit 3db2787

File tree

11 files changed

+70
-65
lines changed

11 files changed

+70
-65
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@
101101
"@types/node": "10.9.4",
102102
"@types/request": "^2.47.1",
103103
"@types/semver": "^6.0.0",
104-
"@types/webpack": "^4.4.11",
105-
"@types/webpack-dev-server": "^3.1.0",
104+
"@types/webpack": "^4.32.1",
105+
"@types/webpack-dev-server": "^3.1.7",
106106
"@types/webpack-sources": "^0.1.5",
107107
"@yarnpkg/lockfile": "1.1.0",
108108
"ajv": "6.10.2",

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
compilation,
1414
} from 'webpack';
1515
import { Source } from 'webpack-sources';
16-
import Compilation = compilation.Compilation;
1716

1817
const NormalModule = require('webpack/lib/NormalModule');
1918

@@ -262,7 +261,7 @@ export class NgBuildAnalyticsPlugin {
262261
}
263262
}
264263

265-
protected _compilation(compiler: Compiler, compilation: Compilation) {
264+
protected _compilation(compiler: Compiler, compilation: compilation.Compilation) {
266265
this._reset();
267266
compilation.hooks.succeedModule.tap('NgBuildAnalyticsPlugin', this._succeedModule.bind(this));
268267
}

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/browser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
7878
splitChunks: {
7979
maxAsyncRequests: Infinity,
8080
cacheGroups: {
81-
default: buildOptions.commonChunk && {
81+
default: !!buildOptions.commonChunk && {
8282
chunks: 'async',
8383
minChunks: 2,
8484
priority: 10,
8585
},
86-
common: buildOptions.commonChunk && {
86+
common: !!buildOptions.commonChunk && {
8787
name: 'common',
8888
chunks: 'async',
8989
minChunks: 2,
9090
enforce: true,
9191
priority: 5,
9292
},
9393
vendors: false,
94-
vendor: buildOptions.vendorChunk && {
94+
vendor: !!buildOptions.vendorChunk && {
9595
name: 'vendor',
9696
chunks: 'initial',
9797
enforce: true,
@@ -105,7 +105,7 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
105105
},
106106
},
107107
},
108-
} as webpack.Options.Optimization,
108+
},
109109
plugins: extraPlugins,
110110
node: false,
111111
};

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
Configuration,
1919
ContextReplacementPlugin,
2020
HashedModuleIdsPlugin,
21-
Output,
2221
debug,
2322
} from 'webpack';
2423
import { RawSource } from 'webpack-sources';
@@ -408,8 +407,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
408407
path: path.resolve(root, buildOptions.outputPath as string),
409408
publicPath: buildOptions.deployUrl,
410409
filename: `[name]${targetInFileName}${hashFormat.chunk}.js`,
411-
// cast required until typings include `futureEmitAssets` property
412-
} as Output,
410+
},
413411
watch: buildOptions.watch,
414412
watchOptions: {
415413
poll: buildOptions.poll,

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getSourceMapDevTool } from './utils';
1414
* Returns a partial specific to creating a bundle for node
1515
* @param wco Options which are include the build options and app config
1616
*/
17-
export function getServerConfig(wco: WebpackConfigOptions) {
17+
export function getServerConfig(wco: WebpackConfigOptions): Configuration {
1818
const extraPlugins = [];
1919
if (wco.buildOptions.sourceMap) {
2020
const { scripts, styles, hidden } = wco.buildOptions.sourceMap;

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,5 @@ export function getTestConfig(
101101
},
102102
},
103103
},
104-
// Webpack typings don't yet include the function form for 'chunks',
105-
// or the built-in vendors cache group.
106-
} as {} as webpack.Configuration;
104+
};
107105
}

packages/angular_devkit/build_angular/src/angular-cli-files/plugins/cleancss-webpack-plugin.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
1-
// tslint:disable
2-
// TODO: cleanup this file, it's copied as is from Angular CLI.
3-
41
/**
52
* @license
63
* Copyright Google Inc. All Rights Reserved.
74
*
85
* Use of this source code is governed by an MIT-style license that can be
96
* found in the LICENSE file at https://angular.io/license
107
*/
11-
128
import * as CleanCSS from 'clean-css';
139
import { Compiler, compilation } from 'webpack';
1410
import { RawSource, Source, SourceMapSource } from 'webpack-sources';
1511

16-
interface Chunk {
17-
files: string[];
18-
}
19-
2012
export interface CleanCssWebpackPluginOptions {
2113
sourceMap: boolean;
2214
test: (file: string) => boolean;
2315
}
2416

2517
function hook(
26-
compiler: any,
27-
action: (compilation: any, chunks: Array<Chunk>) => Promise<void | void[]>,
18+
compiler: Compiler,
19+
action: (
20+
compilation: compilation.Compilation,
21+
chunks: compilation.Chunk[],
22+
) => Promise<void | void[]>,
2823
) {
29-
compiler.hooks.compilation.tap('cleancss-webpack-plugin', (compilation: any) => {
30-
compilation.hooks.optimizeChunkAssets.tapPromise(
31-
'cleancss-webpack-plugin',
32-
(chunks: Array<Chunk>) => action(compilation, chunks),
33-
);
34-
});
24+
compiler.hooks.compilation.tap(
25+
'cleancss-webpack-plugin',
26+
(compilation: compilation.Compilation) => {
27+
compilation.hooks.optimizeChunkAssets.tapPromise('cleancss-webpack-plugin', chunks =>
28+
action(compilation, chunks),
29+
);
30+
},
31+
);
3532
}
3633

3734
export class CleanCssWebpackPlugin {
@@ -40,22 +37,22 @@ export class CleanCssWebpackPlugin {
4037
constructor(options: Partial<CleanCssWebpackPluginOptions>) {
4138
this._options = {
4239
sourceMap: false,
43-
test: (file) => file.endsWith('.css'),
40+
test: file => file.endsWith('.css'),
4441
...options,
4542
};
4643
}
4744

4845
apply(compiler: Compiler): void {
49-
hook(compiler, (compilation: compilation.Compilation, chunks: Array<Chunk>) => {
46+
hook(compiler, (compilation: compilation.Compilation, chunks: compilation.Chunk[]) => {
5047
const cleancss = new CleanCSS({
5148
compatibility: 'ie9',
5249
level: {
5350
2: {
5451
skipProperties: [
5552
'transition', // Fixes #12408
5653
'font', // Fixes #9648
57-
]
58-
}
54+
],
55+
},
5956
},
6057
inline: false,
6158
returnPromise: true,
@@ -79,6 +76,7 @@ export class CleanCssWebpackPlugin {
7976
}
8077

8178
let content: string;
79+
// tslint:disable-next-line: no-any
8280
let map: any;
8381
if (this._options.sourceMap && asset.sourceAndMap) {
8482
const sourceAndMap = asset.sourceAndMap();
@@ -101,8 +99,8 @@ export class CleanCssWebpackPlugin {
10199
}
102100

103101
if (output.errors && output.errors.length > 0) {
104-
output.errors
105-
.forEach((error: string) => compilation.errors.push(new Error(error)));
102+
output.errors.forEach((error: string) => compilation.errors.push(new Error(error)));
103+
106104
return;
107105
}
108106

@@ -116,6 +114,7 @@ export class CleanCssWebpackPlugin {
116114
newSource = new SourceMapSource(
117115
output.styles,
118116
file,
117+
// tslint:disable-next-line: no-any
119118
output.sourceMap.toString() as any,
120119
content,
121120
map,

packages/angular_devkit/build_angular/src/angular-cli-files/plugins/index-html-webpack-plugin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ export class IndexHtmlWebpackPlugin {
6262
compiler.hooks.emit.tapPromise('index-html-webpack-plugin', async compilation => {
6363
// Get input html file
6464
const inputContent = await readFile(this._options.input, compilation);
65-
(compilation as compilation.Compilation & {
66-
fileDependencies: Set<string>;
67-
}).fileDependencies.add(this._options.input);
65+
compilation.fileDependencies.add(this._options.input);
6866

6967
// Get all files for selected entrypoints
7068
const files: FileInfo[] = [];

packages/angular_devkit/build_angular/src/dev-server/index.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,17 @@ export function buildServerConfig(
315315
host: serverOptions.host,
316316
port: serverOptions.port,
317317
headers: { 'Access-Control-Allow-Origin': '*' },
318-
historyApiFallback:
319-
!!browserOptions.index &&
320-
({
321-
index: `${servePath}/${getIndexOutputFile(browserOptions)}`,
322-
disableDotRule: true,
323-
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
324-
rewrites: [
325-
{
326-
from: new RegExp(`^(?!${servePath})/.*`),
327-
to: context => url.format(context.parsedUrl),
328-
},
329-
],
330-
} as WebpackDevServer.HistoryApiFallbackConfig),
318+
historyApiFallback: !!browserOptions.index && {
319+
index: `${servePath}/${getIndexOutputFile(browserOptions)}`,
320+
disableDotRule: true,
321+
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
322+
rewrites: [
323+
{
324+
from: new RegExp(`^(?!${servePath})/.*`),
325+
to: context => url.format(context.parsedUrl),
326+
},
327+
],
328+
},
331329
stats: false,
332330
compress: styles || scripts,
333331
watchOptions: {
@@ -434,8 +432,8 @@ function _addLiveReload(
434432
// This adds it back so that behavior is consistent when using a custom URL path
435433
let sockjsPath = '';
436434
if (clientAddress.pathname) {
437-
clientAddress.pathname = path.posix.join(clientAddress.pathname, 'sockjs-node');
438-
sockjsPath = '&sockPath=' + clientAddress.pathname;
435+
clientAddress.pathname = path.posix.join(clientAddress.pathname, 'sockjs-node');
436+
sockjsPath = '&sockPath=' + clientAddress.pathname;
439437
}
440438

441439
const entryPoints = [`${webpackDevServerPath}?${url.format(clientAddress)}${sockjsPath}`];
@@ -465,7 +463,7 @@ function _addLiveReload(
465463
}
466464
}
467465
if (typeof webpackConfig.entry !== 'object' || Array.isArray(webpackConfig.entry)) {
468-
webpackConfig.entry = {} as webpack.Entry;
466+
webpackConfig.entry = {};
469467
}
470468
if (!Array.isArray(webpackConfig.entry.main)) {
471469
webpackConfig.entry.main = [];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function runWebpackDevServer(
4747

4848
const devServerConfig = options.devServerConfig || config.devServer || {};
4949
if (devServerConfig.stats) {
50-
config.stats = devServerConfig.stats as webpack.Stats.ToStringOptionsObject;
50+
config.stats = devServerConfig.stats;
5151
}
5252
// Disable stats reporting by the devserver, we have our own logger.
5353
devServerConfig.stats = false;

yarn.lock

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,11 @@
935935
dependencies:
936936
defer-to-connect "^1.0.1"
937937

938+
"@types/anymatch@*":
939+
version "1.3.1"
940+
resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a"
941+
integrity sha512-/+CRPXpBDpo2RK9C68N3b2cOvO0Cf5B9aPijHsoDQTHivnGSObdOF2BRQOYjojWTDy6nQvMjmqRXIxH55VjxxA==
942+
938943
"@types/bluebird@*":
939944
version "3.5.26"
940945
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.26.tgz#a38c438ae84fa02431d6892edf86e46edcbca291"
@@ -970,6 +975,14 @@
970975
dependencies:
971976
"@types/node" "*"
972977

978+
"@types/connect-history-api-fallback@*":
979+
version "1.3.2"
980+
resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.3.2.tgz#40a497500238ebf30ae28fdf687c2f92969f2635"
981+
integrity sha512-tobKLYh5XszXIQ2lHTeyK1wMi/3K5WiOKb/sl6MENCirlOcXw0jUBHHmST2dLKnYMv6WHWPOSmR8jIF3za0MBQ==
982+
dependencies:
983+
"@types/express-serve-static-core" "*"
984+
"@types/node" "*"
985+
973986
"@types/connect@*":
974987
version "3.4.32"
975988
resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.32.tgz#aa0e9616b9435ccad02bc52b5b454ffc2c70ba28"
@@ -1327,11 +1340,12 @@
13271340
dependencies:
13281341
"@types/node" "*"
13291342

1330-
"@types/webpack-dev-server@^3.1.0":
1331-
version "3.1.0"
1332-
resolved "https://registry.yarnpkg.com/@types/webpack-dev-server/-/webpack-dev-server-3.1.0.tgz#1fae06ad346d2dd09bc5e34745723946458eed58"
1333-
integrity sha512-nutifgcFiPP3I/+mPWlZCsQNKpWNUGm6qjAMfleZuPfPfybXWymHvlcYsKvg+NPedSkrNh0vu2xKAlak/l+pOg==
1343+
"@types/webpack-dev-server@^3.1.7":
1344+
version "3.1.7"
1345+
resolved "https://registry.yarnpkg.com/@types/webpack-dev-server/-/webpack-dev-server-3.1.7.tgz#a3e7a20366e68bc9853c730b56e994634cb78dac"
1346+
integrity sha512-VIRkDkBDuOkYRXQ1EG/etisQ3odo6pcjSmA1Si4VYANuNhSBsLxfuPGeGERwCx1nDKxK3aaXnicPzi0gUvxUaw==
13341347
dependencies:
1348+
"@types/connect-history-api-fallback" "*"
13351349
"@types/express" "*"
13361350
"@types/http-proxy-middleware" "*"
13371351
"@types/serve-static" "*"
@@ -1346,11 +1360,12 @@
13461360
"@types/source-list-map" "*"
13471361
source-map "^0.6.1"
13481362

1349-
"@types/webpack@*", "@types/webpack@^4.4.11":
1350-
version "4.4.11"
1351-
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.4.11.tgz#0ca832870d55c4e92498c01d22d00d02b0f62ae9"
1352-
integrity sha512-NdESmbpvVEtJgs15kyZYKr5ouLYPMYt9DNG5JEgCekbG/ezFLPCzf4XcAv8caOb+b7x6ieAuSt0eoR0UkSI7RA==
1363+
"@types/webpack@*", "@types/webpack@^4.32.1":
1364+
version "4.32.1"
1365+
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.32.1.tgz#6e95010e806f808abd6551c112097ac09035aacf"
1366+
integrity sha512-9n38CBx9uga1FEAdTipnt0EkbKpsCJFh7xJb1LE65FFb/A6OOLFX022vYsGC1IyVCZ/GroNg9u/RMmlDxGcLIw==
13531367
dependencies:
1368+
"@types/anymatch" "*"
13541369
"@types/node" "*"
13551370
"@types/tapable" "*"
13561371
"@types/uglify-js" "*"

0 commit comments

Comments
 (0)