Skip to content

Commit d30144a

Browse files
clydinmgechev
authored andcommitted
refactor(@ngtools/webpack): adjust types for Webpack 5 support
1 parent 484c94e commit d30144a

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

packages/ngtools/webpack/src/angular_compiler_plugin.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ import {
7676
VirtualWatchFileSystemDecorator,
7777
} from './virtual_file_system_decorator';
7878
import {
79-
Callback,
8079
NodeWatchFileSystemInterface,
8180
NormalModuleFactoryRequest,
8281
} from './webpack';
@@ -869,7 +868,7 @@ export class AngularCompilerPlugin {
869868
// tslint:disable-next-line:no-any
870869
result.dependencies.forEach((d: any) => d.critical = false);
871870
// tslint:disable-next-line:no-any
872-
result.resolveDependencies = (_fs: any, options: any, callback: Callback) => {
871+
result.resolveDependencies = (_fs: any, options: any, callback: any) => {
873872
const dependencies = Object.keys(this._lazyRoutes)
874873
.map((key) => {
875874
const modulePath = this._lazyRoutes[key];

packages/ngtools/webpack/src/virtual_file_system_decorator.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FileDoesNotExistException, Path, getSystemPath, normalize } from '@angu
99
import { Stats } from 'fs';
1010
import { InputFileSystem } from 'webpack';
1111
import { WebpackCompilerHost } from './compiler_host';
12-
import { Callback, NodeWatchFileSystemInterface } from './webpack';
12+
import { NodeWatchFileSystemInterface } from './webpack';
1313

1414
export const NodeWatchFileSystem: NodeWatchFileSystemInterface = require(
1515
'webpack/lib/node/NodeWatchFileSystem');
@@ -29,7 +29,7 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
2929
return this._webpackCompilerHost.getNgFactoryPaths();
3030
}
3131

32-
stat(path: string, callback: (err: Error, stats: Stats) => void): void {
32+
stat(path: string, callback: (err: Error, result: Stats) => void): void {
3333
const result = this._webpackCompilerHost.stat(path);
3434
if (result) {
3535
// tslint:disable-next-line:no-any
@@ -40,8 +40,8 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
4040
}
4141
}
4242

43-
readdir(path: string, callback: Callback<string[]>): void {
44-
// tslint:disable-next-line:no-any
43+
readdir(path: string, callback: (err: Error, result: string[]) => void): void {
44+
// tslint:disable-next-line: no-any
4545
(this._inputFileSystem as any).readdir(path, callback);
4646
}
4747

@@ -55,7 +55,7 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
5555
}
5656
}
5757

58-
readJson(path: string, callback: Callback<{}>): void {
58+
readJson(path: string, callback: (err: Error, result: unknown) => void): void {
5959
// tslint:disable-next-line:no-any
6060
(this._inputFileSystem as any).readJson(path, callback);
6161
}
@@ -112,17 +112,17 @@ export class VirtualWatchFileSystemDecorator extends NodeWatchFileSystem {
112112
super(_virtualInputFileSystem);
113113
}
114114

115-
watch(
116-
files: string[],
117-
dirs: string[],
118-
missing: string[],
119-
startTime: number | undefined,
115+
watch = (
116+
files: Iterable<string>,
117+
dirs: Iterable<string>,
118+
missing: Iterable<string>,
119+
startTime: number,
120120
options: {},
121-
callback: any, // tslint:disable-line:no-any
121+
callback: Parameters<NodeWatchFileSystemInterface['watch']>[5],
122122
callbackUndelayed: (filename: string, timestamp: number) => void,
123-
) {
123+
): ReturnType<NodeWatchFileSystemInterface['watch']> => {
124124
const reverseReplacements = new Map<string, string>();
125-
const reverseTimestamps = (map: Map<string, number>) => {
125+
const reverseTimestamps = <T>(map: Map<string, T>) => {
126126
for (const entry of Array.from(map.entries())) {
127127
const original = reverseReplacements.get(entry[0]);
128128
if (original) {
@@ -144,7 +144,7 @@ export class VirtualWatchFileSystemDecorator extends NodeWatchFileSystem {
144144
}
145145
};
146146

147-
const newCallback = (
147+
const newCallback: Parameters<NodeWatchFileSystemInterface['watch']>[5] = (
148148
err: Error | null,
149149
filesModified: string[],
150150
contextModified: string[],
@@ -169,13 +169,13 @@ export class VirtualWatchFileSystemDecorator extends NodeWatchFileSystem {
169169
);
170170
};
171171

172-
const mapReplacements = (original: string[]): string[] => {
172+
const mapReplacements = (original: Iterable<string>): Iterable<string> => {
173173
if (!this._replacements) {
174174
return original;
175175
}
176176
const replacements = this._replacements;
177177

178-
return original.map(file => {
178+
return [...original].map(file => {
179179
if (typeof replacements === 'function') {
180180
const replacement = getSystemPath(replacements(normalize(file)));
181181
if (replacement !== file) {

packages/ngtools/webpack/src/webpack.ts

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ import { InputFileSystem } from 'webpack';
99

1010
// Declarations for (some) Webpack types. Only what's needed.
1111

12-
// tslint:disable-next-line:no-any
13-
export interface Callback<T = any> {
14-
(err?: Error | null, result?: T): void;
15-
}
16-
1712
export interface NormalModuleFactoryRequest {
1813
request: string;
1914
context: { issuer: string };

0 commit comments

Comments
 (0)