@expo/router-server 56.0.8 → 56.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/getNamedParametrizedRoute.d.ts +12 -0
- package/build/getNamedParametrizedRoute.d.ts.map +1 -0
- package/build/getNamedParametrizedRoute.js +127 -0
- package/build/getNamedParametrizedRoute.js.map +1 -0
- package/build/getServerManifest.d.ts +0 -14
- package/build/getServerManifest.d.ts.map +1 -1
- package/build/getServerManifest.js +2 -131
- package/build/getServerManifest.js.map +1 -1
- package/build/rsc/middleware.d.ts +1 -1
- package/build/rsc/middleware.d.ts.map +1 -1
- package/build/rsc/middleware.js +4 -14
- package/build/rsc/middleware.js.map +1 -1
- package/build/rsc/path.d.ts +0 -17
- package/build/rsc/path.d.ts.map +1 -1
- package/build/rsc/path.js +1 -91
- package/build/rsc/path.js.map +1 -1
- package/build/rsc/router/createPages.d.ts +35 -0
- package/build/rsc/router/createPages.d.ts.map +1 -0
- package/build/rsc/router/createPages.js +258 -0
- package/build/rsc/router/createPages.js.map +1 -0
- package/build/rsc/router/defineRouter.d.ts +10 -6
- package/build/rsc/router/defineRouter.d.ts.map +1 -1
- package/build/rsc/router/defineRouter.js +38 -29
- package/build/rsc/router/defineRouter.js.map +1 -1
- package/build/rsc/router/expo-definedRouter.d.ts +3 -1
- package/build/rsc/router/expo-definedRouter.d.ts.map +1 -1
- package/build/rsc/router/expo-definedRouter.js +90 -94
- package/build/rsc/router/expo-definedRouter.js.map +1 -1
- package/build/rsc/router/index.d.ts +13 -0
- package/build/rsc/router/index.d.ts.map +1 -0
- package/build/rsc/router/index.js +13 -0
- package/build/rsc/router/index.js.map +1 -0
- package/build/rsc/router/noopRouter.d.ts +2 -1
- package/build/rsc/router/noopRouter.d.ts.map +1 -1
- package/build/rsc/router/noopRouter.js +4 -3
- package/build/rsc/router/noopRouter.js.map +1 -1
- package/build/rsc/rsc-renderer.d.ts +2 -0
- package/build/rsc/rsc-renderer.d.ts.map +1 -1
- package/build/rsc/rsc-renderer.js +34 -7
- package/build/rsc/rsc-renderer.js.map +1 -1
- package/build/rsc/server.d.ts +2 -3
- package/build/rsc/server.d.ts.map +1 -1
- package/build/rsc/server.js +7 -34
- package/build/rsc/server.js.map +1 -1
- package/build/utils/html.d.ts.map +1 -1
- package/build/utils/html.js +11 -5
- package/build/utils/html.js.map +1 -1
- package/package.json +8 -8
- package/build/rsc/router/create-expo-pages.d.ts +0 -20
- package/build/rsc/router/create-expo-pages.d.ts.map +0 -1
- package/build/rsc/router/create-expo-pages.js +0 -21
- package/build/rsc/router/create-expo-pages.js.map +0 -1
- package/build/rsc/router/create-pages.d.ts +0 -80
- package/build/rsc/router/create-pages.d.ts.map +0 -1
- package/build/rsc/router/create-pages.js +0 -232
- package/build/rsc/router/create-pages.js.map +0 -1
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
-
/**
|
|
4
|
-
* Copyright © 2024 650 Industries.
|
|
5
|
-
* Copyright © 2024 2023 Daishi Kato
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*
|
|
10
|
-
* https://github.com/dai-shi/waku/blob/3d1cc7d714b67b142c847e879c30f0724fc457a7/packages/waku/src/router/create-pages.ts#L1
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.createPages = createPages;
|
|
14
|
-
const react_1 = require("react");
|
|
15
|
-
const defineRouter_1 = require("./defineRouter");
|
|
16
|
-
const path_1 = require("../path");
|
|
17
|
-
const hasPathSpecPrefix = (prefix, path) => {
|
|
18
|
-
for (let i = 0; i < prefix.length; i++) {
|
|
19
|
-
if (i >= path.length ||
|
|
20
|
-
prefix[i].type !== path[i].type ||
|
|
21
|
-
prefix[i].name !== path[i].name) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
26
|
-
};
|
|
27
|
-
const sanitizeSlug = (slug) => slug.replace(/\./g, '').replace(/ /g, '-');
|
|
28
|
-
function createPages(fn) {
|
|
29
|
-
let configured = false;
|
|
30
|
-
// TODO I think there's room for improvement to refactor these structures
|
|
31
|
-
const staticPathSet = new Set();
|
|
32
|
-
const dynamicPagePathMap = new Map();
|
|
33
|
-
const wildcardPagePathMap = new Map();
|
|
34
|
-
const dynamicLayoutPathMap = new Map();
|
|
35
|
-
const staticComponentMap = new Map();
|
|
36
|
-
const noSsrSet = new WeakSet();
|
|
37
|
-
const buildDataMap = new Map();
|
|
38
|
-
const registerStaticComponent = (id, component) => {
|
|
39
|
-
if (staticComponentMap.has(id) && staticComponentMap.get(id) !== component) {
|
|
40
|
-
throw new Error(`Duplicated component for: ${id}`);
|
|
41
|
-
}
|
|
42
|
-
staticComponentMap.set(id, component);
|
|
43
|
-
};
|
|
44
|
-
const createPage = (page) => {
|
|
45
|
-
if (configured) {
|
|
46
|
-
throw new Error('no longer available');
|
|
47
|
-
}
|
|
48
|
-
const pathSpec = (0, path_1.parsePathWithSlug)(page.path);
|
|
49
|
-
if (page.unstable_disableSSR) {
|
|
50
|
-
noSsrSet.add(pathSpec);
|
|
51
|
-
}
|
|
52
|
-
const { numSlugs, numWildcards } = (() => {
|
|
53
|
-
let numSlugs = 0;
|
|
54
|
-
let numWildcards = 0;
|
|
55
|
-
for (const slug of pathSpec) {
|
|
56
|
-
if (slug.type !== 'literal') {
|
|
57
|
-
numSlugs++;
|
|
58
|
-
}
|
|
59
|
-
if (slug.type === 'wildcard') {
|
|
60
|
-
numWildcards++;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return { numSlugs, numWildcards };
|
|
64
|
-
})();
|
|
65
|
-
if (page.render === 'static' && numSlugs === 0) {
|
|
66
|
-
staticPathSet.add([page.path, pathSpec]);
|
|
67
|
-
const id = (0, path_1.joinPath)(page.path, 'page').replace(/^\//, '');
|
|
68
|
-
registerStaticComponent(id, page.component);
|
|
69
|
-
}
|
|
70
|
-
else if (page.render === 'static' && numSlugs > 0 && 'staticPaths' in page) {
|
|
71
|
-
const staticPaths = page.staticPaths.map((item) => (Array.isArray(item) ? item : [item]).map(sanitizeSlug));
|
|
72
|
-
for (const staticPath of staticPaths) {
|
|
73
|
-
if (staticPath.length !== numSlugs && numWildcards === 0) {
|
|
74
|
-
throw new Error('staticPaths does not match with slug pattern');
|
|
75
|
-
}
|
|
76
|
-
const mapping = {};
|
|
77
|
-
let slugIndex = 0;
|
|
78
|
-
const pathItems = [];
|
|
79
|
-
pathSpec.forEach(({ type, name }) => {
|
|
80
|
-
switch (type) {
|
|
81
|
-
case 'literal':
|
|
82
|
-
pathItems.push(name);
|
|
83
|
-
break;
|
|
84
|
-
case 'wildcard':
|
|
85
|
-
mapping[name] = staticPath.slice(slugIndex);
|
|
86
|
-
staticPath.slice(slugIndex++).forEach((slug) => {
|
|
87
|
-
pathItems.push(slug);
|
|
88
|
-
});
|
|
89
|
-
break;
|
|
90
|
-
case 'group':
|
|
91
|
-
pathItems.push(staticPath[slugIndex++]);
|
|
92
|
-
mapping[name] = pathItems[pathItems.length - 1];
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
staticPathSet.add([page.path, pathItems.map((name) => ({ type: 'literal', name }))]);
|
|
97
|
-
const id = (0, path_1.joinPath)(...pathItems, 'page');
|
|
98
|
-
const WrappedComponent = (props) => (0, react_1.createElement)(page.component, { ...props, ...mapping });
|
|
99
|
-
registerStaticComponent(id, WrappedComponent);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else if (page.render === 'dynamic' && numWildcards === 0) {
|
|
103
|
-
if (dynamicPagePathMap.has(page.path)) {
|
|
104
|
-
throw new Error(`Duplicated dynamic path: ${page.path}`);
|
|
105
|
-
}
|
|
106
|
-
dynamicPagePathMap.set(page.path, [pathSpec, page.component]);
|
|
107
|
-
}
|
|
108
|
-
else if (page.render === 'dynamic' && numWildcards === 1) {
|
|
109
|
-
if (wildcardPagePathMap.has(page.path)) {
|
|
110
|
-
throw new Error(`Duplicated dynamic path: ${page.path}`);
|
|
111
|
-
}
|
|
112
|
-
wildcardPagePathMap.set(page.path, [pathSpec, page.component]);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
throw new Error('Invalid page configuration: ' + page.path);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
const createLayout = (layout) => {
|
|
119
|
-
if (configured) {
|
|
120
|
-
throw new Error('no longer available');
|
|
121
|
-
}
|
|
122
|
-
if (layout.render === 'static') {
|
|
123
|
-
const id = (0, path_1.joinPath)(layout.path, 'layout').replace(/^\//, '');
|
|
124
|
-
registerStaticComponent(id, layout.component);
|
|
125
|
-
}
|
|
126
|
-
else if (layout.render === 'dynamic') {
|
|
127
|
-
if (dynamicLayoutPathMap.has(layout.path)) {
|
|
128
|
-
throw new Error(`Duplicated dynamic path: ${layout.path}`);
|
|
129
|
-
}
|
|
130
|
-
const pathSpec = (0, path_1.parsePathWithSlug)(layout.path);
|
|
131
|
-
dynamicLayoutPathMap.set(layout.path, [pathSpec, layout.component]);
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
throw new Error('Invalid layout configuration');
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
const unstable_setBuildData = (path, data) => {
|
|
138
|
-
buildDataMap.set(path, data);
|
|
139
|
-
};
|
|
140
|
-
let ready;
|
|
141
|
-
const configure = async (buildConfig) => {
|
|
142
|
-
if (!configured && !ready) {
|
|
143
|
-
ready = fn({ createPage, createLayout, unstable_setBuildData }, { unstable_buildConfig: buildConfig });
|
|
144
|
-
await ready;
|
|
145
|
-
configured = true;
|
|
146
|
-
}
|
|
147
|
-
await ready;
|
|
148
|
-
};
|
|
149
|
-
return (0, defineRouter_1.unstable_defineRouter)(async () => {
|
|
150
|
-
await configure();
|
|
151
|
-
const paths = [];
|
|
152
|
-
for (const [path, pathSpec] of staticPathSet) {
|
|
153
|
-
const noSsr = noSsrSet.has(pathSpec);
|
|
154
|
-
const isStatic = (() => {
|
|
155
|
-
for (const [_, [layoutPathSpec]] of dynamicLayoutPathMap) {
|
|
156
|
-
if (hasPathSpecPrefix(layoutPathSpec, pathSpec)) {
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return true;
|
|
161
|
-
})();
|
|
162
|
-
paths.push({
|
|
163
|
-
pattern: (0, path_1.path2regexp)((0, path_1.parsePathWithSlug)(path)),
|
|
164
|
-
path: pathSpec,
|
|
165
|
-
isStatic,
|
|
166
|
-
noSsr,
|
|
167
|
-
data: buildDataMap.get(path),
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
for (const [path, [pathSpec]] of dynamicPagePathMap) {
|
|
171
|
-
const noSsr = noSsrSet.has(pathSpec);
|
|
172
|
-
paths.push({
|
|
173
|
-
pattern: (0, path_1.path2regexp)((0, path_1.parsePathWithSlug)(path)),
|
|
174
|
-
path: pathSpec,
|
|
175
|
-
isStatic: false,
|
|
176
|
-
noSsr,
|
|
177
|
-
data: buildDataMap.get(path),
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
for (const [path, [pathSpec]] of wildcardPagePathMap) {
|
|
181
|
-
const noSsr = noSsrSet.has(pathSpec);
|
|
182
|
-
paths.push({
|
|
183
|
-
pattern: (0, path_1.path2regexp)((0, path_1.parsePathWithSlug)(path)),
|
|
184
|
-
path: pathSpec,
|
|
185
|
-
isStatic: false,
|
|
186
|
-
noSsr,
|
|
187
|
-
data: buildDataMap.get(path),
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
return paths;
|
|
191
|
-
}, async (id, { unstable_setShouldSkip, unstable_buildConfig }) => {
|
|
192
|
-
await configure(unstable_buildConfig);
|
|
193
|
-
const staticComponent = staticComponentMap.get(id);
|
|
194
|
-
if (staticComponent) {
|
|
195
|
-
unstable_setShouldSkip([]);
|
|
196
|
-
return staticComponent;
|
|
197
|
-
}
|
|
198
|
-
for (const [_, [pathSpec, Component]] of dynamicPagePathMap) {
|
|
199
|
-
const mapping = (0, path_1.getPathMapping)([...pathSpec, { type: 'literal', name: 'page' }], id);
|
|
200
|
-
if (mapping) {
|
|
201
|
-
if (Object.keys(mapping).length === 0) {
|
|
202
|
-
unstable_setShouldSkip();
|
|
203
|
-
return Component;
|
|
204
|
-
}
|
|
205
|
-
const WrappedComponent = (props) => (0, react_1.createElement)(Component, { ...props, ...mapping });
|
|
206
|
-
unstable_setShouldSkip();
|
|
207
|
-
return WrappedComponent;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
for (const [_, [pathSpec, Component]] of wildcardPagePathMap) {
|
|
211
|
-
const mapping = (0, path_1.getPathMapping)([...pathSpec, { type: 'literal', name: 'page' }], id);
|
|
212
|
-
if (mapping) {
|
|
213
|
-
const WrappedComponent = (props) => (0, react_1.createElement)(Component, { ...props, ...mapping });
|
|
214
|
-
unstable_setShouldSkip();
|
|
215
|
-
return WrappedComponent;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
for (const [_, [pathSpec, Component]] of dynamicLayoutPathMap) {
|
|
219
|
-
const mapping = (0, path_1.getPathMapping)([...pathSpec, { type: 'literal', name: 'layout' }], id);
|
|
220
|
-
if (mapping) {
|
|
221
|
-
if (Object.keys(mapping).length) {
|
|
222
|
-
throw new Error('[Bug] layout should not have slugs');
|
|
223
|
-
}
|
|
224
|
-
unstable_setShouldSkip();
|
|
225
|
-
return Component;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
unstable_setShouldSkip([]); // negative cache
|
|
229
|
-
return null; // not found
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
//# sourceMappingURL=create-pages.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-pages.js","sourceRoot":"","sources":["../../../src/rsc/router/create-pages.ts"],"names":[],"mappings":";AAAA,sD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O,gBAAgB,CAAC;YAC1B,CAAC;QACH,CAAC;QACD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,IAAI,oBAAoB,EAAE,CAAC;YAC9D,MAAM,OAAO,GAAG,IAAA,qBAAc,EAAC,CAAC,GAAG,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YACvF,IAAI,OAAO,EAAE,CAAC;gBACZ,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;oBAChC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;gBACxD,CAAC;gBACD,sBAAsB,EAAE,CAAC;gBACzB,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;QACD,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB;QAC7C,OAAO,IAAI,CAAC,CAAC,YAAY;IAC3B,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/**\n * Copyright © 2024 650 Industries.\n * Copyright © 2024 2023 Daishi Kato\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * https://github.com/dai-shi/waku/blob/3d1cc7d714b67b142c847e879c30f0724fc457a7/packages/waku/src/router/create-pages.ts#L1\n */\n\nimport type { RouteProps } from 'expo-router/internal/rsc';\nimport { createElement } from 'react';\nimport type { FunctionComponent, ReactNode } from 'react';\n\nimport { unstable_defineRouter } from './defineRouter';\nimport { joinPath, parsePathWithSlug, getPathMapping, path2regexp } from '../path';\nimport type { PathSpec } from '../path';\nimport type { BuildConfig } from '../server';\n\nconst hasPathSpecPrefix = (prefix: PathSpec, path: PathSpec) => {\n for (let i = 0; i < prefix.length; i++) {\n if (\n i >= path.length ||\n prefix[i]!.type !== path[i]!.type ||\n prefix[i]!.name !== path[i]!.name\n ) {\n return false;\n }\n }\n return true;\n};\n\nconst sanitizeSlug = (slug: string) => slug.replace(/\\./g, '').replace(/ /g, '-');\n\n// createPages API (a wrapper around unstable_defineRouter)\n\n/**\n * Type version of `String.prototype.split()`. Splits the first string argument by the second string argument\n * @example\n * ```ts\n * // ['a', 'b', 'c']\n * type Case1 = Split<'abc', ''>\n * // ['a', 'b', 'c']\n * type Case2 = Split<'a,b,c', ','>\n * ```\n */\ntype Split<Str extends string, Del extends string | number> = string extends Str\n ? string[]\n : '' extends Str\n ? []\n : Str extends `${infer T}${Del}${infer U}`\n ? [T, ...Split<U, Del>]\n : [Str];\n\n/** Assumes that the path is a part of a slug path. */\ntype IsValidPathItem<T> = T extends `/${infer _}` ? false : T extends '[]' | '' ? false : true;\n/**\n * This is a helper type to check if a path is valid in a slug path.\n */\nexport type IsValidPathInSlugPath<T> = T extends `/${infer L}/${infer R}`\n ? IsValidPathItem<L> extends true\n ? IsValidPathInSlugPath<`/${R}`>\n : false\n : T extends `/${infer U}`\n ? IsValidPathItem<U>\n : false;\n/** Checks if a particular slug name exists in a path. */\nexport type HasSlugInPath<T, K extends string> = T extends `/[${K}]/${infer _}`\n ? true\n : T extends `/${infer _}/${infer U}`\n ? HasSlugInPath<`/${U}`, K>\n : T extends `/[${K}]`\n ? true\n : false;\n\nexport type HasWildcardInPath<T> = T extends `/[...${string}]/${string}`\n ? true\n : T extends `/${infer _}/${infer U}`\n ? HasWildcardInPath<`/${U}`>\n : T extends `/[...${string}]`\n ? true\n : false;\n\nexport type PathWithSlug<T, K extends string> =\n IsValidPathInSlugPath<T> extends true ? (HasSlugInPath<T, K> extends true ? T : never) : never;\n\ntype _GetSlugs<\n Route extends string,\n SplitRoute extends string[] = Split<Route, '/'>,\n Result extends string[] = [],\n> = SplitRoute extends []\n ? Result\n : SplitRoute extends [`${infer MaybeSlug}`, ...infer Rest]\n ? Rest extends string[]\n ? MaybeSlug extends `[${infer Slug}]`\n ? _GetSlugs<Route, Rest, [...Result, Slug]>\n : _GetSlugs<Route, Rest, Result>\n : never\n : Result;\n\nexport type GetSlugs<Route extends string> = _GetSlugs<Route>;\n\nexport type StaticSlugRoutePathsTuple<\n T extends string,\n Slugs extends unknown[] = GetSlugs<T>,\n Result extends string[] = [],\n> = Slugs extends []\n ? Result\n : Slugs extends [infer _, ...infer Rest]\n ? StaticSlugRoutePathsTuple<T, Rest, [...Result, string]>\n : never;\n\ntype StaticSlugRoutePaths<T extends string> =\n HasWildcardInPath<T> extends true\n ? string[] | string[][]\n : StaticSlugRoutePathsTuple<T> extends [string]\n ? string[]\n : StaticSlugRoutePathsTuple<T>[];\n\nexport type PathWithoutSlug<T> = T extends '/'\n ? T\n : IsValidPathInSlugPath<T> extends true\n ? HasSlugInPath<T, string> extends true\n ? never\n : T\n : never;\n\ntype PathWithStaticSlugs<T extends string> = T extends `/`\n ? T\n : IsValidPathInSlugPath<T> extends true\n ? T\n : never;\n\nexport type PathWithWildcard<\n Path,\n SlugKey extends string,\n WildSlugKey extends string,\n> = PathWithSlug<Path, SlugKey | `...${WildSlugKey}`>;\n\nexport type CreatePage = <Path extends string, SlugKey extends string, WildSlugKey extends string>(\n page: (\n | {\n render: 'static';\n path: PathWithoutSlug<Path>;\n component: FunctionComponent<RouteProps>;\n }\n | {\n render: 'static';\n path: PathWithStaticSlugs<Path>;\n staticPaths: StaticSlugRoutePaths<Path>;\n component: FunctionComponent<RouteProps & Record<SlugKey, string>>;\n }\n | {\n render: 'dynamic';\n path: PathWithoutSlug<Path>;\n component: FunctionComponent<RouteProps>;\n }\n | {\n render: 'dynamic';\n path: PathWithWildcard<Path, SlugKey, WildSlugKey>;\n component: FunctionComponent<\n RouteProps & Record<SlugKey, string> & Record<WildSlugKey, string[]>\n >;\n }\n ) & { unstable_disableSSR?: boolean }\n) => void;\n\nexport type CreateLayout = <T extends string>(layout: {\n render: 'static' | 'dynamic';\n path: PathWithoutSlug<T>;\n component: FunctionComponent<Omit<RouteProps, 'searchParams'> & { children: ReactNode }>;\n}) => void;\n\nexport function createPages(\n fn: (\n fns: {\n createPage: CreatePage;\n createLayout: CreateLayout;\n unstable_setBuildData: (path: string, data: unknown) => void;\n },\n opts: {\n unstable_buildConfig: BuildConfig | undefined;\n }\n ) => Promise<void>\n) {\n let configured = false;\n\n // TODO I think there's room for improvement to refactor these structures\n const staticPathSet = new Set<[string, PathSpec]>();\n const dynamicPagePathMap = new Map<string, [PathSpec, FunctionComponent<any>]>();\n const wildcardPagePathMap = new Map<string, [PathSpec, FunctionComponent<any>]>();\n const dynamicLayoutPathMap = new Map<string, [PathSpec, FunctionComponent<any>]>();\n const staticComponentMap = new Map<string, FunctionComponent<any>>();\n const noSsrSet = new WeakSet<PathSpec>();\n const buildDataMap = new Map<string, unknown>();\n\n const registerStaticComponent = (id: string, component: FunctionComponent<any>) => {\n if (staticComponentMap.has(id) && staticComponentMap.get(id) !== component) {\n throw new Error(`Duplicated component for: ${id}`);\n }\n staticComponentMap.set(id, component);\n };\n\n const createPage: CreatePage = (page) => {\n if (configured) {\n throw new Error('no longer available');\n }\n const pathSpec = parsePathWithSlug(page.path);\n if (page.unstable_disableSSR) {\n noSsrSet.add(pathSpec);\n }\n const { numSlugs, numWildcards } = (() => {\n let numSlugs = 0;\n let numWildcards = 0;\n for (const slug of pathSpec) {\n if (slug.type !== 'literal') {\n numSlugs++;\n }\n if (slug.type === 'wildcard') {\n numWildcards++;\n }\n }\n return { numSlugs, numWildcards };\n })();\n if (page.render === 'static' && numSlugs === 0) {\n staticPathSet.add([page.path, pathSpec]);\n const id = joinPath(page.path, 'page').replace(/^\\//, '');\n registerStaticComponent(id, page.component);\n } else if (page.render === 'static' && numSlugs > 0 && 'staticPaths' in page) {\n const staticPaths = page.staticPaths.map((item) =>\n (Array.isArray(item) ? item : [item]).map(sanitizeSlug)\n );\n for (const staticPath of staticPaths) {\n if (staticPath.length !== numSlugs && numWildcards === 0) {\n throw new Error('staticPaths does not match with slug pattern');\n }\n const mapping: Record<string, string | string[]> = {};\n let slugIndex = 0;\n const pathItems: string[] = [];\n pathSpec.forEach(({ type, name }) => {\n switch (type) {\n case 'literal':\n pathItems.push(name!);\n break;\n case 'wildcard':\n mapping[name!] = staticPath.slice(slugIndex);\n staticPath.slice(slugIndex++).forEach((slug) => {\n pathItems.push(slug);\n });\n break;\n case 'group':\n pathItems.push(staticPath[slugIndex++]!);\n mapping[name!] = pathItems[pathItems.length - 1]!;\n break;\n }\n });\n staticPathSet.add([page.path, pathItems.map((name) => ({ type: 'literal', name }))]);\n const id = joinPath(...pathItems, 'page');\n const WrappedComponent = (props: Record<string, unknown>) =>\n createElement(page.component as any, { ...props, ...mapping });\n registerStaticComponent(id, WrappedComponent);\n }\n } else if (page.render === 'dynamic' && numWildcards === 0) {\n if (dynamicPagePathMap.has(page.path)) {\n throw new Error(`Duplicated dynamic path: ${page.path}`);\n }\n dynamicPagePathMap.set(page.path, [pathSpec, page.component]);\n } else if (page.render === 'dynamic' && numWildcards === 1) {\n if (wildcardPagePathMap.has(page.path)) {\n throw new Error(`Duplicated dynamic path: ${page.path}`);\n }\n wildcardPagePathMap.set(page.path, [pathSpec, page.component]);\n } else {\n throw new Error('Invalid page configuration: ' + page.path);\n }\n };\n\n const createLayout: CreateLayout = (layout) => {\n if (configured) {\n throw new Error('no longer available');\n }\n if (layout.render === 'static') {\n const id = joinPath(layout.path, 'layout').replace(/^\\//, '');\n registerStaticComponent(id, layout.component);\n } else if (layout.render === 'dynamic') {\n if (dynamicLayoutPathMap.has(layout.path)) {\n throw new Error(`Duplicated dynamic path: ${layout.path}`);\n }\n const pathSpec = parsePathWithSlug(layout.path);\n dynamicLayoutPathMap.set(layout.path, [pathSpec, layout.component]);\n } else {\n throw new Error('Invalid layout configuration');\n }\n };\n\n const unstable_setBuildData = (path: string, data: unknown) => {\n buildDataMap.set(path, data);\n };\n\n let ready: Promise<void> | undefined;\n const configure = async (buildConfig?: BuildConfig) => {\n if (!configured && !ready) {\n ready = fn(\n { createPage, createLayout, unstable_setBuildData },\n { unstable_buildConfig: buildConfig }\n );\n await ready;\n configured = true;\n }\n await ready;\n };\n\n return unstable_defineRouter(\n async () => {\n await configure();\n const paths: {\n pattern: string;\n path: PathSpec;\n isStatic: boolean;\n noSsr: boolean;\n data: unknown;\n }[] = [];\n for (const [path, pathSpec] of staticPathSet) {\n const noSsr = noSsrSet.has(pathSpec);\n const isStatic = (() => {\n for (const [_, [layoutPathSpec]] of dynamicLayoutPathMap) {\n if (hasPathSpecPrefix(layoutPathSpec, pathSpec)) {\n return false;\n }\n }\n return true;\n })();\n\n paths.push({\n pattern: path2regexp(parsePathWithSlug(path)),\n path: pathSpec,\n isStatic,\n noSsr,\n data: buildDataMap.get(path),\n });\n }\n for (const [path, [pathSpec]] of dynamicPagePathMap) {\n const noSsr = noSsrSet.has(pathSpec);\n paths.push({\n pattern: path2regexp(parsePathWithSlug(path)),\n path: pathSpec,\n isStatic: false,\n noSsr,\n data: buildDataMap.get(path),\n });\n }\n for (const [path, [pathSpec]] of wildcardPagePathMap) {\n const noSsr = noSsrSet.has(pathSpec);\n paths.push({\n pattern: path2regexp(parsePathWithSlug(path)),\n path: pathSpec,\n isStatic: false,\n noSsr,\n data: buildDataMap.get(path),\n });\n }\n return paths;\n },\n async (id, { unstable_setShouldSkip, unstable_buildConfig }) => {\n await configure(unstable_buildConfig);\n const staticComponent = staticComponentMap.get(id);\n if (staticComponent) {\n unstable_setShouldSkip([]);\n return staticComponent;\n }\n for (const [_, [pathSpec, Component]] of dynamicPagePathMap) {\n const mapping = getPathMapping([...pathSpec, { type: 'literal', name: 'page' }], id);\n if (mapping) {\n if (Object.keys(mapping).length === 0) {\n unstable_setShouldSkip();\n return Component;\n }\n const WrappedComponent = (props: Record<string, unknown>) =>\n createElement(Component, { ...props, ...mapping });\n unstable_setShouldSkip();\n return WrappedComponent;\n }\n }\n for (const [_, [pathSpec, Component]] of wildcardPagePathMap) {\n const mapping = getPathMapping([...pathSpec, { type: 'literal', name: 'page' }], id);\n if (mapping) {\n const WrappedComponent = (props: Record<string, unknown>) =>\n createElement(Component, { ...props, ...mapping });\n unstable_setShouldSkip();\n return WrappedComponent;\n }\n }\n for (const [_, [pathSpec, Component]] of dynamicLayoutPathMap) {\n const mapping = getPathMapping([...pathSpec, { type: 'literal', name: 'layout' }], id);\n if (mapping) {\n if (Object.keys(mapping).length) {\n throw new Error('[Bug] layout should not have slugs');\n }\n unstable_setShouldSkip();\n return Component;\n }\n }\n unstable_setShouldSkip([]); // negative cache\n return null; // not found\n }\n );\n}\n"]}
|