Skip to content

Commit dee6b79

Browse files
alan-agius4clydin
authored andcommitted
refactor: remove @types/webpack
1 parent 0f4bbb5 commit dee6b79

File tree

27 files changed

+85
-195
lines changed

27 files changed

+85
-195
lines changed

etc/api/angular_devkit/build_optimizer/src/_golden-api.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export declare function buildOptimizer(options: BuildOptimizerOptions): Transfor
33
export declare const buildOptimizerLoaderPath: string;
44

55
export declare class BuildOptimizerWebpackPlugin {
6-
apply(compiler: Compiler | WebpackFourCompiler): void;
6+
apply(compiler: Compiler): void;
77
}
88

99
export default function buildOptimizerLoader(this: {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"@types/semver": "^7.0.0",
121121
"@types/text-table": "^0.2.1",
122122
"@types/uuid": "^8.0.0",
123-
"@types/webpack": "^4.41.22",
124123
"@types/webpack-dev-server": "^3.1.7",
125124
"@types/webpack-sources": "^2.0.0",
126125
"@yarnpkg/lockfile": "1.1.0",

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ ts_library(
134134
"@npm//@types/rimraf",
135135
"@npm//@types/semver",
136136
"@npm//@types/text-table",
137-
"@npm//@types/webpack",
138137
"@npm//@types/webpack-dev-server",
139138
"@npm//@types/webpack-sources",
140139
"@npm//ajv",
@@ -215,7 +214,6 @@ ts_library(
215214
":build_angular",
216215
"//packages/angular_devkit/architect/testing",
217216
"//packages/angular_devkit/core",
218-
"@npm//@types/webpack",
219217
"@npm//typescript",
220218
"@npm//webpack",
221219
],

packages/angular_devkit/build_angular/src/extract-i18n/ivy-extract-loader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ interface LocalizeExtractLoaderOptions {
1414
}
1515

1616
export default function localizeExtractLoader(
17-
this: import('webpack').loader.LoaderContext,
17+
// tslint:disable-next-line: no-any
18+
this: any,
1819
content: string,
1920
// Source map types are broken in the webpack type definitions
2021
// tslint:disable-next-line: no-any

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
*
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
7-
*/
8-
import * as webpack from 'webpack';
7+
*/
8+
import { Compilation, WebpackError } from 'webpack';
99

10-
const WebpackError = require('webpack/lib/WebpackError');
11-
12-
export function addWarning(compilation: webpack.compilation.Compilation, message: string): void {
10+
export function addWarning(compilation: Compilation, message: string): void {
1311
compilation.warnings.push(new WebpackError(message));
1412

1513
}
1614

17-
export function addError(compilation: webpack.compilation.Compilation, message: string): void {
15+
export function addError(compilation: Compilation, message: string): void {
1816
compilation.errors.push(new WebpackError(message));
1917

2018
}

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

Lines changed: 0 additions & 17 deletions
This file was deleted.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
142142

143143
const { supportedBrowsers } = new BuildBrowserFeatures(wco.projectRoot);
144144
const postcssOptionsCreator = (inlineSourcemaps: boolean, extracted: boolean | undefined) => {
145-
return (loader: webpack.loader.LoaderContext) => ({
145+
// tslint:disable-next-line: no-any
146+
return (loader: any) => ({
146147
map: inlineSourcemaps
147148
? {
148149
inline: true,

packages/angular_devkit/build_angular/src/webpack/plugins/hmr/hmr-loader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export const HmrLoader = __filename;
1212
const hmrAcceptPath = join(__dirname, './hmr-accept.js').replace(/\\/g, '/');
1313

1414
export default function (
15-
this: import('webpack').loader.LoaderContext,
15+
// tslint:disable-next-line: no-any
16+
this: any,
1617
content: string,
1718
// Source map types are broken in the webpack type definitions
1819
// tslint:disable-next-line: no-any

packages/angular_devkit/build_angular/src/webpack/plugins/postcss-cli-resources.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export interface PostcssCliResourcesOptions {
3232
/** CSS is extracted to a `.css` or is embedded in a `.js` file. */
3333
extracted?: boolean;
3434
filename: (resourcePath: string) => string;
35-
loader: webpack.loader.LoaderContext;
35+
// tslint:disable-next-line: no-any
36+
loader: any;
3637
emitFile: boolean;
3738
}
3839

@@ -92,7 +93,7 @@ export default function(options?: PostcssCliResourcesOptions): Plugin {
9293

9394
const { pathname, hash, search } = url.parse(inputUrl.replace(/\\/g, '/'));
9495
const resolver = (file: string, base: string) => new Promise<string>((resolve, reject) => {
95-
loader.resolve(base, decodeURI(file), (err, result) => {
96+
loader.resolve(base, decodeURI(file), (err: Error, result: string) => {
9697
if (err) {
9798
reject(err);
9899

@@ -113,7 +114,7 @@ export default function(options?: PostcssCliResourcesOptions): Plugin {
113114
}
114115

115116
let outputPath = interpolateName(
116-
{ resourcePath: result } as webpack.loader.LoaderContext,
117+
{ resourcePath: result },
117118
filename(result),
118119
{ content, context: loader.context || loader.rootContext },
119120
)

packages/angular_devkit/build_angular/src/webpack/plugins/scripts-webpack-plugin.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
// tslint:disable
9-
// TODO: cleanup this file, it's copied as is from Angular CLI.
108

11-
import { Compiler, loader } from 'webpack';
12-
import { CachedSource, ConcatSource, OriginalSource, RawSource, Source } from 'webpack-sources';
139
import { interpolateName } from 'loader-utils';
1410
import * as path from 'path';
11+
import { Compilation, Compiler } from 'webpack';
12+
import { CachedSource, ConcatSource, OriginalSource, RawSource, Source } from 'webpack-sources';
1513

1614
const Chunk = require('webpack/lib/Chunk');
1715
const EntryPoint = require('webpack/lib/Entrypoint');
1816

1917
export interface ScriptsWebpackPluginOptions {
2018
name: string;
21-
sourceMap: boolean;
19+
sourceMap?: boolean;
2220
scripts: string[];
2321
filename: string;
2422
basePath: string;
@@ -29,7 +27,7 @@ interface ScriptOutput {
2927
source: CachedSource;
3028
}
3129

32-
function addDependencies(compilation: any, scripts: string[]): void {
30+
function addDependencies(compilation: Compilation, scripts: string[]): void {
3331
for (const script of scripts) {
3432
compilation.fileDependencies.add(script);
3533
}
@@ -38,37 +36,40 @@ export class ScriptsWebpackPlugin {
3836
private _lastBuildTime?: number;
3937
private _cachedOutput?: ScriptOutput;
4038

41-
constructor(private options: Partial<ScriptsWebpackPluginOptions> = {}) { }
39+
constructor(private options: ScriptsWebpackPluginOptions) { }
4240

43-
async shouldSkip(compilation: any, scripts: string[]): Promise<boolean> {
41+
// tslint:disable-next-line: no-any
42+
async shouldSkip(compilation: Compilation, scripts: string[]): Promise<boolean> {
4443
if (this._lastBuildTime == undefined) {
4544
this._lastBuildTime = Date.now();
45+
4646
return false;
4747
}
4848

4949
for (const script of scripts) {
5050
const scriptTime = await new Promise<number | undefined>((resolve, reject) => {
51-
compilation.fileSystemInfo.getFileTimestamp(script, (error: unknown, entry: any) => {
51+
compilation.fileSystemInfo.getFileTimestamp(script, (error, entry) => {
5252
if (error) {
5353
reject(error);
5454

5555
return;
5656
}
5757

58-
resolve(typeof entry !== 'string' ? entry.safeTime : undefined)
59-
})
60-
})
58+
resolve((entry && typeof entry !== 'string') ? entry.safeTime : undefined);
59+
});
60+
});
6161

6262
if (!scriptTime || scriptTime > this._lastBuildTime) {
6363
this._lastBuildTime = Date.now();
64+
6465
return false;
6566
}
6667
}
6768

6869
return true;
6970
}
7071

71-
private _insertOutput(compilation: any, { filename, source }: ScriptOutput, cached = false) {
72+
private _insertOutput(compilation: Compilation, { filename, source }: ScriptOutput, cached = false) {
7273
const chunk = new Chunk(this.options.name);
7374
chunk.rendered = !cached;
7475
chunk.id = this.options.name;
@@ -81,7 +82,8 @@ export class ScriptsWebpackPlugin {
8182
compilation.entrypoints.set(this.options.name, entrypoint);
8283
compilation.chunks.add(chunk);
8384

84-
compilation.assets[filename] = source;
85+
// tslint:disable-next-line: no-any
86+
compilation.assets[filename] = source as any;
8587
compilation.hooks.chunkAsset.call(chunk, filename);
8688
}
8789

@@ -111,6 +113,7 @@ export class ScriptsWebpackPlugin {
111113
compilation.inputFileSystem.readFile(fullPath, (err?: Error, data?: string | Buffer) => {
112114
if (err) {
113115
reject(err);
116+
114117
return;
115118
}
116119

@@ -143,7 +146,7 @@ export class ScriptsWebpackPlugin {
143146

144147
const combinedSource = new CachedSource(concatSource);
145148
const filename = interpolateName(
146-
{ resourcePath: 'scripts.js' } as loader.LoaderContext,
149+
{ resourcePath: 'scripts.js' },
147150
this.options.filename as string,
148151
{ content: combinedSource.source() },
149152
);

0 commit comments

Comments
 (0)