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

Codemod fix #1218

Merged
merged 6 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -48,4 +48,4 @@
"lint": "eslint --quiet",
"lint:fix": "eslint --fix"
}
}
}
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