Skip to content

fix: handle remix-flat-routes folder route pattern (route.tsx) in migration CLI#15

Merged
kenn merged 2 commits intokenn:mainfrom
coji:fix/folder-route-migration
Feb 20, 2026
Merged

fix: handle remix-flat-routes folder route pattern (route.tsx) in migration CLI#15
kenn merged 2 commits intokenn:mainfrom
coji:fix/folder-route-migration

Conversation

@coji
Copy link
Copy Markdown
Contributor

@coji coji commented Feb 19, 2026

Summary

Fixes #14

The migration CLI (npx migrate-auto-routes) fails when the source project uses the remix-flat-routes folder route pattern (route.tsx inside sub-folders of +-suffixed directories). Route files are misclassified as colocated files and placed under +-prefixed folders, making them invisible to the router.

This PR fixes 5 interrelated bugs:

  • isColocatedFile() misclassifies folder route entries (e.g. demo+/about/route.tsx) as colocated
  • scanRouteModules() generates incorrect route IDs with extra /route segment
  • normalizeSnapshotRouteFilePath() doesn't normalize route segments in snapshot comparison
  • +types/route import specifiers are not rewritten when route.tsx becomes a flat file
  • /index.ts extension in imports is not stripped after migration

Changes

  • src/migration/fs-helpers.ts — Fix isColocatedFile() to recognize folder route entries
  • src/migration/route-scanner.ts — Fix route ID generation for route.tsx files
  • src/migration/normalizers.ts — Add route segment skip in snapshot normalization
  • src/migration/import-rewriter.ts — Add rewriteTypesRouteSpecifier() and stripTsExtension()
  • src/migration/migrate.ts — Add route source path exclusion filter in collectColocatedMappings

Test plan

  • All 132 tests pass (8 new tests added)
  • New unit tests for isColocatedFile with folder route patterns
  • New unit tests for +types/route specifier rewriting
  • New unit tests for /index.ts extension stripping
  • New unit tests for route segment snapshot normalization
  • New integration tests for folder route migration, import rewriting, and snapshot equivalence
  • Successfully migrated a real project (techtalk.jp) with 39 routes using folder route pattern

🤖 Generated with Claude Code

coji and others added 2 commits February 19, 2026 21:55
…ration CLI

- Fix isColocatedFile() misclassifying route entry files as colocated
- Fix route ID generation for route.tsx folder routes
- Fix snapshot normalization for route segment
- Add rewriteTypesRouteSpecifier() for +types/route imports
- Add stripTsExtension() for index.ts extension imports
- Add route source path exclusion in collectColocatedMappings

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- isColocatedFile: route entries inside + folders are not colocated
- import-rewriter: +types/route specifier rewriting, /index.ts stripping
- normalizers: route segment collapsed to parent in snapshot comparison
- CLI: folder route migration, +types/route rewriting, snapshot equivalence

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ab2ea15557

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

if (segment.endsWith('+')) return true
if (segment.startsWith('(') && segment.endsWith(')')) return true
if (segment.startsWith('__')) return true
if (segment.startsWith('_')) return true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Treat pathless folder helpers as colocated files

Marking every leading-underscore directory as a route segment causes direct helper files under pathless folder routes (for example demo+/_settings/schema.ts) to be classified as route modules instead of colocated files. In this commit, isColocatedFile() now returns false for that pattern, so scanRouteModules() will include those .ts/.tsx files as routes and the migration will emit extra route entries rather than moving them into +-prefixed colocated paths.

Useful? React with 👍 / 👎.

Comment on lines +93 to +94
if (segment === 'route' && result.length > 0) {
continue
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep literal "route" segments during snapshot normalization

The new segment === 'route' skip removes any non-root route path segment, not just folder-entry markers, so valid routes containing a literal route segment are collapsed in normalized snapshots. Because normalizeSnapshotRouteFilePath() feeds the CLI snapshot diff (src/migration/cli/diff.ts), this can incorrectly report before/after route trees as equivalent and hide real migration mismatches.

Useful? React with 👍 / 👎.

@kenn kenn merged commit 1917653 into kenn:main Feb 20, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migration CLI mishandles remix-flat-routes folder route pattern (route.tsx)

2 participants