Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codemod for v31.2.0 #18

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/codemods/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from 'vitest';

import * as lib from './lib';

const versions: Array<string> = ['31.0.0', '31.1.0'];
const versions: Array<string> = ['31.0.0', '31.1.0', '31.2.0'];

test('module exports', () => {
expect({ ...lib }).toEqual({
Expand Down
8 changes: 7 additions & 1 deletion packages/codemods/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@ag-grid-community/codemods",
"version": "31.1.0",
"version": "31.2.0",
"license": "MIT",
"description": "AG Grid codemods",
"author": "AG Grid <[email protected]>",
Expand Down Expand Up @@ -49,6 +49,12 @@
},
"./version/31.1.0/worker.cjs": {
"require": "./version/31.1.0/worker.cjs"
},
"./version/31.2.0/codemod.cjs": {
"require": "./version/31.2.0/codemod.cjs"
},
"./version/31.2.0/worker.cjs": {
"require": "./version/31.2.0/worker.cjs"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type Types } from '@ag-grid-devtools/ast';
import {
getDeprecationMessage,
transformObjectProperties,
Expand All @@ -12,7 +11,7 @@ import {
type CodemodObjectPropertyReplacement,
} from '../../plugins/transform-grid-options/transform-grid-options';

const MIGRATION_URL_V31_1 = 'https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-31-1/';
const MIGRATION_URL = 'https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-31-1/';

export const replacements: Array<CodemodObjectPropertyReplacement> = transformObjectProperties({
cellFlashDelay: migrateProperty('cellFlashDuration', migrateOptionalValue()),
Expand All @@ -30,7 +29,7 @@ export const replacements: Array<CodemodObjectPropertyReplacement> = transformOb
suppressFilterButton: removeProperty(
getDeprecationMessage(
'columnDefs[..].floatingFilterComponentParams.suppressFilterButton',
MIGRATION_URL_V31_1,
MIGRATION_URL,
),
),
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# `transform-grid-options-v31-2`

> _Transform deprecated Grid options_

Replacement rules are specified in [`replacements.ts`](./replacements.ts).

See the [`transform-grid-options`](../../plugins/transform-grid-options/) plugin for usage instructions.

## Common tasks

### Add a new rule

Replacement rules are specified in [`replacements.ts`](./replacements.ts)

### Add a test case

Create a new unit test scenario for this transform:

```
pnpm run task:create-test --type transform --target transform-grid-options-v31-2
```

### Add to a codemod release

Add this source code transformation to a codemod release:

```
pnpm run task:include-transform --transform transform-grid-options-v31-2
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createGrid } from '@ag-grid-community/core';

const gridApi = createGrid(document.body, {
columnDefs: [
{
colId: 'foo',
},
{
colId: 'bar',
suppressCellFlash: true,
},
{
colId: 'baz',
suppressCellFlash: false,
}
],
rowData: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createGrid } from '@ag-grid-community/core';

const gridApi = createGrid(document.body, {
columnDefs: [
{
colId: 'foo',
},
{
colId: 'bar',
enableCellChangeFlash: false,
},
{
colId: 'baz',
enableCellChangeFlash: true,
}
],
rowData: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scenario": {
"input": "input.js",
"output": "output.js",
"errors": null,
"warnings": null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createGrid } from '@ag-grid-community/core';

const gridApi = createGrid(document.body, {
columnDefs: [
{
colId: 'foo',
dndSource: true,
},
{
colId: 'bar',
dndSource: false,
},
{
colId: 'baz',
dndSource: () => {},
dndSourceOnRowDrag: () => {},
}
],
rowData: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createGrid } from '@ag-grid-community/core';

const gridApi = createGrid(document.body, {
columnDefs: [
{
colId: 'foo',
dndSource: true,
},
{
colId: 'bar',
dndSource: false,
},
{
colId: 'baz',
dndSource: () => {},
dndSourceOnRowDrag: () => {},
}
],
rowData: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = [
new SyntaxError(`The grid option "columnDefs[..].dndSource" is deprecated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-31-2/

> | dndSource: true,
| ^^^^^^^^^^^^^^^`),
new SyntaxError(`The grid option "columnDefs[..].dndSource" is deprecated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-31-2/

> | dndSource: false,
| ^^^^^^^^^^^^^^^^`),
new SyntaxError(`The grid option "columnDefs[..].dndSource" is deprecated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-31-2/

> | dndSource: () => {},
| ^^^^^^^^^^^^^^^^^^^`),
new SyntaxError(`The grid option "columnDefs[..].dndSourceOnRowDrag" is deprecated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-31-2/

> | dndSourceOnRowDrag: () => {},
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`),
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scenario": {
"input": "input.js",
"output": "output.js",
"errors": null,
"warnings": "output.warnings.cjs"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createGrid } from '@ag-grid-community/core';

const gridApi = createGrid(document.body, {
columnDefs: [
{
colId: 'foo',
dndSource: true,
},
{
colId: 'bar',
dndSource: false,
},
{
colId: 'baz',
dndSource: () => {},
dndSourceOnRowDrag: () => {},
}
],
rowData: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createGrid } from '@ag-grid-community/core';

const gridApi = createGrid(document.body, {
columnDefs: [
{
colId: 'foo'
},
{
colId: 'bar'
},
{
colId: 'baz'
}
],
rowData: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createGrid } from '@ag-grid-community/core';

const gridApi = createGrid(document.body, {
columnDefs: [],
rowData: [],
enableCellChangeFlash: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createGrid } from '@ag-grid-community/core';

const gridApi = createGrid(document.body, {
columnDefs: [],
rowData: [],
enableCellChangeFlash: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = [
new SyntaxError(`The grid option "enableCellChangeFlash" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-31-2/

> | enableCellChangeFlash: true,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^`),
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scenario": {
"input": "input.js",
"output": "output.js",
"errors": null,
"warnings": "output.warnings.cjs"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createGrid } from '@ag-grid-community/core';

const gridApi = createGrid(document.body, {
columnDefs: [],
rowData: [],
enableCellChangeFlash: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createGrid } from '@ag-grid-community/core';

const gridApi = createGrid(document.body, {
columnDefs: [],
rowData: []
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"scenario": {
"input": "input.jsx",
"output": "output.jsx",
"input": "input.js",
"output": "output.js",
"errors": null,
"warnings": null,
"options": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './transform-grid-options-v31-2';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { type TransformManifest } from '@ag-grid-devtools/types';

const manifest: TransformManifest = {
name: 'Transform Grid options v31.2',
description: 'Transform deprecated Grid options',
};

export default manifest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
getManualInterventionMessage,
invertOptionalBooleanValue,
migrateProperty,
removeProperty,
transformObjectListValue,
transformObjectProperties,
transformOptionalValue,
transformPropertyValue,
type CodemodObjectPropertyReplacement,
getDeprecationMessage,
} from '../../plugins/transform-grid-options/transform-grid-options';

const MIGRATION_URL = 'https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-31-2/';

export const replacements: Array<CodemodObjectPropertyReplacement> = transformObjectProperties({
enableCellChangeFlash: removeProperty(
getManualInterventionMessage('enableCellChangeFlash', MIGRATION_URL),
),
columnDefs: transformPropertyValue(
transformOptionalValue(
transformObjectListValue(
transformObjectProperties({
suppressCellFlash: migrateProperty('enableCellChangeFlash', invertOptionalBooleanValue()),
dndSource: removeProperty(
getDeprecationMessage('columnDefs[..].dndSource', MIGRATION_URL),
),
dndSourceOnRowDrag: removeProperty(
getDeprecationMessage('columnDefs[..].dndSourceOnRowDrag', MIGRATION_URL),
),
}),
),
),
),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, onTestFinished, test } from 'vitest';
import { loadTransformScenarios } from '../../test/runners/transform';

import transformGridOptionsV31_2 from './transform-grid-options-v31-2';

const __dirname = dirname(fileURLToPath(import.meta.url));

describe(transformGridOptionsV31_2, () => {
const scenariosPath = join(__dirname, './__fixtures__/scenarios');
loadTransformScenarios(scenariosPath, {
transforms: [transformGridOptionsV31_2],
vitest: { describe, expect, test, onTestFinished },
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { type AstCliContext, type AstTransform } from '@ag-grid-devtools/ast';
import { transformGridOptions } from '../../plugins/transform-grid-options';
import { replacements } from './replacements';

const plugin: AstTransform<AstCliContext> = transformGridOptions(replacements);

const transform: AstTransform<AstCliContext> = function transformGridOptionsV31_2(babel) {
return plugin(babel);
};

export default transform;
Loading
Loading