UNPKG

1.56 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.SafeReadonlyHost = void 0;
11const rxjs_1 = require("rxjs");
12const operators_1 = require("rxjs/operators");
13/**
14 * A Host that filters out errors. The only exception is `read()` which will still error out if
15 * the delegate returned an error (e.g. NodeJS will error out if the file doesn't exist).
16 */
17class SafeReadonlyHost {
18 constructor(_delegate) {
19 this._delegate = _delegate;
20 }
21 get capabilities() {
22 return this._delegate.capabilities;
23 }
24 read(path) {
25 return this._delegate.read(path);
26 }
27 list(path) {
28 return this._delegate.list(path).pipe((0, operators_1.catchError)(() => (0, rxjs_1.of)([])));
29 }
30 exists(path) {
31 return this._delegate.exists(path);
32 }
33 isDirectory(path) {
34 return this._delegate.isDirectory(path).pipe((0, operators_1.catchError)(() => (0, rxjs_1.of)(false)));
35 }
36 isFile(path) {
37 return this._delegate.isFile(path).pipe((0, operators_1.catchError)(() => (0, rxjs_1.of)(false)));
38 }
39 // Some hosts may not support stats.
40 stat(path) {
41 const maybeStat = this._delegate.stat(path);
42 return maybeStat && maybeStat.pipe((0, operators_1.catchError)(() => (0, rxjs_1.of)(null)));
43 }
44}
45exports.SafeReadonlyHost = SafeReadonlyHost;