refactor(@ngtools/webpack): adjust types for Webpack 5 support

This commit is contained in:
Charles Lyding 2020-09-01 17:34:12 -04:00 committed by Minko Gechev
parent 484c94ef0a
commit d30144abc7
3 changed files with 17 additions and 23 deletions

View File

@ -76,7 +76,6 @@ import {
VirtualWatchFileSystemDecorator, VirtualWatchFileSystemDecorator,
} from './virtual_file_system_decorator'; } from './virtual_file_system_decorator';
import { import {
Callback,
NodeWatchFileSystemInterface, NodeWatchFileSystemInterface,
NormalModuleFactoryRequest, NormalModuleFactoryRequest,
} from './webpack'; } from './webpack';
@ -869,7 +868,7 @@ export class AngularCompilerPlugin {
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
result.dependencies.forEach((d: any) => d.critical = false); result.dependencies.forEach((d: any) => d.critical = false);
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
result.resolveDependencies = (_fs: any, options: any, callback: Callback) => { result.resolveDependencies = (_fs: any, options: any, callback: any) => {
const dependencies = Object.keys(this._lazyRoutes) const dependencies = Object.keys(this._lazyRoutes)
.map((key) => { .map((key) => {
const modulePath = this._lazyRoutes[key]; const modulePath = this._lazyRoutes[key];

View File

@ -9,7 +9,7 @@ import { FileDoesNotExistException, Path, getSystemPath, normalize } from '@angu
import { Stats } from 'fs'; import { Stats } from 'fs';
import { InputFileSystem } from 'webpack'; import { InputFileSystem } from 'webpack';
import { WebpackCompilerHost } from './compiler_host'; import { WebpackCompilerHost } from './compiler_host';
import { Callback, NodeWatchFileSystemInterface } from './webpack'; import { NodeWatchFileSystemInterface } from './webpack';
export const NodeWatchFileSystem: NodeWatchFileSystemInterface = require( export const NodeWatchFileSystem: NodeWatchFileSystemInterface = require(
'webpack/lib/node/NodeWatchFileSystem'); 'webpack/lib/node/NodeWatchFileSystem');
@ -29,7 +29,7 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
return this._webpackCompilerHost.getNgFactoryPaths(); return this._webpackCompilerHost.getNgFactoryPaths();
} }
stat(path: string, callback: (err: Error, stats: Stats) => void): void { stat(path: string, callback: (err: Error, result: Stats) => void): void {
const result = this._webpackCompilerHost.stat(path); const result = this._webpackCompilerHost.stat(path);
if (result) { if (result) {
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
@ -40,8 +40,8 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
} }
} }
readdir(path: string, callback: Callback<string[]>): void { readdir(path: string, callback: (err: Error, result: string[]) => void): void {
// tslint:disable-next-line:no-any // tslint:disable-next-line: no-any
(this._inputFileSystem as any).readdir(path, callback); (this._inputFileSystem as any).readdir(path, callback);
} }
@ -55,7 +55,7 @@ export class VirtualFileSystemDecorator implements InputFileSystem {
} }
} }
readJson(path: string, callback: Callback<{}>): void { readJson(path: string, callback: (err: Error, result: unknown) => void): void {
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
(this._inputFileSystem as any).readJson(path, callback); (this._inputFileSystem as any).readJson(path, callback);
} }
@ -112,17 +112,17 @@ export class VirtualWatchFileSystemDecorator extends NodeWatchFileSystem {
super(_virtualInputFileSystem); super(_virtualInputFileSystem);
} }
watch( watch = (
files: string[], files: Iterable<string>,
dirs: string[], dirs: Iterable<string>,
missing: string[], missing: Iterable<string>,
startTime: number | undefined, startTime: number,
options: {}, options: {},
callback: any, // tslint:disable-line:no-any callback: Parameters<NodeWatchFileSystemInterface['watch']>[5],
callbackUndelayed: (filename: string, timestamp: number) => void, callbackUndelayed: (filename: string, timestamp: number) => void,
) { ): ReturnType<NodeWatchFileSystemInterface['watch']> => {
const reverseReplacements = new Map<string, string>(); const reverseReplacements = new Map<string, string>();
const reverseTimestamps = (map: Map<string, number>) => { const reverseTimestamps = <T>(map: Map<string, T>) => {
for (const entry of Array.from(map.entries())) { for (const entry of Array.from(map.entries())) {
const original = reverseReplacements.get(entry[0]); const original = reverseReplacements.get(entry[0]);
if (original) { if (original) {
@ -144,7 +144,7 @@ export class VirtualWatchFileSystemDecorator extends NodeWatchFileSystem {
} }
}; };
const newCallback = ( const newCallback: Parameters<NodeWatchFileSystemInterface['watch']>[5] = (
err: Error | null, err: Error | null,
filesModified: string[], filesModified: string[],
contextModified: string[], contextModified: string[],
@ -169,13 +169,13 @@ export class VirtualWatchFileSystemDecorator extends NodeWatchFileSystem {
); );
}; };
const mapReplacements = (original: string[]): string[] => { const mapReplacements = (original: Iterable<string>): Iterable<string> => {
if (!this._replacements) { if (!this._replacements) {
return original; return original;
} }
const replacements = this._replacements; const replacements = this._replacements;
return original.map(file => { return [...original].map(file => {
if (typeof replacements === 'function') { if (typeof replacements === 'function') {
const replacement = getSystemPath(replacements(normalize(file))); const replacement = getSystemPath(replacements(normalize(file)));
if (replacement !== file) { if (replacement !== file) {

View File

@ -9,11 +9,6 @@ import { InputFileSystem } from 'webpack';
// Declarations for (some) Webpack types. Only what's needed. // Declarations for (some) Webpack types. Only what's needed.
// tslint:disable-next-line:no-any
export interface Callback<T = any> {
(err?: Error | null, result?: T): void;
}
export interface NormalModuleFactoryRequest { export interface NormalModuleFactoryRequest {
request: string; request: string;
context: { issuer: string }; context: { issuer: string };