Skip to content
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] Support platform extensions for _layout and routes #27408

Merged
merged 15 commits into from Apr 26, 2024
Merged
1 change: 1 addition & 0 deletions packages/@expo/cli/CHANGELOG.md
Expand Up @@ -49,6 +49,7 @@ _This version does not introduce any user-facing changes._

- Fixed `TypeError: osascript(...) is not a function` when pressing "j" to open JS debugger. ([#28315](https://github.com/expo/expo/pull/28315) by [@kudo](https://github.com/kudo))
- Fix API routes in folders starting with `.` characters. ([#28366](https://github.com/expo/expo/pull/28366) by [@byCedric](https://github.com/byCedric))
- Allow platform extensions for layout and route files ([#27408](https://github.com/expo/expo/pull/27408) by [@marklawlor](https://github.com/marklawlor))

## 0.18.0 — 2024-04-18

Expand Down
Expand Up @@ -181,7 +181,9 @@ export class MetroBundlerDevServer extends BundlerDevServer {

async getExpoRouterRoutesManifestAsync({ appDir }: { appDir: string }) {
// getBuiltTimeServerManifest
const { exp } = getConfig(this.projectRoot);
const manifest = await fetchManifest(this.projectRoot, {
...exp.extra?.router?.platformRoutes,
asJson: true,
appDir,
});
Expand Down Expand Up @@ -219,10 +221,12 @@ export class MetroBundlerDevServer extends BundlerDevServer {
}
);

const { exp } = getConfig(this.projectRoot);

return {
serverManifest: await getBuildTimeServerManifestAsync(),
// Get routes from Expo Router.
manifest: await getManifest({ preserveApiRoutes: false }),
manifest: await getManifest({ preserveApiRoutes: false, ...exp.extra?.router }),
// Get route generating function
async renderAsync(path: string) {
return await getStaticContent(new URL(path, url));
Expand Down Expand Up @@ -574,6 +578,7 @@ export class MetroBundlerDevServer extends BundlerDevServer {
appDir,
routerRoot,
config,
...config.exp.extra?.router,
bundleApiRoute: (functionFilePath) => this.ssrImportApiRoute(functionFilePath),
getStaticPageAsync: (pathname) => {
return this.getStaticPageAsync(pathname);
Expand Down
Expand Up @@ -33,7 +33,7 @@ export function createRouteHandlerMiddleware(
functionFilePath: string
) => Promise<null | Record<string, Function> | Response>;
config: ProjectConfig;
}
} & import('expo-router/build/routes-manifest').Options
) {
if (!resolveFrom.silent(projectRoot, 'expo-router')) {
throw new CommandError(
Expand Down
Expand Up @@ -30,12 +30,15 @@ function getExpoRouteManifestBuilderAsync(projectRoot: string) {
// TODO: Simplify this now that we use Node.js directly, no need for the Metro bundler caching layer.
export async function fetchManifest<TRegex = string>(
projectRoot: string,
options: { asJson?: boolean; appDir: string }
options: {
asJson?: boolean;
appDir: string;
} & import('expo-router/build/routes-manifest').Options
): Promise<ExpoRouterServerManifestV1<TRegex> | null> {
const getManifest = getExpoRouteManifestBuilderAsync(projectRoot);
const paths = getRoutePaths(options.appDir);
// Get the serialized manifest
const jsonManifest = getManifest(paths);
const jsonManifest = getManifest(paths, options);

if (!jsonManifest) {
return null;
Expand Down
1 change: 1 addition & 0 deletions packages/expo-router/CHANGELOG.md
Expand Up @@ -31,6 +31,7 @@ _This version does not introduce any user-facing changes._
- Mark React client components with "use client" directives. ([#27300](https://github.com/expo/expo/pull/27300) by [@EvanBacon](https://github.com/EvanBacon))
- Add URL hash support ([#27105](https://github.com/expo/expo/pull/27105) by [@marklawlor](https://github.com/marklawlor))
- Type `Href` is no longer generic ([#27690](https://github.com/expo/expo/pull/27690) by [@marklawlor](https://github.com/marklawlor))
- Allow platform extensions for layout and route files ([#27408](https://github.com/expo/expo/pull/27408) by [@marklawlor](https://github.com/marklawlor))

### 🐛 Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion packages/expo-router/_ctx.android.js
@@ -1,6 +1,6 @@
export const ctx = require.context(
process.env.EXPO_ROUTER_APP_ROOT,
true,
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*\.[tj]sx?$/,
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*(?:\.ios|\.web)\.[tj]sx?$/,
process.env.EXPO_ROUTER_IMPORT_MODE
);
2 changes: 1 addition & 1 deletion packages/expo-router/_ctx.ios.js
@@ -1,6 +1,6 @@
export const ctx = require.context(
process.env.EXPO_ROUTER_APP_ROOT,
true,
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*\.[tj]sx?$/,
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*(?:\.android|\.web)?\.[tj]sx?$/,
process.env.EXPO_ROUTER_IMPORT_MODE
);
2 changes: 1 addition & 1 deletion packages/expo-router/_ctx.web.js
@@ -1,6 +1,6 @@
export const ctx = require.context(
process.env.EXPO_ROUTER_APP_ROOT,
true,
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*\.[tj]sx?$/,
/^(?:\.\/)(?!(?:(?:(?:.*\+api)|(?:\+html)))\.[tj]sx?$).*(?:\.android|\.ios|\.native)?\.[tj]sx?$/,
process.env.EXPO_ROUTER_IMPORT_MODE
);
2 changes: 2 additions & 0 deletions packages/expo-router/build/getRoutes.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-router/build/getRoutes.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 51 additions & 9 deletions packages/expo-router/build/getRoutes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-router/build/getRoutes.js.map

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion packages/expo-router/build/global-state/router-store.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.