Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

KubaJastrz/typesafe-remix-codemod

Repository files navigation

Note

Project has been deprecated, as the underlying design for typesafe routes has changed in the mean time.




Codemod for Type-safe Remix/React Router

More info: https://github.com/orgs/remix-run/projects/5?pane=issue&itemId=62153560

First demo: https://x.com/kuba_jastrz/status/1798783656305025372

Before:

before

After:

after

This is only a concept image, the actual codemod doesn't fully work like this yet. It's close though 😄

Usage

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

How it works

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.

Contributing

# 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

Todo

Progress is being tracked in Issue #2.