UNPKG

@angular-devkit/core

Version:

Angular DevKit - Core Utility Library

167 lines 19.3 kB
"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.TargetDefinitionCollection = exports.ProjectDefinitionCollection = void 0; class DefinitionCollection { constructor(initial, _listener) { this._listener = _listener; this._map = new Map(initial && Object.entries(initial)); } delete(key) { const result = this._map.delete(key); if (result) { this._listener?.(key, undefined, this); } return result; } set(key, value) { const updatedValue = value !== this.get(key); if (updatedValue) { this._map.set(key, value); this._listener?.(key, value, this); } return this; } forEach(callbackfn, thisArg) { this._map.forEach((value, key) => callbackfn(value, key, this), thisArg); } get(key) { return this._map.get(key); } has(key) { return this._map.has(key); } get size() { return this._map.size; } [Symbol.iterator]() { return this._map[Symbol.iterator](); } entries() { return this._map.entries(); } keys() { return this._map.keys(); } values() { return this._map.values(); } } function isJsonValue(value) { const visited = new Set(); switch (typeof value) { case 'boolean': case 'number': case 'string': return true; case 'object': if (value === null) { return true; } visited.add(value); for (const property of Object.values(value)) { if (typeof value === 'object' && visited.has(property)) { continue; } if (!isJsonValue(property)) { return false; } } return true; default: return false; } } class ProjectDefinitionCollection extends DefinitionCollection { constructor(initial, listener) { super(initial, listener); } add(definition) { if (this.has(definition.name)) { throw new Error('Project name already exists.'); } this._validateName(definition.name); const project = { root: definition.root, prefix: definition.prefix, sourceRoot: definition.sourceRoot, targets: new TargetDefinitionCollection(), extensions: {}, }; if (definition.targets) { for (const [name, target] of Object.entries(definition.targets)) { if (target) { project.targets.set(name, target); } } } for (const [name, value] of Object.entries(definition)) { switch (name) { case 'name': case 'root': case 'sourceRoot': case 'prefix': case 'targets': break; default: if (isJsonValue(value)) { project.extensions[name] = value; } else { throw new TypeError(`"${name}" must be a JSON value.`); } break; } } super.set(definition.name, project); return project; } set(name, value) { this._validateName(name); super.set(name, value); return this; } _validateName(name) { if (typeof name !== 'string' || !/^(?:@\w[\w.-]*\/)?\w[\w.-]*$/.test(name)) { throw new Error('Project name must be a valid npm package name.'); } } } exports.ProjectDefinitionCollection = ProjectDefinitionCollection; class TargetDefinitionCollection extends DefinitionCollection { constructor(initial, listener) { super(initial, listener); } add(definition) { if (this.has(definition.name)) { throw new Error('Target name already exists.'); } this._validateName(definition.name); const target = { builder: definition.builder, options: definition.options, configurations: definition.configurations, defaultConfiguration: definition.defaultConfiguration, }; super.set(definition.name, target); return target; } set(name, value) { this._validateName(name); super.set(name, value); return this; } _validateName(name) { if (typeof name !== 'string') { throw new TypeError('Target name must be a string.'); } } } exports.TargetDefinitionCollection = TargetDefinitionCollection; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmaW5pdGlvbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9hbmd1bGFyX2RldmtpdC9jb3JlL3NyYy93b3Jrc3BhY2UvZGVmaW5pdGlvbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7R0FNRzs7O0FBK0JILE1BQU0sb0JBQW9CO0lBR3hCLFlBQVksT0FBMkIsRUFBVSxTQUEyQztRQUEzQyxjQUFTLEdBQVQsU0FBUyxDQUFrQztRQUMxRixJQUFJLENBQUMsSUFBSSxHQUFHLElBQUksR0FBRyxDQUFDLE9BQU8sSUFBSSxNQUFNLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUM7SUFDMUQsQ0FBQztJQUVELE1BQU0sQ0FBQyxHQUFXO1FBQ2hCLE1BQU0sTUFBTSxHQUFHLElBQUksQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDO1FBRXJDLElBQUksTUFBTSxFQUFFO1lBQ1YsSUFBSSxDQUFDLFNBQVMsRUFBRSxDQUFDLEdBQUcsRUF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