Skip to content

Commit

Permalink
Codemod fix (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
beerose authored Feb 26, 2025
1 parent 8b854bd commit d221695
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`rename-toml transform should rename edgedb.toml file to gel.toml 1`] = `
"[gel]
"[instance]
version = "x""
`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs/promises';
import * as glob from 'glob';
import { findAndUpdateFileExtensions } from '../scripts/esdledgeql-to-gel-file-extensions-update';
import { findAndUpdateFileExtensions } from '../scripts/esdl-to-gel-file-extensions-update';

jest.mock('fs/promises');
jest.mock('glob');
Expand All @@ -20,7 +20,7 @@ describe('ESDL to GEL Extension Update Script', () => {

await findAndUpdateFileExtensions('/root');

expect(mockGlob.sync).toHaveBeenCalledWith('**/*.{esdl,edgeql}', {
expect(mockGlob.sync).toHaveBeenCalledWith('**/*.esdl', {
cwd: '/root',
ignore: ['**/node_modules/**'],
absolute: true
Expand All @@ -31,23 +31,6 @@ describe('ESDL to GEL Extension Update Script', () => {
expect(mockFs.rename).toHaveBeenCalledWith('/path/to/types.esdl', '/path/to/types.gel');
});

it('should rename .edgeql files to .gel', async () => {
mockGlob.sync.mockReturnValue(['/path/to/schema.esdl', '/path/to/types.edgeql']);
mockFs.rename.mockResolvedValue(undefined);

await findAndUpdateFileExtensions('/root');

expect(mockGlob.sync).toHaveBeenCalledWith('**/*.{esdl,edgeql}', {
cwd: '/root',
ignore: ['**/node_modules/**'],
absolute: true
});

expect(mockFs.rename).toHaveBeenCalledTimes(2);
expect(mockFs.rename).toHaveBeenCalledWith('/path/to/schema.esdl', '/path/to/schema.gel');
expect(mockFs.rename).toHaveBeenCalledWith('/path/to/types.edgeql', '/path/to/types.gel');
});

it('should handle file rename errors', async () => {
const consoleSpy = jest.spyOn(console, 'error').mockImplementation();

Expand Down
2 changes: 1 addition & 1 deletion packages/codemod/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import pc from "picocolors";
import * as glob from "glob";
import path from "node:path";
import { run } from "jscodeshift/src/Runner.js";
import { findAndUpdateFileExtensions } from "./scripts/esdledgeql-to-gel-file-extensions-update.js";
import { findAndUpdateFileExtensions } from "./scripts/esdl-to-gel-file-extensions-update.js";
import { findAndUpdatePackageJson } from "./scripts/package-json-update.js";
import { findAndUpdateToml } from "./scripts/edgeql-to-gel-toml-file-update.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gel/codemod",
"version": "1.0.0",
"version": "1.0.1",
"description": "Upgrade EdgeDB code to Gel",
"homepage": "https://edgedb.com/docs",
"author": "EdgeDB <info@edgedb.com>",
Expand Down
2 changes: 1 addition & 1 deletion packages/codemod/scripts/edgeql-to-gel-toml-file-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as glob from 'glob';

async function updateTomlContent(content: string): Promise<string> {
return content
.replace(/\[edgedb\]/g, '[gel]');
.replace(/\[edgedb\]/g, '[instance]');
}

async function processTomlFile(filePath: string): Promise<string[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ async function updateEsdlToGelExt(filePath: string): Promise<string[]> {
const changes: string[] = [];

try {
await fs.rename(filePath, filePath.replace(/\.(esdl|edgeql)$/, '.gel'));
changes.push(`Updated file extension from .esdl and .edgeql to .gel`);
await fs.rename(filePath, filePath.replace(/\.(esdl)$/, '.gel'));
changes.push(`Updated file extension from .esdl to .gel`);

return changes;
}
Expand All @@ -18,14 +18,14 @@ async function updateEsdlToGelExt(filePath: string): Promise<string[]> {

export async function findAndUpdateFileExtensions(rootDir: string) {
try {
const files = glob.sync('**/*.{esdl,edgeql}', {
const files = glob.sync('**/*.esdl', {
cwd: rootDir,
ignore: ['**/node_modules/**'],
absolute: true
});

console.log(`Found ${files.length} ${files.length === 1 ? 'file' : 'files'
} with .esdl/.edgeql extension`);
} with .esdl extension`);

for (const file of files) {
console.log(`Processing ${file}...`);
Expand Down

0 comments on commit d221695

Please sign in to comment.