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
[router] move typed-routes logic into expo-router #26578
Conversation
options.projectRoot, | ||
'expo-router/build/typed-routes' | ||
); | ||
return typedRoutesModule ? typedRoutes(typedRoutesModule, options) : legacyTypedRoutes(options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We switch to the expo-router
version if available
@@ -383,6 +384,8 @@ export function assertDuplicateRoutes(filenames: string[]) { | |||
|
|||
/** Given a Metro context module, return an array of nested routes. */ | |||
export function getRoutes(contextModule: RequireContext, options?: Options): RouteNode | null { | |||
options = { importMode: EXPO_ROUTER_IMPORT_MODE, ...options }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typed routes need to force async
loading, so this option can now be overridden.
interface RequireContextPonyFill extends RequireContext { | ||
__add(file: string): void; | ||
__delete(file: string): void; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to rebuild the context every time a file changes, so I added these methods to modify the context.
"types": [ | ||
"jest", | ||
"jest-require", | ||
"node" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typed-routes
use node:fs
and node:path
, so I added node
to the types. We could also remove this can just ts-ignore
the imports.
@@ -0,0 +1,345 @@ | |||
/* eslint-disable */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new centralised location for Expo Router types that can be shared by both the code-base and typed routes. After this is merged, I'd adjust the expo-router
package to use these types.
|
||
const typedRoutesModule = require(typedRoutesModulePath); | ||
|
||
if (metro && server) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be an assertion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer adding a comment explaining why these values could be false.
577c3b3
to
62d9c44
Compare
781ab12
to
3c0b988
Compare
eeeac35
to
d02796e
Compare
9dbb76b
to
6d5952d
Compare
136055c
to
2c30c89
Compare
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
00784a3
to
b8deb57
Compare
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
# Why The logic introduced in #26578 breaks router for all platforms in development only. <!-- Please describe the motivation for this PR, and link to relevant GitHub issues, forums posts, or feature requests. --> # How <!-- How did you build this feature or fix this bug and why? --> # Test Plan <!-- Please describe how you tested this change and how a reviewer could reproduce your test, especially if this PR does not include automated tests! If possible, please also provide terminal output and/or screenshots demonstrating your test/reproduction. --> # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Why
Recreation of #25654. I'm splitting that PR into two PRs.
I've also removed the custom directory-traversal logic and switched to using
getRoutes()
directly. This is in preparation of#26507 which fixes issue with the type generation.
Close ENG-10759
How
Previous
@expo/cli
new
@expo/cli
checks for the existence ofexpo-router/build/typed-routes
. If so, it uses it instead of the current logic.getRoutes()
and traverse theRouteNode
instead of the file-system.Test Plan
This PR only tests the integration between
getRoutes()
and theexpo-router.d.ts
. The next PR will add type tests that are in #25654Checklist
npx expo prebuild
& EAS Build (eg: updated a module plugin).