source: trip-planner-front/node_modules/@angular/cdk/schematics/ng-update/devkit-file-system.mjs@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 9.4 KB
Line 
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.DevkitFileSystem = void 0;
11const core_1 = require("@angular-devkit/core");
12const file_system_1 = require("../update-tool/file-system");
13const path = require("path");
14/**
15 * File system that leverages the virtual tree from the CLI devkit. This file
16 * system is commonly used by `ng update` migrations that run as part of the
17 * Angular CLI.
18 */
19class DevkitFileSystem extends file_system_1.FileSystem {
20 constructor(_tree) {
21 super();
22 this._tree = _tree;
23 this._updateRecorderCache = new Map();
24 }
25 resolve(...segments) {
26 // Note: We use `posix.resolve` as the devkit paths are using posix separators.
27 return core_1.normalize(path.posix.resolve('/', ...segments.map(core_1.normalize)));
28 }
29 edit(filePath) {
30 if (this._updateRecorderCache.has(filePath)) {
31 return this._updateRecorderCache.get(filePath);
32 }
33 const recorder = this._tree.beginUpdate(filePath);
34 this._updateRecorderCache.set(filePath, recorder);
35 return recorder;
36 }
37 commitEdits() {
38 this._updateRecorderCache.forEach(r => this._tree.commitUpdate(r));
39 this._updateRecorderCache.clear();
40 }
41 fileExists(filePath) {
42 return this._tree.exists(filePath);
43 }
44 directoryExists(dirPath) {
45 // The devkit tree does not expose an API for checking whether a given
46 // directory exists. It throws a specific error though if a directory
47 // is being read as a file. We use that to check if a directory exists.
48 try {
49 this._tree.get(dirPath);
50 }
51 catch (e) {
52 // Note: We do not use an `instanceof` check here. It could happen that the devkit version
53 // used by the CLI is different than the one we end up loading. This can happen depending
54 // on how Yarn/NPM hoists the NPM packages / whether there are multiple versions installed.
55 if (e instanceof Error && e.constructor.name === 'PathIsDirectoryException') {
56 return true;
57 }
58 }
59 return false;
60 }
61 overwrite(filePath, content) {
62 this._tree.overwrite(filePath, content);
63 }
64 create(filePath, content) {
65 this._tree.create(filePath, content);
66 }
67 delete(filePath) {
68 this._tree.delete(filePath);
69 }
70 read(filePath) {
71 const buffer = this._tree.read(filePath);
72 return buffer !== null ? buffer.toString() : null;
73 }
74 readDirectory(dirPath) {
75 const { subdirs: directories, subfiles: files } = this._tree.getDir(dirPath);
76 return { directories, files };
77 }
78}
79exports.DevkitFileSystem = DevkitFileSystem;
80//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGV2a2l0LWZpbGUtc3lzdGVtLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9zY2hlbWF0aWNzL25nLXVwZGF0ZS9kZXZraXQtZmlsZS1zeXN0ZW0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7R0FNRzs7O0FBRUgsK0NBQXFEO0FBRXJELDREQUFzRTtBQUN0RSw2QkFBNkI7QUFFN0I7Ozs7R0FJRztBQUNILE1BQWEsZ0JBQWlCLFNBQVEsd0JBQVU7SUFHOUMsWUFBb0IsS0FBVztRQUM3QixLQUFLLEVBQUUsQ0FBQztRQURVLFVBQUssR0FBTCxLQUFLLENBQU07UUFGdkIseUJBQW9CLEdBQUcsSUFBSSxHQUFHLEVBQTBCLENBQUM7SUFJakUsQ0FBQztJQUVELE9BQU8sQ0FBQyxHQUFHLFFBQWtCO1FBQzNCLCtFQUErRTtRQUMvRSxPQUFPLGdCQUFTLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsR0FBRyxFQUFFLEdBQUcsUUFBUSxDQUFDLEdBQUcsQ0FBQyxnQkFBUyxDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQ3hFLENBQUM7SUFFRCxJQUFJLENBQUMsUUFBYztRQUNqQixJQU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