Skip to content
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"@types/glob": "8.1.0",
"glob": "11.0.0",
"prettier": "3.3.3",
"typedoc": "^0.26.6",
"typedoc": "^0.26.7",
"typescript": "5.5.4",
"tsx": "4.17.0",
"vite": "5.4.1",
"tsx": "4.19.1",
"vite": "5.4.4",
"vitest": "1.6.0",
"@vitest/coverage-v8": "1.6.0"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
},
"peerDependencies": {
"eslint": "8.57.0",
"typedoc": "^0.26.6",
"typedoc": "^0.26.7",
"typescript": "5.5.4",
"vite": "^5.4.1",
"vite": "^5.4.4",
"vitest": "^1.6.0"
}
}
2 changes: 1 addition & 1 deletion packages/build-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"prettier": "3.3.3",
"rollup-plugin-preserve-shebang": "1.0.1",
"typescript": "5.5.4",
"vite": "^5.4.1",
"vite": "^5.4.4",
"vite-plugin-dts": "4.0.3",
"vite-plugin-node-polyfills": "0.22.0",
"vite-plugin-static-copy": "1.0.6",
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"dependencies": {
"@typescript-eslint/parser": "7.18.0",
"eslint": "8.57.0",
"tsx": "4.17.0"
"tsx": "4.19.1"
},
"devDependencies": {
"@ag-grid-devtools/ast": "workspace:*",
Expand All @@ -92,7 +92,7 @@
"@ag-grid-devtools/types": "workspace:*",
"@ag-grid-devtools/utils": "workspace:*",
"@ag-grid-devtools/worker-utils": "workspace:*",
"@types/diff": "5.2.1",
"@types/diff": "5.2.2",
"@types/graceful-fs": "4.1.9",
"@types/node": "22.4.1",
"@types/semver": "7.5.8",
Expand All @@ -107,9 +107,9 @@
},
"peerDependencies": {
"eslint": "8.57.0",
"typedoc": "^0.26.6",
"typedoc": "^0.26.7",
"typescript": "5.5.4",
"vite": "^5.4.1",
"vite": "^5.4.4",
"vitest": "^1.6.0"
}
}
1 change: 1 addition & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Enum, dynamicRequire, match } from '@ag-grid-devtools/utils';
import path from 'path';
import {
parseArgs as parseMigrateCommandArgs,
cli as migrate,
Expand Down
23 changes: 12 additions & 11 deletions packages/cli/src/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Options:
See https://ag-grid.com/javascript-data-grid/codemods/#configuration-file

Additional arguments:
[<file>...] List of input files to operate on.
[<file>...<dir>...] List of input files and directories to operate on.
Defaults to all source files in the current working directory excluding patterns in .gitignore

Other options:
Expand Down Expand Up @@ -323,18 +323,19 @@ async function migrate(
? (await getGitSourceFiles(gitRoot)).map((path) => resolve(gitRoot, path))
: null;

let inputFilePaths: string[];

if (input.length > 0) {
inputFilePaths = input.map((path) => resolve(cwd, path));
} else {
const skipFiles: string[] = [];
if (userConfigPath) {
skipFiles.push(userConfigPath);
}
inputFilePaths = await findSourceFiles(cwd, SOURCE_FILE_EXTENSIONS, skipFiles, gitRoot);
let skipFiles = new Set<string>();
if (userConfigPath) {
skipFiles.add(userConfigPath);
}

const inputFilePaths = await findSourceFiles(
cwd,
input.length > 0 ? input : [cwd],
SOURCE_FILE_EXTENSIONS,
skipFiles,
gitRoot,
);

if (!allowUntracked) {
const trackedFilePaths = gitSourceFilePaths ? new Set(gitSourceFilePaths) : null;
let untrackedInputFiles = trackedFilePaths
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const exportedValue: string;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createGrid } from '@ag-grid-community/core';

(() => {
const gridOptions = { foo: 'bar' };
gridOptions.baz = 3;
const gridApi = createGrid(document.getQuerySelector('main'), gridOptions);
gridApi.sizeColumnsToFit();
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createGrid } from '@ag-grid-community/core';

(() => {
const gridOptions = { foo: 'bar' };
gridOptions.baz = 3;
const gridApi = createGrid(document.getQuerySelector('main'), gridOptions);
gridApi.sizeColumnsToFit();
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createGrid } from '@ag-grid-community/core';

(() => {
const gridOptions = { foo: 'bar' };
gridOptions.baz = 3;
const gridApi = createGrid(document.getQuerySelector('main'), gridOptions);
gridApi.sizeColumnsToFit();
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect, test } from 'vitest';
import { cli } from '../../../cli';
import { CliE2ETestEnv } from '../e2e-test-utils';

const env = new CliE2ETestEnv(import.meta.url);

test(
'cli e2e - input files and directories',
async () => {
await env.init();
await cli(
['migrate', '--num-threads=3', '--allow-untracked', '--from=30.0.0', 'file1.js', 'dir'],
env.cliOptions,
);
expect(await env.loadExpectedSrc('file1.js')).toEqual(await env.loadTempSrc('file1.js'));

expect(await env.loadExpectedSrc('dir/file2.js')).toEqual(
await env.loadTempSrc('dir/file2.js'),
);

expect(await env.loadExpectedSrc('dir/file3.js')).toEqual(
await env.loadTempSrc('dir/file3.js'),
);

expect(await env.loadInputSrc('untouched.js')).toEqual(await env.loadTempSrc('untouched.js'));
},
env.TIMEOUT,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Grid as AgGrid } from '@ag-grid-community/core';

(() => {
const gridOptions = { foo: 'bar' };
gridOptions.baz = 3;
new AgGrid(document.getQuerySelector('main'), gridOptions);
gridOptions.api.sizeColumnsToFit();
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Grid as AgGrid } from '@ag-grid-community/core';

(() => {
const gridOptions = { foo: 'bar' };
gridOptions.baz = 3;
new AgGrid(document.getQuerySelector('main'), gridOptions);
gridOptions.api.sizeColumnsToFit();
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Grid as AgGrid } from '@ag-grid-community/core';

(() => {
const gridOptions = { foo: 'bar' };
gridOptions.baz = 3;
new AgGrid(document.getQuerySelector('main'), gridOptions);
gridOptions.api.sizeColumnsToFit();
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Grid as AgGrid } from '@ag-grid-community/core';

(() => {
const gridOptions = { foo: 'untouched' };
gridOptions.baz = 3;
new AgGrid(document.getQuerySelector('main'), gridOptions);
gridOptions.api.sizeColumnsToFit();
})();
85 changes: 67 additions & 18 deletions packages/cli/src/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,77 @@ export async function findGitRoot(path: string): Promise<string | undefined> {
}
}

export async function isDirectory(path: string): Promise<boolean> {
try {
return (await stat(path)).isDirectory();
} catch {
return false;
}
}

async function resolveFilesOrDirectories(
input: string[],
cwd: string,
): Promise<{ filesSet: Set<string>; directoriesSet: Set<string> }> {
const files = new Set<string>();
const directories = new Set<string>();

const checks = input.map(async (item) => {
const fullPath = resolve(cwd, item);
try {
const statResult = await stat(fullPath);
if (statResult.isDirectory()) {
directories.add(fullPath);
} else {
files.add(fullPath);
}
} catch {
files.add(fullPath);
}
});

await Promise.all(checks);

return { filesSet: files, directoriesSet: directories };
}

export async function findSourceFiles(
path: string,
cwd: string,
paths: string[],
extensions: string[],
skipFiles: string[],
skipFiles: ReadonlySet<string> | null,
gitRoot: string | undefined,
): Promise<Array<string>> {
path = resolve(path);

let files = await glob(
extensions.map((ext) => `**/*${ext}`),
{
dot: true,
cwd: path,
nodir: true,
absolute: true,
ignore: ['**/node_modules/**', '**/.git/**'],
},
);

if (skipFiles.length > 0) {
const skipFilesSet = new Set(skipFiles);
files = files.filter((file) => !skipFilesSet.has(file));
const { filesSet, directoriesSet } = await resolveFilesOrDirectories(paths, cwd);

for (let path of directoriesSet) {
path = resolve(path);
for (const file of await glob(
extensions.map((ext) => `**/*${ext}`),
{
dot: true,
cwd: path,
nodir: true,
absolute: true,
ignore: [
'**/node_modules/**',
'**/.git/**',
'**/.hg/**',
'**/.svn/**',

// ignore .d.ts files as we cannot properly parse and process them
'**/*.d.ts',
],
},
)) {
filesSet.add(file);
}
}

let files = Array.from(filesSet);

if (skipFiles && skipFiles.size > 0) {
files = files.filter((file) => !skipFiles.has(file));
}

interface DirGitignore {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export function getCliPackageVersion(): string {
}

export function getCliCommand(): string {
return `npx ${getCliPackageName()}@${getCliPackageVersion().replace(/^(\d+\.\d+).+$/, '$1')}`;
return `npx ${getCliPackageName()}@latest`;
}
4 changes: 2 additions & 2 deletions packages/codemod-task-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
},
"peerDependencies": {
"eslint": "8.57.0",
"typedoc": "^0.26.6",
"typedoc": "^0.26.7",
"typescript": "5.5.4",
"vite": "^5.4.1",
"vite": "^5.4.4",
"vitest": "^1.6.0"
}
}
4 changes: 2 additions & 2 deletions packages/codemod-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
"peerDependencies": {
"@typescript-eslint/parser": "7.18.0",
"eslint": "8.57.0",
"typedoc": "^0.26.6",
"typedoc": "^0.26.7",
"typescript": "5.5.4",
"vite": "^5.4.1",
"vite": "^5.4.4",
"vitest": "^1.6.0"
}
}
4 changes: 2 additions & 2 deletions packages/codemods-tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
},
"peerDependencies": {
"eslint": "8.57.0",
"typedoc": "^0.26.6",
"typedoc": "^0.26.7",
"typescript": "5.5.4",
"vite": "^5.4.1",
"vite": "^5.4.4",
"vitest": "^1.6.0"
}
}
2 changes: 1 addition & 1 deletion packages/systemjs-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"peerDependencies": {
"eslint": "8.57.0",
"typescript": "^5.5.4",
"vite": "^5.4.1",
"vite": "^5.4.4",
"vite-plugin-node-polyfills": "^0.22"
}
}
4 changes: 2 additions & 2 deletions packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
"@vitest/expect": "^1.6.0",
"@vitest/runner": "^1.6.0",
"eslint": "8.57.0",
"typedoc": "^0.26.6",
"typedoc": "^0.26.7",
"typescript": "5.5.4",
"vite": "^5.4.1",
"vite": "^5.4.4",
"vitest": "^1.6.0"
}
}
4 changes: 2 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
},
"peerDependencies": {
"eslint": "8.57.0",
"typedoc": "^0.26.6",
"typedoc": "^0.26.7",
"typescript": "5.5.4",
"vite": "^5.4.1"
"vite": "^5.4.4"
}
}
4 changes: 2 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
},
"peerDependencies": {
"eslint": "8.57.0",
"typedoc": "^0.26.6",
"typedoc": "^0.26.7",
"typescript": "5.5.4",
"vite": "^5.4.1",
"vite": "^5.4.4",
"vitest": "^1.6.0"
}
}
4 changes: 2 additions & 2 deletions packages/worker-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
},
"peerDependencies": {
"eslint": "8.57.0",
"typedoc": "^0.26.6",
"typedoc": "^0.26.7",
"typescript": "5.5.4",
"vite": "^5.4.1",
"vite": "^5.4.4",
"vitest": "^1.6.0"
}
}
Loading