/
githubmirror
/
angular-cli
Обзор
Документация
Войти
/
githubmirror
/
angular-cli
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/schematics/angular/utility/add-declaration-to-ng-module.ts
64 строки
2 KB
Alan Agius
refactor(@schematics/angular): remove third-party typescript copy
28 апр 2026, 14:35
28 апр 2026, 14:35
c6dd57a
Код
Авторство
О чём код?
/** * @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 { Rule, Tree, strings } from '@angular-devkit/schematics'; import ts from 'typescript'; import { addDeclarationToModule, addSymbolToNgModuleMetadata } from './ast-utils'; import { InsertChange } from './change'; import { buildRelativePath } from './find-module'; export interface DeclarationToNgModuleOptions { module?: string; path?: string; name: string; flat?: boolean; export?: boolean; type: string; typeSeparator?: '.' | '-'; skipImport?: boolean; standalone?: boolean; } export function addDeclarationToNgModule(options: DeclarationToNgModuleOptions): Rule { return (host: Tree) => { const modulePath = options.module; if (options.skipImport || options.standalone || !modulePath) { return host; } const typeSeparator = options.typeSeparator ?? '.'; const sourceText = host.readText(modulePath); const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true); const filePath = `/${options.path}/` + (options.flat ? '' : strings.dasherize(options.name) + '/') + strings.dasherize(options.name) + (options.type ? typeSeparator + strings.dasherize(options.type) : ''); const importPath = buildRelativePath(modulePath, filePath); const classifiedName = strings.classify(options.name) + (options.type ? strings.classify(options.type) : ''); const changes = addDeclarationToModule(source, modulePath, classifiedName, importPath); if (options.export) { changes.push(...addSymbolToNgModuleMetadata(source, modulePath, 'exports', classifiedName)); } const recorder = host.beginUpdate(modulePath); for (const change of changes) { if (change instanceof InsertChange) { recorder.insertLeft(change.pos, change.toAdd); } } host.commitUpdate(recorder); return host; }; }