From e7051fd3db2b8018d09df7fcc4770341920485cf Mon Sep 17 00:00:00 2001 From: Vladimir Potekhin <46284632+vladimirpotekhin@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:02:09 +0300 Subject: [PATCH] chore: `ng-add` add NG_EVENT_PLUGINS to main module providers, add plugins package (#8803) --- projects/cdk/schematics/ng-add/index.ts | 5 ++++ .../ng-add/steps/add-taiga-modules.ts | 4 +++ .../tests/schematic-ng-add-standalone.spec.ts | 2 ++ .../ng-add/tests/schematic-ng-add.spec.ts | 25 +++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/projects/cdk/schematics/ng-add/index.ts b/projects/cdk/schematics/ng-add/index.ts index c74adf8d5f03..d1022decbb0b 100644 --- a/projects/cdk/schematics/ng-add/index.ts +++ b/projects/cdk/schematics/ng-add/index.ts @@ -22,6 +22,11 @@ function addDependencies(tree: Tree, options: TuiSchema): void { }); }); + addPackageJsonDependency(tree, { + name: '@taiga-ui/event-plugins', + version: '^4.0.2', + }); + removeTaigaSchematicsPackage(tree); if (packages.includes('addon-table') || packages.includes('addon-mobile')) { diff --git a/projects/cdk/schematics/ng-add/steps/add-taiga-modules.ts b/projects/cdk/schematics/ng-add/steps/add-taiga-modules.ts index a245a265e9ab..f406f5d397d4 100644 --- a/projects/cdk/schematics/ng-add/steps/add-taiga-modules.ts +++ b/projects/cdk/schematics/ng-add/steps/add-taiga-modules.ts @@ -11,6 +11,7 @@ import type { import { addImportToComponent, addImportToNgModule, + addProviderToNgModule, createProject, getMainModule, Node, @@ -46,6 +47,9 @@ function addTuiModules({ addUniqueImport(mainModulePath, module.name, module.packageName); }); + addProviderToNgModule(mainClass, 'NG_EVENT_PLUGINS', {unique: true}); + addUniqueImport(mainModulePath, 'NG_EVENT_PLUGINS', '@taiga-ui/event-plugins'); + context.logger.info( `${modules.map((module) => module.name)} was added to ${mainModulePath}`, ); diff --git a/projects/cdk/schematics/ng-add/tests/schematic-ng-add-standalone.spec.ts b/projects/cdk/schematics/ng-add/tests/schematic-ng-add-standalone.spec.ts index 7e135931c646..6a35304df559 100644 --- a/projects/cdk/schematics/ng-add/tests/schematic-ng-add-standalone.spec.ts +++ b/projects/cdk/schematics/ng-add/tests/schematic-ng-add-standalone.spec.ts @@ -50,6 +50,7 @@ describe('ng-add [Standalone]', () => { "@angular/core": "~13.0.0", "@taiga-ui/cdk": "${TAIGA_VERSION}", "@taiga-ui/core": "${TAIGA_VERSION}", + "@taiga-ui/event-plugins": "^4.0.2", "@taiga-ui/icons": "${TAIGA_VERSION}", "@taiga-ui/kit": "${TAIGA_VERSION}" } @@ -75,6 +76,7 @@ describe('ng-add [Standalone]', () => { "@taiga-ui/addon-mobile": "${TAIGA_VERSION}", "@taiga-ui/cdk": "${TAIGA_VERSION}", "@taiga-ui/core": "${TAIGA_VERSION}", + "@taiga-ui/event-plugins": "^4.0.2", "@taiga-ui/icons": "${TAIGA_VERSION}", "@taiga-ui/kit": "${TAIGA_VERSION}" } diff --git a/projects/cdk/schematics/ng-add/tests/schematic-ng-add.spec.ts b/projects/cdk/schematics/ng-add/tests/schematic-ng-add.spec.ts index c23e7fe32b5c..db4299cb1ce6 100644 --- a/projects/cdk/schematics/ng-add/tests/schematic-ng-add.spec.ts +++ b/projects/cdk/schematics/ng-add/tests/schematic-ng-add.spec.ts @@ -50,6 +50,7 @@ describe('ng-add', () => { "@angular/core": "~13.0.0", "@taiga-ui/cdk": "${TAIGA_VERSION}", "@taiga-ui/core": "${TAIGA_VERSION}", + "@taiga-ui/event-plugins": "^4.0.2", "@taiga-ui/icons": "${TAIGA_VERSION}", "@taiga-ui/kit": "${TAIGA_VERSION}" } @@ -75,6 +76,7 @@ describe('ng-add', () => { "@taiga-ui/addon-mobile": "${TAIGA_VERSION}", "@taiga-ui/cdk": "${TAIGA_VERSION}", "@taiga-ui/core": "${TAIGA_VERSION}", + "@taiga-ui/event-plugins": "^4.0.2", "@taiga-ui/icons": "${TAIGA_VERSION}", "@taiga-ui/kit": "${TAIGA_VERSION}" } @@ -100,6 +102,7 @@ describe('ng-add', () => { "@taiga-ui/addon-mobile": "${TAIGA_VERSION}", "@taiga-ui/cdk": "${TAIGA_VERSION}", "@taiga-ui/core": "${TAIGA_VERSION}", + "@taiga-ui/event-plugins": "^4.0.2", "@taiga-ui/icons": "${TAIGA_VERSION}", "@taiga-ui/kit": "${TAIGA_VERSION}" } @@ -235,6 +238,28 @@ describe('ng-add', () => { `); }); + it('should add root and provider to main module', async () => { + const tree = await runner.runSchematic( + 'ng-add-setup-project', + {'skip-logs': process.env['TUI_CI'] === 'true'} as Partial, + host, + ); + + expect(tree.readContent('test/app/app.module.ts')) + .toBe(`import { NG_EVENT_PLUGINS } from "@taiga-ui/event-plugins"; +import { TuiRoot } from "@taiga-ui/core"; +import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; +import {NgModule} from '@angular/core'; +import {App} from './app.component'; + +@NgModule({declarations: [App], + imports: [BrowserAnimationsModule, TuiRoot], + providers: [NG_EVENT_PLUGINS] +}) +export class AppModule {} +`); + }); + afterEach(() => { resetActiveProject(); });