From 0a5f852be0b09e9866c105b9c4369e0c4f05ad0c Mon Sep 17 00:00:00 2001 From: Steve Brush Date: Thu, 23 Jan 2025 10:28:13 -0500 Subject: [PATCH] fix(components/packages): remove v11 `ag-grid` schematic (#3053) --- .../migrations/migration-collection.json | 5 - .../ag-grid/ag-grid.schematic.spec.ts | 160 ------------------ .../update-12/ag-grid/ag-grid.schematic.ts | 139 --------------- .../migrations/update-12/ag-grid/schema.json | 5 - 4 files changed, 309 deletions(-) delete mode 100644 libs/components/packages/src/schematics/migrations/update-12/ag-grid/ag-grid.schematic.spec.ts delete mode 100644 libs/components/packages/src/schematics/migrations/update-12/ag-grid/ag-grid.schematic.ts delete mode 100644 libs/components/packages/src/schematics/migrations/update-12/ag-grid/schema.json diff --git a/libs/components/packages/src/schematics/migrations/migration-collection.json b/libs/components/packages/src/schematics/migrations/migration-collection.json index 42f0d5c372..3e725b1c54 100644 --- a/libs/components/packages/src/schematics/migrations/migration-collection.json +++ b/libs/components/packages/src/schematics/migrations/migration-collection.json @@ -5,11 +5,6 @@ "factory": "./noop/noop.schematic", "description": "Update all SKY UX component packages" }, - "ag-grid": { - "version": "0.0.0-PLACEHOLDER", - "factory": "./update-12/ag-grid/ag-grid.schematic", - "description": "Apply code changes for AG Grid 32." - }, "axe-core": { "version": "0.0.0-PLACEHOLDER", "factory": "./update-12/axe-core/axe-core.schematic", diff --git a/libs/components/packages/src/schematics/migrations/update-12/ag-grid/ag-grid.schematic.spec.ts b/libs/components/packages/src/schematics/migrations/update-12/ag-grid/ag-grid.schematic.spec.ts deleted file mode 100644 index 73d066cf1b..0000000000 --- a/libs/components/packages/src/schematics/migrations/update-12/ag-grid/ag-grid.schematic.spec.ts +++ /dev/null @@ -1,160 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; - -import fs from 'fs-extra'; -import { joinPathFragments } from 'nx/src/utils/path'; -import { workspaceRoot } from 'nx/src/utils/workspace-root'; - -const UPDATE_TO_VERSION = '32.3.3'; - -describe('ag-grid.schematic', () => { - const runner = new SchematicTestRunner( - 'schematics', - require.resolve('../../migration-collection.json'), - ); - const angularJson = { - version: 1, - projects: { - test: { - projectType: 'application', - root: '', - architect: {}, - }, - }, - }; - - function setupTest( - packageJson: Record> = {}, - ): { tree: Tree } { - const tree = Tree.empty(); - tree.create('/angular.json', JSON.stringify(angularJson)); - tree.create('/package.json', JSON.stringify(packageJson)); - return { tree }; - } - - it('should test the current version', () => { - const packageJson = fs.readJSONSync( - joinPathFragments(workspaceRoot, 'package.json'), - ); - expect(packageJson.dependencies['ag-grid-community']).toBe( - UPDATE_TO_VERSION, - ); - }); - - it('should work', async () => { - expect.assertions(1); - const { tree } = setupTest({ - dependencies: { - 'ag-grid-community': UPDATE_TO_VERSION, - 'ag-grid-angular': UPDATE_TO_VERSION, - 'ag-grid-enterprise': UPDATE_TO_VERSION, - }, - }); - await runner.runSchematic('ag-grid', {}, tree); - expect(JSON.parse(tree.readText('/package.json'))).toEqual({ - dependencies: { - 'ag-grid-community': UPDATE_TO_VERSION, - 'ag-grid-angular': UPDATE_TO_VERSION, - 'ag-grid-enterprise': UPDATE_TO_VERSION, - }, - }); - }); - - it('should add missing peer', async () => { - expect.assertions(1); - const { tree } = setupTest({ - dependencies: { - 'ag-grid-angular': UPDATE_TO_VERSION, - }, - }); - await runner.runSchematic('ag-grid', {}, tree); - expect(JSON.parse(tree.readText('/package.json'))).toEqual({ - dependencies: { - 'ag-grid-community': `^${UPDATE_TO_VERSION}`, - 'ag-grid-angular': UPDATE_TO_VERSION, - }, - }); - }); - - it('should noop', async () => { - expect.assertions(1); - const { tree } = setupTest({ - dependencies: { - other: '27.1.1', - }, - }); - await runner.runSchematic('ag-grid', {}, tree); - expect(JSON.parse(tree.readText('/package.json'))).toEqual({ - dependencies: { - other: '27.1.1', - }, - }); - }); - - it('should warn about mixing modules and packages', async () => { - expect.assertions(1); - const { tree } = setupTest({ - dependencies: { - '@ag-grid-community/core': UPDATE_TO_VERSION, - '@skyux/ag-grid': '0.0.0', - 'ag-grid-community': UPDATE_TO_VERSION, - 'ag-grid-angular': UPDATE_TO_VERSION, - }, - }); - tree.create( - 'src/app/app.component.ts', - ` - import { SkyAgGridService } from '@skyux/ag-grid'; - import { GridOptions } from '@ag-grid-community/core'; - - export class AppComponent { - public options: GridOptions; - #agGridService: SkyAgGridService; - - constructor(agGridService: SkyAgGridService) { - this.#agGridService = agGridService; - let customOptions: Partial = {}; - customOptions.suppressCellSelection = true; - this.options = this.agGridService.getGridOptions({ - ...customOptions, - suppressCellSelection: true - }); - } - }`, - ); - tree.create( - 'src/app/ent.component.ts', - ` - import { SkyAgGridService } from '@skyux/ag-grid'; - import { GridOptions } from '@ag-grid-enterprise/core'; - - export class AppComponent { - public options: GridOptions; - #agGridService: SkyAgGridService; - - constructor(agGridService: SkyAgGridService) { - this.#agGridService = agGridService; - let customOptions: Partial = {}; - customOptions.suppressCellSelection = true; - this.options = this.agGridService.getGridOptions({ - ...customOptions, - suppressCellSelection: true - }); - } - }`, - ); - tree.create( - 'src/app/options.component.ts', - `import { SkyGetGridOptionsArgs } from '@skyux/ag-grid';`, - ); - tree.create( - 'src/app/other.component.ts', - `import { ColDef } from '@ag-grid-community/core';`, - ); - tree.create('src/app/unrelated.component.ts', `// No grid.`); - await runner.runSchematic('ag-grid', {}, tree); - expect(tree.readText('src/app/other.component.ts')).toEqual( - `import { ColDef } from '@ag-grid-community/core';`, - ); - }); -}); diff --git a/libs/components/packages/src/schematics/migrations/update-12/ag-grid/ag-grid.schematic.ts b/libs/components/packages/src/schematics/migrations/update-12/ag-grid/ag-grid.schematic.ts deleted file mode 100644 index aa8c38b009..0000000000 --- a/libs/components/packages/src/schematics/migrations/update-12/ag-grid/ag-grid.schematic.ts +++ /dev/null @@ -1,139 +0,0 @@ -import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; -import { - NodePackageInstallTask, - RunSchematicTask, -} from '@angular-devkit/schematics/tasks'; -import { - NodeDependencyType, - addPackageJsonDependency, - getPackageJsonDependency, -} from '@schematics/angular/utility/dependencies'; - -import { visitProjectFiles } from '../../../utility/visit-project-files'; -import { getWorkspace } from '../../../utility/workspace'; - -const ANY_MODULE = '@ag-grid-community/'; -const ENT_MODULE = '@ag-grid-enterprise/'; -const AG_GRID = 'ag-grid-community'; -const AG_GRID_ENT = 'ag-grid-enterprise'; -const AG_GRID_NG = 'ag-grid-angular'; -const AG_GRID_SKY = '@skyux/ag-grid'; - -const AG_GRID_VERSION = '^32.3.3'; - -/** - * Check package.json for AG Grid dependencies. - */ -function checkAgGridDependency(tree: Tree, context: SchematicContext): boolean { - const agGridDependency = getPackageJsonDependency(tree, AG_GRID); - const agGridDependencyEnt = getPackageJsonDependency(tree, AG_GRID_ENT); - const agGridDependencyNg = getPackageJsonDependency(tree, AG_GRID_NG); - if (agGridDependency || agGridDependencyEnt || agGridDependencyNg) { - if (!agGridDependency) { - // Missing peer dependency. - addPackageJsonDependency(tree, { - name: AG_GRID, - type: NodeDependencyType.Default, - version: AG_GRID_VERSION, - }); - context.addTask(new NodePackageInstallTask()); - } - return true; - } - - const packageJson = tree.readJson('package.json') as Record< - string, - Record - >; - - return ['dependencies', 'devDependencies'].some((dep) => - Object.keys((packageJson && packageJson[dep]) || {}).some( - (dep) => dep.startsWith(ANY_MODULE) || dep.startsWith(ENT_MODULE), - ), - ); -} - -/** - * Check if the file includes any AG Grid imports. - */ -function includesAgGrid(updatedContent: string): boolean { - return ( - updatedContent.includes(AG_GRID) || - updatedContent.includes(AG_GRID_ENT) || - updatedContent.includes(AG_GRID_SKY) - ); -} - -/** - * Visit all files and apply the changes. - */ -async function updateSourceFiles( - tree: Tree, - context: SchematicContext, -): Promise { - const warned: string[] = []; - - function warnOnce(message: string) { - if (!warned.includes(message)) { - warned.push(message); - context.logger.warn(message); - } - } - - const { workspace } = await getWorkspace(tree); - workspace.projects.forEach((project) => { - context.logger.debug( - `Running SKY UX AG Grid updates within ${project.sourceRoot || project.root}.`, - ); - visitProjectFiles(tree, project.sourceRoot || project.root, (filePath) => { - // If the file is not a TypeScript file, we can skip it. - if (!filePath.endsWith('.ts') || filePath.includes('schematics')) { - return; - } - const content = tree.readText(filePath); - if (!content || !includesAgGrid(content)) { - return; - } - - // Prompt the user to moderate the use of AG Grid modules - if (content.includes(ANY_MODULE) || content.includes(ENT_MODULE)) { - warnOnce( - `\n - AG Grid recommends not mixing module and package imports. - https://ag-grid.com/angular-data-grid/modules/\n\n`, - ); - } - }); - }); -} - -/** - * Upgrade to AG Grid 32 and address breaking changes: - * - * Also advise against mixing modules and packages. - */ -export default function (): Rule { - return async (tree: Tree, context: SchematicContext): Promise => { - const hasAgGrid = checkAgGridDependency(tree, context); - - // AG Grid is not installed, so we don't need to do anything. - if (!hasAgGrid) { - context.logger.debug(`AG Grid is not installed.`); - return; - } - - await updateSourceFiles(tree, context); - const { workspace } = await getWorkspace(tree); - for (const project of workspace.projects.values()) { - const sourceRoot = project.sourceRoot || `${project.root}/src`; - context.logger.debug( - `Scheduling AG Grid code modifications for ${sourceRoot}.`, - ); - context.addTask( - new RunSchematicTask('@skyux/packages', 'ag-grid-migrate', { - sourceRoot, - }), - ); - } - }; -} diff --git a/libs/components/packages/src/schematics/migrations/update-12/ag-grid/schema.json b/libs/components/packages/src/schematics/migrations/update-12/ag-grid/schema.json deleted file mode 100644 index 0007fb2db8..0000000000 --- a/libs/components/packages/src/schematics/migrations/update-12/ag-grid/schema.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "type": "object", - "properties": {} -}