/
githubmirror
/
angular-cli
Обзор
Документация
Войти
/
githubmirror
/
angular-cli
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/angular_devkit/schematics/tools/schema-option-transform.ts
52 строки
2 KB
Charles Lyding
refactor(@angular-devkit/schematics): remove usage of custom deepCopy (#33051)
27 апр 2026, 18:40
27 апр 2026, 18:40
ba7dd2f
Код
Авторство
О чём код?
/** * @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 */ import { schema } from '@angular-devkit/core'; import { Observable, from, of as observableOf } from 'rxjs'; import { first, map, mergeMap } from 'rxjs/operators'; import { FileSystemSchematicContext, FileSystemSchematicDescription } from './description'; export class InvalidInputOptions<T = {}> extends schema.SchemaValidationException { constructor(options: T, errors: schema.SchemaValidatorError[]) { super( errors, `Schematic input does not validate against the Schema: ${JSON.stringify(options)}\nErrors:\n`, ); } } // This can only be used in NodeJS. export function validateOptionsWithSchema(registry: schema.SchemaRegistry) { return <T extends {} | null>( schematic: FileSystemSchematicDescription, options: T, context?: FileSystemSchematicContext, ): Observable<T> => { // Prevent a schematic from changing the options object by making a copy of it. options = structuredClone(options); const withPrompts = context ? context.interactive : true; if (schematic.schema && schematic.schemaJson) { // Make a deep copy of options. return from(registry.compile(schematic.schemaJson)).pipe( mergeMap((validator) => validator(options, { withPrompts })), first(), map((result) => { if (!result.success) { throw new InvalidInputOptions(options, result.errors || []); } return options; }), ); } return observableOf(options); }; }