Skip to content

Commit 0d8953c

Browse files
committed
refactor(@angular-devkit/core): use chokidar types instead of custom interface
Replace `ChokidarWatcher` with types from `chokidar` (cherry picked from commit a169f26)
1 parent 9874aff commit 0d8953c

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

goldens/public-api/angular_devkit/core/node/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
```ts
66

7+
/// <reference types="node" />
8+
79
import { ErrorObject } from 'ajv';
810
import { Format } from 'ajv';
911
import { Observable } from 'rxjs';

goldens/public-api/angular_devkit/schematics/src/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
```ts
66

7+
/// <reference types="node" />
8+
79
import { analytics } from '@angular-devkit/core';
810
import { BaseException } from '@angular-devkit/core';
911
import { logging } from '@angular-devkit/core';

goldens/public-api/angular_devkit/schematics/tasks/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
```ts
66

7+
/// <reference types="node" />
8+
79
// @public (undocumented)
810
export class NodePackageInstallTask implements TaskConfigurationGenerator<NodePackageTaskOptions> {
911
constructor(workingDirectory?: string);

goldens/public-api/angular_devkit/schematics/testing/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
```ts
66

7+
/// <reference types="node" />
8+
79
import { analytics } from '@angular-devkit/core';
810
import { logging } from '@angular-devkit/core';
911
import { Observable } from 'rxjs';

packages/angular_devkit/core/node/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ts_library(
2828
deps = [
2929
"//packages/angular_devkit/core",
3030
"@npm//@types/node",
31+
"@npm//chokidar",
3132
"@npm//rxjs",
3233
],
3334
)

packages/angular_devkit/core/node/host.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import type { FSWatcher as ChokidarWatcher } from 'chokidar';
910
import fs, {
1011
PathLike,
1112
Stats,
@@ -20,7 +21,7 @@ import fs, {
2021
unlinkSync,
2122
writeFileSync,
2223
} from 'fs';
23-
import { dirname as pathDirname, join as pathJoin } from 'path';
24+
import { dirname as pathDirname } from 'path';
2425
import { Observable, concat, from as observableFrom, of, throwError } from 'rxjs';
2526
import { concatMap, map, mergeMap, publish, refCount } from 'rxjs/operators';
2627
import {
@@ -34,18 +35,6 @@ import {
3435
virtualFs,
3536
} from '../src';
3637

37-
interface ChokidarWatcher {
38-
// eslint-disable-next-line @typescript-eslint/no-misused-new
39-
new (options: {}): ChokidarWatcher;
40-
41-
add(path: string): ChokidarWatcher;
42-
on(type: 'change', cb: (path: string) => void): ChokidarWatcher;
43-
on(type: 'add', cb: (path: string) => void): ChokidarWatcher;
44-
on(type: 'unlink', cb: (path: string) => void): ChokidarWatcher;
45-
46-
close(): void;
47-
}
48-
4938
async function exists(path: PathLike): Promise<boolean> {
5039
try {
5140
await fsPromises.access(path, constants.F_OK);
@@ -59,7 +48,7 @@ async function exists(path: PathLike): Promise<boolean> {
5948
// This will only be initialized if the watch() method is called.
6049
// Otherwise chokidar appears only in type positions, and shouldn't be referenced
6150
// in the JavaScript output.
62-
let FSWatcher: ChokidarWatcher;
51+
let FSWatcher: typeof ChokidarWatcher;
6352
function loadFSWatcher() {
6453
if (!FSWatcher) {
6554
try {
@@ -161,7 +150,8 @@ export class NodeJsAsyncHost implements virtualFs.Host<Stats> {
161150
): Observable<virtualFs.HostWatchEvent> | null {
162151
return new Observable<virtualFs.HostWatchEvent>((obs) => {
163152
loadFSWatcher();
164-
const watcher = new FSWatcher({ persistent: true }).add(getSystemPath(path));
153+
const watcher = new FSWatcher({ persistent: true });
154+
watcher.add(getSystemPath(path));
165155

166156
watcher
167157
.on('change', (path) => {
@@ -308,9 +298,9 @@ export class NodeJsSyncHost implements virtualFs.Host<Stats> {
308298
_options?: virtualFs.HostWatchOptions,
309299
): Observable<virtualFs.HostWatchEvent> | null {
310300
return new Observable<virtualFs.HostWatchEvent>((obs) => {
311-
const opts = { persistent: false };
312301
loadFSWatcher();
313-
const watcher = new FSWatcher(opts).add(getSystemPath(path));
302+
const watcher = new FSWatcher({ persistent: false });
303+
watcher.add(getSystemPath(path));
314304

315305
watcher
316306
.on('change', (path) => {

0 commit comments

Comments
 (0)