-
-
Notifications
You must be signed in to change notification settings - Fork 992
generator refactor #4337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
schiller-manuel
wants to merge
39
commits into
alpha
Choose a base branch
from
generator-refactor
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
generator refactor #4337
+13,961
−22,560
Conversation
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
only invoke the plugin's transform hook when the id matches
View your CI Pipeline Execution ↗ for commit 942b67e.
☁️ Nx Cloud last updated this comment at |
More templates
@tanstack/arktype-adapter
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-with-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-plugin
@tanstack/react-start-server
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-devtools-core
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-utils
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-plugin
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-server-functions-client
@tanstack/start-server-functions-fetcher
@tanstack/start-server-functions-server
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/zod-adapter
commit: |
this ensures they are not formatted by prettier since 'snapshots' is already ignored by prettier
otherwise, the following error occurs: > Error: EXDEV: cross-device link not permitted, rename '/tmp/tanstack-router-7wje9z/35d0e8564e9868341e48407dc66dab17' -> '/home/workflows/workspace/e2e/react-router/rspack-basic-virtual-named-export-config-file-based/src/routeTree.gen.ts'
the type errors raised are due these old TS versions not being as smart about inference. however, the type errors errors are only relevant at build time of the library and not when consuming the library
e5ac9b6
to
dcd829a
Compare
baab168
to
b741198
Compare
7d6d6aa
to
f040710
Compare
37df1c1
to
8635d4b
Compare
862523b
to
1d44694
Compare
2ad5544
to
b92286e
Compare
c07b85a
to
e1c9a93
Compare
399433d
to
9b0c498
Compare
ddfd3f0
to
4d94495
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
This PR introduces a refactoring of the router-generator:
The router-generator is now plugin based. This way we can realize a clean separation of Router and Start while also keeping code duplication at a minimum. The plugin API is not public.
The route manifest is not embedded into the generated route tree file anymore. Instead, it is handled by a generator plugin that is installed by start-plugin-core. This plugin builds up the route manifest and provides it for others to consume via
globalThis
. Thus, no file is written for the route manifest.As a consequence, the
disableManifestGeneration
option was removed from the generator config.The plugin mechanism allows to remove the separate server-route-generator and implement the Start specific logic via a router-generator plugin. The
serverRouteTree
is now also written into the same routeTree.gen.ts file as therouteTree
.For the client build, the
serverRouteTree
and all of its imports / types are stripped out so now server stuff ends up in the client bundle.Since the regex based approach for handling route file rewrites finally reached its limitations, route file rewrites are now handled via an AST based approach.
see https://github.com/TanStack/router/blob/generator-refactor/packages/router-generator/src/transform/transform.ts
The router-generator is now optimized for dev by leveraging a double-buffer cache mechanism.
See https://github.com/TanStack/router/blob/generator-refactor/packages/router-generator/src/generator.ts#L144-L153
When a single route file is saved and the change does not result in outputting a new route tree file (i.e. no relevant exports (
Route
,ServerRoute
) have been added or removed), router-generator will process this change in ~2-3 ms.The router-generator now detects whether a file was changed by another process before writing to it.
https://github.com/TanStack/router/blob/generator-refactor/packages/router-generator/src/generator.ts#L929-L966
File writes are realized atomically via renaming.
router-generator will write the new content to a temporary file and then will rename the temporary file to the target file name. This can lead to issues when temp directory and target directory are not on the same device.
For example on a github runner, this leads to the following error:
Hence a new config option
tmpDir
was introduced which allows customization of the temp directory location for router-generator.This PR also changes the default of
verboseFileRoutes
for Start to the same as for router-generator, so users have to op-in into the new syntax and import handling.