Skip to content

Apply codemods to source code after adding component #761

Closed

Description

@Guria

Example use case

Based on the codemods I apply for park-ui, this includes migrating from forwardRef for React 19 and several custom rules:
https://github.com/Guria/modern-stack/tree/main/.config/codemods/park-ui-fixes

Initially, I thought about creating another transform package, but it expects the function to accept code as input and return the transformed code. That API does not fit well with how most codemod tools work in practice.

It also seems that most well-known codemod tools are CLI-only and do not expose a traditional programmatic API:
codemod/codemod#1961 (comment)

I currently see two possible solutions:

  1. Introduce post-add and post-update hooks. This feels tricky because it is hard to reliably track what changed and when.

  2. Rely on the same engine as the codemod tool and add a small harness to access their registry of published codemods.

There might be a third option to set up a virtual filesystem and run codemods against that, but I do not think it is worth the effort.

Activity

  1. ieedan commented on Feb 9, 2026

    @ieedan
    Collaborator

    I feel like most of this is best accomplished through transform plugins. Is there any reason a transform plugin couldn't rely on the code mode engine? Or have a more generic codemod transform that allows you to specify specific code mods?

    I certainly wouldn't want jsrepo to depend on a codemod engine.

    In the absence of that though introducing hooks could be a fine solution to quite a bit of people's problems. It's been a plan to introduce them for some time just haven't actually got around to it due to there not really being a need from anyone just yet.

  2. ieedan commented on Feb 11, 2026

    @ieedan
    Collaborator

    Hooks proposal in #762 lmk if it will address this properly

  3. ieedan commented on Feb 17, 2026

    @ieedan
    Collaborator

    I think we can close this with #762

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions