Skip to content

Commit e06394a

Browse files
Release v34 (#116)
Maintain version compatibility with AG Grid.
2 parents 21b404f + 2831316 commit e06394a

File tree

29 files changed

+230
-20
lines changed

29 files changed

+230
-20
lines changed

packages/ast/src/types/transform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export interface FsContext extends TransformContext {
4747
}
4848

4949
export interface AstCliContext extends FsContext {
50-
warn(node: NodePath<AstNode> | null, message: string): void;
51-
fail(node: NodePath<AstNode> | null, message: string): void;
50+
warn(node: NodePath<AstNode> | Error | null, message: string): void;
51+
fail(node: NodePath<AstNode> | Error | null, message: string): void;
5252
}
5353

5454
export type AstTransformResult = {

packages/cli/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ The AG Grid developer toolkit is distributed as a command-line tool that assists
99
Run the following command to list available commands:
1010

1111
```
12-
npx @ag-grid-devtools/cli --help
12+
npx @ag-grid-devtools/cli@latest --help
1313
```
1414

15-
> _Note that it is recommended to run a specific version of the developer toolkit, e.g._ `@ag-grid-devtools/cli@31.0`
15+
> _Note that it is recommended to run the latest version of the developer toolkit, e.g._ `@ag-grid-devtools/cli@latest` as this will contain all previous migrations as well as the latest bug fixes.
1616
1717
### Available commands
1818

1919
The CLI tool contains the following commands:
2020

2121
- `migrate`: Migrate an existing codebase to use a newer version of AG grid
2222

23-
See the command-line help for more details.
23+
See the command-line help for more details or the [AG Grid Docs](https://ag-grid.com/javascript-data-grid/codemods/).

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@ag-grid-devtools/cli",
4-
"version": "33.3.0",
4+
"version": "34.0.0",
55
"license": "MIT",
66
"description": "AG Grid developer toolkit",
77
"author": "AG Grid <[email protected]>",

packages/cli/src/codemods/plugins/jscodeshift/jscodeshift.adapter.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import j, { Collection } from 'jscodeshift';
2-
import { AstCliContext, AstTransform, NodePath } from '@ag-grid-devtools/ast';
2+
import { AstCliContext, AstTransform, NodePath, Node } from '@ag-grid-devtools/ast';
33

4-
export type JSCodeShiftTransformer = (root: Collection) => void | any;
4+
export type ErrorSpec = { path: j.ASTPath<j.Node>; message: string };
5+
6+
export type JSCodeShiftTransformer = (root: Collection) => void | {
7+
errors: ErrorSpec[];
8+
warnings: ErrorSpec[];
9+
};
510

611
// Use https://astexplorer.net/ to iterate on your transformer
712
// Parser: Typescript
@@ -15,11 +20,16 @@ export type JSCodeShiftTransformer = (root: Collection) => void | any;
1520
export const jsCodeShiftTransform = (
1621
...transforms: JSCodeShiftTransformer[]
1722
): AstTransform<AstCliContext> => {
23+
const errors: Error[] = [];
24+
const warnings: Error[] = [];
25+
let source: any;
26+
1827
return (_babel) => ({
1928
visitor: {
2029
Program: {
2130
exit(path: NodePath) {
22-
const root: Collection<any> = j((path.hub as any).file.ast);
31+
source = (path.hub as any).file.ast;
32+
const root: Collection<any> = j(source);
2333
const getFirstNode = () => root.find(j.Program).get('body', 0).node;
2434

2535
// save initial comment if any
@@ -28,7 +38,21 @@ export const jsCodeShiftTransform = (
2838

2939
// transform
3040
for (const transform of transforms) {
31-
transform(root);
41+
const result = transform(root);
42+
if (result?.errors) {
43+
errors.push(
44+
...result.errors.map((error) =>
45+
path.hub.buildError(error.path.node as Node, error.message),
46+
),
47+
);
48+
}
49+
if (result?.warnings) {
50+
warnings.push(
51+
...result.warnings.map((warning) =>
52+
path.hub.buildError(warning.path.node as Node, warning.message),
53+
),
54+
);
55+
}
3256
}
3357

3458
// restore initial comment if any
@@ -43,5 +67,14 @@ export const jsCodeShiftTransform = (
4367
},
4468
},
4569
},
70+
post(_file) {
71+
for (const warning of warnings) {
72+
this.opts.warn(warning, warning.message);
73+
}
74+
75+
for (const error of errors) {
76+
this.opts.fail(error, error.message);
77+
}
78+
},
4679
});
4780
};

packages/cli/src/codemods/transforms/transform-modules-to-packages-v33/transformers/package-transforms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const packageLicenseManager: JSCodeShiftTransformer = (root) => {
4747

4848
if (alreadyExists) {
4949
// This package file already has a ModuleRegistry import so looks like it has already been transformed
50-
return root.toSource();
50+
return;
5151
}
5252

5353
const usingCharts: UsingCharts = process.env.AG_USING_CHARTS as any;

packages/cli/src/codemods/transforms/transform-sparklines-options-v33-0/transformers/sparkline-chart-type-subobject.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { JSCodeShiftTransformer } from '../../../plugins/jscodeshift';
44
const chartTypeKeys = ['area', 'bar', 'column', 'line'];
55

66
// find [chart-type] keys, and merge their contents into the parent object
7-
export const chartTypeSubobject: JSCodeShiftTransformer = (root) =>
7+
export const chartTypeSubobject: JSCodeShiftTransformer = (root) => {
88
root
99
.find(j.ObjectProperty, { key: { name: 'cellRendererParams' } })
1010
.find(j.ObjectProperty, { key: { name: 'sparklineOptions' } })
@@ -17,3 +17,4 @@ export const chartTypeSubobject: JSCodeShiftTransformer = (root) =>
1717
});
1818
path.replace();
1919
});
20+
};

packages/cli/src/codemods/transforms/transform-sparklines-options-v33-0/transformers/sparkline-column.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import j from 'jscodeshift';
22
import { JSCodeShiftTransformer } from '../../../plugins/jscodeshift';
33

44
// update bar/column types to bar with matching direction
5-
export const columnToVerticalBarTransform: JSCodeShiftTransformer = (root) =>
5+
export const columnToVerticalBarTransform: JSCodeShiftTransformer = (root) => {
66
root
77
.find(j.ObjectProperty, { key: { name: 'cellRendererParams' } })
88
.find(j.ObjectProperty, { key: { name: 'sparklineOptions' } })
@@ -14,3 +14,4 @@ export const columnToVerticalBarTransform: JSCodeShiftTransformer = (root) =>
1414
path.replace(j.objectProperty(j.identifier('type'), j.stringLiteral('bar')));
1515
path.insertAfter(j.objectProperty(j.identifier('direction'), j.stringLiteral(direction)));
1616
});
17+
};
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import j from 'jscodeshift';
22
import { JSCodeShiftTransformer } from '../../../plugins/jscodeshift';
33

4-
export const removeCrosshairs: JSCodeShiftTransformer = (root) =>
4+
export const removeCrosshairs: JSCodeShiftTransformer = (root) => {
55
root
66
.find(j.ObjectProperty, { key: { name: 'cellRendererParams' } })
77
.find(j.ObjectProperty, { key: { name: 'sparklineOptions' } })
88
.find(j.ObjectProperty, { key: { name: 'crosshairs' } })
99
.forEach((path) => path.replace());
10+
};

packages/cli/src/codemods/transforms/transform-sparklines-options-v33-0/transformers/sparkline-types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import j from 'jscodeshift';
22
import { JSCodeShiftTransformer } from '../../../plugins/jscodeshift';
33
import { newType, oldTypes } from './constants';
44

5-
export const replaceTypes: JSCodeShiftTransformer = (root) =>
5+
export const replaceTypes: JSCodeShiftTransformer = (root) => {
66
root
77
.find(j.TSTypeReference)
88
.filter((path) => oldTypes.includes((path.value.typeName as any).name))
99
.forEach((path) => path.replace(j.tsTypeReference(j.identifier(newType))));
10+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 34.0.0
2+
3+
Codemod for upgrading to [AG Grid v34.0.0](https://github.com/ag-grid/ag-grid/releases/tag/v34.0.0)
4+
5+
## Usage
6+
7+
```
8+
npx @ag-grid-devtools/cli migrate --to 34.0.0
9+
```
10+
11+
Source code transformations applied by this codemod are specified in [`transforms.ts`](./transforms.ts).
12+
13+
## Common tasks
14+
15+
### Add a transform
16+
17+
Option 1: Create a new source code transformation to add to this codemod release version:
18+
19+
```
20+
pnpm run task:create-transform --release 34.0.0
21+
```
22+
23+
Option 2: Add an existing source code transformation to this codemod release version:
24+
25+
```
26+
pnpm run task:include-transform --version 34.0.0
27+
```
28+
29+
### Add a test case
30+
31+
Create a new unit test scenario for this version:
32+
33+
```
34+
pnpm run task:create-test --type version --target 34.0.0
35+
```

0 commit comments

Comments
 (0)