Skip to content

Commit 18b72a8

Browse files
clydindgp1130
authored andcommitted
refactor(@angular-devkit/core): remove unneeded import statements from Node.js file host
This reduces the number of imports for the Node.js file host classes. The `fs` default import was only used in one place and named imports were already in use for `node:fs` which allowed the one use to be converted to a named import. The type only import for `chokidar` was also only used in one type annotation and was moved to the type annotation directly.
1 parent e3cb349 commit 18b72a8

File tree

2 files changed

+7
-8
lines changed
  • goldens/public-api/angular_devkit/core/node
  • packages/angular_devkit/core/node

2 files changed

+7
-8
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { Observable } from 'rxjs';
1010
import { Operator } from 'rxjs';
1111
import { PartialObserver } from 'rxjs';
12-
import { Stats as Stats_2 } from 'fs';
12+
import { Stats as Stats_2 } from 'node:fs';
1313
import { Subject } from 'rxjs';
1414
import { Subscription } from 'rxjs';
1515

packages/angular_devkit/core/node/host.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import type { FSWatcher as ChokidarWatcher } from 'chokidar';
10-
import fs, {
9+
import {
1110
PathLike,
1211
Stats,
1312
constants,
@@ -17,10 +16,11 @@ import fs, {
1716
readFileSync,
1817
readdirSync,
1918
renameSync,
19+
rmSync,
2020
statSync,
2121
writeFileSync,
22-
} from 'fs';
23-
import { dirname as pathDirname } from 'path';
22+
} from 'node:fs';
23+
import { dirname as pathDirname } from 'node:path';
2424
import { Observable, from as observableFrom } from 'rxjs';
2525
import { map, mergeMap, publish, refCount } from 'rxjs/operators';
2626
import { Path, PathFragment, dirname, fragment, getSystemPath, normalize, virtualFs } from '../src';
@@ -38,11 +38,10 @@ async function exists(path: PathLike): Promise<boolean> {
3838
// This will only be initialized if the watch() method is called.
3939
// Otherwise chokidar appears only in type positions, and shouldn't be referenced
4040
// in the JavaScript output.
41-
let FSWatcher: typeof ChokidarWatcher;
41+
let FSWatcher: typeof import('chokidar').FSWatcher;
4242
function loadFSWatcher() {
4343
if (!FSWatcher) {
4444
try {
45-
// eslint-disable-next-line import/no-extraneous-dependencies
4645
FSWatcher = require('chokidar').FSWatcher;
4746
} catch (e) {
4847
if ((e as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {
@@ -176,7 +175,7 @@ export class NodeJsSyncHost implements virtualFs.Host<Stats> {
176175

177176
delete(path: Path): Observable<void> {
178177
return new Observable<void>((obs) => {
179-
fs.rmSync(getSystemPath(path), { force: true, recursive: true, maxRetries: 3 });
178+
rmSync(getSystemPath(path), { force: true, recursive: true, maxRetries: 3 });
180179

181180
obs.complete();
182181
});

0 commit comments

Comments
 (0)