More info: https://github.com/orgs/remix-run/projects/5?pane=issue&itemId=62153560
First demo: https://x.com/kuba_jastrz/status/1798783656305025372
Before:
After:
This is only a concept image, the actual codemod doesn't fully work like this yet. It's close though 😄
I don't know how to package this yet, but you can run it locally:
git clone https://github.com/KubaJastrz/typesafe-remix-codemod
cd typesafe-remix-codemod
cargo run ./remix-app # or path to any other remix app
The codemod finds all route files with npx -y @remix-run/dev routes --json
and iterates over them with oxc_parser.
It makes transformations in two passes per file. The first one is to modify the existing function bodies and remove the useLoaderData
/useActionData
hook calls. The second pass is to replace all Remix exports with the new defineRoute
default export.
# run against local remix app
cargo run ./remix-app
cargo run ./epic-stack
# revert codemod changes
git restore ./remix-app
git restore ./epic-stack
# test
cargo test
# review snapshots
cargo insta review
Progress is being tracked in Issue #2.