Skip to content

Create @fedify/codemods package #377

@dahlia

Description

@dahlia

Summary

Following the discussion in #375, we should create a dedicated @fedify/codemods package to provide automated code transformations for Fedify projects. This would initially support migrating from @fedify/fedify/x/* modules to separate packages, and establish infrastructure for future breaking changes.

In #375, @ThisIsMissEm suggested offering a codemod to handle the @fedify/fedify/x/* modules migration instead of just making it a breaking change. This is a great idea since the migration is essentially just changing import paths, which is perfect for automation. As @ThisIsMissEm also mentioned, we could publish a @fedify/codemods package and keep codemods available for several releases.

The broader benefit is that having codemod infrastructure in place makes future breaking changes much more palatable for users. We can deprecate APIs, ship the codemod during the deprecation period, and then safely remove the old APIs knowing users have an automated migration path.

Implementation

Build a jscodeshift-based package that can transform import statements from the old x-module paths to new package names:

// Before
import { federation } from '@fedify/fedify/x/sveltekit';
const hono = await import('@fedify/fedify/x/hono');
export * from '@fedify/fedify/x/deno';

// After  
import { federation } from '@fedify/sveltekit';
const hono = await import('@fedify/hono');
export * from '@fedify/deno';

The CLI would be something like:

npx @fedify/codemods migrate-x-modules
npx @fedify/codemods migrate-x-modules --dry-run

jscodeshift is the obvious choice here since it's the industry standard for JavaScript codemods. We'd need to handle static imports, dynamic imports, and re-exports. The parser should support both TypeScript and JSX since Fedify is used across different project types.

Beyond just transforming imports, it could also update package.json dependencies automatically and provide rollback functionality. The package should be thoroughly tested to ensure it doesn't break existing code.

This would need to be ready before we ship the deprecation warnings for the @fedify/fedify/x/* modules, so it should be prioritized alongside the work in #375. Having the codemod available when we announce the deprecation makes the whole transition much smoother for users.

Users get a one-command migration instead of manually updating dozens of import statements, and we establish a pattern for future API changes that builds trust with the community. The React ecosystem has shown how valuable codemods are for major migrations, and this would put Fedify in the same category of well-maintained projects that care about developer experience.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions