first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
import type { RenderRscArgs } from 'expo-server/private';
type ImportMap = {
router: () => Promise<typeof import('./router/expo-definedRouter')>;
};
export declare function renderRscWithImportsAsync(distFolder: string, imports: ImportMap, { body, platform, searchParams, config, method, input, contentType, headers }: RenderRscArgs): Promise<ReadableStream<any>>;
export declare function renderRscAsync(distFolder: string, args: RenderRscArgs): Promise<ReadableStream<any>>;
export {};
//# sourceMappingURL=middleware.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/rsc/middleware.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAkEzD,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,MAAM,OAAO,CAAC,cAAc,6BAA6B,CAAC,CAAC,CAAC;CACrE,CAAC;AAEF,wBAAsB,yBAAyB,CAC7C,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,SAAS,EAClB,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,aAAa,GAC3F,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAiE9B;AAED,wBAAsB,cAAc,CAClC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAY9B"}

View File

@@ -0,0 +1,106 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderRscWithImportsAsync = renderRscWithImportsAsync;
exports.renderRscAsync = renderRscAsync;
/**
* Copyright © 2024 650 Industries.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// This module is bundled with Metro in web/react-server mode and redirects to platform specific renderers.
const expo_constants_1 = __importDefault(require("expo-constants"));
const node_path_1 = __importDefault(require("node:path"));
const rsc_renderer_1 = require("./rsc-renderer");
const debug_1 = require("../utils/debug");
const debug = (0, debug_1.createDebug)('expo:router:server:rsc-renderer');
// Tracking the implementation in expo/cli's MetroBundlerDevServer
const rscRenderContext = new Map();
function serverRequire(...targetOutputModulePath) {
// NOTE(@kitten): This `__dirname` will be located in the output file system, e.g. `dist/server/*`
const filePath = node_path_1.default.join(__dirname, ...targetOutputModulePath);
return $$require_external(filePath);
}
function getRscRenderContext(platform) {
// NOTE(EvanBacon): We memoize this now that there's a persistent server storage cache for Server Actions.
if (rscRenderContext.has(platform)) {
return rscRenderContext.get(platform);
}
const context = {};
rscRenderContext.set(platform, context);
return context;
}
function getServerActionManifest(_distFolder, platform) {
const filePath = `../../rsc/${platform}/action-manifest.js`;
return serverRequire(filePath);
}
function getSSRManifest(_distFolder, platform) {
const filePath = `../../rsc/${platform}/ssr-manifest.js`;
return serverRequire(filePath);
}
async function renderRscWithImportsAsync(distFolder, imports, { body, platform, searchParams, config, method, input, contentType, headers }) {
globalThis.__expo_platform_header = platform;
if (method === 'POST' && !body) {
throw new Error('Server request must be provided when method is POST (server actions)');
}
const context = getRscRenderContext(platform);
context['__expo_requestHeaders'] = headers;
const router = await imports.router();
const entries = router.default({
redirects: expo_constants_1.default.expoConfig?.extra?.router?.redirects,
rewrites: expo_constants_1.default.expoConfig?.extra?.router?.rewrites,
});
const ssrManifest = getSSRManifest(distFolder, platform);
const actionManifest = getServerActionManifest(distFolder, platform);
return (0, rsc_renderer_1.renderRsc)({
body: body ?? undefined,
context,
config,
input,
contentType,
decodedBody: searchParams.get('x-expo-params'),
}, {
isExporting: true,
resolveClientEntry(file, isServer) {
debug('resolveClientEntry', file, { isServer });
if (isServer) {
if (!(file in actionManifest)) {
throw new Error(`Could not find file in server action manifest: ${file}. ${JSON.stringify(actionManifest)}`);
}
const [id, chunk] = actionManifest[file];
return {
id,
chunks: chunk ? [chunk] : [],
};
}
if (!(file in ssrManifest)) {
throw new Error(`Could not find file in SSR manifest: ${file}`);
}
const [id, chunk] = ssrManifest[file];
return {
id,
chunks: chunk ? [chunk] : [],
};
},
async loadServerModuleRsc(file) {
debug('loadServerModuleRsc', file);
// NOTE(@kitten): [WORKAROUND] Assumes __dirname is at `dist/server/_expo/functions/_flight`
return serverRequire('../../../', file);
},
entries: entries,
});
}
async function renderRscAsync(distFolder, args) {
const platform = args.platform;
return renderRscWithImportsAsync(distFolder, {
router: () => {
// NOTE(@kitten): [WORKAROUND] Assumes __dirname is at `dist/server/_expo/functions/_flight`
return serverRequire(`../../rsc/${platform}/router.js`);
},
}, args);
}
//# sourceMappingURL=middleware.js.map

File diff suppressed because one or more lines are too long

34
node_modules/@expo/router-server/build/rsc/path.d.ts generated vendored Normal file
View File

@@ -0,0 +1,34 @@
/**
* Copyright © 2024 650 Industries.
* Copyright © 2024 2023 Daishi Kato
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* https://github.com/dai-shi/waku/blob/32d52242c1450b5f5965860e671ff73c42da8bd0/packages/waku/src/lib/utils/path.ts#L1
*/
export declare const encodeFilePathToAbsolute: (filePath: string) => string;
export declare const decodeFilePathFromAbsolute: (filePath: string) => string;
export declare const filePathToFileURL: (filePath: string) => string;
/** Return the original "osPath" based on the file URL */
export declare const fileURLToFilePath: (fileURL: string) => string;
export declare const joinPath: (...paths: string[]) => string;
export declare const extname: (filePath: string) => string;
export type PathSpecItem = {
type: 'literal';
name: string;
} | {
type: 'group';
name?: string;
} | {
type: 'wildcard';
name?: string;
};
export type PathSpec = readonly PathSpecItem[];
export declare const parsePathWithSlug: (path: string) => PathSpec;
export declare const getPathMapping: (pathSpec: PathSpec, pathname: string) => Record<string, string | string[]> | null;
/**
* Transform a path spec to a regular expression.
*/
export declare const path2regexp: (path: PathSpec) => string;
//# sourceMappingURL=path.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/rsc/path.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAYH,eAAO,MAAM,wBAAwB,GAAI,UAAU,MAAM,WAQxD,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAI,UAAU,MAAM,WAK1D,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,UAAU,MAAM,WAAoC,CAAC;AAEvF,yDAAyD;AACzD,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,WAahD,CAAC;AAGF,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,MAAM,EAAE,WAmB1C,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,UAAU,MAAM,WAGvC,CAAC;AAEF,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACxC,MAAM,MAAM,QAAQ,GAAG,SAAS,YAAY,EAAE,CAAC;AAE/C,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,QAiB3C,CAAC;AAEP,eAAO,MAAM,cAAc,GACzB,UAAU,QAAQ,EAClB,UAAU,MAAM,KACf,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,IAgDtC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,QAAQ,WAWzC,CAAC"}

174
node_modules/@expo/router-server/build/rsc/path.js generated vendored Normal file
View File

@@ -0,0 +1,174 @@
"use strict";
/**
* Copyright © 2024 650 Industries.
* Copyright © 2024 2023 Daishi Kato
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* https://github.com/dai-shi/waku/blob/32d52242c1450b5f5965860e671ff73c42da8bd0/packages/waku/src/lib/utils/path.ts#L1
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.path2regexp = exports.getPathMapping = exports.parsePathWithSlug = exports.extname = exports.joinPath = exports.fileURLToFilePath = exports.filePathToFileURL = exports.decodeFilePathFromAbsolute = exports.encodeFilePathToAbsolute = void 0;
// Terminology:
// - filePath: posix-like file path, e.g. `/foo/bar.js` or `c:/foo/bar.js`
// This is used by Vite.
// - fileURL: file URL, e.g. `file:///foo/bar.js` or `file:///c:/foo/bar.js`
// This is used by import().
// - osPath: os dependent path, e.g. `/foo/bar.js` or `c:\foo\bar.js`
// This is used by node:fs.
const ABSOLUTE_WIN32_PATH_REGEXP = /^\/[a-zA-Z]:\//;
const encodeFilePathToAbsolute = (filePath) => {
if (ABSOLUTE_WIN32_PATH_REGEXP.test(filePath)) {
throw new Error('Unsupported absolute file path');
}
if (filePath.startsWith('/')) {
return filePath;
}
return '/' + filePath;
};
exports.encodeFilePathToAbsolute = encodeFilePathToAbsolute;
const decodeFilePathFromAbsolute = (filePath) => {
if (ABSOLUTE_WIN32_PATH_REGEXP.test(filePath)) {
return filePath.slice(1);
}
return filePath;
};
exports.decodeFilePathFromAbsolute = decodeFilePathFromAbsolute;
const filePathToFileURL = (filePath) => 'file://' + encodeURI(filePath);
exports.filePathToFileURL = filePathToFileURL;
/** Return the original "osPath" based on the file URL */
const fileURLToFilePath = (fileURL) => {
if (!fileURL.startsWith('file://')) {
throw new Error('Not a file URL');
}
const filePath = decodeURI(fileURL.slice('file://'.length));
// File URLs are always formatted in POSIX, using a leading `/` (URL pathname) separator.
// On POSIX systems, this leading `/` is the root directory, which is valid for absolute file paths.
// On UNIX systems, this leading `/` needs to be stripped, and the actual UNIX formatted path is returned - to match Metro's behavior
return ABSOLUTE_WIN32_PATH_REGEXP.test(filePath)
? filePath.slice(1).replace(/\//g, '\\')
: filePath;
};
exports.fileURLToFilePath = fileURLToFilePath;
// for filePath
const joinPath = (...paths) => {
const isAbsolute = paths[0]?.startsWith('/');
const items = [].concat(...paths.map((path) => path.split('/')));
let i = 0;
while (i < items.length) {
if (items[i] === '.' || items[i] === '') {
items.splice(i, 1);
}
else if (items[i] === '..') {
if (i > 0) {
items.splice(i - 1, 2);
--i;
}
else {
items.splice(i, 1);
}
}
else {
++i;
}
}
return (isAbsolute ? '/' : '') + items.join('/') || '.';
};
exports.joinPath = joinPath;
const extname = (filePath) => {
const index = filePath.lastIndexOf('.');
return index > 0 ? filePath.slice(index) : '';
};
exports.extname = extname;
const parsePathWithSlug = (path) => path
.split('/')
.filter(Boolean)
.map((name) => {
let type = 'literal';
const isSlug = name.startsWith('[') && name.endsWith(']');
if (isSlug) {
type = 'group';
name = name.slice(1, -1);
}
const isWildcard = name.startsWith('...');
if (isWildcard) {
type = 'wildcard';
name = name.slice(3);
}
return { type, name };
});
exports.parsePathWithSlug = parsePathWithSlug;
const getPathMapping = (pathSpec, pathname) => {
const actual = pathname.split('/').filter(Boolean);
if (pathSpec.length > actual.length) {
return null;
}
const mapping = {};
let wildcardStartIndex = -1;
for (let i = 0; i < pathSpec.length; i++) {
const { type, name } = pathSpec[i];
if (type === 'literal') {
if (name !== actual[i]) {
return null;
}
}
else if (type === 'wildcard') {
wildcardStartIndex = i;
break;
}
else if (name) {
mapping[name] = actual[i];
}
}
if (wildcardStartIndex === -1) {
if (pathSpec.length !== actual.length) {
return null;
}
return mapping;
}
let wildcardEndIndex = -1;
for (let i = 0; i < pathSpec.length; i++) {
const { type, name } = pathSpec[pathSpec.length - i - 1];
if (type === 'literal') {
if (name !== actual[actual.length - i - 1]) {
return null;
}
}
else if (type === 'wildcard') {
wildcardEndIndex = actual.length - i - 1;
break;
}
else if (name) {
mapping[name] = actual[actual.length - i - 1];
}
}
if (wildcardStartIndex === -1 || wildcardEndIndex === -1) {
throw new Error('Invalid wildcard path');
}
const wildcardName = pathSpec[wildcardStartIndex].name;
if (wildcardName) {
mapping[wildcardName] = actual.slice(wildcardStartIndex, wildcardEndIndex + 1);
}
return mapping;
};
exports.getPathMapping = getPathMapping;
/**
* Transform a path spec to a regular expression.
*/
const path2regexp = (path) => {
const parts = path.map(({ type, name }) => {
if (type === 'literal') {
return name;
}
else if (type === 'group') {
return `([^/]+)`;
}
else {
return `(.*)`;
}
});
return `^/${parts.join('/')}$`;
};
exports.path2regexp = path2regexp;
//# sourceMappingURL=path.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,20 @@
import { type GetRoutesOptions } from 'expo-router/internal/routing';
import { createPages } from './create-pages';
import { EntriesDev } from '../server';
type CreatePagesFn = Parameters<typeof createPages>[0];
type CreatePagesFns = Parameters<CreatePagesFn>[0];
type CreatePagesOptions = Parameters<CreatePagesFn>[1] & {
getRouteOptions?: GetRoutesOptions;
};
/**
* Wrapper around `createPages` to pass data from the server to the fn
*
* This is separated from the `createPages` function allowing us to keep the createPages
* in sync with the original Waku implementation.
*
* @param fn
* @returns
*/
export declare function createExpoPages(fn: (fn: CreatePagesFns, options: CreatePagesOptions) => ReturnType<CreatePagesFn>): (getRouteOptions?: GetRoutesOptions) => EntriesDev;
export {};
//# sourceMappingURL=create-expo-pages.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"create-expo-pages.d.ts","sourceRoot":"","sources":["../../../src/rsc/router/create-expo-pages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,KAAK,cAAc,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,KAAK,kBAAkB,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG;IACvD,eAAe,CAAC,EAAE,gBAAgB,CAAC;CACpC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,CAAC,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,kBAAkB,KAAK,UAAU,CAAC,aAAa,CAAC,IAE1E,kBAAkB,gBAAgB,KAAG,UAAU,CAKxD"}

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createExpoPages = createExpoPages;
const create_pages_1 = require("./create-pages");
/**
* Wrapper around `createPages` to pass data from the server to the fn
*
* This is separated from the `createPages` function allowing us to keep the createPages
* in sync with the original Waku implementation.
*
* @param fn
* @returns
*/
function createExpoPages(fn) {
return (getRouteOptions) => {
return {
default: (0, create_pages_1.createPages)((a, b) => fn(a, { ...b, getRouteOptions })),
};
};
}
//# sourceMappingURL=create-expo-pages.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"create-expo-pages.js","sourceRoot":"","sources":["../../../src/rsc/router/create-expo-pages.ts"],"names":[],"mappings":";;AAoBA,0CAQC;AA1BD,iDAA6C;AAS7C;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAC7B,EAAkF;IAElF,OAAO,CAAC,eAAkC,EAAc,EAAE;QACxD,OAAO;YACL,OAAO,EAAE,IAAA,0BAAW,EAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC;SACjE,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { type GetRoutesOptions } from 'expo-router/internal/routing';\n\nimport { createPages } from './create-pages';\nimport { EntriesDev } from '../server';\n\ntype CreatePagesFn = Parameters<typeof createPages>[0];\ntype CreatePagesFns = Parameters<CreatePagesFn>[0];\ntype CreatePagesOptions = Parameters<CreatePagesFn>[1] & {\n getRouteOptions?: GetRoutesOptions;\n};\n\n/**\n * Wrapper around `createPages` to pass data from the server to the fn\n *\n * This is separated from the `createPages` function allowing us to keep the createPages\n * in sync with the original Waku implementation.\n *\n * @param fn\n * @returns\n */\nexport function createExpoPages(\n fn: (fn: CreatePagesFns, options: CreatePagesOptions) => ReturnType<CreatePagesFn>\n) {\n return (getRouteOptions?: GetRoutesOptions): EntriesDev => {\n return {\n default: createPages((a, b) => fn(a, { ...b, getRouteOptions })),\n };\n };\n}\n"]}

View File

@@ -0,0 +1,80 @@
/**
* Copyright © 2024 650 Industries.
* Copyright © 2024 2023 Daishi Kato
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* https://github.com/dai-shi/waku/blob/3d1cc7d714b67b142c847e879c30f0724fc457a7/packages/waku/src/router/create-pages.ts#L1
*/
import type { RouteProps } from 'expo-router/internal/rsc';
import type { FunctionComponent, ReactNode } from 'react';
import type { BuildConfig } from '../server';
/**
* Type version of `String.prototype.split()`. Splits the first string argument by the second string argument
* @example
* ```ts
* // ['a', 'b', 'c']
* type Case1 = Split<'abc', ''>
* // ['a', 'b', 'c']
* type Case2 = Split<'a,b,c', ','>
* ```
*/
type Split<Str extends string, Del extends string | number> = string extends Str ? string[] : '' extends Str ? [] : Str extends `${infer T}${Del}${infer U}` ? [T, ...Split<U, Del>] : [Str];
/** Assumes that the path is a part of a slug path. */
type IsValidPathItem<T> = T extends `/${infer _}` ? false : T extends '[]' | '' ? false : true;
/**
* This is a helper type to check if a path is valid in a slug path.
*/
export type IsValidPathInSlugPath<T> = T extends `/${infer L}/${infer R}` ? IsValidPathItem<L> extends true ? IsValidPathInSlugPath<`/${R}`> : false : T extends `/${infer U}` ? IsValidPathItem<U> : false;
/** Checks if a particular slug name exists in a path. */
export type HasSlugInPath<T, K extends string> = T extends `/[${K}]/${infer _}` ? true : T extends `/${infer _}/${infer U}` ? HasSlugInPath<`/${U}`, K> : T extends `/[${K}]` ? true : false;
export type HasWildcardInPath<T> = T extends `/[...${string}]/${string}` ? true : T extends `/${infer _}/${infer U}` ? HasWildcardInPath<`/${U}`> : T extends `/[...${string}]` ? true : false;
export type PathWithSlug<T, K extends string> = IsValidPathInSlugPath<T> extends true ? (HasSlugInPath<T, K> extends true ? T : never) : never;
type _GetSlugs<Route extends string, SplitRoute extends string[] = Split<Route, '/'>, Result extends string[] = []> = SplitRoute extends [] ? Result : SplitRoute extends [`${infer MaybeSlug}`, ...infer Rest] ? Rest extends string[] ? MaybeSlug extends `[${infer Slug}]` ? _GetSlugs<Route, Rest, [...Result, Slug]> : _GetSlugs<Route, Rest, Result> : never : Result;
export type GetSlugs<Route extends string> = _GetSlugs<Route>;
export type StaticSlugRoutePathsTuple<T extends string, Slugs extends unknown[] = GetSlugs<T>, Result extends string[] = []> = Slugs extends [] ? Result : Slugs extends [infer _, ...infer Rest] ? StaticSlugRoutePathsTuple<T, Rest, [...Result, string]> : never;
type StaticSlugRoutePaths<T extends string> = HasWildcardInPath<T> extends true ? string[] | string[][] : StaticSlugRoutePathsTuple<T> extends [string] ? string[] : StaticSlugRoutePathsTuple<T>[];
export type PathWithoutSlug<T> = T extends '/' ? T : IsValidPathInSlugPath<T> extends true ? HasSlugInPath<T, string> extends true ? never : T : never;
type PathWithStaticSlugs<T extends string> = T extends `/` ? T : IsValidPathInSlugPath<T> extends true ? T : never;
export type PathWithWildcard<Path, SlugKey extends string, WildSlugKey extends string> = PathWithSlug<Path, SlugKey | `...${WildSlugKey}`>;
export type CreatePage = <Path extends string, SlugKey extends string, WildSlugKey extends string>(page: ({
render: 'static';
path: PathWithoutSlug<Path>;
component: FunctionComponent<RouteProps>;
} | {
render: 'static';
path: PathWithStaticSlugs<Path>;
staticPaths: StaticSlugRoutePaths<Path>;
component: FunctionComponent<RouteProps & Record<SlugKey, string>>;
} | {
render: 'dynamic';
path: PathWithoutSlug<Path>;
component: FunctionComponent<RouteProps>;
} | {
render: 'dynamic';
path: PathWithWildcard<Path, SlugKey, WildSlugKey>;
component: FunctionComponent<RouteProps & Record<SlugKey, string> & Record<WildSlugKey, string[]>>;
}) & {
unstable_disableSSR?: boolean;
}) => void;
export type CreateLayout = <T extends string>(layout: {
render: 'static' | 'dynamic';
path: PathWithoutSlug<T>;
component: FunctionComponent<Omit<RouteProps, 'searchParams'> & {
children: ReactNode;
}>;
}) => void;
export declare function createPages(fn: (fns: {
createPage: CreatePage;
createLayout: CreateLayout;
unstable_setBuildData: (path: string, data: unknown) => void;
}, opts: {
unstable_buildConfig: BuildConfig | undefined;
}) => Promise<void>): {
renderEntries: import("../server").RenderEntries;
getBuildConfig: import("../server").GetBuildConfig | undefined;
getSsrConfig: import("../server").GetSsrConfig | undefined;
};
export {};
//# sourceMappingURL=create-pages.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"create-pages.d.ts","sourceRoot":"","sources":["../../../src/rsc/router/create-pages.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAK1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAmB7C;;;;;;;;;GASG;AACH,KAAK,KAAK,CAAC,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,GAAG,MAAM,IAAI,MAAM,SAAS,GAAG,GAC5E,MAAM,EAAE,GACR,EAAE,SAAS,GAAG,GACZ,EAAE,GACF,GAAG,SAAS,GAAG,MAAM,CAAC,GAAG,GAAG,GAAG,MAAM,CAAC,EAAE,GACtC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GACrB,CAAC,GAAG,CAAC,CAAC;AAEd,sDAAsD;AACtD,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,SAAS,IAAI,GAAG,EAAE,GAAG,KA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,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC,CACrE,CAAC;CACH,CACJ,GAAG;IAAE,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAAE,KAClC,IAAI,CAAC;AAEV,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE;IACpD,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACzB,SAAS,EAAE,iBAAiB,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,GAAG;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;CAC1F,KAAK,IAAI,CAAC;AAEX,wBAAgB,WAAW,CACzB,EAAE,EAAE,CACF,GAAG,EAAE;IACH,UAAU,EAAE,UAAU,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;IAC3B,qBAAqB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9D,EACD,IAAI,EAAE;IACJ,oBAAoB,EAAE,WAAW,GAAG,SAAS,CAAC;CAC/C,KACE,OAAO,CAAC,IAAI,CAAC;;;;EA+NnB"}

View File

@@ -0,0 +1,232 @@
"use strict";
/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* Copyright © 2024 650 Industries.
* Copyright © 2024 2023 Daishi Kato
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* https://github.com/dai-shi/waku/blob/3d1cc7d714b67b142c847e879c30f0724fc457a7/packages/waku/src/router/create-pages.ts#L1
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPages = createPages;
const react_1 = require("react");
const defineRouter_1 = require("./defineRouter");
const path_1 = require("../path");
const hasPathSpecPrefix = (prefix, path) => {
for (let i = 0; i < prefix.length; i++) {
if (i >= path.length ||
prefix[i].type !== path[i].type ||
prefix[i].name !== path[i].name) {
return false;
}
}
return true;
};
const sanitizeSlug = (slug) => slug.replace(/\./g, '').replace(/ /g, '-');
function createPages(fn) {
let configured = false;
// TODO I think there's room for improvement to refactor these structures
const staticPathSet = new Set();
const dynamicPagePathMap = new Map();
const wildcardPagePathMap = new Map();
const dynamicLayoutPathMap = new Map();
const staticComponentMap = new Map();
const noSsrSet = new WeakSet();
const buildDataMap = new Map();
const registerStaticComponent = (id, component) => {
if (staticComponentMap.has(id) && staticComponentMap.get(id) !== component) {
throw new Error(`Duplicated component for: ${id}`);
}
staticComponentMap.set(id, component);
};
const createPage = (page) => {
if (configured) {
throw new Error('no longer available');
}
const pathSpec = (0, path_1.parsePathWithSlug)(page.path);
if (page.unstable_disableSSR) {
noSsrSet.add(pathSpec);
}
const { numSlugs, numWildcards } = (() => {
let numSlugs = 0;
let numWildcards = 0;
for (const slug of pathSpec) {
if (slug.type !== 'literal') {
numSlugs++;
}
if (slug.type === 'wildcard') {
numWildcards++;
}
}
return { numSlugs, numWildcards };
})();
if (page.render === 'static' && numSlugs === 0) {
staticPathSet.add([page.path, pathSpec]);
const id = (0, path_1.joinPath)(page.path, 'page').replace(/^\//, '');
registerStaticComponent(id, page.component);
}
else if (page.render === 'static' && numSlugs > 0 && 'staticPaths' in page) {
const staticPaths = page.staticPaths.map((item) => (Array.isArray(item) ? item : [item]).map(sanitizeSlug));
for (const staticPath of staticPaths) {
if (staticPath.length !== numSlugs && numWildcards === 0) {
throw new Error('staticPaths does not match with slug pattern');
}
const mapping = {};
let slugIndex = 0;
const pathItems = [];
pathSpec.forEach(({ type, name }) => {
switch (type) {
case 'literal':
pathItems.push(name);
break;
case 'wildcard':
mapping[name] = staticPath.slice(slugIndex);
staticPath.slice(slugIndex++).forEach((slug) => {
pathItems.push(slug);
});
break;
case 'group':
pathItems.push(staticPath[slugIndex++]);
mapping[name] = pathItems[pathItems.length - 1];
break;
}
});
staticPathSet.add([page.path, pathItems.map((name) => ({ type: 'literal', name }))]);
const id = (0, path_1.joinPath)(...pathItems, 'page');
const WrappedComponent = (props) => (0, react_1.createElement)(page.component, { ...props, ...mapping });
registerStaticComponent(id, WrappedComponent);
}
}
else if (page.render === 'dynamic' && numWildcards === 0) {
if (dynamicPagePathMap.has(page.path)) {
throw new Error(`Duplicated dynamic path: ${page.path}`);
}
dynamicPagePathMap.set(page.path, [pathSpec, page.component]);
}
else if (page.render === 'dynamic' && numWildcards === 1) {
if (wildcardPagePathMap.has(page.path)) {
throw new Error(`Duplicated dynamic path: ${page.path}`);
}
wildcardPagePathMap.set(page.path, [pathSpec, page.component]);
}
else {
throw new Error('Invalid page configuration: ' + page.path);
}
};
const createLayout = (layout) => {
if (configured) {
throw new Error('no longer available');
}
if (layout.render === 'static') {
const id = (0, path_1.joinPath)(layout.path, 'layout').replace(/^\//, '');
registerStaticComponent(id, layout.component);
}
else if (layout.render === 'dynamic') {
if (dynamicLayoutPathMap.has(layout.path)) {
throw new Error(`Duplicated dynamic path: ${layout.path}`);
}
const pathSpec = (0, path_1.parsePathWithSlug)(layout.path);
dynamicLayoutPathMap.set(layout.path, [pathSpec, layout.component]);
}
else {
throw new Error('Invalid layout configuration');
}
};
const unstable_setBuildData = (path, data) => {
buildDataMap.set(path, data);
};
let ready;
const configure = async (buildConfig) => {
if (!configured && !ready) {
ready = fn({ createPage, createLayout, unstable_setBuildData }, { unstable_buildConfig: buildConfig });
await ready;
configured = true;
}
await ready;
};
return (0, defineRouter_1.unstable_defineRouter)(async () => {
await configure();
const paths = [];
for (const [path, pathSpec] of staticPathSet) {
const noSsr = noSsrSet.has(pathSpec);
const isStatic = (() => {
for (const [_, [layoutPathSpec]] of dynamicLayoutPathMap) {
if (hasPathSpecPrefix(layoutPathSpec, pathSpec)) {
return false;
}
}
return true;
})();
paths.push({
pattern: (0, path_1.path2regexp)((0, path_1.parsePathWithSlug)(path)),
path: pathSpec,
isStatic,
noSsr,
data: buildDataMap.get(path),
});
}
for (const [path, [pathSpec]] of dynamicPagePathMap) {
const noSsr = noSsrSet.has(pathSpec);
paths.push({
pattern: (0, path_1.path2regexp)((0, path_1.parsePathWithSlug)(path)),
path: pathSpec,
isStatic: false,
noSsr,
data: buildDataMap.get(path),
});
}
for (const [path, [pathSpec]] of wildcardPagePathMap) {
const noSsr = noSsrSet.has(pathSpec);
paths.push({
pattern: (0, path_1.path2regexp)((0, path_1.parsePathWithSlug)(path)),
path: pathSpec,
isStatic: false,
noSsr,
data: buildDataMap.get(path),
});
}
return paths;
}, async (id, { unstable_setShouldSkip, unstable_buildConfig }) => {
await configure(unstable_buildConfig);
const staticComponent = staticComponentMap.get(id);
if (staticComponent) {
unstable_setShouldSkip([]);
return staticComponent;
}
for (const [_, [pathSpec, Component]] of dynamicPagePathMap) {
const mapping = (0, path_1.getPathMapping)([...pathSpec, { type: 'literal', name: 'page' }], id);
if (mapping) {
if (Object.keys(mapping).length === 0) {
unstable_setShouldSkip();
return Component;
}
const WrappedComponent = (props) => (0, react_1.createElement)(Component, { ...props, ...mapping });
unstable_setShouldSkip();
return WrappedComponent;
}
}
for (const [_, [pathSpec, Component]] of wildcardPagePathMap) {
const mapping = (0, path_1.getPathMapping)([...pathSpec, { type: 'literal', name: 'page' }], id);
if (mapping) {
const WrappedComponent = (props) => (0, react_1.createElement)(Component, { ...props, ...mapping });
unstable_setShouldSkip();
return WrappedComponent;
}
}
for (const [_, [pathSpec, Component]] of dynamicLayoutPathMap) {
const mapping = (0, path_1.getPathMapping)([...pathSpec, { type: 'literal', name: 'layout' }], id);
if (mapping) {
if (Object.keys(mapping).length) {
throw new Error('[Bug] layout should not have slugs');
}
unstable_setShouldSkip();
return Component;
}
}
unstable_setShouldSkip([]); // negative cache
return null; // not found
});
}
//# sourceMappingURL=create-pages.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,30 @@
/**
* Copyright © 2024 650 Industries.
* Copyright © 2024 2023 Daishi Kato
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { type RouteProps, type ShouldSkip } from 'expo-router/internal/rsc';
import type { FunctionComponent, ReactNode } from 'react';
import type { PathSpec } from '../path';
import { defineEntries } from '../server';
import type { BuildConfig } from '../server';
type RoutePropsForLayout = Omit<RouteProps, 'searchParams'> & {
children: ReactNode;
};
type ShouldSkipValue = ShouldSkip[number][1];
export declare function unstable_defineRouter(getPathConfig: () => Promise<Iterable<{
pattern: string;
path: PathSpec;
isStatic?: boolean;
noSsr?: boolean;
data?: unknown;
}>>, getComponent: (componentId: string, // "**/layout" or "**/page"
options: {
unstable_setShouldSkip: (val?: ShouldSkipValue) => void;
unstable_buildConfig: BuildConfig | undefined;
}) => Promise<FunctionComponent<RouteProps> | FunctionComponent<RoutePropsForLayout> | null>): ReturnType<typeof defineEntries>;
export declare function unstable_redirect(pathname: string, searchParams?: URLSearchParams, skip?: string[]): void;
export {};
//# sourceMappingURL=defineRouter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"defineRouter.d.ts","sourceRoot":"","sources":["../../../src/rsc/router/defineRouter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAUL,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAkB,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAI1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,aAAa,EAAY,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAA+C,MAAM,WAAW,CAAC;AAE1F,KAAK,mBAAmB,GAAG,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,GAAG;IAC5D,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,KAAK,eAAe,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAgB7C,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,OAAO,CAC1B,QAAQ,CAAC;IACP,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC,CACH,EACD,YAAY,EAAE,CACZ,WAAW,EAAE,MAAM,EAAE,2BAA2B;AAChD,OAAO,EAAE;IAEP,sBAAsB,EAAE,CAAC,GAAG,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;IACxD,oBAAoB,EAAE,WAAW,GAAG,SAAS,CAAC;CAC/C,KACE,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,GAC1F,UAAU,CAAC,OAAO,aAAa,CAAC,CAmKlC;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,eAAe,EAC9B,IAAI,CAAC,EAAE,MAAM,EAAE,QAUhB"}

View File

@@ -0,0 +1,169 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unstable_defineRouter = unstable_defineRouter;
exports.unstable_redirect = unstable_redirect;
/**
* Copyright © 2024 650 Industries.
* Copyright © 2024 2023 Daishi Kato
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const rsc_1 = require("expo-router/internal/rsc");
const react_1 = require("react");
const path_1 = require("../path");
const server_1 = require("../server");
const safeJsonParse = (str) => {
if (typeof str === 'string') {
try {
const obj = JSON.parse(str);
if (typeof obj === 'object') {
return obj;
}
}
catch {
// ignore
}
}
return undefined;
};
function unstable_defineRouter(getPathConfig, getComponent) {
let cachedPathConfig;
const getMyPathConfig = async (buildConfig) => {
if (buildConfig) {
return buildConfig;
}
if (!cachedPathConfig) {
cachedPathConfig = Array.from(await getPathConfig()).map((item) => {
const is404 = item.path.length === 1 &&
item.path[0].type === 'literal' &&
item.path[0].name === '404';
return {
pattern: item.pattern,
pathname: item.path,
isStatic: item.isStatic,
customData: { is404, noSsr: !!item.noSsr, data: item.data },
};
});
}
return cachedPathConfig;
};
const existsPath = async (pathname, buildConfig) => {
const pathConfig = await getMyPathConfig(buildConfig);
const found = pathConfig.find(({ pathname: pathSpec }) => (0, path_1.getPathMapping)(pathSpec, pathname));
return found
? found.customData.noSsr
? ['FOUND', 'NO_SSR']
: ['FOUND']
: pathConfig.some(({ customData: { is404 } }) => is404) // FIXMEs should avoid re-computation
? ['NOT_FOUND', 'HAS_404']
: ['NOT_FOUND'];
};
const renderEntries = async (input, { params, buildConfig }) => {
const pathname = (0, rsc_1.parseInputString)(input);
if ((await existsPath(pathname, buildConfig))[0] === 'NOT_FOUND') {
return null;
}
const shouldSkipObj = {};
const parsedParams = safeJsonParse(params);
const query = typeof parsedParams?.query === 'string' ? parsedParams.query : '';
const skip = Array.isArray(parsedParams?.skip) ? parsedParams?.skip : [];
const componentIds = (0, rsc_1.getComponentIds)(pathname);
const entries = (await Promise.all(componentIds.map(async (id) => {
if (skip?.includes(id)) {
return [];
}
const setShouldSkip = (val) => {
if (val) {
shouldSkipObj[id] = val;
}
else {
delete shouldSkipObj[id];
}
};
const component = await getComponent(id, {
unstable_setShouldSkip: setShouldSkip,
unstable_buildConfig: buildConfig,
});
if (!component) {
return [];
}
const element = (0, react_1.createElement)(component, id.endsWith('/layout') ? { path: pathname } : { path: pathname, query }, (0, react_1.createElement)(rsc_1.Children));
return [[id, element]];
}))).flat();
entries.push([rsc_1.SHOULD_SKIP_ID, Object.entries(shouldSkipObj)]);
entries.push([rsc_1.LOCATION_ID, [pathname, query]]);
return Object.fromEntries(entries);
};
const getBuildConfig = async (unstable_collectClientModules) => {
const pathConfig = await getMyPathConfig();
const path2moduleIds = {};
for (const { pathname: pathSpec } of pathConfig) {
if (pathSpec.some(({ type }) => type !== 'literal')) {
continue;
}
const pathname = '/' + pathSpec.map(({ name }) => name).join('/');
const input = (0, rsc_1.getInputString)(pathname);
const moduleIds = await unstable_collectClientModules(input);
path2moduleIds[pathname] = moduleIds;
}
const customCode = `
globalThis.__EXPO_ROUTER_PREFETCH__ = (path) => {
const path2ids = ${JSON.stringify(path2moduleIds)};
for (const id of path2ids[path] || []) {
import(id);
}
};`;
const buildConfig = [];
for (const { pathname: pathSpec, isStatic, customData } of pathConfig) {
const entries = [];
if (pathSpec.every(({ type }) => type === 'literal')) {
const pathname = '/' + pathSpec.map(({ name }) => name).join('/');
const input = (0, rsc_1.getInputString)(pathname);
entries.push({ input, isStatic });
}
buildConfig.push({
pathname: pathSpec,
isStatic,
entries,
customCode,
customData,
});
}
return buildConfig;
};
const getSsrConfig = async (pathname, { searchParams, buildConfig }) => {
const pathStatus = await existsPath(pathname, buildConfig);
if (pathStatus[1] === 'NO_SSR') {
return null;
}
if (pathStatus[0] === 'NOT_FOUND') {
if (pathStatus[1] === 'HAS_404') {
pathname = '/404';
}
else {
return null;
}
}
const componentIds = (0, rsc_1.getComponentIds)(pathname);
const input = (0, rsc_1.getInputString)(pathname);
const html = (0, react_1.createElement)(rsc_1.ServerRouter, { route: { path: pathname, query: searchParams.toString(), hash: '' } }, componentIds.reduceRight((acc, id) => (0, react_1.createElement)(rsc_1.Slot, { id, fallback: acc }, acc), null));
return {
input,
params: JSON.stringify({ query: searchParams.toString() }),
html,
};
};
return { renderEntries, getBuildConfig, getSsrConfig };
}
function unstable_redirect(pathname, searchParams, skip) {
if (skip) {
searchParams = new URLSearchParams(searchParams);
for (const id of skip) {
searchParams.append(rsc_1.PARAM_KEY_SKIP, id);
}
}
const input = (0, rsc_1.getInputString)(pathname);
(0, server_1.rerender)(input, searchParams);
}
//# sourceMappingURL=defineRouter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
declare const _default: (getRouteOptions?: import("expo-router/build/getRoutes").Options) => import("../server").EntriesDev;
export default _default;
//# sourceMappingURL=expo-definedRouter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"expo-definedRouter.d.ts","sourceRoot":"","sources":["../../../src/rsc/router/expo-definedRouter.ts"],"names":[],"mappings":";AAiBA,wBAyHG"}

View File

@@ -0,0 +1,111 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ctx_1 = require("expo-router/_ctx");
const routing_1 = require("expo-router/internal/routing");
const create_expo_pages_1 = require("./create-expo-pages");
const getRoutesSSR_1 = require("../../getRoutesSSR");
const loadStaticParamsAsync_1 = require("../../loadStaticParamsAsync");
const UNIMPLEMENTED_PARAMS = new Proxy({}, {
// Assert that params is unimplemented when accessed.
get() {
throw new Error('generateStaticParams(): params is not implemented yet');
},
});
exports.default = (0, create_expo_pages_1.createExpoPages)(async ({ createPage, createLayout }, { getRouteOptions }) => {
const routes = (0, getRoutesSSR_1.getRoutes)(_ctx_1.ctx, {
...getRouteOptions,
platform: process.env.EXPO_OS,
skipGenerated: true,
importMode: 'lazy',
});
if (!routes)
return;
async function loadAndConvertStaticParamsAsync(route) {
const loaded = route.loadRoute();
let staticPaths = undefined;
if (route.dynamic) {
const params = await (0, loadStaticParamsAsync_1.evalStaticParamsAsync)(route, { parentParams: UNIMPLEMENTED_PARAMS }, loaded.generateStaticParams);
// Sort `params` like `[{a: 'x', b: 'y'}, { a: 'z', b: 'w' }]` for a route.dynamic like `[{name: 'a', deep: false}, {name: 'b', deep: false}]` to `[['a', 'y'], ['z', 'w]]`
staticPaths = params?.map((p) => {
const grouped = [];
for (const dynamic of route.dynamic) {
const defined = p[dynamic.name];
if (!defined) {
throw new Error('generateStaticParams is missing param: ' +
dynamic.name +
'. In route: ' +
route.contextKey);
}
if (Array.isArray(defined)) {
if (defined.length > 1) {
throw new Error('generateStaticParams does not support returning multiple static paths for deep dynamic routes in React Server Components yet. Update route: ' +
route.contextKey);
}
}
const first = Array.isArray(defined) ? defined[0] : defined;
grouped.push(first);
}
return grouped;
});
}
else if (loaded.generateStaticParams) {
throw new Error('Cannot use generateStaticParams without a dynamic route: ' + route.contextKey);
}
return staticPaths;
}
async function addLayout(route) {
const normal = (0, routing_1.getContextKey)(route.contextKey).replace(/\/index$/, '');
const loaded = route.loadRoute();
if (loaded.generateStaticParams) {
throw new Error('generateStaticParams is not supported in _layout routes with React Server Components enabled yet.');
}
createLayout({
// NOTE(EvanBacon): Support routes with top-level "use client"
component: loaded.default,
path: normal,
render: 'static',
...loaded.unstable_settings,
});
await Promise.all(route.children.sort(routing_1.sortRoutes).map(async (child) => {
if (child.type === 'layout') {
await addLayout(child);
}
else {
const normal = (0, routing_1.getContextKey)(child.contextKey).replace(/\/index$/, '');
const loaded = child.loadRoute();
const settings = loaded.unstable_settings;
// Support generateStaticParams for dynamic routes by defining the route twice.
if (loaded.generateStaticParams) {
createPage({
// NOTE(EvanBacon): Support routes with top-level "use client"
component: loaded.default,
path: normal,
render: 'static',
...loaded.unstable_settings,
staticPaths: (await loadAndConvertStaticParamsAsync(child)),
});
if (settings?.render !== 'static') {
createPage({
// NOTE(EvanBacon): Support routes with top-level "use client"
component: loaded.default,
path: normal,
render: 'dynamic',
...settings,
});
}
}
else {
createPage({
// NOTE(EvanBacon): Support routes with top-level "use client"
component: loaded.default,
path: normal,
render: 'dynamic',
...settings,
});
}
}
}));
}
await addLayout(routes);
});
//# sourceMappingURL=expo-definedRouter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
declare const _default: (getRouteOptions?: import("expo-router/build/getRoutes").Options) => import("../server").EntriesDev;
export default _default;
//# sourceMappingURL=noopRouter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"noopRouter.d.ts","sourceRoot":"","sources":["../../../src/rsc/router/noopRouter.ts"],"names":[],"mappings":";AAEA,wBAEG"}

View File

@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const create_expo_pages_1 = require("./create-expo-pages");
exports.default = (0, create_expo_pages_1.createExpoPages)(async () => {
// noop the router for client-only mode. This ensures we skip loading the routes in react-server mode.
});
//# sourceMappingURL=noopRouter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"noopRouter.js","sourceRoot":"","sources":["../../../src/rsc/router/noopRouter.ts"],"names":[],"mappings":";;AAAA,2DAAsD;AAEtD,kBAAe,IAAA,mCAAe,EAAC,KAAK,IAAI,EAAE;IACxC,sGAAsG;AACxG,CAAC,CAAC,CAAC","sourcesContent":["import { createExpoPages } from './create-expo-pages';\n\nexport default createExpoPages(async () => {\n // noop the router for client-only mode. This ensures we skip loading the routes in react-server mode.\n});\n"]}

View File

@@ -0,0 +1,44 @@
/**
* Copyright © 2024 650 Industries.
* Copyright © 2024 dai-shi.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* From waku https://github.com/dai-shi/waku/blob/32d52242c1450b5f5965860e671ff73c42da8bd0/packages/waku/src/lib/renderers/rsc-renderer.ts
*/
import '@expo/metro-runtime/rsc/runtime';
import { type EntriesDev } from './server';
export interface RenderContext<T = unknown> {
rerender: (input: string, searchParams?: URLSearchParams) => void;
context: T;
}
type ResolvedConfig = any;
export type RenderRscArgs = {
config: ResolvedConfig;
input: string;
context: Record<string, unknown> | undefined;
body?: ReadableStream | undefined;
contentType?: string | undefined;
decodedBody?: unknown;
moduleIdCallback?: (module: {
id: string;
chunks: string[];
name: string;
async: boolean;
}) => void;
onError?: (err: unknown) => void;
};
type ResolveClientEntry = (id: string, server: boolean) => {
id: string;
chunks: string[];
};
type RenderRscOpts = {
isExporting: boolean;
entries: EntriesDev;
resolveClientEntry: ResolveClientEntry;
loadServerModuleRsc: (url: string) => Promise<any>;
};
export declare function renderRsc(args: RenderRscArgs, opts: RenderRscOpts): Promise<ReadableStream>;
export {};
//# sourceMappingURL=rsc-renderer.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"rsc-renderer.d.ts","sourceRoot":"","sources":["../../src/rsc/rsc-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,iCAAiC,CAAC;AAOzC,OAAO,EAAsB,KAAK,UAAU,EAAmB,MAAM,UAAU,CAA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AO,CAAC,cAAc,CAAC,CAwKjG"}

View File

@@ -0,0 +1,200 @@
"use strict";
/**
* Copyright © 2024 650 Industries.
* Copyright © 2024 dai-shi.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* From waku https://github.com/dai-shi/waku/blob/32d52242c1450b5f5965860e671ff73c42da8bd0/packages/waku/src/lib/renderers/rsc-renderer.ts
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderRsc = renderRsc;
// This file must remain platform agnostic for production exports.
// Import the runtime to support polyfills for webpack to load modules in the server using Metro.
require("@expo/metro-runtime/rsc/runtime");
const rsc_1 = require("expo-router/internal/rsc");
const server_1 = require("react-server-dom-webpack/server");
const path_1 = require("./path");
const server_2 = require("./server");
async function renderRsc(args, opts) {
const { input, body, contentType, context, onError } = args;
const { resolveClientEntry, entries } = opts;
const { default: { renderEntries },
// @ts-expect-error
buildConfig, } = entries;
function resolveRequest(isServer, encodedId) {
const [
// File is the on-disk location of the module, this is injected during the "use client" transformation (babel).
file,
// The name of the import (e.g. "default" or "")
// This will be empty when using `module.exports = ` and `require('...')`.
name = '',] = encodedId.split('#');
const filePath = file.startsWith('file://') ? (0, path_1.fileURLToFilePath)(file) : file;
args.moduleIdCallback?.({
id: filePath,
chunks: [
// TODO: Add a lookup later which reads from the SSR manifest to get the correct chunk.
// NOTE(EvanBacon): This is a placeholder since we need to render RSC to get the client boundaries, which we then inject later.
'chunk:' + filePath,
],
name,
async: true,
});
// We'll augment the file path with the incoming RSC request which will forward the metro props required to make a cache hit, e.g. platform=web&...
// This is similar to how we handle lazy bundling.
const resolved = resolveClientEntry(filePath, isServer);
return { id: resolved.id, chunks: resolved.chunks, name, async: true };
}
const bundlerConfig = new Proxy({}, {
get(_target, encodedId) {
return resolveRequest(false, encodedId);
},
});
const serverConfig = new Proxy({}, {
get(_target, encodedId) {
return resolveRequest(true, encodedId);
},
});
// @ts-ignore: Not part of global types. This is added to support server actions loading more actions.
global[`${__METRO_GLOBAL_PREFIX__}__loadBundleAsync`] = opts.loadServerModuleRsc;
const renderWithContext = async (context, input, params) => {
const renderStore = {
context: context || {},
rerender: () => {
throw new Error('Cannot rerender');
},
};
return (0, server_2.runWithRenderStore)(renderStore, async () => {
const elements = await renderEntries(input, {
params,
buildConfig,
});
if (elements === null) {
const err = new Error('No function component found at: ' + input);
err.statusCode = 404;
throw err;
}
if (Object.keys(elements).some((key) => key.startsWith('_'))) {
throw new Error('"_" prefix is reserved');
}
return (0, server_1.renderToReadableStream)(elements, bundlerConfig, {
onError,
});
});
};
const renderWithContextWithAction = async (context, actionFn, actionArgs) => {
let elementsPromise = Promise.resolve({});
let rendered = false;
const renderStore = {
context: context || {},
rerender: async (input, params) => {
if (rendered) {
throw new Error('already rendered');
}
elementsPromise = Promise.all([
elementsPromise,
renderEntries(input, { params, buildConfig }),
]).then(([oldElements, newElements]) => ({
...oldElements,
// FIXME we should actually check if newElements is null and send an error
...newElements,
}));
},
};
return (0, server_2.runWithRenderStore)(renderStore, async () => {
const actionValue = await actionFn(...actionArgs);
const elements = await elementsPromise;
rendered = true;
if (Object.keys(elements).some((key) => key.startsWith('_'))) {
throw new Error('"_" prefix is reserved');
}
return (0, server_1.renderToReadableStream)({ ...elements, _value: actionValue }, bundlerConfig, {
onError,
});
});
};
let decodedBody = args.decodedBody;
if (body) {
const bodyStr = await streamToString(body);
if (typeof contentType === 'string' && contentType.startsWith('multipart/form-data')) {
// XXX This doesn't support streaming unlike busboy
const formData = parseFormData(bodyStr, contentType);
decodedBody = await (0, server_1.decodeReply)(formData, serverConfig);
}
else if (bodyStr) {
decodedBody = await (0, server_1.decodeReply)(bodyStr, serverConfig);
}
}
const actionId = (0, rsc_1.decodeActionId)(input);
if (actionId) {
if (!opts.isExporting &&
// @ts-ignore
!process.env.EXPO_UNSTABLE_SERVER_FUNCTIONS) {
throw new Error('Experimental support for React Server Functions is not enabled');
}
const args = Array.isArray(decodedBody) ? decodedBody : [];
const chunkInfo = serverConfig[actionId];
// Load module into memory.
await Promise.all(chunkInfo.chunks.map((chunk) => globalThis.__webpack_chunk_load__(chunk)));
// Import module.
const mod = globalThis.__webpack_require__(chunkInfo.id);
const fn = chunkInfo.name === '*' ? chunkInfo.name : mod[chunkInfo.name] || mod;
if (!fn) {
throw new Error(`Could not find server action: ${actionId}. Module: ${JSON.stringify(chunkInfo, null, 2)}`);
}
return renderWithContextWithAction(context, fn, args);
}
// method === 'GET'
return renderWithContext(context, input, decodedBody);
}
// TODO is this correct? better to use a library?
const parseFormData = (body, contentType) => {
const boundary = contentType.split('boundary=')[1];
const parts = body.split(`--${boundary}`);
const formData = new FormData();
for (const part of parts) {
if (part.trim() === '' || part === '--')
continue;
const [rawHeaders, content] = part.split('\r\n\r\n', 2);
const headers = rawHeaders.split('\r\n').reduce((acc, currentHeader) => {
const [key, value] = currentHeader.split(': ');
acc[key.toLowerCase()] = value;
return acc;
}, {});
const contentDisposition = headers['content-disposition'];
const nameMatch = /name="([^"]+)"/.exec(contentDisposition);
const filenameMatch = /filename="([^"]+)"/.exec(contentDisposition);
if (nameMatch) {
const name = nameMatch[1];
if (filenameMatch) {
const filename = filenameMatch[1];
const type = headers['content-type'] || 'application/octet-stream';
const blob = new Blob([content], { type });
formData.append(name, blob, filename);
}
else {
formData.append(name, content.trim());
}
}
}
return formData;
};
const streamToString = async (stream) => {
const decoder = new TextDecoder();
const reader = stream.getReader();
const outs = [];
let result;
do {
result = await reader.read();
if (result.value) {
if (!(result.value instanceof Uint8Array)) {
throw new Error('Unexepected buffer type');
}
outs.push(decoder.decode(result.value, { stream: true }));
}
} while (!result.done);
outs.push(decoder.decode());
return outs.join('');
};
//# sourceMappingURL=rsc-renderer.js.map

File diff suppressed because one or more lines are too long

63
node_modules/@expo/router-server/build/rsc/server.d.ts generated vendored Normal file
View File

@@ -0,0 +1,63 @@
/**
* Copyright © 2024 650 Industries.
* Copyright © 2024 2023 Daishi Kato
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { ReactNode } from 'react';
import type { PathSpec } from './path';
export declare const REQUEST_HEADERS = "__expo_requestHeaders";
type Config = any;
type Elements = Record<string, ReactNode>;
export type BuildConfig = {
pathname: string | PathSpec;
isStatic?: boolean | undefined;
entries?: {
input: string;
skipPrefetch?: boolean | undefined;
isStatic?: boolean | undefined;
}[];
context?: Record<string, unknown>;
customCode?: string;
customData?: unknown;
}[];
export type RenderEntries = (input: string, options: {
params: unknown | undefined;
buildConfig: BuildConfig | undefined;
}) => Promise<Elements | null>;
export type GetBuildConfig = (unstable_collectClientModules: (input: string) => Promise<string[]>) => Promise<BuildConfig>;
export type GetSsrConfig = (pathname: string, options: {
searchParams: URLSearchParams;
buildConfig?: BuildConfig | undefined;
}) => Promise<{
input: string;
searchParams?: URLSearchParams;
html: ReactNode;
} | null>;
export declare function defineEntries(renderEntries: RenderEntries, getBuildConfig?: GetBuildConfig, getSsrConfig?: GetSsrConfig): {
renderEntries: RenderEntries;
getBuildConfig: GetBuildConfig | undefined;
getSsrConfig: GetSsrConfig | undefined;
};
export type EntriesDev = {
default: ReturnType<typeof defineEntries>;
};
export type EntriesPrd = EntriesDev & {
loadConfig: () => Promise<Config>;
loadModule: (id: string) => Promise<unknown>;
dynamicHtmlPaths: [pathSpec: PathSpec, htmlHead: string][];
publicIndexHtml: string;
};
type RenderStore = {
rerender: (input: string, params?: unknown) => void;
context: Record<string, unknown>;
};
/**
* This is an internal function and not for public use.
*/
export declare const runWithRenderStore: <T>(renderStore: RenderStore, fn: () => T) => T;
export declare function rerender(input: string, params?: unknown): Promise<void>;
export declare function getContext<RscContext extends Record<string, unknown> = Record<string, unknown>>(): RscContext;
export {};
//# sourceMappingURL=server.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/rsc/server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,Q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,IAAI,EAAE,SAAS,CAAC;CACjB,GAAG,IAAI,CAAC,CAAC;AAEV,wBAAgB,aAAa,CAC3B,aAAa,EAAE,aAAa,EAC5B,cAAc,CAAC,EAAE,cAAc,EAC/B,YAAY,CAAC,EAAE,YAAY;;;;EAG5B;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG;IACpC,UAAU,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C,gBAAgB,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;IAC3D,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,KAAK,WAAW,GAAK;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACpD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AA2BF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAAE,aAAa,WAAW,EAAE,IAAI,MAAM,CAAC,KAAG,CAY7E,CAAC;AAEF,wBAAsB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,iBAO7D;AAED,wBAAgB,UAAU,CACxB,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACjE,UAAU,CAOd"}

72
node_modules/@expo/router-server/build/rsc/server.js generated vendored Normal file
View File

@@ -0,0 +1,72 @@
"use strict";
/**
* Copyright © 2024 650 Industries.
* Copyright © 2024 2023 Daishi Kato
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.runWithRenderStore = exports.REQUEST_HEADERS = void 0;
exports.defineEntries = defineEntries;
exports.rerender = rerender;
exports.getContext = getContext;
const node_async_hooks_1 = require("node:async_hooks");
exports.REQUEST_HEADERS = '__expo_requestHeaders';
function defineEntries(renderEntries, getBuildConfig, getSsrConfig) {
return { renderEntries, getBuildConfig, getSsrConfig };
}
// TODO(EvanBacon): This can leak between platforms and runs.
// We need to share this module between the server action module and the renderer module, per platform, and invalidate on refreshes.
function getGlobalCacheForPlatform() {
// HACK: This is a workaround for the shared middleware being shared between web and native.
// In production the shared middleware is web-only and that causes the first version of this module
// to be bound to web.
const platform = globalThis.__expo_platform_header ?? process.env.EXPO_OS;
if (!globalThis.__EXPO_RSC_CACHE__) {
globalThis.__EXPO_RSC_CACHE__ = new Map();
}
if (globalThis.__EXPO_RSC_CACHE__.has(platform)) {
return globalThis.__EXPO_RSC_CACHE__.get(platform);
}
const serverCache = new node_async_hooks_1.AsyncLocalStorage();
globalThis.__EXPO_RSC_CACHE__.set(platform, serverCache);
return serverCache;
}
let previousRenderStore;
let currentRenderStore;
/**
* This is an internal function and not for public use.
*/
const runWithRenderStore = (renderStore, fn) => {
const renderStorage = getGlobalCacheForPlatform();
if (renderStorage) {
return renderStorage.run(renderStore, fn);
}
previousRenderStore = currentRenderStore;
currentRenderStore = renderStore;
try {
return fn();
}
finally {
currentRenderStore = previousRenderStore;
}
};
exports.runWithRenderStore = runWithRenderStore;
async function rerender(input, params) {
const renderStorage = getGlobalCacheForPlatform();
const renderStore = renderStorage.getStore() ?? currentRenderStore;
if (!renderStore) {
throw new Error('Render store is not available for rerender');
}
renderStore.rerender(input, params);
}
function getContext() {
const renderStorage = getGlobalCacheForPlatform();
const renderStore = renderStorage.getStore() ?? currentRenderStore;
if (!renderStore) {
throw new Error('Render store is not available for accessing context');
}
return renderStore.context;
}
//# sourceMappingURL=server.js.map

File diff suppressed because one or more lines are too long