Icard/angular-clarity-master(work.../node_modules/@angular-devkit/schematics/tools/file-system-engine-host.js

117 lines
13 KiB
JavaScript

"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
*/
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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileSystemEngineHost = void 0;
const fs_1 = require("fs");
const path_1 = require("path");
const rxjs_1 = require("rxjs");
const src_1 = require("../src");
const export_ref_1 = require("./export-ref");
const file_system_engine_host_base_1 = require("./file-system-engine-host-base");
/**
* A simple EngineHost that uses a root with one directory per collection inside of it. The
* collection declaration follows the same rules as the regular FileSystemEngineHostBase.
*/
class FileSystemEngineHost extends file_system_engine_host_base_1.FileSystemEngineHostBase {
constructor(_root) {
super();
this._root = _root;
}
_resolveCollectionPath(name) {
try {
// Allow `${_root}/${name}.json` as a collection.
const maybePath = require.resolve((0, path_1.join)(this._root, name + '.json'));
if ((0, fs_1.existsSync)(maybePath)) {
return maybePath;
}
}
catch (error) { }
try {
// Allow `${_root}/${name}/collection.json.
const maybePath = require.resolve((0, path_1.join)(this._root, name, 'collection.json'));
if ((0, fs_1.existsSync)(maybePath)) {
return maybePath;
}
}
catch (error) { }
throw new file_system_engine_host_base_1.CollectionCannotBeResolvedException(name);
}
_resolveReferenceString(refString, parentPath) {
// Use the same kind of export strings as NodeModule.
const ref = new export_ref_1.ExportStringRef(refString, parentPath);
if (!ref.ref) {
return null;
}
return { ref: ref.ref, path: ref.module };
}
_transformCollectionDescription(name, desc) {
if (!desc.schematics || typeof desc.schematics != 'object') {
throw new file_system_engine_host_base_1.CollectionMissingSchematicsMapException(name);
}
return {
...desc,
name,
};
}
_transformSchematicDescription(name, _collection, desc) {
if (!desc.factoryFn || !desc.path || !desc.description) {
throw new file_system_engine_host_base_1.SchematicMissingFieldsException(name);
}
return desc;
}
hasTaskExecutor(name) {
if (super.hasTaskExecutor(name)) {
return true;
}
try {
const maybePath = require.resolve((0, path_1.join)(this._root, name));
if ((0, fs_1.existsSync)(maybePath)) {
return true;
}
}
catch { }
return false;
}
createTaskExecutor(name) {
if (!super.hasTaskExecutor(name)) {
try {
const path = require.resolve((0, path_1.join)(this._root, name));
// Default handling code is for old tasks that incorrectly export `default` with non-ESM module
return (0, rxjs_1.from)(Promise.resolve(`${path}`).then(s => __importStar(require(s))).then((mod) => (mod.default?.default || mod.default)())).pipe((0, rxjs_1.catchError)(() => (0, rxjs_1.throwError)(new src_1.UnregisteredTaskException(name))));
}
catch { }
}
return super.createTaskExecutor(name);
}
}
exports.FileSystemEngineHost = FileSystemEngineHost;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmlsZS1zeXN0ZW0tZW5naW5lLWhvc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9hbmd1bGFyX2RldmtpdC9zY2hlbWF0aWNzL3Rvb2xzL2ZpbGUtc3lzdGVtLWVuZ2luZS1ob3N0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQ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