@angular/cdk
Version:
Angular Material Component Development Kit
116 lines • 4.54 kB
JavaScript
;
/**
* @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;
};
})();
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 = __importStar(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 {
constructor(_tree) {
super();
this._tree = _tree;
this._updateRecorderCache = new Map();
}
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=devkit-file-system.js.map