From f28acd16c0b4eb855a876c186ca7ea782956d49d Mon Sep 17 00:00:00 2001 From: Vladimir Potekhin <46284632+vladimirpotekhin@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:20:18 +0300 Subject: [PATCH] chore: check proprietary using two packages (#8685) --- .../cdk/schematics/ng-update/v4/migrate-icons/index.ts | 5 ++++- .../v4/migrate-icons/rename-proprietary-icons.ts | 9 +++++---- .../schematics/ng-update/v4/steps/migrate-proprietary.ts | 7 +++---- .../cdk/schematics/ng-update/v4/steps/migrate-root.ts | 7 +++---- .../ng-update/v4/tests/schematic-migrate-icons.spec.ts | 2 +- .../v4/tests/schematic-migrate-proprietary.spec.ts | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/projects/cdk/schematics/ng-update/v4/migrate-icons/index.ts b/projects/cdk/schematics/ng-update/v4/migrate-icons/index.ts index fd058bacde2d..beba74904024 100644 --- a/projects/cdk/schematics/ng-update/v4/migrate-icons/index.ts +++ b/projects/cdk/schematics/ng-update/v4/migrate-icons/index.ts @@ -38,5 +38,8 @@ export function migrateIcons(options: TuiSchema): Rule { } function hasProprietaryIcons(tree: Tree): boolean { - return !!getPackageJsonDependency(tree, '@taiga-ui/proprietary-icons'); + return ( + !!getPackageJsonDependency(tree, '@taiga-ui/proprietary-icons') || + !!getPackageJsonDependency(tree, '@taiga-ui/proprietary') + ); } diff --git a/projects/cdk/schematics/ng-update/v4/migrate-icons/rename-proprietary-icons.ts b/projects/cdk/schematics/ng-update/v4/migrate-icons/rename-proprietary-icons.ts index 9ae7f7a4465b..9dca843865ff 100644 --- a/projects/cdk/schematics/ng-update/v4/migrate-icons/rename-proprietary-icons.ts +++ b/projects/cdk/schematics/ng-update/v4/migrate-icons/rename-proprietary-icons.ts @@ -15,11 +15,14 @@ export function renameProprietaryIcons( const regex = /['"`]tuiIcon(?!Button\b)[A-Z][a-zA-Z0-9]*\b/g; + const invalidIcons = new Set(); + text = text.replaceAll(regex, (icon) => { if (icon.match(/['"`]tuiIcon(?!Tds)\w*/)) { logger.warn( `[WARNING] in ${file.getSourceFile().getFilePath()}: Invalid icon name ${icon}. Please select an icon from the proprietary pack.`, ); + invalidIcons.add(icon.slice(1)); return icon; } @@ -27,10 +30,8 @@ export function renameProprietaryIcons( return convertString(icon); }); - const invalidIcons = [...new Set(text.match(/\b(tuiIcon(?!Tds|Button)\w*)\b/g))]; - - if (invalidIcons.length) { - const message = `TODO (Taiga UI migration): invalid icons ${invalidIcons.join(', ')}. Please select an icon from the proprietary pack`; + if (invalidIcons.size > 0) { + const message = `TODO (Taiga UI migration): invalid icons ${Array.from(invalidIcons).join(', ')}. Please select an icon from the proprietary pack`; const todo = file.getFilePath().endsWith('html') ? `` : `// ${message}`; diff --git a/projects/cdk/schematics/ng-update/v4/steps/migrate-proprietary.ts b/projects/cdk/schematics/ng-update/v4/steps/migrate-proprietary.ts index 383905c35e1e..98ef13cad344 100644 --- a/projects/cdk/schematics/ng-update/v4/steps/migrate-proprietary.ts +++ b/projects/cdk/schematics/ng-update/v4/steps/migrate-proprietary.ts @@ -17,10 +17,9 @@ export function migrateProprietary( options: TuiSchema, ): void { try { - const hasProprietary = !!getPackageJsonDependency( - fileSystem.tree, - '@taiga-ui/proprietary-core', - )?.version; + const hasProprietary = + !!getPackageJsonDependency(fileSystem.tree, '@taiga-ui/proprietary-core') || + !!getPackageJsonDependency(fileSystem.tree, '@taiga-ui/proprietary'); if (!hasProprietary) { return; diff --git a/projects/cdk/schematics/ng-update/v4/steps/migrate-root.ts b/projects/cdk/schematics/ng-update/v4/steps/migrate-root.ts index 18d0a9f0a6cb..9c11b419004c 100644 --- a/projects/cdk/schematics/ng-update/v4/steps/migrate-root.ts +++ b/projects/cdk/schematics/ng-update/v4/steps/migrate-root.ts @@ -82,10 +82,9 @@ function addProviders(callExpression: Node, fileSystem: DevkitFileSystem): void ); getActiveProject(); - const proprietary = getPackageJsonDependency( - fileSystem.tree, - '@taiga-ui/proprietary-core', - ); + const proprietary = + getPackageJsonDependency(fileSystem.tree, '@taiga-ui/proprietary-core') || + getPackageJsonDependency(fileSystem.tree, '@taiga-ui/proprietary'); if (proprietary) { array.addElement('TBANK_PROVIDERS'); diff --git a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-icons.spec.ts b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-icons.spec.ts index 8d54af499445..691d53fc4880 100644 --- a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-icons.spec.ts +++ b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-icons.spec.ts @@ -60,7 +60,7 @@ export class Test { icon = iconsName.tuiIconStart; }`; -const PROPR_COMPONENT_AFTER = `// TODO (Taiga UI migration): invalid icons tuiIconStar, tuiIconArrowDown, tuiIconStart. Please select an icon from the proprietary pack +const PROPR_COMPONENT_AFTER = `// TODO (Taiga UI migration): invalid icons tuiIconStar, tuiIconArrowDown. Please select an icon from the proprietary pack import { Component } from "@angular/core"; const iconsMap = { diff --git a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-proprietary.spec.ts b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-proprietary.spec.ts index b8de43bc659a..0d30108061bf 100644 --- a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-proprietary.spec.ts +++ b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-proprietary.spec.ts @@ -60,7 +60,7 @@ export class Test { @Input() illustration: string | null = null; readonly operationIcon: TuiFeedItemIcon = { - icon: '@tui.tds-transport-auto-ruble-medium', + icon: '@tui.fancy.medium.transport-auto-ruble', color: '#428BF9', background: '#428bf91f', };