feat: routeTransforms option for non-TS route languages#2156
Open
STRd6 wants to merge 2 commits into
Open
Conversation
Route modules are analyzed for their exports with esbuild's tsx loader, which fails on languages that compile to JS/TS (Civet, CoffeeScript, ...), silently dropping the route. Let bundler plugins/users register a per-extension source transform that runs before analysis. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 103fb5e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for solid-start-landing-page ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
commit: |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #1549 (on
main/v2; the vinxi-based 1.x line has the same issue — happy to backport, see notes below).Problem
Route modules are analyzed for their exports by reading the file off disk and parsing it with esbuild's tsx loader (
analyzeModuleinfs-routes/router.ts, vendored from vinxi). Languages that compile to JS/TS — Civet, CoffeeScript, etc. — can't be parsed that way, sotoRoutethrows,addRouteswallows the error, and the route is silently dropped even though the user registered the extension viaextensionsand added a bundler plugin that handles the language everywhere else.Reported here as #1549 and to Civet as DanielXMoore/Civet#1319. Civet currently works around it by monkey-patching
toRouteand substitutingfs.readFileSyncduring analysis (DanielXMoore/Civet#2148) — this PR is the seam that makes that workaround unnecessary.Approach
A per-extension source transform that runs before export analysis, so all the existing pick/route-config/HTTP-method logic is reused and the transform author never sees es-module-lexer's shapes:
FileSystemRouterConfiggainsrouteTransforms?: Record<string, RouteModuleTransform>(extension without dot, matching howextensionsis spelled), threaded throughsolidStart().analyzeModule(src)is split intoanalyzeCode(code, sourcePath)plus a newanalyzeRouteModule(sourcePath, config)that applies the matching transform first (andawait inits the lexer, which watcher-triggered updates could otherwise race).toRoutebecomes async; its only callers (addRoute/updateRoute) were already async and now await it.The hardcoded
.md/.mdxcarve-out intoRouteis untouched, but could conceivably migrate to this mechanism later.Verification
tsc --noEmitonpackages/startis clean.vitest runshows 2 failures that also fail for me on unmodifiedmain(server-fns related), 5 passing.Notes
routeTransforms,sourcePath) and shape are open to feedback — e.g. this could alternatively hang offextensionsentries in a tuple form like vite-plugin-solid'sextensionsoption.analyzeModule; sincetoRoutelives in this repo there too, a near-identical backport is possible without touching vinxi.🤖 Generated with Claude Code