Primeiro commit do projeto Angular

This commit is contained in:
2026-03-14 20:41:55 +00:00
parent 9bebe1de72
commit 94f4f46395
22413 changed files with 3221690 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Path } from '../path';
import { ResolverHost } from './resolver';
/**
* A Virtual Host that allow to alias some paths to other paths.
*
* This does not verify, when setting an alias, that the target or source exist. Neither does it
* check whether it's a file or a directory. Please not that directories are also renamed/replaced.
*
* No recursion is done on the resolution, which means the following is perfectly valid then:
*
* ```
* host.aliases.set(normalize('/file/a'), normalize('/file/b'));
* host.aliases.set(normalize('/file/b'), normalize('/file/a'));
* ```
*
* This will result in a proper swap of two files for each others.
*
* @example
* const host = new SimpleMemoryHost();
* host.write(normalize('/some/file'), content).subscribe();
*
* const aHost = new AliasHost(host);
* aHost.read(normalize('/some/file'))
* .subscribe(x => expect(x).toBe(content));
* aHost.aliases.set(normalize('/some/file'), normalize('/other/path');
*
* // This file will not exist because /other/path does not exist.
* aHost.read(normalize('/some/file'))
* .subscribe(undefined, err => expect(err.message).toMatch(/does not exist/));
*
* @example
* const host = new SimpleMemoryHost();
* host.write(normalize('/some/folder/file'), content).subscribe();
*
* const aHost = new AliasHost(host);
* aHost.read(normalize('/some/folder/file'))
* .subscribe(x => expect(x).toBe(content));
* aHost.aliases.set(normalize('/some'), normalize('/other');
*
* // This file will not exist because /other/path does not exist.
* aHost.read(normalize('/some/folder/file'))
* .subscribe(undefined, err => expect(err.message).toMatch(/does not exist/));
*
* // Create the file with new content and verify that this has the new content.
* aHost.write(normalize('/other/folder/file'), content2).subscribe();
* aHost.read(normalize('/some/folder/file'))
* .subscribe(x => expect(x).toBe(content2));
*/
export declare class AliasHost<StatsT extends object = {}> extends ResolverHost<StatsT> {
protected _aliases: Map<Path, Path>;
protected _resolve(path: Path): Path;
get aliases(): Map<Path, Path>;
}
+84
View File
@@ -0,0 +1,84 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AliasHost = void 0;
const path_1 = require("../path");
const resolver_1 = require("./resolver");
/**
* A Virtual Host that allow to alias some paths to other paths.
*
* This does not verify, when setting an alias, that the target or source exist. Neither does it
* check whether it's a file or a directory. Please not that directories are also renamed/replaced.
*
* No recursion is done on the resolution, which means the following is perfectly valid then:
*
* ```
* host.aliases.set(normalize('/file/a'), normalize('/file/b'));
* host.aliases.set(normalize('/file/b'), normalize('/file/a'));
* ```
*
* This will result in a proper swap of two files for each others.
*
* @example
* const host = new SimpleMemoryHost();
* host.write(normalize('/some/file'), content).subscribe();
*
* const aHost = new AliasHost(host);
* aHost.read(normalize('/some/file'))
* .subscribe(x => expect(x).toBe(content));
* aHost.aliases.set(normalize('/some/file'), normalize('/other/path');
*
* // This file will not exist because /other/path does not exist.
* aHost.read(normalize('/some/file'))
* .subscribe(undefined, err => expect(err.message).toMatch(/does not exist/));
*
* @example
* const host = new SimpleMemoryHost();
* host.write(normalize('/some/folder/file'), content).subscribe();
*
* const aHost = new AliasHost(host);
* aHost.read(normalize('/some/folder/file'))
* .subscribe(x => expect(x).toBe(content));
* aHost.aliases.set(normalize('/some'), normalize('/other');
*
* // This file will not exist because /other/path does not exist.
* aHost.read(normalize('/some/folder/file'))
* .subscribe(undefined, err => expect(err.message).toMatch(/does not exist/));
*
* // Create the file with new content and verify that this has the new content.
* aHost.write(normalize('/other/folder/file'), content2).subscribe();
* aHost.read(normalize('/some/folder/file'))
* .subscribe(x => expect(x).toBe(content2));
*/
class AliasHost extends resolver_1.ResolverHost {
_aliases = new Map();
_resolve(path) {
let maybeAlias = this._aliases.get(path);
const sp = (0, path_1.split)(path);
const remaining = [];
// Also resolve all parents of the requested files, only picking the first one that matches.
// This can have surprising behaviour when aliases are inside another alias. It will always
// use the closest one to the file.
while (!maybeAlias && sp.length > 0) {
const p = (0, path_1.join)(path_1.NormalizedRoot, ...sp);
maybeAlias = this._aliases.get(p);
if (maybeAlias) {
maybeAlias = (0, path_1.join)(maybeAlias, ...remaining);
}
// Allow non-null-operator because we know sp.length > 0 (condition on while).
remaining.unshift(sp.pop()); // eslint-disable-line @typescript-eslint/no-non-null-assertion
}
return maybeAlias || path;
}
get aliases() {
return this._aliases;
}
}
exports.AliasHost = AliasHost;
//# sourceMappingURL=alias.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"alias.js","sourceRoot":"","sources":["alias.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,kCAA0E;AAC1E,yCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAa,SAAsC,SAAQ,uBAAoB;IACnE,QAAQ,GAAoB,IAAI,GAAG,EAAE,CAAC;IAEtC,QAAQ,CAAC,IAAU;QAC3B,IAAI,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,EAAE,GAAG,IAAA,YAAK,EAAC,IAAI,CAAC,CAAC;QACvB,MAAM,SAAS,GAAmB,EAAE,CAAC;QAErC,4FAA4F;QAC5F,2FAA2F;QAC3F,mCAAmC;QACnC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpC,MAAM,CAAC,GAAG,IAAA,WAAI,EAAC,qBAAc,EAAE,GAAG,EAAE,CAAC,CAAC;YACtC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAElC,IAAI,UAAU,EAAE,CAAC;gBACf,UAAU,GAAG,IAAA,WAAI,EAAC,UAAU,EAAE,GAAG,SAAS,CAAC,CAAC;YAC9C,CAAC;YACD,8EAA8E;YAC9E,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAG,CAAC,CAAC,CAAC,+DAA+D;QAC/F,CAAC;QAED,OAAO,UAAU,IAAI,IAAI,CAAC;IAC5B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AA5BD,8BA4BC"}
+10
View File
@@ -0,0 +1,10 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { FileBuffer } from './interface';
export declare function stringToFileBuffer(str: string): FileBuffer;
export declare function fileBufferToString(fileBuffer: FileBuffer): string;
+22
View File
@@ -0,0 +1,22 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringToFileBuffer = stringToFileBuffer;
exports.fileBufferToString = fileBufferToString;
const node_util_1 = require("node:util");
function stringToFileBuffer(str) {
return new node_util_1.TextEncoder().encode(str).buffer;
}
function fileBufferToString(fileBuffer) {
if (fileBuffer.toString.length === 1) {
return fileBuffer.toString('utf-8');
}
return new node_util_1.TextDecoder('utf-8').decode(new Uint8Array(fileBuffer));
}
//# sourceMappingURL=buffer.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["buffer.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAKH,gDAEC;AAED,gDAMC;AAbD,yCAAqD;AAGrD,SAAgB,kBAAkB,CAAC,GAAW;IAC5C,OAAO,IAAI,uBAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC;AAED,SAAgB,kBAAkB,CAAC,UAAsB;IACvD,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,OAAQ,UAAU,CAAC,QAAoC,CAAC,OAAO,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,IAAI,uBAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;AACrE,CAAC"}
+21
View File
@@ -0,0 +1,21 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Path, PathFragment } from '../path';
import { FileBuffer, FileBufferLike, Host, Stats } from './interface';
export interface SyncHostHandler<StatsT extends object = {}> {
read(path: Path): FileBuffer;
list(path: Path): PathFragment[];
exists(path: Path): boolean;
isDirectory(path: Path): boolean;
isFile(path: Path): boolean;
stat(path: Path): Stats<StatsT> | null;
write(path: Path, content: FileBufferLike): void;
delete(path: Path): void;
rename(from: Path, to: Path): void;
}
export declare function createSyncHost<StatsT extends object = {}>(handler: SyncHostHandler<StatsT>): Host<StatsT>;
+55
View File
@@ -0,0 +1,55 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSyncHost = createSyncHost;
const rxjs_1 = require("rxjs");
function wrapAction(action) {
return new rxjs_1.Observable((subscriber) => {
subscriber.next(action());
subscriber.complete();
});
}
function createSyncHost(handler) {
return new (class {
get capabilities() {
return { synchronous: true };
}
read(path) {
return wrapAction(() => handler.read(path));
}
list(path) {
return wrapAction(() => handler.list(path));
}
exists(path) {
return wrapAction(() => handler.exists(path));
}
isDirectory(path) {
return wrapAction(() => handler.isDirectory(path));
}
isFile(path) {
return wrapAction(() => handler.isFile(path));
}
stat(path) {
return wrapAction(() => handler.stat(path));
}
write(path, content) {
return wrapAction(() => handler.write(path, content));
}
delete(path) {
return wrapAction(() => handler.delete(path));
}
rename(from, to) {
return wrapAction(() => handler.rename(from, to));
}
watch() {
return null;
}
})();
}
//# sourceMappingURL=create.js.map
+1
View File
@@ -0,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U,EAAE,OAAuB;YACvC,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,CAAC,IAAU;YACf,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,CAAC,IAAU,EAAE,EAAQ;YACzB,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;QACpD,CAAC;QAED,KAAK;YACH,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC,EAAE,CAAC;AACP,CAAC"}
+19
View File
@@ -0,0 +1,19 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Observable } from 'rxjs';
import { Path, PathFragment } from '../path';
import { FileBuffer, HostCapabilities, ReadonlyHost, Stats } from './interface';
export declare class Empty implements ReadonlyHost {
readonly capabilities: HostCapabilities;
read(path: Path): Observable<FileBuffer>;
list(path: Path): Observable<PathFragment[]>;
exists(path: Path): Observable<boolean>;
isDirectory(path: Path): Observable<boolean>;
isFile(path: Path): Observable<boolean>;
stat(path: Path): Observable<Stats<{}> | null>;
}
+38
View File
@@ -0,0 +1,38 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Empty = void 0;
const rxjs_1 = require("rxjs");
const exception_1 = require("../../exception");
class Empty {
capabilities = {
synchronous: true,
};
read(path) {
return (0, rxjs_1.throwError)(new exception_1.FileDoesNotExistException(path));
}
list(path) {
return (0, rxjs_1.of)([]);
}
exists(path) {
return (0, rxjs_1.of)(false);
}
isDirectory(path) {
return (0, rxjs_1.of)(false);
}
isFile(path) {
return (0, rxjs_1.of)(false);
}
stat(path) {
// We support stat() but have no file.
return (0, rxjs_1.of)(null);
}
}
exports.Empty = Empty;
//# sourceMappingURL=empty.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,+BAAkD;AAClD,+CAA4D;AAI5D,MAAa,KAAK;IACP,YAAY,GAAqB;QACxC,WAAW,EAAE,IAAI;KAClB,CAAC;IAEF,IAAI,CAAC,IAAU;QACb,OAAO,IAAA,iBAAU,EAAC,IAAI,qCAAyB,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,CAAC,IAAU;QACb,OAAO,IAAA,SAAE,EAAC,EAAE,CAAC,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,IAAU;QACf,OAAO,IAAA,SAAE,EAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED,WAAW,CAAC,IAAU;QACpB,OAAO,IAAA,SAAE,EAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,IAAU;QACf,OAAO,IAAA,SAAE,EAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,IAAU;QACb,sCAAsC;QACtC,OAAO,IAAA,SAAE,EAAC,IAAI,CAAC,CAAC;IAClB,CAAC;CACF;AA7BD,sBA6BC"}
+21
View File
@@ -0,0 +1,21 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import * as test from './test';
export * from './alias';
export * from './buffer';
export * from './create';
export * from './empty';
export * from './interface';
export * from './memory';
export * from './pattern';
export * from './record';
export * from './safe';
export * from './scoped';
export * from './sync';
export * from './resolver';
export { test };
+61
View File
@@ -0,0 +1,61 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.test = void 0;
const test = __importStar(require("./test"));
exports.test = test;
__exportStar(require("./alias"), exports);
__exportStar(require("./buffer"), exports);
__exportStar(require("./create"), exports);
__exportStar(require("./empty"), exports);
__exportStar(require("./interface"), exports);
__exportStar(require("./memory"), exports);
__exportStar(require("./pattern"), exports);
__exportStar(require("./record"), exports);
__exportStar(require("./safe"), exports);
__exportStar(require("./scoped"), exports);
__exportStar(require("./sync"), exports);
__exportStar(require("./resolver"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AActB,oBAAI;AAZb,0CAAwB;AACxB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,4CAA0B;AAC1B,2CAAyB;AACzB,yCAAuB;AACvB,2CAAyB;AACzB,yCAAuB;AACvB,6CAA2B"}
+53
View File
@@ -0,0 +1,53 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Observable } from 'rxjs';
import { Path, PathFragment } from '../path';
export type FileBuffer = ArrayBuffer;
export type FileBufferLike = ArrayBufferLike;
export interface HostWatchOptions {
readonly persistent?: boolean;
readonly recursive?: boolean;
}
export declare enum HostWatchEventType {
Changed = 0,
Created = 1,
Deleted = 2,
Renamed = 3
}
export type Stats<T extends object = {}> = T & {
isFile(): boolean;
isDirectory(): boolean;
readonly size: number;
readonly atime: Date;
readonly mtime: Date;
readonly ctime: Date;
readonly birthtime: Date;
};
export interface HostWatchEvent {
readonly time: Date;
readonly type: HostWatchEventType;
readonly path: Path;
}
export interface HostCapabilities {
synchronous: boolean;
}
export interface ReadonlyHost<StatsT extends object = {}> {
readonly capabilities: HostCapabilities;
read(path: Path): Observable<FileBuffer>;
list(path: Path): Observable<PathFragment[]>;
exists(path: Path): Observable<boolean>;
isDirectory(path: Path): Observable<boolean>;
isFile(path: Path): Observable<boolean>;
stat(path: Path): Observable<Stats<StatsT> | null> | null;
}
export interface Host<StatsT extends object = {}> extends ReadonlyHost<StatsT> {
write(path: Path, content: FileBufferLike): Observable<void>;
delete(path: Path): Observable<void>;
rename(from: Path, to: Path): Observable<void>;
watch(path: Path, options?: HostWatchOptions): Observable<HostWatchEvent> | null;
}
+18
View File
@@ -0,0 +1,18 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.HostWatchEventType = void 0;
var HostWatchEventType;
(function (HostWatchEventType) {
HostWatchEventType[HostWatchEventType["Changed"] = 0] = "Changed";
HostWatchEventType[HostWatchEventType["Created"] = 1] = "Created";
HostWatchEventType[HostWatchEventType["Deleted"] = 2] = "Deleted";
HostWatchEventType[HostWatchEventType["Renamed"] = 3] = "Renamed";
})(HostWatchEventType || (exports.HostWatchEventType = HostWatchEventType = {}));
//# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
{"version":3,"file":"interface.js","sourceRoot":"","sources":["interface.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAaH,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,iEAAW,CAAA;IACX,iEAAW,CAAA;IACX,iEAAW,CAAA;IACX,iEAAW,CAAA;AACb,CAAC,EALW,kBAAkB,kCAAlB,kBAAkB,QAK7B"}
+49
View File
@@ -0,0 +1,49 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Observable } from 'rxjs';
import { Path, PathFragment } from '../path';
import { FileBuffer, Host, HostCapabilities, HostWatchEvent, HostWatchEventType, HostWatchOptions, Stats } from './interface';
export interface SimpleMemoryHostStats {
readonly content: FileBuffer | null;
inspect(): string;
}
export declare class SimpleMemoryHost implements Host<{}> {
protected _cache: Map<Path, Stats<SimpleMemoryHostStats>>;
private _watchers;
protected _newDirStats(): Stats<SimpleMemoryHostStats>;
protected _newFileStats(content: FileBuffer, oldStats?: Stats<SimpleMemoryHostStats>): Stats<SimpleMemoryHostStats>;
constructor();
protected _toAbsolute(path: Path): Path;
protected _updateWatchers(path: Path, type: HostWatchEventType): void;
get capabilities(): HostCapabilities;
/**
* List of protected methods that give direct access outside the observables to the cache
* and internal states.
*/
protected _write(path: Path, content: FileBuffer): void;
protected _read(path: Path): FileBuffer;
protected _delete(path: Path): void;
protected _rename(from: Path, to: Path): void;
protected _list(path: Path): PathFragment[];
protected _exists(path: Path): boolean;
protected _isDirectory(path: Path): boolean;
protected _isFile(path: Path): boolean;
protected _stat(path: Path): Stats<SimpleMemoryHostStats> | null;
protected _watch(path: Path, options?: HostWatchOptions): Observable<HostWatchEvent>;
write(path: Path, content: FileBuffer): Observable<void>;
read(path: Path): Observable<FileBuffer>;
delete(path: Path): Observable<void>;
rename(from: Path, to: Path): Observable<void>;
list(path: Path): Observable<PathFragment[]>;
exists(path: Path): Observable<boolean>;
isDirectory(path: Path): Observable<boolean>;
isFile(path: Path): Observable<boolean>;
stat(path: Path): Observable<Stats<{}> | null> | null;
watch(path: Path, options?: HostWatchOptions): Observable<HostWatchEvent> | null;
reset(): void;
}
+332
View File
@@ -0,0 +1,332 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleMemoryHost = void 0;
const rxjs_1 = require("rxjs");
const exception_1 = require("../../exception");
const path_1 = require("../path");
const interface_1 = require("./interface");
class SimpleMemoryHost {
_cache = new Map();
_watchers = new Map();
_newDirStats() {
return {
inspect() {
return '<Directory>';
},
isFile() {
return false;
},
isDirectory() {
return true;
},
size: 0,
atime: new Date(),
ctime: new Date(),
mtime: new Date(),
birthtime: new Date(),
content: null,
};
}
_newFileStats(content, oldStats) {
return {
inspect() {
return `<File size(${content.byteLength})>`;
},
isFile() {
return true;
},
isDirectory() {
return false;
},
size: content.byteLength,
atime: oldStats ? oldStats.atime : new Date(),
ctime: new Date(),
mtime: new Date(),
birthtime: oldStats ? oldStats.birthtime : new Date(),
content,
};
}
constructor() {
this._cache.set((0, path_1.normalize)('/'), this._newDirStats());
}
_toAbsolute(path) {
return (0, path_1.isAbsolute)(path) ? path : (0, path_1.normalize)('/' + path);
}
_updateWatchers(path, type) {
const time = new Date();
let currentPath = path;
let parent = null;
if (this._watchers.size == 0) {
// Nothing to do if there's no watchers.
return;
}
const maybeWatcher = this._watchers.get(currentPath);
if (maybeWatcher) {
maybeWatcher.forEach((watcher) => {
const [options, subject] = watcher;
subject.next({ path, time, type });
if (!options.persistent && type == interface_1.HostWatchEventType.Deleted) {
subject.complete();
this._watchers.delete(currentPath);
}
});
}
do {
currentPath = parent !== null ? parent : currentPath;
parent = (0, path_1.dirname)(currentPath);
const maybeWatcher = this._watchers.get(currentPath);
if (maybeWatcher) {
maybeWatcher.forEach((watcher) => {
const [options, subject] = watcher;
if (!options.recursive) {
return;
}
subject.next({ path, time, type });
if (!options.persistent && type == interface_1.HostWatchEventType.Deleted) {
subject.complete();
this._watchers.delete(currentPath);
}
});
}
} while (parent != currentPath);
}
get capabilities() {
return { synchronous: true };
}
/**
* List of protected methods that give direct access outside the observables to the cache
* and internal states.
*/
_write(path, content) {
path = this._toAbsolute(path);
const old = this._cache.get(path);
if (old && old.isDirectory()) {
throw new exception_1.PathIsDirectoryException(path);
}
// Update all directories. If we find a file we know it's an invalid write.
const fragments = (0, path_1.split)(path);
let curr = (0, path_1.normalize)('/');
for (const fr of fragments) {
curr = (0, path_1.join)(curr, fr);
const maybeStats = this._cache.get(fr);
if (maybeStats) {
if (maybeStats.isFile()) {
throw new exception_1.PathIsFileException(curr);
}
}
else {
this._cache.set(curr, this._newDirStats());
}
}
// Create the stats.
const stats = this._newFileStats(content, old);
this._cache.set(path, stats);
this._updateWatchers(path, old ? interface_1.HostWatchEventType.Changed : interface_1.HostWatchEventType.Created);
}
_read(path) {
path = this._toAbsolute(path);
const maybeStats = this._cache.get(path);
if (!maybeStats) {
throw new exception_1.FileDoesNotExistException(path);
}
else if (maybeStats.isDirectory()) {
throw new exception_1.PathIsDirectoryException(path);
}
else if (!maybeStats.content) {
throw new exception_1.PathIsDirectoryException(path);
}
else {
return maybeStats.content;
}
}
_delete(path) {
path = this._toAbsolute(path);
if (this._isDirectory(path)) {
for (const [cachePath] of this._cache.entries()) {
if (cachePath.startsWith(path + path_1.NormalizedSep) || cachePath === path) {
this._cache.delete(cachePath);
}
}
}
else {
this._cache.delete(path);
}
this._updateWatchers(path, interface_1.HostWatchEventType.Deleted);
}
_rename(from, to) {
from = this._toAbsolute(from);
to = this._toAbsolute(to);
if (!this._cache.has(from)) {
throw new exception_1.FileDoesNotExistException(from);
}
else if (this._cache.has(to)) {
throw new exception_1.FileAlreadyExistException(to);
}
if (this._isDirectory(from)) {
for (const path of this._cache.keys()) {
if (path.startsWith(from + path_1.NormalizedSep)) {
const content = this._cache.get(path);
if (content) {
// We don't need to clone or extract the content, since we're moving files.
this._cache.set((0, path_1.join)(to, path_1.NormalizedSep, path.slice(from.length)), content);
}
}
}
}
else {
const content = this._cache.get(from);
if (content) {
const fragments = (0, path_1.split)(to);
const newDirectories = [];
let curr = (0, path_1.normalize)('/');
for (const fr of fragments) {
curr = (0, path_1.join)(curr, fr);
const maybeStats = this._cache.get(fr);
if (maybeStats) {
if (maybeStats.isFile()) {
throw new exception_1.PathIsFileException(curr);
}
}
else {
newDirectories.push(curr);
}
}
for (const newDirectory of newDirectories) {
this._cache.set(newDirectory, this._newDirStats());
}
this._cache.delete(from);
this._cache.set(to, content);
}
}
this._updateWatchers(from, interface_1.HostWatchEventType.Renamed);
}
_list(path) {
path = this._toAbsolute(path);
if (this._isFile(path)) {
throw new exception_1.PathIsFileException(path);
}
const fragments = (0, path_1.split)(path);
const result = new Set();
if (path !== path_1.NormalizedRoot) {
for (const p of this._cache.keys()) {
if (p.startsWith(path + path_1.NormalizedSep)) {
result.add((0, path_1.split)(p)[fragments.length]);
}
}
}
else {
for (const p of this._cache.keys()) {
if (p.startsWith(path_1.NormalizedSep) && p !== path_1.NormalizedRoot) {
result.add((0, path_1.split)(p)[1]);
}
}
}
return [...result];
}
_exists(path) {
return !!this._cache.get(this._toAbsolute(path));
}
_isDirectory(path) {
const maybeStats = this._cache.get(this._toAbsolute(path));
return maybeStats ? maybeStats.isDirectory() : false;
}
_isFile(path) {
const maybeStats = this._cache.get(this._toAbsolute(path));
return maybeStats ? maybeStats.isFile() : false;
}
_stat(path) {
const maybeStats = this._cache.get(this._toAbsolute(path));
if (!maybeStats) {
return null;
}
else {
return maybeStats;
}
}
_watch(path, options) {
path = this._toAbsolute(path);
const subject = new rxjs_1.Subject();
let maybeWatcherArray = this._watchers.get(path);
if (!maybeWatcherArray) {
maybeWatcherArray = [];
this._watchers.set(path, maybeWatcherArray);
}
maybeWatcherArray.push([options || {}, subject]);
return subject.asObservable();
}
write(path, content) {
return new rxjs_1.Observable((obs) => {
this._write(path, content);
obs.next();
obs.complete();
});
}
read(path) {
return new rxjs_1.Observable((obs) => {
const content = this._read(path);
obs.next(content);
obs.complete();
});
}
delete(path) {
return new rxjs_1.Observable((obs) => {
this._delete(path);
obs.next();
obs.complete();
});
}
rename(from, to) {
return new rxjs_1.Observable((obs) => {
this._rename(from, to);
obs.next();
obs.complete();
});
}
list(path) {
return new rxjs_1.Observable((obs) => {
obs.next(this._list(path));
obs.complete();
});
}
exists(path) {
return new rxjs_1.Observable((obs) => {
obs.next(this._exists(path));
obs.complete();
});
}
isDirectory(path) {
return new rxjs_1.Observable((obs) => {
obs.next(this._isDirectory(path));
obs.complete();
});
}
isFile(path) {
return new rxjs_1.Observable((obs) => {
obs.next(this._isFile(path));
obs.complete();
});
}
// Some hosts may not support stat.
stat(path) {
return new rxjs_1.Observable((obs) => {
obs.next(this._stat(path));
obs.complete();
});
}
watch(path, options) {
return this._watch(path, options);
}
reset() {
this._cache.clear();
this._watchers.clear();
}
}
exports.SimpleMemoryHost = SimpleMemoryHost;
//# sourceMappingURL=memory.js.map
File diff suppressed because one or more lines are too long
+17
View File
@@ -0,0 +1,17 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Path } from '../path';
import { ResolverHost } from './resolver';
export type ReplacementFunction = (path: Path) => Path;
/**
*/
export declare class PatternMatchingHost<StatsT extends object = {}> extends ResolverHost<StatsT> {
protected _patterns: Map<RegExp, ReplacementFunction>;
addPattern(pattern: string | string[], replacementFn: ReplacementFunction): void;
protected _resolve(path: Path): Path;
}
+35
View File
@@ -0,0 +1,35 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.PatternMatchingHost = void 0;
const picomatch_1 = require("picomatch");
const resolver_1 = require("./resolver");
/**
*/
class PatternMatchingHost extends resolver_1.ResolverHost {
_patterns = new Map();
addPattern(pattern, replacementFn) {
const patterns = Array.isArray(pattern) ? pattern : [pattern];
for (const glob of patterns) {
const { output } = (0, picomatch_1.parse)(glob);
this._patterns.set(new RegExp(`^${output}$`), replacementFn);
}
}
_resolve(path) {
let newPath = path;
this._patterns.forEach((fn, re) => {
if (re.test(path)) {
newPath = fn(newPath);
}
});
return newPath;
}
}
exports.PatternMatchingHost = PatternMatchingHost;
//# sourceMappingURL=pattern.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"pattern.js","sourceRoot":"","sources":["pattern.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,yCAA+C;AAE/C,yCAA0C;AAI1C;GACG;AACH,MAAa,mBAAgD,SAAQ,uBAAoB;IAC7E,SAAS,GAAqC,IAAI,GAAG,EAAE,CAAC;IAElE,UAAU,CAAC,OAA0B,EAAE,aAAkC;QACvE,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC9D,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC5B,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,iBAAS,EAAC,IAAI,CAAC,CAAC;YACnC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,aAAa,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAES,QAAQ,CAAC,IAAU;QAC3B,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE;YAChC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAClB,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;YACxB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AArBD,kDAqBC"}
+92
View File
@@ -0,0 +1,92 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Observable } from 'rxjs';
import { Path, PathFragment } from '../path';
import { FileBuffer, Host, HostCapabilities, HostWatchOptions, ReadonlyHost, Stats } from './interface';
import { SimpleMemoryHost } from './memory';
export interface CordHostCreate {
kind: 'create';
path: Path;
content: FileBuffer;
}
export interface CordHostOverwrite {
kind: 'overwrite';
path: Path;
content: FileBuffer;
}
export interface CordHostRename {
kind: 'rename';
from: Path;
to: Path;
}
export interface CordHostDelete {
kind: 'delete';
path: Path;
}
export type CordHostRecord = CordHostCreate | CordHostOverwrite | CordHostRename | CordHostDelete;
/**
* A Host that records changes to the underlying Host, while keeping a record of Create, Overwrite,
* Rename and Delete of files.
*
* This is fully compatible with Host, but will keep a staging of every changes asked. That staging
* follows the principle of the Tree (e.g. can create a file that already exists).
*
* Using `create()` and `overwrite()` will force those operations, but using `write` will add
* the create/overwrite records IIF the files does/doesn't already exist.
*/
export declare class CordHost extends SimpleMemoryHost {
protected _back: ReadonlyHost;
protected _filesToCreate: Set<Path>;
protected _filesToRename: Map<Path, Path>;
protected _filesToRenameRevert: Map<Path, Path>;
protected _filesToDelete: Set<Path>;
protected _filesToOverwrite: Set<Path>;
constructor(_back: ReadonlyHost);
get backend(): ReadonlyHost;
get capabilities(): HostCapabilities;
/**
* Create a copy of this host, including all actions made.
* @returns {CordHost} The carbon copy.
*/
clone(): CordHost;
/**
* Commit the changes recorded to a Host. It is assumed that the host does have the same structure
* as the host that was used for backend (could be the same host).
* @param host The host to create/delete/rename/overwrite files to.
* @param force Whether to skip existence checks when creating/overwriting. This is
* faster but might lead to incorrect states. Because Hosts natively don't support creation
* versus overwriting (it's only writing), we check for existence before completing a request.
* @returns An observable that completes when done, or error if an error occured.
*/
commit(host: Host, force?: boolean): Observable<void>;
records(): CordHostRecord[];
/**
* Specialized version of {@link CordHost#write} which forces the creation of a file whether it
* exists or not.
* @param {} path
* @param {FileBuffer} content
* @returns {Observable<void>}
*/
create(path: Path, content: FileBuffer): Observable<void>;
overwrite(path: Path, content: FileBuffer): Observable<void>;
write(path: Path, content: FileBuffer): Observable<void>;
read(path: Path): Observable<FileBuffer>;
delete(path: Path): Observable<void>;
rename(from: Path, to: Path): Observable<void>;
list(path: Path): Observable<PathFragment[]>;
exists(path: Path): Observable<boolean>;
isDirectory(path: Path): Observable<boolean>;
isFile(path: Path): Observable<boolean>;
stat(path: Path): Observable<Stats | null> | null;
watch(path: Path, options?: HostWatchOptions): null;
willCreate(path: Path): boolean;
willOverwrite(path: Path): boolean;
willDelete(path: Path): boolean;
willRename(path: Path): boolean;
willRenameTo(path: Path, to: Path): boolean;
}
+315
View File
@@ -0,0 +1,315 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CordHost = void 0;
const rxjs_1 = require("rxjs");
const exception_1 = require("../../exception");
const memory_1 = require("./memory");
/**
* A Host that records changes to the underlying Host, while keeping a record of Create, Overwrite,
* Rename and Delete of files.
*
* This is fully compatible with Host, but will keep a staging of every changes asked. That staging
* follows the principle of the Tree (e.g. can create a file that already exists).
*
* Using `create()` and `overwrite()` will force those operations, but using `write` will add
* the create/overwrite records IIF the files does/doesn't already exist.
*/
class CordHost extends memory_1.SimpleMemoryHost {
_back;
_filesToCreate = new Set();
_filesToRename = new Map();
_filesToRenameRevert = new Map();
_filesToDelete = new Set();
_filesToOverwrite = new Set();
constructor(_back) {
super();
this._back = _back;
}
get backend() {
return this._back;
}
get capabilities() {
// Our own host is always Synchronous, but the backend might not be.
return {
synchronous: this._back.capabilities.synchronous,
};
}
/**
* Create a copy of this host, including all actions made.
* @returns {CordHost} The carbon copy.
*/
clone() {
const dolly = new CordHost(this._back);
dolly._cache = new Map(this._cache);
dolly._filesToCreate = new Set(this._filesToCreate);
dolly._filesToRename = new Map(this._filesToRename);
dolly._filesToRenameRevert = new Map(this._filesToRenameRevert);
dolly._filesToDelete = new Set(this._filesToDelete);
dolly._filesToOverwrite = new Set(this._filesToOverwrite);
return dolly;
}
/**
* Commit the changes recorded to a Host. It is assumed that the host does have the same structure
* as the host that was used for backend (could be the same host).
* @param host The host to create/delete/rename/overwrite files to.
* @param force Whether to skip existence checks when creating/overwriting. This is
* faster but might lead to incorrect states. Because Hosts natively don't support creation
* versus overwriting (it's only writing), we check for existence before completing a request.
* @returns An observable that completes when done, or error if an error occured.
*/
commit(host, force = false) {
// Really commit everything to the actual host.
return (0, rxjs_1.from)(this.records()).pipe((0, rxjs_1.concatMap)((record) => {
switch (record.kind) {
case 'delete':
return host.delete(record.path);
case 'rename':
return host.rename(record.from, record.to);
case 'create':
return host.exists(record.path).pipe((0, rxjs_1.switchMap)((exists) => {
if (exists && !force) {
return (0, rxjs_1.throwError)(new exception_1.FileAlreadyExistException(record.path));
}
else {
return host.write(record.path, record.content);
}
}));
case 'overwrite':
return host.exists(record.path).pipe((0, rxjs_1.switchMap)((exists) => {
if (!exists && !force) {
return (0, rxjs_1.throwError)(new exception_1.FileDoesNotExistException(record.path));
}
else {
return host.write(record.path, record.content);
}
}));
}
}), (0, rxjs_1.reduce)(() => { }));
}
records() {
return [
...[...this._filesToDelete.values()].map((path) => ({
kind: 'delete',
path,
})),
...[...this._filesToRename.entries()].map(([from, to]) => ({
kind: 'rename',
from,
to,
})),
...[...this._filesToCreate.values()].map((path) => ({
kind: 'create',
path,
content: this._read(path),
})),
...[...this._filesToOverwrite.values()].map((path) => ({
kind: 'overwrite',
path,
content: this._read(path),
})),
];
}
/**
* Specialized version of {@link CordHost#write} which forces the creation of a file whether it
* exists or not.
* @param {} path
* @param {FileBuffer} content
* @returns {Observable<void>}
*/
create(path, content) {
if (super._exists(path)) {
throw new exception_1.FileAlreadyExistException(path);
}
if (this._filesToDelete.has(path)) {
this._filesToDelete.delete(path);
this._filesToOverwrite.add(path);
}
else {
this._filesToCreate.add(path);
}
return super.write(path, content);
}
overwrite(path, content) {
return this.isDirectory(path).pipe((0, rxjs_1.switchMap)((isDir) => {
if (isDir) {
return (0, rxjs_1.throwError)(new exception_1.PathIsDirectoryException(path));
}
return this.exists(path);
}), (0, rxjs_1.switchMap)((exists) => {
if (!exists) {
return (0, rxjs_1.throwError)(new exception_1.FileDoesNotExistException(path));
}
if (!this._filesToCreate.has(path)) {
this._filesToOverwrite.add(path);
}
return super.write(path, content);
}));
}
write(path, content) {
return this.exists(path).pipe((0, rxjs_1.switchMap)((exists) => {
if (exists) {
// It exists, but might be being renamed or deleted. In that case we want to create it.
if (this.willRename(path) || this.willDelete(path)) {
return this.create(path, content);
}
else {
return this.overwrite(path, content);
}
}
else {
return this.create(path, content);
}
}));
}
read(path) {
if (this._exists(path)) {
return super.read(path);
}
return this._back.read(path);
}
delete(path) {
if (this._exists(path)) {
if (this._filesToCreate.has(path)) {
this._filesToCreate.delete(path);
}
else if (this._filesToOverwrite.has(path)) {
this._filesToOverwrite.delete(path);
this._filesToDelete.add(path);
}
else {
const maybeOrigin = this._filesToRenameRevert.get(path);
if (maybeOrigin) {
this._filesToRenameRevert.delete(path);
this._filesToRename.delete(maybeOrigin);
this._filesToDelete.add(maybeOrigin);
}
else {
return (0, rxjs_1.throwError)(new exception_1.UnknownException(`This should never happen. Path: ${JSON.stringify(path)}.`));
}
}
return super.delete(path);
}
else {
return this._back.exists(path).pipe((0, rxjs_1.switchMap)((exists) => {
if (exists) {
this._filesToDelete.add(path);
return (0, rxjs_1.of)();
}
else {
return (0, rxjs_1.throwError)(new exception_1.FileDoesNotExistException(path));
}
}));
}
}
rename(from, to) {
return (0, rxjs_1.concat)(this.exists(to), this.exists(from)).pipe((0, rxjs_1.toArray)(), (0, rxjs_1.switchMap)(([existTo, existFrom]) => {
if (!existFrom) {
return (0, rxjs_1.throwError)(new exception_1.FileDoesNotExistException(from));
}
if (from === to) {
return rxjs_1.EMPTY;
}
if (existTo) {
return (0, rxjs_1.throwError)(new exception_1.FileAlreadyExistException(to));
}
// If we're renaming a file that's been created, shortcircuit to creating the `to` path.
if (this._filesToCreate.has(from)) {
this._filesToCreate.delete(from);
this._filesToCreate.add(to);
return super.rename(from, to);
}
if (this._filesToOverwrite.has(from)) {
this._filesToOverwrite.delete(from);
// Recursively call this function. This is so we don't repeat the bottom logic. This
// if will be by-passed because we just deleted the `from` path from files to overwrite.
return (0, rxjs_1.concat)(this.rename(from, to), new rxjs_1.Observable((x) => {
this._filesToOverwrite.add(to);
x.complete();
}));
}
if (this._filesToDelete.has(to)) {
this._filesToDelete.delete(to);
this._filesToDelete.add(from);
this._filesToOverwrite.add(to);
// We need to delete the original and write the new one.
return this.read(from).pipe((0, rxjs_1.map)((content) => this._write(to, content)));
}
const maybeTo1 = this._filesToRenameRevert.get(from);
if (maybeTo1) {
// We already renamed to this file (A => from), let's rename the former to the new
// path (A => to).
this._filesToRename.delete(maybeTo1);
this._filesToRenameRevert.delete(from);
from = maybeTo1;
}
this._filesToRename.set(from, to);
this._filesToRenameRevert.set(to, from);
// If the file is part of our data, just rename it internally.
if (this._exists(from)) {
return super.rename(from, to);
}
else {
// Create a file with the same content.
return this._back.read(from).pipe((0, rxjs_1.switchMap)((content) => super.write(to, content)));
}
}));
}
list(path) {
return (0, rxjs_1.concat)(super.list(path), this._back.list(path)).pipe((0, rxjs_1.reduce)((list, curr) => {
curr.forEach((elem) => list.add(elem));
return list;
}, new Set()), (0, rxjs_1.map)((set) => [...set]));
}
exists(path) {
return this._exists(path)
? (0, rxjs_1.of)(true)
: this.willDelete(path) || this.willRename(path)
? (0, rxjs_1.of)(false)
: this._back.exists(path);
}
isDirectory(path) {
return this._exists(path) ? super.isDirectory(path) : this._back.isDirectory(path);
}
isFile(path) {
return this._exists(path)
? super.isFile(path)
: this.willDelete(path) || this.willRename(path)
? (0, rxjs_1.of)(false)
: this._back.isFile(path);
}
stat(path) {
return this._exists(path)
? super.stat(path)
: this.willDelete(path) || this.willRename(path)
? (0, rxjs_1.of)(null)
: this._back.stat(path);
}
watch(path, options) {
// Watching not supported.
return null;
}
willCreate(path) {
return this._filesToCreate.has(path);
}
willOverwrite(path) {
return this._filesToOverwrite.has(path);
}
willDelete(path) {
return this._filesToDelete.has(path);
}
willRename(path) {
return this._filesToRename.has(path);
}
willRenameTo(path, to) {
return this._filesToRename.get(path) === to;
}
}
exports.CordHost = CordHost;
//# sourceMappingURL=record.js.map
File diff suppressed because one or more lines are too long
+30
View File
@@ -0,0 +1,30 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Observable } from 'rxjs';
import { Path, PathFragment } from '../path';
import { FileBuffer, Host, HostCapabilities, HostWatchEvent, HostWatchOptions, Stats } from './interface';
/**
* A Host that runs a method before calling its delegate. This is an abstract class and its actual
* behaviour is entirely dependant of the subclass.
*/
export declare abstract class ResolverHost<T extends object> implements Host<T> {
protected _delegate: Host<T>;
protected abstract _resolve(path: Path): Path;
constructor(_delegate: Host<T>);
get capabilities(): HostCapabilities;
write(path: Path, content: FileBuffer): Observable<void>;
read(path: Path): Observable<FileBuffer>;
delete(path: Path): Observable<void>;
rename(from: Path, to: Path): Observable<void>;
list(path: Path): Observable<PathFragment[]>;
exists(path: Path): Observable<boolean>;
isDirectory(path: Path): Observable<boolean>;
isFile(path: Path): Observable<boolean>;
stat(path: Path): Observable<Stats<T> | null> | null;
watch(path: Path, options?: HostWatchOptions): Observable<HostWatchEvent> | null;
}
+57
View File
@@ -0,0 +1,57 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResolverHost = void 0;
/**
* A Host that runs a method before calling its delegate. This is an abstract class and its actual
* behaviour is entirely dependant of the subclass.
*/
class ResolverHost {
_delegate;
constructor(_delegate) {
this._delegate = _delegate;
}
get capabilities() {
return this._delegate.capabilities;
}
write(path, content) {
return this._delegate.write(this._resolve(path), content);
}
read(path) {
return this._delegate.read(this._resolve(path));
}
delete(path) {
return this._delegate.delete(this._resolve(path));
}
rename(from, to) {
return this._delegate.rename(this._resolve(from), this._resolve(to));
}
list(path) {
return this._delegate.list(this._resolve(path));
}
exists(path) {
return this._delegate.exists(this._resolve(path));
}
isDirectory(path) {
return this._delegate.isDirectory(this._resolve(path));
}
isFile(path) {
return this._delegate.isFile(this._resolve(path));
}
// Some hosts may not support stat.
stat(path) {
return this._delegate.stat(this._resolve(path));
}
// Some hosts may not support watching.
watch(path, options) {
return this._delegate.watch(this._resolve(path), options);
}
}
exports.ResolverHost = ResolverHost;
//# sourceMappingURL=resolver.js.map
@@ -0,0 +1 @@
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["resolver.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAaH;;;GAGG;AACH,MAAsB,YAAY;IAGV;IAAtB,YAAsB,SAAkB;QAAlB,cAAS,GAAT,SAAS,CAAS;IAAG,CAAC;IAE5C,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;IACrC,CAAC;IAED,K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,CAAC,IAAI,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,uCAAuC;IACvC,KAAK,CAAC,IAAU,EAAE,OAA0B;QAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF;AA7CD,oCA6CC"}
+25
View File
@@ -0,0 +1,25 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Observable } from 'rxjs';
import { Path, PathFragment } from '../path';
import { FileBuffer, HostCapabilities, ReadonlyHost, Stats } from './interface';
/**
* A Host that filters out errors. The only exception is `read()` which will still error out if
* the delegate returned an error (e.g. NodeJS will error out if the file doesn't exist).
*/
export declare class SafeReadonlyHost<StatsT extends object = {}> implements ReadonlyHost<StatsT> {
private _delegate;
constructor(_delegate: ReadonlyHost<StatsT>);
get capabilities(): HostCapabilities;
read(path: Path): Observable<FileBuffer>;
list(path: Path): Observable<PathFragment[]>;
exists(path: Path): Observable<boolean>;
isDirectory(path: Path): Observable<boolean>;
isFile(path: Path): Observable<boolean>;
stat(path: Path): Observable<Stats<StatsT> | null> | null;
}
+46
View File
@@ -0,0 +1,46 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SafeReadonlyHost = void 0;
const rxjs_1 = require("rxjs");
/**
* A Host that filters out errors. The only exception is `read()` which will still error out if
* the delegate returned an error (e.g. NodeJS will error out if the file doesn't exist).
*/
class SafeReadonlyHost {
_delegate;
constructor(_delegate) {
this._delegate = _delegate;
}
get capabilities() {
return this._delegate.capabilities;
}
read(path) {
return this._delegate.read(path);
}
list(path) {
return this._delegate.list(path).pipe((0, rxjs_1.catchError)(() => (0, rxjs_1.of)([])));
}
exists(path) {
return this._delegate.exists(path);
}
isDirectory(path) {
return this._delegate.isDirectory(path).pipe((0, rxjs_1.catchError)(() => (0, rxjs_1.of)(false)));
}
isFile(path) {
return this._delegate.isFile(path).pipe((0, rxjs_1.catchError)(() => (0, rxjs_1.of)(false)));
}
// Some hosts may not support stats.
stat(path) {
const maybeStat = this._delegate.stat(path);
return maybeStat && maybeStat.pipe((0, rxjs_1.catchError)(() => (0, rxjs_1.of)(null)));
}
}
exports.SafeReadonlyHost = SafeReadonlyHost;
//# sourceMappingURL=safe.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"safe.js","sourceRoot":"","sources":["safe.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,+BAAkD;AAIlD;;;GAGG;AACH,MAAa,gBAAgB;IACP;IAApB,YAAoB,SAA+B;QAA/B,cAAS,GAAT,SAAS,CAAsB;IAAG,CAAC;IAEvD,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,IAAU;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,CAAC,IAAU;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAA,iBAAU,EAAC,GAAG,EAAE,CAAC,IAAA,SAAE,EAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,CAAC,IAAU;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IACD,WAAW,CAAC,IAAU;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAA,iBAAU,EAAC,GAAG,EAAE,CAAC,IAAA,SAAE,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM,CAAC,IAAU;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAA,iBAAU,EAAC,GAAG,EAAE,CAAC,IAAA,SAAE,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;IAED,oCAAoC;IACpC,IAAI,CAAC,IAAU;QACb,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE5C,OAAO,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,IAAA,iBAAU,EAAC,GAAG,EAAE,CAAC,IAAA,SAAE,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;CACF;AA/BD,4CA+BC"}
+15
View File
@@ -0,0 +1,15 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Path } from '../path';
import { Host } from './interface';
import { ResolverHost } from './resolver';
export declare class ScopedHost<T extends object> extends ResolverHost<T> {
protected _root: Path;
constructor(delegate: Host<T>, _root?: Path);
protected _resolve(path: Path): Path;
}
+24
View File
@@ -0,0 +1,24 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScopedHost = void 0;
const path_1 = require("../path");
const resolver_1 = require("./resolver");
class ScopedHost extends resolver_1.ResolverHost {
_root;
constructor(delegate, _root = path_1.NormalizedRoot) {
super(delegate);
this._root = _root;
}
_resolve(path) {
return (0, path_1.join)(this._root, path);
}
}
exports.ScopedHost = ScopedHost;
//# sourceMappingURL=scoped.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"scoped.js","sourceRoot":"","sources":["scoped.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,kCAAqD;AAErD,yCAA0C;AAE1C,MAAa,UAA6B,SAAQ,uBAAe;IAGnD;IAFZ,YACE,QAAiB,EACP,QAAc,qBAAc;QAEtC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAFN,UAAK,GAAL,KAAK,CAAuB;IAGxC,CAAC;IAES,QAAQ,CAAC,IAAU;QAC3B,OAAO,IAAA,WAAI,EAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;CACF;AAXD,gCAWC"}
+34
View File
@@ -0,0 +1,34 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Observable } from 'rxjs';
import { BaseException } from '../../exception';
import { Path, PathFragment } from '../path';
import { FileBuffer, FileBufferLike, Host, HostCapabilities, HostWatchEvent, HostWatchOptions, Stats } from './interface';
export declare class SynchronousDelegateExpectedException extends BaseException {
constructor();
}
/**
* Implement a synchronous-only host interface (remove the Observable parts).
*/
export declare class SyncDelegateHost<T extends object = {}> {
protected _delegate: Host<T>;
constructor(_delegate: Host<T>);
protected _doSyncCall<ResultT>(observable: Observable<ResultT>): ResultT;
get capabilities(): HostCapabilities;
get delegate(): Host<T>;
write(path: Path, content: FileBufferLike): void;
read(path: Path): FileBuffer;
delete(path: Path): void;
rename(from: Path, to: Path): void;
list(path: Path): PathFragment[];
exists(path: Path): boolean;
isDirectory(path: Path): boolean;
isFile(path: Path): boolean;
stat(path: Path): Stats<T> | null;
watch(path: Path, options?: HostWatchOptions): Observable<HostWatchEvent> | null;
}
+93
View File
@@ -0,0 +1,93 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SyncDelegateHost = exports.SynchronousDelegateExpectedException = void 0;
const exception_1 = require("../../exception");
class SynchronousDelegateExpectedException extends exception_1.BaseException {
constructor() {
super(`Expected a synchronous delegate but got an asynchronous one.`);
}
}
exports.SynchronousDelegateExpectedException = SynchronousDelegateExpectedException;
/**
* Implement a synchronous-only host interface (remove the Observable parts).
*/
class SyncDelegateHost {
_delegate;
constructor(_delegate) {
this._delegate = _delegate;
if (!_delegate.capabilities.synchronous) {
throw new SynchronousDelegateExpectedException();
}
}
_doSyncCall(observable) {
let completed = false;
let result = undefined;
let errorResult = undefined;
// Perf note: this is not using an observer object to avoid a performance penalty in RxJS.
// See https://github.com/ReactiveX/rxjs/pull/5646 for details.
observable.subscribe((x) => (result = x), (err) => (errorResult = err), () => (completed = true));
if (errorResult !== undefined) {
throw errorResult;
}
if (!completed) {
throw new SynchronousDelegateExpectedException();
}
// The non-null operation is to work around `void` type. We don't allow to return undefined
// but ResultT could be void, which is undefined in JavaScript, so this doesn't change the
// behaviour.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return result;
}
get capabilities() {
return this._delegate.capabilities;
}
get delegate() {
return this._delegate;
}
write(path, content) {
return this._doSyncCall(this._delegate.write(path, content));
}
read(path) {
return this._doSyncCall(this._delegate.read(path));
}
delete(path) {
return this._doSyncCall(this._delegate.delete(path));
}
rename(from, to) {
return this._doSyncCall(this._delegate.rename(from, to));
}
list(path) {
return this._doSyncCall(this._delegate.list(path));
}
exists(path) {
return this._doSyncCall(this._delegate.exists(path));
}
isDirectory(path) {
return this._doSyncCall(this._delegate.isDirectory(path));
}
isFile(path) {
return this._doSyncCall(this._delegate.isFile(path));
}
// Some hosts may not support stat.
stat(path) {
const result = this._delegate.stat(path);
if (result) {
return this._doSyncCall(result);
}
else {
return null;
}
}
watch(path, options) {
return this._delegate.watch(path, options);
}
}
exports.SyncDelegateHost = SyncDelegateHost;
//# sourceMappingURL=sync.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"sync.js","sourceRoot":"","sources":["sync.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAGH,+CAAgD;AAYhD,MAAa,oCAAqC,SAAQ,yB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U,EAAE,OAA0B;QAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;CACF;AAjFD,4CAiFC"}
+48
View File
@@ -0,0 +1,48 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { Observable } from 'rxjs';
import { Path, PathFragment } from '../path';
import { FileBuffer, HostWatchEvent, HostWatchOptions, Stats } from './interface';
import { SimpleMemoryHost, SimpleMemoryHostStats } from './memory';
import { SyncDelegateHost } from './sync';
export type TestLogRecord = {
kind: 'write' | 'read' | 'delete' | 'list' | 'exists' | 'isDirectory' | 'isFile' | 'stat' | 'watch';
path: Path;
} | {
kind: 'rename';
from: Path;
to: Path;
};
export declare class TestHost extends SimpleMemoryHost {
protected _records: TestLogRecord[];
protected _sync: SyncDelegateHost<{}> | null;
constructor(map?: {
[path: string]: string;
});
get records(): TestLogRecord[];
clearRecords(): void;
get files(): Path[];
get sync(): SyncDelegateHost<{}>;
clone(): TestHost;
protected _write(path: Path, content: FileBuffer): void;
protected _read(path: Path): ArrayBuffer;
protected _delete(path: Path): void;
protected _rename(from: Path, to: Path): void;
protected _list(path: Path): PathFragment[];
protected _exists(path: Path): boolean;
protected _isDirectory(path: Path): boolean;
protected _isFile(path: Path): boolean;
protected _stat(path: Path): Stats<SimpleMemoryHostStats> | null;
protected _watch(path: Path, options?: HostWatchOptions): Observable<HostWatchEvent>;
$write(path: string, content: string): void;
$read(path: string): string;
$list(path: string): PathFragment[];
$exists(path: string): boolean;
$isDirectory(path: string): boolean;
$isFile(path: string): boolean;
}
+119
View File
@@ -0,0 +1,119 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestHost = void 0;
const path_1 = require("../path");
const buffer_1 = require("./buffer");
const memory_1 = require("./memory");
const sync_1 = require("./sync");
class TestHost extends memory_1.SimpleMemoryHost {
_records = [];
_sync = null;
constructor(map = {}) {
super();
for (const filePath of Object.getOwnPropertyNames(map)) {
this._write((0, path_1.normalize)(filePath), (0, buffer_1.stringToFileBuffer)(map[filePath]));
}
}
get records() {
return [...this._records];
}
clearRecords() {
this._records = [];
}
get files() {
const sync = this.sync;
function _visit(p) {
return sync
.list(p)
.map((fragment) => (0, path_1.join)(p, fragment))
.reduce((files, path) => {
if (sync.isDirectory(path)) {
return files.concat(_visit(path));
}
else {
return files.concat(path);
}
}, []);
}
return _visit((0, path_1.normalize)('/'));
}
get sync() {
if (!this._sync) {
this._sync = new sync_1.SyncDelegateHost(this);
}
return this._sync;
}
clone() {
const newHost = new TestHost();
newHost._cache = new Map(this._cache);
return newHost;
}
// Override parents functions to keep a record of all operators that were done.
_write(path, content) {
this._records.push({ kind: 'write', path });
return super._write(path, content);
}
_read(path) {
this._records.push({ kind: 'read', path });
return super._read(path);
}
_delete(path) {
this._records.push({ kind: 'delete', path });
return super._delete(path);
}
_rename(from, to) {
this._records.push({ kind: 'rename', from, to });
return super._rename(from, to);
}
_list(path) {
this._records.push({ kind: 'list', path });
return super._list(path);
}
_exists(path) {
this._records.push({ kind: 'exists', path });
return super._exists(path);
}
_isDirectory(path) {
this._records.push({ kind: 'isDirectory', path });
return super._isDirectory(path);
}
_isFile(path) {
this._records.push({ kind: 'isFile', path });
return super._isFile(path);
}
_stat(path) {
this._records.push({ kind: 'stat', path });
return super._stat(path);
}
_watch(path, options) {
this._records.push({ kind: 'watch', path });
return super._watch(path, options);
}
$write(path, content) {
return super._write((0, path_1.normalize)(path), (0, buffer_1.stringToFileBuffer)(content));
}
$read(path) {
return (0, buffer_1.fileBufferToString)(super._read((0, path_1.normalize)(path)));
}
$list(path) {
return super._list((0, path_1.normalize)(path));
}
$exists(path) {
return super._exists((0, path_1.normalize)(path));
}
$isDirectory(path) {
return super._isDirectory((0, path_1.normalize)(path));
}
$isFile(path) {
return super._isFile((0, path_1.normalize)(path));
}
}
exports.TestHost = TestHost;
//# sourceMappingURL=test.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAGH,kCAA8D;AAC9D,qCAAkE;AAElE,qCAAmE;AACnE,iCAA0C;AAsB1C,MAAa,QAAS,SAAQ,yBAAgB;IAClC,QAAQ,GAAoB,EAAE,CAAC;IAC/B,KAAK,GAAgC,IAAI,CAAC;IAEpD,YAAY,MAAkC,EAAE;QAC9C,KAAK,EAAE,CAAC;QAER,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,CAAC;YACvD,IAAI,CAAC,MAAM,CAAC,IAAA,gBAAS,EAAC,QAAQ,CAAC,EAAE,IAAA,2BAAkB,EAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED,IAAI,OAAO;QACT,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IACD,YAAY;QACV,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACrB,CAAC;IAED,IAAI,KAAK;QACP,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,SAAS,MAAM,CAAC,CAAO;YACrB,OAAO,IAAI;iBACR,IAAI,CAAC,CAAC,CAAC;iBACP,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAA,WAAI,EAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;iBACpC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;gBACtB,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC3B,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;gBACpC,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EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAE5C,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,IAAY,EAAE,OAAe;QAClC,OAAO,KAAK,CAAC,MAAM,CAAC,IAAA,gBAAS,EAAC,IAAI,CAAC,EAAE,IAAA,2BAAkB,EAAC,OAAO,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,OAAO,IAAA,2BAAkB,EAAC,KAAK,CAAC,KAAK,CAAC,IAAA,gBAAS,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,OAAO,KAAK,CAAC,KAAK,CAAC,IAAA,gBAAS,EAAC,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,OAAO,KAAK,CAAC,OAAO,CAAC,IAAA,gBAAS,EAAC,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,YAAY,CAAC,IAAY;QACvB,OAAO,KAAK,CAAC,YAAY,CAAC,IAAA,gBAAS,EAAC,IAAI,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,OAAO,KAAK,CAAC,OAAO,CAAC,IAAA,gBAAS,EAAC,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC;CACF;AA/HD,4BA+HC"}
+10
View File
@@ -0,0 +1,10 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import * as virtualFs from './host/index';
export * from './path';
export { virtualFs };
+50
View File
@@ -0,0 +1,50 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.virtualFs = void 0;
const virtualFs = __importStar(require("./host/index"));
exports.virtualFs = virtualFs;
__exportStar(require("./path"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,wDAA0C;AAGjC,8BAAS;AADlB,yCAAuB"}
+111
View File
@@ -0,0 +1,111 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { BaseException } from '../exception';
import { TemplateTag } from '../utils/literals';
export declare class InvalidPathException extends BaseException {
constructor(path: string);
}
export declare class PathMustBeAbsoluteException extends BaseException {
constructor(path: string);
}
export declare class PathCannotBeFragmentException extends BaseException {
constructor(path: string);
}
/**
* A Path recognized by most methods in the DevKit.
*/
export type Path = string & {
__PRIVATE_DEVKIT_PATH: void;
};
/**
* A Path fragment (file or directory name) recognized by most methods in the DevKit.
*/
export type PathFragment = Path & {
__PRIVATE_DEVKIT_PATH_FRAGMENT: void;
};
/**
* The Separator for normalized path.
*/
export declare const NormalizedSep: Path;
/**
* The root of a normalized path.
*/
export declare const NormalizedRoot: Path;
/**
* Split a path into multiple path fragments. Each fragments except the last one will end with
* a path separator.
* @param {Path} path The path to split.
* @returns {Path[]} An array of path fragments.
*/
export declare function split(path: Path): PathFragment[];
/**
*
*/
export declare function extname(path: Path): string;
/**
* Return the basename of the path, as a Path. See path.basename
*/
export declare function basename(path: Path): PathFragment;
/**
* Return the dirname of the path, as a Path. See path.dirname
*/
export declare function dirname(path: Path): Path;
/**
* Join multiple paths together, and normalize the result. Accepts strings that will be
* normalized as well (but the original must be a path).
*/
export declare function join(p1: Path, ...others: string[]): Path;
/**
* Returns true if a path is absolute.
*/
export declare function isAbsolute(p: Path): boolean;
/**
* Returns a path such that `join(from, relative(from, to)) == to`.
* Both paths must be absolute, otherwise it does not make much sense.
*/
export declare function relative(from: Path, to: Path): Path;
/**
* Returns a Path that is the resolution of p2, from p1. If p2 is absolute, it will return p2,
* otherwise will join both p1 and p2.
*/
export declare function resolve(p1: Path, p2: Path): Path;
export declare function fragment(path: string): PathFragment;
/**
* Reset the cache. This is only useful for testing.
* @private
*/
export declare function resetNormalizeCache(): void;
/**
* Normalize a string into a Path. This is the only mean to get a Path type from a string that
* represents a system path. This method cache the results as real world paths tend to be
* duplicated often.
* Normalization includes:
* - Windows backslashes `\\` are replaced with `/`.
* - Windows drivers are replaced with `/X/`, where X is the drive letter.
* - Absolute paths starts with `/`.
* - Multiple `/` are replaced by a single one.
* - Path segments `.` are removed.
* - Path segments `..` are resolved.
* - If a path is absolute, having a `..` at the start is invalid (and will throw).
* @param path The path to be normalized.
*/
export declare function normalize(path: string): Path;
/**
* The no cache version of the normalize() function. Used for benchmarking and testing.
*/
export declare function noCacheNormalize(path: string): Path;
export declare const path: TemplateTag<Path>;
export type WindowsPath = string & {
__PRIVATE_DEVKIT_WINDOWS_PATH: void;
};
export type PosixPath = string & {
__PRIVATE_DEVKIT_POSIX_PATH: void;
};
export declare function asWindowsPath(path: Path): WindowsPath;
export declare function asPosixPath(path: Path): PosixPath;
export declare function getSystemPath(path: Path): string;
+286
View File
@@ -0,0 +1,286 @@
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.path = exports.NormalizedRoot = exports.NormalizedSep = exports.PathCannotBeFragmentException = exports.PathMustBeAbsoluteException = exports.InvalidPathException = void 0;
exports.split = split;
exports.extname = extname;
exports.basename = basename;
exports.dirname = dirname;
exports.join = join;
exports.isAbsolute = isAbsolute;
exports.relative = relative;
exports.resolve = resolve;
exports.fragment = fragment;
exports.resetNormalizeCache = resetNormalizeCache;
exports.normalize = normalize;
exports.noCacheNormalize = noCacheNormalize;
exports.asWindowsPath = asWindowsPath;
exports.asPosixPath = asPosixPath;
exports.getSystemPath = getSystemPath;
const exception_1 = require("../exception");
class InvalidPathException extends exception_1.BaseException {
constructor(path) {
super(`Path ${JSON.stringify(path)} is invalid.`);
}
}
exports.InvalidPathException = InvalidPathException;
class PathMustBeAbsoluteException extends exception_1.BaseException {
constructor(path) {
super(`Path ${JSON.stringify(path)} must be absolute.`);
}
}
exports.PathMustBeAbsoluteException = PathMustBeAbsoluteException;
class PathCannotBeFragmentException extends exception_1.BaseException {
constructor(path) {
super(`Path ${JSON.stringify(path)} cannot be made a fragment.`);
}
}
exports.PathCannotBeFragmentException = PathCannotBeFragmentException;
/**
* The Separator for normalized path.
*/
exports.NormalizedSep = '/';
/**
* The root of a normalized path.
*/
exports.NormalizedRoot = exports.NormalizedSep;
/**
* Split a path into multiple path fragments. Each fragments except the last one will end with
* a path separator.
* @param {Path} path The path to split.
* @returns {Path[]} An array of path fragments.
*/
function split(path) {
const fragments = path.split(exports.NormalizedSep).map((x) => fragment(x));
if (fragments.at(-1)?.length === 0) {
fragments.pop();
}
return fragments;
}
/**
*
*/
function extname(path) {
const base = basename(path);
const i = base.lastIndexOf('.');
if (i < 1) {
return '';
}
else {
return base.slice(i);
}
}
/**
* Return the basename of the path, as a Path. See path.basename
*/
function basename(path) {
const i = path.lastIndexOf(exports.NormalizedSep);
if (i == -1) {
return fragment(path);
}
else {
return fragment(path.slice(path.lastIndexOf(exports.NormalizedSep) + 1));
}
}
/**
* Return the dirname of the path, as a Path. See path.dirname
*/
function dirname(path) {
const index = path.lastIndexOf(exports.NormalizedSep);
if (index === -1) {
return '';
}
const endIndex = index === 0 ? 1 : index; // case of file under root: '/file'
return normalize(path.slice(0, endIndex));
}
/**
* Join multiple paths together, and normalize the result. Accepts strings that will be
* normalized as well (but the original must be a path).
*/
function join(p1, ...others) {
if (others.length > 0) {
return normalize((p1 ? p1 + exports.NormalizedSep : '') + others.join(exports.NormalizedSep));
}
else {
return p1;
}
}
/**
* Returns true if a path is absolute.
*/
function isAbsolute(p) {
return p.startsWith(exports.NormalizedSep);
}
/**
* Returns a path such that `join(from, relative(from, to)) == to`.
* Both paths must be absolute, otherwise it does not make much sense.
*/
function relative(from, to) {
if (!isAbsolute(from)) {
throw new PathMustBeAbsoluteException(from);
}
if (!isAbsolute(to)) {
throw new PathMustBeAbsoluteException(to);
}
let p;
if (from == to) {
p = '';
}
else {
const splitFrom = split(from);
const splitTo = split(to);
while (splitFrom.length > 0 && splitTo.length > 0 && splitFrom[0] == splitTo[0]) {
splitFrom.shift();
splitTo.shift();
}
if (splitFrom.length == 0) {
p = splitTo.join(exports.NormalizedSep);
}
else {
p = splitFrom
.map(() => '..')
.concat(splitTo)
.join(exports.NormalizedSep);
}
}
return normalize(p);
}
/**
* Returns a Path that is the resolution of p2, from p1. If p2 is absolute, it will return p2,
* otherwise will join both p1 and p2.
*/
function resolve(p1, p2) {
if (isAbsolute(p2)) {
return p2;
}
else {
return join(p1, p2);
}
}
function fragment(path) {
if (path.indexOf(exports.NormalizedSep) != -1) {
throw new PathCannotBeFragmentException(path);
}
return path;
}
/**
* normalize() cache to reduce computation. For now this grows and we never flush it, but in the
* future we might want to add a few cache flush to prevent this from growing too large.
*/
let normalizedCache = new Map();
/**
* Reset the cache. This is only useful for testing.
* @private
*/
function resetNormalizeCache() {
normalizedCache = new Map();
}
/**
* Normalize a string into a Path. This is the only mean to get a Path type from a string that
* represents a system path. This method cache the results as real world paths tend to be
* duplicated often.
* Normalization includes:
* - Windows backslashes `\\` are replaced with `/`.
* - Windows drivers are replaced with `/X/`, where X is the drive letter.
* - Absolute paths starts with `/`.
* - Multiple `/` are replaced by a single one.
* - Path segments `.` are removed.
* - Path segments `..` are resolved.
* - If a path is absolute, having a `..` at the start is invalid (and will throw).
* @param path The path to be normalized.
*/
function normalize(path) {
let maybePath = normalizedCache.get(path);
if (!maybePath) {
maybePath = noCacheNormalize(path);
normalizedCache.set(path, maybePath);
}
return maybePath;
}
/**
* The no cache version of the normalize() function. Used for benchmarking and testing.
*/
function noCacheNormalize(path) {
if (path == '' || path == '.') {
return '';
}
else if (path == exports.NormalizedRoot) {
return exports.NormalizedRoot;
}
// Match absolute windows path.
const original = path;
if (path.match(/^[A-Z]:[/\\]/i)) {
path = '\\' + path[0].toUpperCase() + '\\' + path.slice(3);
}
// We convert Windows paths as well here.
const p = path.split(/[/\\]/g);
let relative = false;
let i = 1;
// Special case the first one.
if (p[0] != '') {
p.unshift('.');
relative = true;
}
while (i < p.length) {
if (p[i] == '.') {
p.splice(i, 1);
}
else if (p[i] == '..') {
if (i < 2 && !relative) {
throw new InvalidPathException(original);
}
else if (i >= 2 && p[i - 1] != '..') {
p.splice(i - 1, 2);
i--;
}
else {
i++;
}
}
else if (p[i] == '') {
p.splice(i, 1);
}
else {
i++;
}
}
if (p.length == 1) {
return p[0] == '' ? exports.NormalizedSep : '';
}
else {
if (p[0] == '.') {
p.shift();
}
return p.join(exports.NormalizedSep);
}
}
const path = (strings, ...values) => {
return normalize(String.raw(strings, ...values));
};
exports.path = path;
function asWindowsPath(path) {
const drive = path.match(/^\/(\w)(?:\/(.*))?$/);
if (drive) {
const subPath = drive[2] ? drive[2].replace(/\//g, '\\') : '';
return `${drive[1]}:\\${subPath}`;
}
return path.replace(/\//g, '\\');
}
function asPosixPath(path) {
return path;
}
function getSystemPath(path) {
if (process.platform.startsWith('win32')) {
return asWindowsPath(path);
}
else {
return asPosixPath(path);
}
}
//# sourceMappingURL=path.js.map
File diff suppressed because one or more lines are too long