"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.io/license */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DevkitFileSystem = void 0; const core_1 = require("@angular-devkit/core"); const file_system_1 = require("../update-tool/file-system"); const path = require("path"); /** * File system that leverages the virtual tree from the CLI devkit. This file * system is commonly used by `ng update` migrations that run as part of the * Angular CLI. */ class DevkitFileSystem extends file_system_1.FileSystem { _tree; _updateRecorderCache = new Map(); constructor(_tree) { super(); this._tree = _tree; } resolve(...segments) { // Note: We use `posix.resolve` as the devkit paths are using posix separators. return (0, core_1.normalize)(path.posix.resolve('/', ...segments.map(core_1.normalize))); } edit(filePath) { if (this._updateRecorderCache.has(filePath)) { return this._updateRecorderCache.get(filePath); } const recorder = this._tree.beginUpdate(filePath); this._updateRecorderCache.set(filePath, recorder); return recorder; } commitEdits() { this._updateRecorderCache.forEach(r => this._tree.commitUpdate(r)); this._updateRecorderCache.clear(); } fileExists(filePath) { return this._tree.exists(filePath); } directoryExists(dirPath) { // The devkit tree does not expose an API for checking whether a given // directory exists. It throws a specific error though if a directory // is being read as a file. We use that to check if a directory exists. try { this._tree.get(dirPath); } catch (e) { // Note: We do not use an `instanceof` check here. It could happen that // the devkit version used by the CLI is different than the one we end up // loading. This can happen depending on how Yarn/NPM hoists the NPM // packages / whether there are multiple versions installed. Typescript // throws a compilation error if the type isn't specified and we can't // check the type, so we have to cast the error output to any. if (e.constructor.name === 'PathIsDirectoryException') { return true; } } return false; } overwrite(filePath, content) { this._tree.overwrite(filePath, content); } create(filePath, content) { this._tree.create(filePath, content); } delete(filePath) { this._tree.delete(filePath); } read(filePath) { const buffer = this._tree.read(filePath); return buffer !== null ? buffer.toString() : null; } readDirectory(dirPath) { const { subdirs: directories, subfiles: files } = this._tree.getDir(dirPath); return { directories, files }; } } exports.DevkitFileSystem = DevkitFileSystem; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJma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