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

Class CordHost

packages/angular_devkit/core/src/virtual-fs/host/record.ts:70–418  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68 * the create/overwrite records IIF the files does/doesn't already exist.
69 */
70export class CordHost extends SimpleMemoryHost {
71 protected _filesToCreate: Set<Path> = new Set();
72 protected _filesToRename: Map<Path, Path> = new Map();
73 protected _filesToRenameRevert: Map<Path, Path> = new Map();
74 protected _filesToDelete: Set<Path> = new Set();
75 protected _filesToOverwrite: Set<Path> = new Set();
76
77 constructor(protected _back: ReadonlyHost) {
78 super();
79 }
80
81 get backend(): ReadonlyHost {
82 return this._back;
83 }
84 override get capabilities(): HostCapabilities {
85 // Our own host is always Synchronous, but the backend might not be.
86 return {
87 synchronous: this._back.capabilities.synchronous,
88 };
89 }
90
91 /**
92 * Create a copy of this host, including all actions made.
93 * @returns {CordHost} The carbon copy.
94 */
95 clone(): CordHost {
96 const dolly = new CordHost(this._back);
97
98 dolly._cache = new Map(this._cache);
99 dolly._filesToCreate = new Set(this._filesToCreate);
100 dolly._filesToRename = new Map(this._filesToRename);
101 dolly._filesToRenameRevert = new Map(this._filesToRenameRevert);
102 dolly._filesToDelete = new Set(this._filesToDelete);
103 dolly._filesToOverwrite = new Set(this._filesToOverwrite);
104
105 return dolly;
106 }
107
108 /**
109 * Commit the changes recorded to a Host. It is assumed that the host does have the same structure
110 * as the host that was used for backend (could be the same host).
111 * @param host The host to create/delete/rename/overwrite files to.
112 * @param force Whether to skip existence checks when creating/overwriting. This is
113 * faster but might lead to incorrect states. Because Hosts natively don't support creation
114 * versus overwriting (it's only writing), we check for existence before completing a request.
115 * @returns An observable that completes when done, or error if an error occured.
116 */
117 commit(host: Host, force = false): Observable<void> {
118 // Really commit everything to the actual host.
119 return observableFrom(this.records()).pipe(
120 concatMap((record) => {
121 switch (record.kind) {
122 case 'delete':
123 return host.delete(record.path);
124 case 'rename':
125 return host.rename(record.from, record.to);
126 case 'create':
127 return host.exists(record.path).pipe(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected