Skip to content

Commit

Permalink
Release v33.0.0 (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenCooper authored Dec 11, 2024
2 parents b4cb82d + 12ae31a commit 15482ac
Show file tree
Hide file tree
Showing 241 changed files with 4,921 additions and 147 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ pnpm install
### Contributing

See the [Developer Guide](./DEVELOPER.md) for more details.

6 changes: 5 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@ag-grid-devtools/cli",
"version": "32.2.1",
"version": "33.0.0",
"license": "MIT",
"description": "AG Grid developer toolkit",
"author": "AG Grid <info@ag-grid.com>",
Expand Down Expand Up @@ -78,6 +78,8 @@
},
"types": "./index.d.ts",
"dependencies": {
"@types/jscodeshift": "0.12.0",
"jscodeshift": "17.1.1",
"@typescript-eslint/parser": "7.18.0",
"eslint": "8.57.0",
"tsx": "4.19.1"
Expand All @@ -94,12 +96,14 @@
"@ag-grid-devtools/worker-utils": "workspace:*",
"@types/diff": "5.2.2",
"@types/graceful-fs": "4.1.9",
"@types/jscodeshift": "0.12.0",
"@types/node": "22.7.3",
"@types/semver": "7.5.8",
"diff": "5.2.0",
"glob": "11.0.0",
"graceful-fs": "4.2.11",
"ignore": "5.3.2",
"jscodeshift": "17.1.1",
"prettier": "3.3.3",
"semver": "7.6.3",
"vite-plugin-dts": "4.0.3",
Expand Down
10 changes: 9 additions & 1 deletion packages/cli/src/codemods/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { expect, test } from 'vitest';

import * as lib from './lib';

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

test('module exports', () => {
expect({ ...lib }).toEqual({
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/codemods/plugins/jscodeshift/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# jscodeshift Plugin

The `jscodeshift` plugin is a tool used for running codemods over JavaScript and TypeScript codebases. It leverages the `jscodeshift` library, which provides a simple API for transforming code using the power of abstract syntax trees (ASTs).
2 changes: 2 additions & 0 deletions packages/cli/src/codemods/plugins/jscodeshift/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './jscodeshift.adapter';
export * from './transforms';
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import j, { Collection } from 'jscodeshift';
import { AstCliContext, AstTransform, NodePath } from '@ag-grid-devtools/ast';

export type JSCodeShiftTransformer = (root: Collection) => void | any;

// Use https://astexplorer.net/ to iterate on your transformer
// Parser: Typescript
// Transform: jscodeshift
//
// NOTE: Less efficient than the raw visitor pattern, but:
// * + easier to write (the tree is already parsed)
// * + easier to reason about
// * + easier to iterate over
// * - multiple passes through parse/transform cycle
export const jsCodeShiftTransform = (
...transforms: JSCodeShiftTransformer[]
): AstTransform<AstCliContext> => {
return (_babel) => ({
visitor: {
Program: {
exit(path: NodePath) {
const root: Collection<any> = j((path.hub as any).file.ast);
const getFirstNode = () => root.find(j.Program).get('body', 0).node;

// save initial comment if any
const firstNode = getFirstNode();
const { comments } = firstNode;

// transform
for (const transform of transforms) {
transform(root);
}

// restore initial comment if any
const firstNode2 = getFirstNode();
if (firstNode2 !== firstNode) {
firstNode2.comments = comments;
}

// inject result back into babel AST
const program = root.getAST()[0].node.program;
path.replaceWith(program);
},
},
},
});
};
4 changes: 4 additions & 0 deletions packages/cli/src/codemods/plugins/jscodeshift/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "JSCodeshift",
"description": "Transform using JSCodeshift"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './multi-type-import-to-single';
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import j, { Collection } from 'jscodeshift';
import { JSCodeShiftTransformer } from '../jscodeshift.adapter';

// Find old named imports and replace them with the new named import
// remove the old import if no other named imports are present
export const multiTypeImportToSingle =
(
oldPackage: string,
oldImports: string[],
newPackage: string,
newImport: string,
): JSCodeShiftTransformer =>
(root) => {
// find old imports
const importToBeInspected: Collection<any> = root
.find(j.ImportDeclaration)
.filter((path) => path.node.source.value === oldPackage);

// get all named imports in old import
const allSpecifiers = importToBeInspected.find(j.ImportSpecifier);

// get all old named imports
const importsToBeRemoved = allSpecifiers.filter((path) =>
oldImports.includes(path.node.imported.name),
);

const matches = importsToBeRemoved.length;
const nonMatchingImports = allSpecifiers.length - matches;

// remove old named imports, if any
importsToBeRemoved.forEach((path) => path.replace());

// remove import line if no other named imports were present
if (nonMatchingImports === 0) {
const importSpecifiers = importToBeInspected.find(j.ImportSpecifier);
if (importSpecifiers.length === 0) {
importToBeInspected.forEach((path) => path.replace());
}
}

// no need to add new import if no old imports were found
if (matches === 0) {
return;
}

// construct new import
const newImportDeclaration = j.importDeclaration(
[j.importSpecifier(j.identifier(newImport))],
j.stringLiteral(newPackage),
'type',
);

// find attachment point
const imports = root.find(j.ImportDeclaration);

if (imports.length > 0) {
// after imports
imports.insertAfter(newImportDeclaration);
} else {
// top of file
root.get().node.program.body.unshift(newImportDeclaration);
}
};
2 changes: 2 additions & 0 deletions packages/cli/src/codemods/test/runners/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export function loadTransformScenarios(
options: {
transforms: Array<AstTransform<AstCliContext> | AstTransformWithOptions<AstCliContext>>;
vitest: ExampleVitestHelpers;
test?: (filename: string) => boolean;
userConfig?: UserConfig;
},
): void {
const { transforms, vitest, userConfig } = options;
return loadAstTransformExampleScenarios(scenariosPath, {
vitest,
test: options.test,
runner: (input) => {
const { source, errors, warnings } = transformFileAst(input.source, transforms, {
filename: input.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ gridApi.addAggFunc({
foo: () => {}
});
gridApi.addAggFunc({
"foo bar": () => {}
'foo bar': () => {}
});
gridApi.addAggFunc({
[(() => 'foo')()]: () => {}
Expand Down
Loading

0 comments on commit 15482ac

Please sign in to comment.