Skip to content

Commit 2631faa

Browse files
committed
feat(@angular-devkit/core): hosts should return null for ENOENT
Asking for stats on an existing file should return null, but it is not the same null (can be async and as a result) as if the host does not support stat altogether.
1 parent 8e391f8 commit 2631faa

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

packages/angular_devkit/core/src/virtual-fs/host/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface ReadonlyHost<StatsT extends object = {}> {
5959
isFile(path: Path): Observable<boolean>;
6060

6161
// Some hosts may not support stats.
62-
stat(path: Path): Observable<Stats<StatsT>> | null;
62+
stat(path: Path): Observable<Stats<StatsT> | null> | null;
6363
}
6464

6565
export interface Host<StatsT extends object = {}> extends ReadonlyHost<StatsT> {

packages/angular_devkit/core/src/virtual-fs/host/memory.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface SimpleMemoryHostStats {
3838
}
3939

4040
export class SimpleMemoryHost implements Host<{}> {
41-
protected readonly _cache = new Map<Path, Stats<SimpleMemoryHostStats>>();
41+
protected _cache = new Map<Path, Stats<SimpleMemoryHostStats>>();
4242
private _watchers = new Map<Path, [HostWatchOptions, Subject<HostWatchEvent>][]>();
4343

4444
protected _newDirStats() {
@@ -257,11 +257,11 @@ export class SimpleMemoryHost implements Host<{}> {
257257
return maybeStats ? maybeStats.isFile() : false;
258258
}
259259

260-
protected _stat(path: Path): Stats<SimpleMemoryHostStats> {
260+
protected _stat(path: Path): Stats<SimpleMemoryHostStats> | null {
261261
const maybeStats = this._cache.get(this._toAbsolute(path));
262262

263263
if (!maybeStats) {
264-
throw new FileDoesNotExistException(path);
264+
return null;
265265
} else {
266266
return maybeStats;
267267
}
@@ -343,8 +343,8 @@ export class SimpleMemoryHost implements Host<{}> {
343343
}
344344

345345
// Some hosts may not support stat.
346-
stat(path: Path): Observable<Stats<{}>> {
347-
return new Observable<Stats<{}>>(obs => {
346+
stat(path: Path): Observable<Stats<{}> | null> | null {
347+
return new Observable<Stats<{}> | null>(obs => {
348348
obs.next(this._stat(path));
349349
obs.complete();
350350
});

packages/angular_devkit/core/src/virtual-fs/host/sync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class SyncDelegateHost<T extends object = {}> {
9393

9494
// Some hosts may not support stat.
9595
stat(path: Path): Stats<T> | null {
96-
const result: Observable<Stats<T>> | null = this._delegate.stat(path);
96+
const result: Observable<Stats<T> | null> | null = this._delegate.stat(path);
9797

9898
if (result) {
9999
return this._doSyncCall(result);

packages/angular_devkit/core/src/virtual-fs/host/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class TestHost extends SimpleMemoryHost {
116116

117117
return super._isFile(path);
118118
}
119-
protected _stat(path: Path): Stats<SimpleMemoryHostStats> {
119+
protected _stat(path: Path): Stats<SimpleMemoryHostStats> | null {
120120
this._records.push({ kind: 'stat', path });
121121

122122
return super._stat(path);

0 commit comments

Comments
 (0)