From 8c80d2b61fa59ed7f7c5870a5e4ff70ca08f413b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Mon, 13 Jan 2025 18:19:27 +0300 Subject: [PATCH] chore(schematics): add providers for proprietary (#10156) --- .../ng-update/v4/steps/migrate-editor.ts | 57 ++++++++++++++++++- .../schematic-migrate-addon-editor.spec.ts | 10 +++- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/projects/cdk/schematics/ng-update/v4/steps/migrate-editor.ts b/projects/cdk/schematics/ng-update/v4/steps/migrate-editor.ts index b04864227a86..39a9c55841ca 100644 --- a/projects/cdk/schematics/ng-update/v4/steps/migrate-editor.ts +++ b/projects/cdk/schematics/ng-update/v4/steps/migrate-editor.ts @@ -1,10 +1,15 @@ /// import type {DevkitFileSystem} from 'ng-morph'; import { + addProviderToComponent, + addProviderToNgModule, FINISH_SYMBOL, + getNgComponents, + getNgModules, getPackageJsonDependency, getSourceFiles, infoLog, + Node, REPLACE_SYMBOL, saveActiveProject, SMALL_TAB_SYMBOL, @@ -13,10 +18,12 @@ import { import {ALL_TS_FILES} from '../../../constants/file-globs'; import type {TuiSchema} from '../../../ng-add/schema'; +import {addUniqueImport} from '../../../utils/add-unique-import'; +import {getNamedImportReferences} from '../../../utils/get-named-import-references'; import {replaceIdentifiers} from '../../steps/replace-identifier'; import {replacePackageName} from '../../steps/replace-package-name'; -export const TUI_EDITOR_VERSION = '^4.11.0'; +export const TUI_EDITOR_VERSION = '^4.21.0'; export function migrateEditor(fileSystem: DevkitFileSystem, options: TuiSchema): void { const moduleSpecifier = ['@tinkoff/tui-editor', '@taiga-ui/addon-editor']; @@ -31,6 +38,8 @@ export function migrateEditor(fileSystem: DevkitFileSystem, options: TuiSchema): !options['skip-logs'] && infoLog(`${SMALL_TAB_SYMBOL}${REPLACE_SYMBOL} migrating editor...`); + addProprietaryProviders(fileSystem); + replaceIdentifiers(options, [ { from: {name: 'TuiEditorModule', moduleSpecifier}, @@ -107,3 +116,49 @@ export function migrateEditor(fileSystem: DevkitFileSystem, options: TuiSchema): !options['skip-logs'] && titleLog(`${FINISH_SYMBOL} successfully migrated \n`); } + +function addProprietaryProviders(fileSystem: DevkitFileSystem): void { + const proprietary = + getPackageJsonDependency(fileSystem.tree, '@taiga-ui/proprietary-core') || + getPackageJsonDependency(fileSystem.tree, '@taiga-ui/proprietary'); + + if (!proprietary) { + return; + } + + const refs = [ + ...getNamedImportReferences('TuiEditorModule', '@tinkoff/tui-editor'), + ...getNamedImportReferences('TuiEditorModule', '@taiga-ui/addon-editor'), + ]; + + for (const ref of refs) { + if (ref.wasForgotten()) { + return; + } + + const parent = ref.getParent(); + const filePath = parent?.getSourceFile().getFilePath() ?? ''; + + if (Node.isImportSpecifier(parent)) { + addUniqueImport(filePath, 'tuiEditorOptionsProvider', '@taiga-ui/editor'); + addUniqueImport( + filePath, + 'TUI_PROPRIETARY_EDITOR_ICONS', + '@taiga-ui/proprietary', + ); + } else if (Node.isArrayLiteralExpression(parent)) { + const componentClass = getNgComponents(filePath)[0]; + const moduleClass = getNgModules(filePath)[0]; + const provider = + 'tuiEditorOptionsProvider({icons: TUI_PROPRIETARY_EDITOR_ICONS})'; + + if (componentClass) { + addProviderToComponent(componentClass, provider); + } + + if (moduleClass) { + addProviderToNgModule(moduleClass, provider); + } + } + } +} diff --git a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-addon-editor.spec.ts b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-addon-editor.spec.ts index d05a5c83925b..dcb5c0b85c1d 100644 --- a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-addon-editor.spec.ts +++ b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-addon-editor.spec.ts @@ -59,7 +59,8 @@ export class Test { }`; const COMPONENT_AFTER = `import { TUI_SANITIZER } from "@taiga-ui/legacy"; -import { TuiEditor, TuiEditorSocket, TUI_EDITOR_DEFAULT_EXTENSIONS, TUI_EDITOR_DEFAULT_TOOLS } from "@taiga-ui/editor"; +import { TUI_PROPRIETARY_EDITOR_ICONS } from "@taiga-ui/proprietary"; +import { tuiEditorOptionsProvider, TuiEditor, TuiEditorSocket, TUI_EDITOR_DEFAULT_EXTENSIONS, TUI_EDITOR_DEFAULT_TOOLS } from "@taiga-ui/editor"; import { TuiRoot, TuiAlert, TuiDialog } from '@taiga-ui/core'; import {NgDompurifySanitizer} from '@taiga-ui/dompurify'; @@ -85,7 +86,8 @@ import {TuiEditorTool} from '@taiga-ui/editor'; { provide: TUI_SANITIZER, useClass: NgDompurifySanitizer, - } + }, + tuiEditorOptionsProvider({icons: TUI_PROPRIETARY_EDITOR_ICONS}) ], }) export class Test { @@ -99,6 +101,7 @@ const PACKAGE_JSON_BEFORE = `{ "@angular/core": "~13.0.0", "@taiga-ui/core": "~3.35.0", "@taiga-ui/cdk": "~3.35.0", + "@taiga-ui/proprietary-core": "~3.35.0", "@taiga-ui/addon-editor": "~3.35.0", "@tinkoff/ng-polymorpheus": "1.2.3", "@tinkoff/ng-event-plugins": "4.5.6" @@ -113,7 +116,8 @@ const PACKAGE_JSON_AFTER = `{ "@taiga-ui/editor": "${TUI_EDITOR_VERSION}", "@taiga-ui/event-plugins": "${TUI_EVENT_PLUGINS_VERSION}", "@taiga-ui/legacy": "${TUI_VERSION}", - "@taiga-ui/polymorpheus": "${TUI_POLYMORPHEUS_VERSION}" + "@taiga-ui/polymorpheus": "${TUI_POLYMORPHEUS_VERSION}", + "@taiga-ui/proprietary": "${TUI_VERSION}" } }`.trim();