feat: treat React Router / Remix route modules as entry points - #697
Open
wkeuppens wants to merge 1 commit into
Open
feat: treat React Router / Remix route modules as entry points#697wkeuppens wants to merge 1 commit into
wkeuppens wants to merge 1 commit into
Conversation
Route modules and framework entry points have no importers by design -- the file-based router loads them from the filesystem -- so every one of them is reported as an orphaned file on every project of this shape. Mirrors the existing Next.js App Router handling rather than adding a new mechanism: detect the framework at the scan root, then exempt its convention files. Detection prefers a react-router.config.* or remix.config.* file and falls back to checking package.json for @react-router/* or @remix-run/*, because the framework's own template ships a Vite config rather than a react-router.config. Exempted: anything beneath an app/routes/ or src/routes/ directory, plus root, entry.client and entry.server beside it. An ordinary module such as app/db.server.js is deliberately still reported -- a genuinely orphaned file has to stay visible, which is what the negative tests cover. On a real React Router project this drops orphaned findings from 49 to 27.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Route modules in a file-based router have no importers by design — the framework loads them from the filesystem — so every one is reported as an orphaned file. On a React Router project that is most of the app.
Next.js App Router already has convention handling here. This adds the same for React Router / Remix rather than introducing a second mechanism.
Detection
Prefers a
react-router.config.*orremix.config.*file, and falls back to checkingpackage.jsonfor@react-router/*or@remix-run/*— because the framework's own template ships a Vite config rather than areact-router.configfile, so the config-file check alone misses most real projects.Exempted
app/routes/orsrc/routes/directoryroot,entry.clientandentry.serverbeside it.stemstrips only the last suffix, soentry.server.jsxstems toentry.server, which is what is matched.An ordinary module such as
app/db.server.jsis still reported. A genuinely orphaned file has to stay visible or the detector stops being worth running, so there are explicit negative tests for that and for a file merely namedroot.jsdeeper in the tree.Effect
On a real React Router project (a Shopify app, ~96 JS/JSX files), orphaned findings drop from 49 to 27.
14 new tests, mirroring the existing
TestDetectNextjsProject/TestIsNextjsConventionEntryclasses.Relationship to #696
Independent — different file, and this branches from
main. #696 fixes the import graph dropping every edge whenfile_listis relative. With both applied, orphaned findings on that same project go from 49 to a handful, and the remainder are genuine.