Skip to content

Commit

Permalink
chore(schematics): valid migration for NG_EVENT_PLUGINS (#10115)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Jan 9, 2025
1 parent 3d7263b commit 9171c49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
7 changes: 6 additions & 1 deletion projects/cdk/schematics/ng-update/v4/steps/migrate-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {DevkitFileSystem} from 'ng-morph';
import {
addProviderToNgModule,
getActiveProject,
getImports,
getNgModules,
getPackageJsonDependency,
infoLog,
Expand Down Expand Up @@ -98,7 +99,11 @@ function addProviders({
addProviderToNgModule(module, 'NG_EVENT_PLUGINS', {unique: true});
}

if (providersArray || module) {
const shouldAddImport =
(providersArray || module) &&
!getImports(path, {moduleSpecifier: '@tinkoff/ng-event-plugins'}).length;

if (shouldAddImport) {
addUniqueImport(path, 'NG_EVENT_PLUGINS', '@taiga-ui/event-plugins');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,44 @@ const MODULE_BEFORE = `import { TuiMobileCalendarDialogModule } from "@taiga-ui/
import { OldModule } from "@namespace/cdk";
import { TuiMarkerIconModule } from "@taiga-ui/kit";
import { TuiProprietaryRootModule } from "@taiga-ui/proprietary-core";
import { NG_EVENT_PLUGINS } from '@tinkoff/ng-event-plugins';
@NgModule({
imports: [TuiMobileCalendarDialogModule, TuiProprietaryRootModule, OldModule, TuiAvatar, TuiAvatar, TuiAvatar, TuiMarkerIconModule],
providers: [Provider]
})
export class Test {
}`;
export class Test1 {
}
@NgModule({
imports: [],
providers: [Provider, NG_EVENT_PLUGINS]
})
export class Test2 {
}
`;

const MODULE_AFTER = `import { newProvider } from "@namespace/new";
import { tuiProvideMobileCalendar } from "@taiga-ui/addon-mobile";
import { TuiAvatar } from "@taiga-ui/kit";
import { TBANK_PROVIDERS } from "@taiga-ui/proprietary";
import { NG_EVENT_PLUGINS } from "@taiga-ui/event-plugins";
import { TuiRoot } from "@taiga-ui/core";
import { NG_EVENT_PLUGINS } from '@taiga-ui/event-plugins';
@NgModule({
imports: [TuiRoot, TuiAvatar],
providers: [Provider, NG_EVENT_PLUGINS, TBANK_PROVIDERS, tuiProvideMobileCalendar(), newProvider]
})
export class Test {
}`;
export class Test1 {
}
@NgModule({
imports: [],
providers: [Provider, NG_EVENT_PLUGINS]
})
export class Test2 {
}
`;

const COMPONENT_BEFORE = `import { TuiMobileCalendarDialogModule } from "@taiga-ui/addon-mobile";
import { OldModule } from "@namespace/cdk";
Expand Down

0 comments on commit 9171c49

Please sign in to comment.