MCPcopy Index your code
hub / github.com/angular/angular-cli / NodeJsAsyncHost

Class NodeJsAsyncHost

packages/angular_devkit/core/node/host.ts:64–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62 * synchronous and one asynchronous.
63 */
64export class NodeJsAsyncHost implements virtualFs.Host<Stats> {
65 get capabilities(): virtualFs.HostCapabilities {
66 return { synchronous: false };
67 }
68
69 write(path: Path, content: virtualFs.FileBuffer): Observable<void> {
70 return observableFrom(fsPromises.mkdir(getSystemPath(dirname(path)), { recursive: true })).pipe(
71 mergeMap(() => fsPromises.writeFile(getSystemPath(path), new Uint8Array(content))),
72 );
73 }
74
75 read(path: Path): Observable<virtualFs.FileBuffer> {
76 return observableFrom(fsPromises.readFile(getSystemPath(path))).pipe(
77 map((buffer) => new Uint8Array(buffer).buffer),
78 );
79 }
80
81 delete(path: Path): Observable<void> {
82 return observableFrom(
83 fsPromises.rm(getSystemPath(path), { force: true, recursive: true, maxRetries: 3 }),
84 );
85 }
86
87 rename(from: Path, to: Path): Observable<void> {
88 return observableFrom(fsPromises.rename(getSystemPath(from), getSystemPath(to)));
89 }
90
91 list(path: Path): Observable<PathFragment[]> {
92 return observableFrom(fsPromises.readdir(getSystemPath(path))).pipe(
93 map((names) => names.map((name) => fragment(name))),
94 );
95 }
96
97 exists(path: Path): Observable<boolean> {
98 return observableFrom(exists(getSystemPath(path)));
99 }
100
101 isDirectory(path: Path): Observable<boolean> {
102 return this.stat(path).pipe(map((stat) => stat.isDirectory()));
103 }
104
105 isFile(path: Path): Observable<boolean> {
106 return this.stat(path).pipe(map((stat) => stat.isFile()));
107 }
108
109 // Some hosts may not support stat.
110 stat(path: Path): Observable<virtualFs.Stats<Stats>> {
111 return observableFrom(fsPromises.stat(getSystemPath(path)));
112 }
113
114 // Some hosts may not support watching.
115 watch(
116 path: Path,
117 _options?: virtualFs.HostWatchOptions,
118 ): Observable<virtualFs.HostWatchEvent> | null {
119 return new Observable<virtualFs.HostWatchEvent>((obs) => {
120 loadFSWatcher();
121 const watcher = new FSWatcher({ persistent: true });

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected