Skip to content

Commit beb78ef

Browse files
committed
refactor(@angular-devkit/build-angular): use Webpack provided watcher typings instead of custom
Webpack 5 now provides type definitions for the majority of the watch subsystem. These type definitions allow the removal of the custom types that were previously used.
1 parent 1877c24 commit beb78ef

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

packages/angular_devkit/build_angular/src/webpack/plugins/builder-watch-plugin.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ export interface BuilderWatcherFactory {
2020
): { close(): void };
2121
}
2222

23-
export interface WebpackWatcher {
24-
close(): void;
25-
pause(): void;
26-
getFileTimeInfoEntries(): Map<string, { safeTime: number; timestamp: number }>;
27-
getContextTimeInfoEntries(): Map<string, { safeTime: number; timestamp: number }>;
28-
}
29-
3023
class TimeInfoMap extends Map<string, { safeTime: number; timestamp: number }> {
3124
update(path: string, timestamp: number): void {
3225
this.set(path, Object.freeze({ safeTime: timestamp, timestamp }));
@@ -42,41 +35,26 @@ class TimeInfoMap extends Map<string, { safeTime: number; timestamp: number }> {
4235
}
4336
}
4437

45-
type WatchCallback = (
46-
error: Error | undefined,
47-
files: Map<string, { safeTime: number; timestamp: number }>,
48-
contexts: Map<string, { safeTime: number; timestamp: number }>,
49-
changes: Set<string>,
50-
removals: Set<string>,
51-
) => void;
52-
53-
export interface WebpackWatchFileSystem {
54-
watch(
55-
files: Iterable<string>,
56-
directories: Iterable<string>,
57-
missing: Iterable<string>,
58-
startTime: number,
59-
options: {},
60-
callback: WatchCallback,
61-
callbackUndelayed: (file: string, time: number) => void,
62-
): WebpackWatcher;
63-
}
38+
// Extract watch related types from the Webpack compiler type since they are not directly exported
39+
type WebpackWatchFileSystem = Compiler['watchFileSystem'];
40+
type WatchOptions = Parameters<WebpackWatchFileSystem['watch']>[4];
41+
type WatchCallback = Parameters<WebpackWatchFileSystem['watch']>[5];
6442

6543
class BuilderWatchFileSystem implements WebpackWatchFileSystem {
6644
constructor(
6745
private readonly watcherFactory: BuilderWatcherFactory,
68-
private readonly inputFileSystem: { purge?(path?: string): void },
46+
private readonly inputFileSystem: Compiler['inputFileSystem'],
6947
) {}
7048

7149
watch(
7250
files: Iterable<string>,
7351
directories: Iterable<string>,
7452
missing: Iterable<string>,
7553
startTime: number,
76-
_options: {},
54+
_options: WatchOptions,
7755
callback: WatchCallback,
7856
callbackUndelayed?: (file: string, time: number) => void,
79-
): WebpackWatcher {
57+
): ReturnType<WebpackWatchFileSystem['watch']> {
8058
const watchedFiles = new Set(files);
8159
const watchedDirectories = new Set(directories);
8260
const watchedMissing = new Set(missing);
@@ -152,7 +130,7 @@ class BuilderWatchFileSystem implements WebpackWatchFileSystem {
152130
export class BuilderWatchPlugin {
153131
constructor(private readonly watcherFactory: BuilderWatcherFactory) {}
154132

155-
apply(compiler: Compiler & { watchFileSystem: unknown }): void {
133+
apply(compiler: Compiler): void {
156134
compiler.hooks.environment.tap('BuilderWatchPlugin', () => {
157135
compiler.watchFileSystem = new BuilderWatchFileSystem(
158136
this.watcherFactory,

0 commit comments

Comments
 (0)