expo-router 3.2.0 → 3.3.1
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/_ctx.android.js +1 -1
- package/_ctx.ios.js +1 -1
- package/_ctx.web.js +1 -1
- package/babel.js +1 -209
- package/build/LocationProvider.d.ts.map +1 -1
- package/build/LocationProvider.js +14 -2
- package/build/LocationProvider.js.map +1 -1
- package/build/Route.d.ts +2 -0
- package/build/Route.d.ts.map +1 -1
- package/build/Route.js.map +1 -1
- package/build/fork/getPathFromState.d.ts.map +1 -1
- package/build/fork/getPathFromState.js +7 -3
- package/build/fork/getPathFromState.js.map +1 -1
- package/build/fork/getStateFromPath.d.ts.map +1 -1
- package/build/fork/getStateFromPath.js +12 -4
- package/build/fork/getStateFromPath.js.map +1 -1
- package/build/getRoutes.d.ts +8 -4
- package/build/getRoutes.d.ts.map +1 -1
- package/build/getRoutes.js +105 -24
- package/build/getRoutes.js.map +1 -1
- package/build/getServerManifest.d.ts +14 -37
- package/build/getServerManifest.d.ts.map +1 -1
- package/build/getServerManifest.js.map +1 -1
- package/build/global-state/router-store.js +1 -1
- package/build/global-state/router-store.js.map +1 -1
- package/build/global-state/routing.js +3 -3
- package/build/global-state/routing.js.map +1 -1
- package/build/hooks.d.ts.map +1 -1
- package/build/hooks.js +24 -5
- package/build/hooks.js.map +1 -1
- package/build/import-mode/index.d.ts +1 -1
- package/build/import-mode/index.d.ts.map +1 -1
- package/build/import-mode/index.js +1 -1
- package/build/import-mode/index.js.map +1 -1
- package/build/loadStaticParamsAsync.d.ts +1 -0
- package/build/loadStaticParamsAsync.d.ts.map +1 -1
- package/build/loadStaticParamsAsync.js +107 -72
- package/build/loadStaticParamsAsync.js.map +1 -1
- package/build/qualified-entry.d.ts.map +1 -1
- package/build/qualified-entry.js +7 -5
- package/build/qualified-entry.js.map +1 -1
- package/build/routes-manifest.d.ts.map +1 -1
- package/build/routes-manifest.js +1 -0
- package/build/routes-manifest.js.map +1 -1
- package/build/static/html.d.ts.map +1 -1
- package/build/static/html.js +2 -2
- package/build/static/html.js.map +1 -1
- package/build/static/renderStaticContent.d.ts +3 -30
- package/build/static/renderStaticContent.d.ts.map +1 -1
- package/build/static/renderStaticContent.js +11 -9
- package/build/static/renderStaticContent.js.map +1 -1
- package/build/testing-library/index.js +1 -3
- package/build/testing-library/index.js.map +1 -1
- package/build/testing-library/mocks.d.ts.map +1 -1
- package/build/testing-library/mocks.js +10 -5
- package/build/testing-library/mocks.js.map +1 -1
- package/build/useScreens.d.ts.map +1 -1
- package/build/useScreens.js +13 -20
- package/build/useScreens.js.map +1 -1
- package/build/utils/url.d.ts +2 -0
- package/build/utils/url.d.ts.map +1 -1
- package/build/utils/url.js +13 -1
- package/build/utils/url.js.map +1 -1
- package/build/views/ErrorBoundary.js +7 -3
- package/build/views/ErrorBoundary.js.map +1 -1
- package/build/views/Sitemap.js +5 -1
- package/build/views/Sitemap.js.map +1 -1
- package/build/views/SuspenseFallback.d.ts +1 -1
- package/build/views/SuspenseFallback.d.ts.map +1 -1
- package/build/views/SuspenseFallback.js +7 -3
- package/build/views/SuspenseFallback.js.map +1 -1
- package/html.d.ts +1 -0
- package/ios/ExpoHeadModule.swift +0 -2
- package/package.json +10 -8
- package/plugin/build/index.d.ts +2 -2
- package/plugin/options.json +3 -3
- package/build/import-mode/index.android.d.ts +0 -3
- package/build/import-mode/index.android.d.ts.map +0 -1
- package/build/import-mode/index.android.js +0 -4
- package/build/import-mode/index.android.js.map +0 -1
- package/build/import-mode/index.ios.d.ts +0 -3
- package/build/import-mode/index.ios.d.ts.map +0 -1
- package/build/import-mode/index.ios.js +0 -4
- package/build/import-mode/index.ios.js.map +0 -1
- package/build/import-mode/index.web.d.ts +0 -3
- package/build/import-mode/index.web.d.ts.map +0 -1
- package/build/import-mode/index.web.js +0 -4
- package/build/import-mode/index.web.js.map +0 -1
|
@@ -1,65 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadStaticParamsAsync = void 0;
|
|
4
|
-
async function recurseAndFlattenNodes(nodes, props, func) {
|
|
5
|
-
const tarr = await Promise.all(nodes.map((node) => func(node, props)).flat());
|
|
6
|
-
return tarr.filter(Boolean);
|
|
7
|
-
}
|
|
3
|
+
exports.assertStaticParams = exports.loadStaticParamsAsync = void 0;
|
|
8
4
|
async function loadStaticParamsAsync(route) {
|
|
9
|
-
const
|
|
10
|
-
route.children =
|
|
5
|
+
const expandedChildren = await Promise.all(route.children.map((route) => loadStaticParamsRecursive(route, { parentParams: {} })));
|
|
6
|
+
route.children = expandedChildren.flat();
|
|
11
7
|
return route;
|
|
12
8
|
}
|
|
13
9
|
exports.loadStaticParamsAsync = loadStaticParamsAsync;
|
|
14
|
-
function assertStaticParams(route, params) {
|
|
15
|
-
const matches = route.dynamic.every((dynamic) => {
|
|
16
|
-
const value = params[dynamic.name];
|
|
17
|
-
return value !== undefined && value !== null;
|
|
18
|
-
});
|
|
19
|
-
if (!matches) {
|
|
20
|
-
throw new Error(`generateStaticParams() must return an array of params that match the dynamic route. Received ${JSON.stringify(params)}`);
|
|
21
|
-
}
|
|
22
|
-
const validateSingleParam = (dynamic, value, allowMultipleSegments) => {
|
|
23
|
-
if (typeof value !== 'string') {
|
|
24
|
-
throw new Error(`generateStaticParams() for route "${route.contextKey}" expected param "${dynamic.name}" to be of type string, instead found "${typeof value}" while parsing "${value}".`);
|
|
25
|
-
}
|
|
26
|
-
const parts = value.split('/').filter(Boolean);
|
|
27
|
-
if (parts.length > 1 && !allowMultipleSegments) {
|
|
28
|
-
throw new Error(`generateStaticParams() for route "${route.contextKey}" expected param "${dynamic.name}" to not contain "/" (multiple segments) while parsing "${value}".`);
|
|
29
|
-
}
|
|
30
|
-
if (parts.length === 0) {
|
|
31
|
-
throw new Error(`generateStaticParams() for route "${route.contextKey}" expected param "${dynamic.name}" not to be empty while parsing "${value}".`);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
route.dynamic.forEach((dynamic) => {
|
|
35
|
-
const value = params[dynamic.name];
|
|
36
|
-
if (dynamic.deep) {
|
|
37
|
-
// TODO: We could split strings by `/` and use that too.
|
|
38
|
-
if (!Array.isArray(value)) {
|
|
39
|
-
validateSingleParam(dynamic, value, true);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
validateSingleParam(dynamic, value.filter(Boolean).join('/'), true);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
validateSingleParam(dynamic, value);
|
|
47
|
-
}
|
|
48
|
-
return value !== undefined && value !== null;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/** lodash.uniqBy */
|
|
52
|
-
function uniqBy(array, key) {
|
|
53
|
-
const seen = {};
|
|
54
|
-
return array.filter((item) => {
|
|
55
|
-
const k = key(item);
|
|
56
|
-
if (seen[k]) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
seen[k] = true;
|
|
60
|
-
return true;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
10
|
async function loadStaticParamsRecursive(route, props) {
|
|
64
11
|
if (!route?.dynamic && !route?.children?.length) {
|
|
65
12
|
return [route];
|
|
@@ -70,19 +17,28 @@ async function loadStaticParamsRecursive(route, props) {
|
|
|
70
17
|
staticParams = await loaded.generateStaticParams({
|
|
71
18
|
params: props.parentParams || {},
|
|
72
19
|
});
|
|
73
|
-
|
|
74
|
-
throw new Error(`generateStaticParams() must return an array of params, received ${staticParams}`);
|
|
75
|
-
}
|
|
20
|
+
assertStaticParamsType(staticParams);
|
|
76
21
|
// Assert that at least one param from each matches the dynamic route.
|
|
77
22
|
staticParams.forEach((params) => assertStaticParams(route, params));
|
|
78
23
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
24
|
+
const traverseForNode = async (nextParams) => {
|
|
25
|
+
const nextChildren = [];
|
|
26
|
+
for (const child of route.children) {
|
|
27
|
+
const children = await loadStaticParamsRecursive(child, {
|
|
28
|
+
...props,
|
|
29
|
+
parentParams: nextParams,
|
|
30
|
+
});
|
|
31
|
+
nextChildren.push(...children);
|
|
32
|
+
}
|
|
33
|
+
return uniqBy(nextChildren, (i) => i.route);
|
|
34
|
+
};
|
|
35
|
+
if (!staticParams.length) {
|
|
36
|
+
const nextParams = {
|
|
82
37
|
...props.parentParams,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
38
|
+
};
|
|
39
|
+
route.children = await traverseForNode(nextParams);
|
|
40
|
+
return [route];
|
|
41
|
+
}
|
|
86
42
|
const createParsedRouteName = (input, params) => {
|
|
87
43
|
let parsedRouteName = input;
|
|
88
44
|
route.dynamic?.map((query) => {
|
|
@@ -98,6 +54,11 @@ async function loadStaticParamsRecursive(route, props) {
|
|
|
98
54
|
return parsedRouteName;
|
|
99
55
|
};
|
|
100
56
|
const generatedRoutes = await Promise.all(staticParams.map(async (params) => {
|
|
57
|
+
const nextParams = {
|
|
58
|
+
...props.parentParams,
|
|
59
|
+
...params,
|
|
60
|
+
};
|
|
61
|
+
const dynamicChildren = await traverseForNode(nextParams);
|
|
101
62
|
const parsedRoute = createParsedRouteName(route.route, params);
|
|
102
63
|
const generatedContextKey = createParsedRouteName(route.contextKey, params);
|
|
103
64
|
return {
|
|
@@ -107,15 +68,89 @@ async function loadStaticParamsRecursive(route, props) {
|
|
|
107
68
|
// Convert the dynamic route to a static route.
|
|
108
69
|
dynamic: null,
|
|
109
70
|
route: parsedRoute,
|
|
110
|
-
children:
|
|
111
|
-
...props,
|
|
112
|
-
parentParams: {
|
|
113
|
-
...props.parentParams,
|
|
114
|
-
...staticParams,
|
|
115
|
-
},
|
|
116
|
-
}, loadStaticParamsRecursive)).flat(), (i) => i.route),
|
|
71
|
+
children: dynamicChildren,
|
|
117
72
|
};
|
|
118
73
|
}));
|
|
119
74
|
return [route, ...generatedRoutes];
|
|
120
75
|
}
|
|
76
|
+
/** lodash.uniqBy */
|
|
77
|
+
function uniqBy(array, key) {
|
|
78
|
+
const seen = {};
|
|
79
|
+
return array.filter((item) => {
|
|
80
|
+
const k = key(item);
|
|
81
|
+
if (seen[k]) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
seen[k] = true;
|
|
85
|
+
return true;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function assertStaticParamsType(params) {
|
|
89
|
+
if (!Array.isArray(params)) {
|
|
90
|
+
throw new Error(`generateStaticParams() must return an array of params, received ${params}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function formatExpected(expected, received) {
|
|
94
|
+
const total = {
|
|
95
|
+
...received,
|
|
96
|
+
};
|
|
97
|
+
for (const item of expected) {
|
|
98
|
+
if (total[item] == null) {
|
|
99
|
+
total[item] = String(total[item]);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
total[item] = `"${total[item]}"`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return [
|
|
106
|
+
'{',
|
|
107
|
+
Object.entries(total)
|
|
108
|
+
.map(([key, value]) => ` "${key}": ${value}`)
|
|
109
|
+
.join(',\n'),
|
|
110
|
+
'}',
|
|
111
|
+
].join('\n');
|
|
112
|
+
}
|
|
113
|
+
function assertStaticParams(route, params) {
|
|
114
|
+
// Type checking
|
|
115
|
+
if (!route.dynamic) {
|
|
116
|
+
throw new Error('assertStaticParams() must be called on a dynamic route.');
|
|
117
|
+
}
|
|
118
|
+
const matches = route.dynamic.every((dynamic) => {
|
|
119
|
+
const value = params[dynamic.name];
|
|
120
|
+
return value !== undefined && value !== null;
|
|
121
|
+
});
|
|
122
|
+
if (!matches) {
|
|
123
|
+
const plural = route.dynamic.length > 1 ? 's' : '';
|
|
124
|
+
const expected = route.dynamic.map((dynamic) => dynamic.name);
|
|
125
|
+
throw new Error(`[${route.contextKey}]: generateStaticParams() must return an array of params that match the dynamic route${plural}. Expected non-nullish values for key${plural}: ${expected
|
|
126
|
+
.map((v) => `"${v}"`)
|
|
127
|
+
.join(', ')}.\nReceived:\n${formatExpected(expected, params)}`);
|
|
128
|
+
}
|
|
129
|
+
const validateSingleParam = (dynamic, value, allowMultipleSegments) => {
|
|
130
|
+
if (typeof value !== 'string') {
|
|
131
|
+
throw new Error(`generateStaticParams() for route "${route.contextKey}" expected param "${dynamic.name}" to be of type string, instead found "${typeof value}" while parsing "${value}".`);
|
|
132
|
+
}
|
|
133
|
+
const parts = value.split('/').filter(Boolean);
|
|
134
|
+
if (parts.length > 1 && !allowMultipleSegments) {
|
|
135
|
+
throw new Error(`generateStaticParams() for route "${route.contextKey}" expected param "${dynamic.name}" to not contain "/" (multiple segments) while parsing "${value}".`);
|
|
136
|
+
}
|
|
137
|
+
if (parts.length === 0) {
|
|
138
|
+
throw new Error(`generateStaticParams() for route "${route.contextKey}" expected param "${dynamic.name}" not to be empty while parsing "${value}".`);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
// `[shape]/bar/[...colors]` -> `[shape]`, `[...colors]`
|
|
142
|
+
for (const dynamic of route.dynamic) {
|
|
143
|
+
let parameter = params[dynamic.name];
|
|
144
|
+
if (dynamic.deep) {
|
|
145
|
+
if (Array.isArray(parameter)) {
|
|
146
|
+
parameter = parameter.filter(Boolean).join('/');
|
|
147
|
+
}
|
|
148
|
+
validateSingleParam(dynamic, parameter, true);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
validateSingleParam(dynamic, parameter);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.assertStaticParams = assertStaticParams;
|
|
121
156
|
//# sourceMappingURL=loadStaticParamsAsync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadStaticParamsAsync.js","sourceRoot":"","sources":["../src/loadStaticParamsAsync.ts"],"names":[],"mappings":";;;AAEA,KAAK,UAAU,sBAAsB,CAInC,KAAU,EAAE,KAAa,EAAE,IAAc;IACzC,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,G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BACR,YAAY,EAAE;oBACZ,GAAG,KAAK,CAAC,YAAY;oBACrB,GAAG,YAAY;iBAChB;aACF,EACD,yBAAyB,CAC1B,CACF,CAAC,IAAI,EAAE,EACR,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CACf;SACF,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,CAAC,KAAK,EAAE,GAAG,eAAe,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import type { DynamicConvention, RouteNode } from './Route';\n\nasync function recurseAndFlattenNodes<\n T,\n TProps,\n TProcess extends (node: T, props: any) => Promise<T[]>,\n>(nodes: T[], props: TProps, func: TProcess): Promise<T[]> {\n const tarr = await Promise.all(nodes.map((node) => func(node, props)).flat());\n return tarr.filter(Boolean) as T[];\n}\n\nexport async function loadStaticParamsAsync(route: RouteNode): Promise<RouteNode> {\n const processed = (\n await Promise.all(\n route.children.map((route) => loadStaticParamsRecursive(route, { parentParams: {} }))\n )\n ).flat();\n\n route.children = processed;\n return route;\n}\n\nfunction assertStaticParams(route: RouteNode, params: Record<string, string | string[]>) {\n const matches = route.dynamic!.every((dynamic) => {\n const value = params[dynamic.name];\n return value !== undefined && value !== null;\n });\n if (!matches) {\n throw new Error(\n `generateStaticParams() must return an array of params that match the dynamic route. Received ${JSON.stringify(\n params\n )}`\n );\n }\n\n const validateSingleParam = (\n dynamic: DynamicConvention,\n value: any,\n allowMultipleSegments?: boolean\n ) => {\n if (typeof value !== 'string') {\n throw new Error(\n `generateStaticParams() for route \"${route.contextKey}\" expected param \"${\n dynamic.name\n }\" to be of type string, instead found \"${typeof value}\" while parsing \"${value}\".`\n );\n }\n const parts = value.split('/').filter(Boolean);\n if (parts.length > 1 && !allowMultipleSegments) {\n throw new Error(\n `generateStaticParams() for route \"${route.contextKey}\" expected param \"${dynamic.name}\" to not contain \"/\" (multiple segments) while parsing \"${value}\".`\n );\n }\n if (parts.length === 0) {\n throw new Error(\n `generateStaticParams() for route \"${route.contextKey}\" expected param \"${dynamic.name}\" not to be empty while parsing \"${value}\".`\n );\n }\n };\n\n route.dynamic!.forEach((dynamic) => {\n const value = params[dynamic.name];\n if (dynamic.deep) {\n // TODO: We could split strings by `/` and use that too.\n if (!Array.isArray(value)) {\n validateSingleParam(dynamic, value, true);\n } else {\n validateSingleParam(dynamic, value.filter(Boolean).join('/'), true);\n }\n } else {\n validateSingleParam(dynamic, value);\n }\n return value !== undefined && value !== null;\n });\n}\n\n/** lodash.uniqBy */\nfunction uniqBy<T>(array: T[], key: (item: T) => string): T[] {\n const seen: { [key: string]: boolean } = {};\n return array.filter((item) => {\n const k = key(item);\n if (seen[k]) {\n return false;\n }\n seen[k] = true;\n return true;\n });\n}\n\nasync function loadStaticParamsRecursive(\n route: RouteNode,\n props: { parentParams: any }\n): Promise<RouteNode[]> {\n if (!route?.dynamic && !route?.children?.length) {\n return [route];\n }\n\n const loaded = await route.loadRoute();\n\n let staticParams: Record<string, string | string[]>[] = [];\n\n if (loaded.generateStaticParams) {\n staticParams = await loaded.generateStaticParams({\n params: props.parentParams || {},\n });\n if (!Array.isArray(staticParams)) {\n throw new Error(\n `generateStaticParams() must return an array of params, received ${staticParams}`\n );\n }\n\n // Assert that at least one param from each matches the dynamic route.\n staticParams.forEach((params) => assertStaticParams(route, params));\n }\n\n route.children = uniqBy(\n (\n await recurseAndFlattenNodes(\n [...route.children],\n {\n ...props,\n parentParams: {\n ...props.parentParams,\n ...staticParams,\n },\n },\n loadStaticParamsRecursive\n )\n ).flat(),\n (i) => i.route\n );\n\n const createParsedRouteName = (input: string, params: any) => {\n let parsedRouteName = input;\n route.dynamic?.map((query) => {\n const param = params[query.name];\n const formattedParameter = Array.isArray(param) ? param.join('/') : param;\n if (query.deep) {\n parsedRouteName = parsedRouteName.replace(`[...${query.name}]`, formattedParameter);\n } else {\n parsedRouteName = parsedRouteName.replace(`[${query.name}]`, param);\n }\n });\n\n return parsedRouteName;\n };\n\n const generatedRoutes = await Promise.all(\n staticParams.map(async (params) => {\n const parsedRoute = createParsedRouteName(route.route, params);\n const generatedContextKey = createParsedRouteName(route.contextKey, params);\n\n return {\n ...route,\n // TODO: Add a new field for this\n contextKey: generatedContextKey,\n // Convert the dynamic route to a static route.\n dynamic: null,\n route: parsedRoute,\n children: uniqBy(\n (\n await recurseAndFlattenNodes(\n [...route.children],\n {\n ...props,\n parentParams: {\n ...props.parentParams,\n ...staticParams,\n },\n },\n loadStaticParamsRecursive\n )\n ).flat(),\n (i) => i.route\n ),\n };\n })\n );\n\n return [route, ...generatedRoutes];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"loadStaticParamsAsync.js","sourceRoot":"","sources":["../src/loadStaticParamsAsync.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,qBAAqB,CAAC,KAAgB;IAC1D,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,GAAG,CACxC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,yBAAyB,CAAC,KAAK,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC,CACtF,CAAC;IACF,KAAK,CAAC,QAAQ,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC;IACzC,OAAO,KAAK,CAAC;AACf,CAAC;AAND,sDAMC;AAED,KAAK,UAAU,yBAAyB,CACtC,KAAgB,EAChB,KAA4B;IAE5B,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE;QAC/C,OAAO,CAAC,KAAK,CAAC,CAAC;KAChB;IAED,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,SAAS,EAAE,CAAC;IAEvC,IAAI,YAAY,GAAwC,EAAE,CAAC;IAE3D,IAAI,MAAM,CAAC,oBAAoB,EAAE;QAC/B,YAAY,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC;YAC/C,MAAM,EAAE,KAAK,CAAC,YAAY,IAAI,EAAE;SACjC,CAAC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AM,KAAK,CAAC,EAAE;YACtB,MAAM,IAAI,KAAK,CACb,qCAAqC,KAAK,CAAC,UAAU,qBAAqB,OAAO,CAAC,IAAI,oCAAoC,KAAK,IAAI,CACpI,CAAC;SACH;IACH,CAAC,CAAC;IAEF,wDAAwD;IACxD,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE;QACnC,IAAI,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,OAAO,CAAC,IAAI,EAAE;YAChB,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;gBAC5B,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACjD;YACD,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;SAC/C;aAAM;YACL,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;SACzC;KACF;AACH,CAAC;AA7DD,gDA6DC","sourcesContent":["import type { DynamicConvention, RouteNode } from './Route';\n\nexport async function loadStaticParamsAsync(route: RouteNode): Promise<RouteNode> {\n const expandedChildren = await Promise.all(\n route.children.map((route) => loadStaticParamsRecursive(route, { parentParams: {} }))\n );\n route.children = expandedChildren.flat();\n return route;\n}\n\nasync function loadStaticParamsRecursive(\n route: RouteNode,\n props: { parentParams: any }\n): Promise<RouteNode[]> {\n if (!route?.dynamic && !route?.children?.length) {\n return [route];\n }\n\n const loaded = await route.loadRoute();\n\n let staticParams: Record<string, string | string[]>[] = [];\n\n if (loaded.generateStaticParams) {\n staticParams = await loaded.generateStaticParams({\n params: props.parentParams || {},\n });\n\n assertStaticParamsType(staticParams);\n // Assert that at least one param from each matches the dynamic route.\n staticParams.forEach((params) => assertStaticParams(route, params));\n }\n\n const traverseForNode = async (nextParams: Record<string, string | string[]>) => {\n const nextChildren: RouteNode[] = [];\n for (const child of route.children) {\n const children = await loadStaticParamsRecursive(child, {\n ...props,\n parentParams: nextParams,\n });\n nextChildren.push(...children);\n }\n\n return uniqBy(nextChildren, (i) => i.route);\n };\n\n if (!staticParams.length) {\n const nextParams = {\n ...props.parentParams,\n };\n\n route.children = await traverseForNode(nextParams);\n\n return [route];\n }\n\n const createParsedRouteName = (input: string, params: any) => {\n let parsedRouteName = input;\n route.dynamic?.map((query) => {\n const param = params[query.name];\n const formattedParameter = Array.isArray(param) ? param.join('/') : param;\n if (query.deep) {\n parsedRouteName = parsedRouteName.replace(`[...${query.name}]`, formattedParameter);\n } else {\n parsedRouteName = parsedRouteName.replace(`[${query.name}]`, param);\n }\n });\n\n return parsedRouteName;\n };\n\n const generatedRoutes = await Promise.all(\n staticParams.map(async (params) => {\n const nextParams = {\n ...props.parentParams,\n ...params,\n };\n\n const dynamicChildren = await traverseForNode(nextParams);\n const parsedRoute = createParsedRouteName(route.route, params);\n const generatedContextKey = createParsedRouteName(route.contextKey, params);\n\n return {\n ...route,\n // TODO: Add a new field for this\n contextKey: generatedContextKey,\n // Convert the dynamic route to a static route.\n dynamic: null,\n route: parsedRoute,\n children: dynamicChildren,\n };\n })\n );\n\n return [route, ...generatedRoutes];\n}\n\n/** lodash.uniqBy */\nfunction uniqBy<T>(array: T[], key: (item: T) => string): T[] {\n const seen: { [key: string]: boolean } = {};\n return array.filter((item) => {\n const k = key(item);\n if (seen[k]) {\n return false;\n }\n seen[k] = true;\n return true;\n });\n}\n\nfunction assertStaticParamsType(params: any): asserts params is Record<string, string | string[]> {\n if (!Array.isArray(params)) {\n throw new Error(`generateStaticParams() must return an array of params, received ${params}`);\n }\n}\n\nfunction formatExpected(expected: string[], received: Record<string, any>): string {\n const total = {\n ...received,\n };\n for (const item of expected) {\n if (total[item] == null) {\n total[item] = String(total[item]);\n } else {\n total[item] = `\"${total[item]}\"`;\n }\n }\n\n return [\n '{',\n Object.entries(total)\n .map(([key, value]) => ` \"${key}\": ${value}`)\n .join(',\\n'),\n '}',\n ].join('\\n');\n}\n\nexport function assertStaticParams(\n route: Pick<RouteNode, 'contextKey' | 'dynamic'>,\n params: Record<string, string | string[]>\n) {\n // Type checking\n if (!route.dynamic) {\n throw new Error('assertStaticParams() must be called on a dynamic route.');\n }\n const matches = route.dynamic.every((dynamic) => {\n const value = params[dynamic.name];\n return value !== undefined && value !== null;\n });\n if (!matches) {\n const plural = route.dynamic.length > 1 ? 's' : '';\n const expected = route.dynamic.map((dynamic) => dynamic.name);\n throw new Error(\n `[${\n route.contextKey\n }]: generateStaticParams() must return an array of params that match the dynamic route${plural}. Expected non-nullish values for key${plural}: ${expected\n .map((v) => `\"${v}\"`)\n .join(', ')}.\\nReceived:\\n${formatExpected(expected, params)}`\n );\n }\n\n const validateSingleParam = (\n dynamic: DynamicConvention,\n value: any,\n allowMultipleSegments?: boolean\n ) => {\n if (typeof value !== 'string') {\n throw new Error(\n `generateStaticParams() for route \"${route.contextKey}\" expected param \"${\n dynamic.name\n }\" to be of type string, instead found \"${typeof value}\" while parsing \"${value}\".`\n );\n }\n const parts = value.split('/').filter(Boolean);\n if (parts.length > 1 && !allowMultipleSegments) {\n throw new Error(\n `generateStaticParams() for route \"${route.contextKey}\" expected param \"${dynamic.name}\" to not contain \"/\" (multiple segments) while parsing \"${value}\".`\n );\n }\n if (parts.length === 0) {\n throw new Error(\n `generateStaticParams() for route \"${route.contextKey}\" expected param \"${dynamic.name}\" not to be empty while parsing \"${value}\".`\n );\n }\n };\n\n // `[shape]/bar/[...colors]` -> `[shape]`, `[...colors]`\n for (const dynamic of route.dynamic) {\n let parameter = params[dynamic.name];\n if (dynamic.deep) {\n if (Array.isArray(parameter)) {\n parameter = parameter.filter(Boolean).join('/');\n }\n validateSingleParam(dynamic, parameter, true);\n } else {\n validateSingleParam(dynamic, parameter);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qualified-entry.d.ts","sourceRoot":"","sources":["../src/qualified-entry.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"qualified-entry.d.ts","sourceRoot":"","sources":["../src/qualified-entry.tsx"],"names":[],"mappings":";AAcA,wBAAgB,GAAG,gBAMlB"}
|
package/build/qualified-entry.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// The entry component (one that uses context modules) cannot be in the same file as the
|
|
3
|
+
// entry side-effects, otherwise they'll be updated when files are added/removed from the
|
|
4
|
+
// app directory. This will cause a lot of unfortunate errors regarding HMR and Fast Refresh.
|
|
5
|
+
// This is because Fast Refresh is sending the entire file containing an updated component.
|
|
2
6
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
8
|
};
|
|
5
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
10
|
exports.App = void 0;
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
// This is because Fast Refresh is sending the entire file containing an updated component.
|
|
11
|
+
// This has to be the string "expo-router/_ctx" as we resolve the exact string to
|
|
12
|
+
// a different file in a custom resolver for bundle splitting in Node.js.
|
|
13
|
+
const _ctx_1 = require("expo-router/_ctx");
|
|
11
14
|
const react_1 = __importDefault(require("react"));
|
|
12
15
|
const ExpoRoot_1 = require("./ExpoRoot");
|
|
13
16
|
const head_1 = require("./head");
|
|
14
|
-
const _ctx_1 = require("../_ctx");
|
|
15
17
|
// Must be exported or Fast Refresh won't update the context
|
|
16
18
|
function App() {
|
|
17
19
|
return (<head_1.Head.Provider>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qualified-entry.js","sourceRoot":"","sources":["../src/qualified-entry.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"qualified-entry.js","sourceRoot":"","sources":["../src/qualified-entry.tsx"],"names":[],"mappings":";AAAA,wFAAwF;AACxF,yFAAyF;AACzF,6FAA6F;AAC7F,2FAA2F;;;;;;AAE3F,iFAAiF;AACjF,yEAAyE;AACzE,2CAAuC;AACvC,kDAA0B;AAE1B,yCAAsC;AACtC,iCAA8B;AAE9B,4DAA4D;AAC5D,SAAgB,GAAG;IACjB,OAAO,CACL,CAAC,WAAI,CAAC,QAAQ,CACZ;MAAA,CAAC,mBAAQ,CAAC,OAAO,CAAC,CAAC,UAAG,CAAC,EACzB;IAAA,EAAE,WAAI,CAAC,QAAQ,CAAC,CACjB,CAAC;AACJ,CAAC;AAND,kBAMC","sourcesContent":["// The entry component (one that uses context modules) cannot be in the same file as the\n// entry side-effects, otherwise they'll be updated when files are added/removed from the\n// app directory. This will cause a lot of unfortunate errors regarding HMR and Fast Refresh.\n// This is because Fast Refresh is sending the entire file containing an updated component.\n\n// This has to be the string \"expo-router/_ctx\" as we resolve the exact string to\n// a different file in a custom resolver for bundle splitting in Node.js.\nimport { ctx } from 'expo-router/_ctx';\nimport React from 'react';\n\nimport { ExpoRoot } from './ExpoRoot';\nimport { Head } from './head';\n\n// Must be exported or Fast Refresh won't update the context\nexport function App() {\n return (\n <Head.Provider>\n <ExpoRoot context={ctx} />\n </Head.Provider>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes-manifest.d.ts","sourceRoot":"","sources":["../src/routes-manifest.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,SAAS,CAAC,MAAM,GAAG,MAAM,IAAI;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAAC,MAAM,GAAG,MAAM,IAAI;IAClD,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;IAC/B,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;IAChC,cAAc,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;CACrC,CAAC;AAYF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,oBAAoB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"routes-manifest.d.ts","sourceRoot":"","sources":["../src/routes-manifest.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,SAAS,CAAC,MAAM,GAAG,MAAM,IAAI;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAAC,MAAM,GAAG,MAAM,IAAI;IAClD,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;IAC/B,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;IAChC,cAAc,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;CACrC,CAAC;AAYF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,oBAAoB,GAAG,IAAI,CAYjF"}
|
package/build/routes-manifest.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes-manifest.js","sourceRoot":"","sources":["../src/routes-manifest.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,sBAAsB;AACtB,2CAAwC;AACxC,2DAAwD;AAgBxD,SAAS,uBAAuB,CAAC,MAAgB,EAAE;IACjD,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,KAAI,CAAC,EAAE,CAAC,CAAC;IAElD,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE;QAC3C,KAAK,EAAE,GAAG,EAAE,CAAC,GAAG;KACjB,CAAC,CAAC;IAEH,OAAO,aAA+B,CAAC;AACzC,CAAC;AAED,SAAgB,oBAAoB,CAAC,KAAe;IAClD,mCAAmC;IACnC,MAAM,SAAS,GAAG,IAAA,qBAAS,EAAC,uBAAuB,CAAC,KAAK,CAAC,EAAE;QAC1D,iBAAiB,EAAE,IAAI;QACvB,mBAAmB,EAAE,IAAI;
|
|
1
|
+
{"version":3,"file":"routes-manifest.js","sourceRoot":"","sources":["../src/routes-manifest.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,sBAAsB;AACtB,2CAAwC;AACxC,2DAAwD;AAgBxD,SAAS,uBAAuB,CAAC,MAAgB,EAAE;IACjD,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,KAAI,CAAC,EAAE,CAAC,CAAC;IAElD,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE;QAC3C,KAAK,EAAE,GAAG,EAAE,CAAC,GAAG;KACjB,CAAC,CAAC;IAEH,OAAO,aAA+B,CAAC;AACzC,CAAC;AAED,SAAgB,oBAAoB,CAAC,KAAe;IAClD,mCAAmC;IACnC,MAAM,SAAS,GAAG,IAAA,qBAAS,EAAC,uBAAuB,CAAC,KAAK,CAAC,EAAE;QAC1D,iBAAiB,EAAE,IAAI;QACvB,mBAAmB,EAAE,IAAI;QACzB,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC;IAEH,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,IAAI,CAAC;KACb;IACD,OAAO,IAAA,qCAAiB,EAAC,SAAS,CAAC,CAAC;AACtC,CAAC;AAZD,oDAYC","sourcesContent":["// This file runs in Node.js environments.\n// no relative imports\nimport { getRoutes } from './getRoutes';\nimport { getServerManifest } from './getServerManifest';\nimport { RequireContext } from './types';\n\nexport type RouteInfo<TRegex = string> = {\n file: string;\n page: string;\n namedRegex: TRegex;\n routeKeys: { [named: string]: string };\n};\n\nexport type ExpoRoutesManifestV1<TRegex = string> = {\n apiRoutes: RouteInfo<TRegex>[];\n htmlRoutes: RouteInfo<TRegex>[];\n notFoundRoutes: RouteInfo<TRegex>[];\n};\n\nfunction createMockContextModule(map: string[] = []) {\n const contextModule = (key) => ({ default() {} });\n\n Object.defineProperty(contextModule, 'keys', {\n value: () => map,\n });\n\n return contextModule as RequireContext;\n}\n\nexport function createRoutesManifest(paths: string[]): ExpoRoutesManifestV1 | null {\n // TODO: Drop this part for Node.js\n const routeTree = getRoutes(createMockContextModule(paths), {\n preserveApiRoutes: true,\n ignoreRequireErrors: true,\n ignoreEntryPoints: true,\n });\n\n if (!routeTree) {\n return null;\n }\n return getServerManifest(routeTree);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/static/html.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;GAEG;AACH,wBAAgB,oBAAoB,gBASnC;AAED,wBAAgB,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/static/html.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;GAEG;AACH,wBAAgB,oBAAoB,gBASnC;AAED,wBAAgB,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,eAY/D"}
|
package/build/static/html.js
CHANGED
|
@@ -16,7 +16,7 @@ const react_1 = __importDefault(require("react"));
|
|
|
16
16
|
*/
|
|
17
17
|
function ScrollViewStyleReset() {
|
|
18
18
|
return (<style id="expo-reset" dangerouslySetInnerHTML={{
|
|
19
|
-
__html: `#root,body
|
|
19
|
+
__html: `#root,body,html{height:100%}body{overflow:hidden}#root{display:flex}`,
|
|
20
20
|
}}/>);
|
|
21
21
|
}
|
|
22
22
|
exports.ScrollViewStyleReset = ScrollViewStyleReset;
|
|
@@ -25,7 +25,7 @@ function Html({ children }) {
|
|
|
25
25
|
<head>
|
|
26
26
|
<meta charSet="utf-8"/>
|
|
27
27
|
<meta httpEquiv="X-UA-Compatible" content="IE=edge"/>
|
|
28
|
-
<meta name="viewport" content="width=device-width,initial-scale=1,
|
|
28
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
|
|
29
29
|
<ScrollViewStyleReset />
|
|
30
30
|
</head>
|
|
31
31
|
<body>{children}</body>
|
package/build/static/html.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/static/html.tsx"],"names":[],"mappings":";;;;;;AAAA;;;;;GAKG;AACH,kDAA0B;AAE1B;;GAEG;AACH,SAAgB,oBAAoB;IAClC,OAAO,CACL,CAAC,KAAK,CACJ,EAAE,CAAC,YAAY,CACf,uBAAuB,CAAC,CAAC;YACvB,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/static/html.tsx"],"names":[],"mappings":";;;;;;AAAA;;;;;GAKG;AACH,kDAA0B;AAE1B;;GAEG;AACH,SAAgB,oBAAoB;IAClC,OAAO,CACL,CAAC,KAAK,CACJ,EAAE,CAAC,YAAY,CACf,uBAAuB,CAAC,CAAC;YACvB,MAAM,EAAE,sEAAsE;SAC/E,CAAC,EACF,CACH,CAAC;AACJ,CAAC;AATD,oDASC;AAED,SAAgB,IAAI,CAAC,EAAE,QAAQ,EAAiC;IAC9D,OAAO,CACL,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CACb;MAAA,CAAC,IAAI,CACH;QAAA,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EACrB;QAAA,CAAC,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,OAAO,CAAC,SAAS,EACnD;QAAA,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,uDAAuD,EACrF;QAAA,CAAC,oBAAoB,CAAC,AAAD,EACvB;MAAA,EAAE,IAAI,CACN;MAAA,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,CACxB;IAAA,EAAE,IAAI,CAAC,CACR,CAAC;AACJ,CAAC;AAZD,oBAYC","sourcesContent":["/**\n * Copyright © 2023 650 Industries.\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 */\nimport React from 'react';\n\n/**\n * Root style-reset for full-screen React Native web apps with a root `<ScrollView />` should use the following styles to ensure native parity. [Learn more](https://necolas.github.io/react-native-web/docs/setup/#root-element).\n */\nexport function ScrollViewStyleReset() {\n return (\n <style\n id=\"expo-reset\"\n dangerouslySetInnerHTML={{\n __html: `#root,body,html{height:100%}body{overflow:hidden}#root{display:flex}`,\n }}\n />\n );\n}\n\nexport function Html({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\">\n <head>\n <meta charSet=\"utf-8\" />\n <meta httpEquiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\" />\n <ScrollViewStyleReset />\n </head>\n <body>{children}</body>\n </html>\n );\n}\n"]}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import '@expo/metro-runtime';
|
|
8
8
|
import { getRoutes } from '../getRoutes';
|
|
9
|
+
import { ExpoRouterServerManifestV1 } from '../getServerManifest';
|
|
9
10
|
/** Get the linking manifest from a Node.js process. */
|
|
10
11
|
declare function getManifest(options?: Parameters<typeof getRoutes>[1]): Promise<{
|
|
11
12
|
initialRouteName?: string | undefined;
|
|
@@ -18,35 +19,7 @@ declare function getManifest(options?: Parameters<typeof getRoutes>[1]): Promise
|
|
|
18
19
|
*
|
|
19
20
|
* This is used for the production manifest where we pre-render certain pages and should no longer treat them as dynamic.
|
|
20
21
|
*/
|
|
21
|
-
declare function getBuildTimeServerManifestAsync(options?: Parameters<typeof getRoutes>[1]): Promise<
|
|
22
|
-
|
|
23
|
-
generated: boolean | undefined;
|
|
24
|
-
file: string;
|
|
25
|
-
page: string;
|
|
26
|
-
namedRegex: string;
|
|
27
|
-
routeKeys: {
|
|
28
|
-
[named: string]: string;
|
|
29
|
-
};
|
|
30
|
-
}[];
|
|
31
|
-
htmlRoutes: {
|
|
32
|
-
generated: boolean | undefined;
|
|
33
|
-
file: string;
|
|
34
|
-
page: string;
|
|
35
|
-
namedRegex: string;
|
|
36
|
-
routeKeys: {
|
|
37
|
-
[named: string]: string;
|
|
38
|
-
};
|
|
39
|
-
}[];
|
|
40
|
-
notFoundRoutes: {
|
|
41
|
-
generated: boolean | undefined;
|
|
42
|
-
file: string;
|
|
43
|
-
page: string;
|
|
44
|
-
namedRegex: string;
|
|
45
|
-
routeKeys: {
|
|
46
|
-
[named: string]: string;
|
|
47
|
-
};
|
|
48
|
-
}[];
|
|
49
|
-
}>;
|
|
50
|
-
export declare function getStaticContent(location: URL): string;
|
|
22
|
+
declare function getBuildTimeServerManifestAsync(options?: Parameters<typeof getRoutes>[1]): Promise<ExpoRouterServerManifestV1>;
|
|
23
|
+
export declare function getStaticContent(location: URL): Promise<string>;
|
|
51
24
|
export { getManifest, getBuildTimeServerManifestAsync };
|
|
52
25
|
//# sourceMappingURL=renderStaticContent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderStaticContent.d.ts","sourceRoot":"","sources":["../../src/static/renderStaticContent.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,qBAAqB,CAAC;AAY7B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"renderStaticContent.d.ts","sourceRoot":"","sources":["../../src/static/renderStaticContent.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,qBAAqB,CAAC;AAY7B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAqB,MAAM,sBAAsB,CAAC;AAQrF,uDAAuD;AACvD,iBAAe,WAAW,CAAC,OAAO,GAAE,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAM;;;GAWvE;AAED;;;;;;GAMG;AACH,iBAAe,+BAA+B,CAC5C,OAAO,GAAE,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAM,GAC5C,OAAO,CAAC,0BAA0B,CAAC,CAWrC;AAYD,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CA0DrE;AAmBD,OAAO,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC"}
|
|
@@ -37,12 +37,12 @@ require("@expo/metro-runtime");
|
|
|
37
37
|
const native_1 = require("@react-navigation/native");
|
|
38
38
|
const Font = __importStar(require("expo-font/build/server"));
|
|
39
39
|
const react_1 = __importDefault(require("react"));
|
|
40
|
-
const
|
|
40
|
+
const server_node_1 = __importDefault(require("react-dom/server.node"));
|
|
41
41
|
const react_native_web_1 = require("react-native-web");
|
|
42
42
|
const getRootComponent_1 = require("./getRootComponent");
|
|
43
43
|
const _ctx_1 = require("../../_ctx");
|
|
44
44
|
const ExpoRoot_1 = require("../ExpoRoot");
|
|
45
|
-
const
|
|
45
|
+
const getReactNavigationConfig_1 = require("../getReactNavigationConfig");
|
|
46
46
|
const getRoutes_1 = require("../getRoutes");
|
|
47
47
|
const getServerManifest_1 = require("../getServerManifest");
|
|
48
48
|
const head_1 = require("../head");
|
|
@@ -57,7 +57,7 @@ async function getManifest(options = {}) {
|
|
|
57
57
|
}
|
|
58
58
|
// Evaluate all static params
|
|
59
59
|
await (0, loadStaticParamsAsync_1.loadStaticParamsAsync)(routeTree);
|
|
60
|
-
return (0,
|
|
60
|
+
return (0, getReactNavigationConfig_1.getReactNavigationConfig)(routeTree, false);
|
|
61
61
|
}
|
|
62
62
|
exports.getManifest = getManifest;
|
|
63
63
|
/**
|
|
@@ -68,9 +68,7 @@ exports.getManifest = getManifest;
|
|
|
68
68
|
* This is used for the production manifest where we pre-render certain pages and should no longer treat them as dynamic.
|
|
69
69
|
*/
|
|
70
70
|
async function getBuildTimeServerManifestAsync(options = {}) {
|
|
71
|
-
const routeTree = (0, getRoutes_1.getRoutes)(_ctx_1.ctx,
|
|
72
|
-
...options,
|
|
73
|
-
});
|
|
71
|
+
const routeTree = (0, getRoutes_1.getRoutes)(_ctx_1.ctx, options);
|
|
74
72
|
if (!routeTree) {
|
|
75
73
|
throw new Error('No routes found');
|
|
76
74
|
}
|
|
@@ -87,7 +85,7 @@ function resetReactNavigationContexts() {
|
|
|
87
85
|
const contexts = '__react_navigation__elements_contexts';
|
|
88
86
|
global[contexts] = new Map();
|
|
89
87
|
}
|
|
90
|
-
function getStaticContent(location) {
|
|
88
|
+
async function getStaticContent(location) {
|
|
91
89
|
const headContext = {};
|
|
92
90
|
const ref = react_1.default.createRef();
|
|
93
91
|
const {
|
|
@@ -109,11 +107,15 @@ function getStaticContent(location) {
|
|
|
109
107
|
// This MUST be run before `ReactDOMServer.renderToString` to prevent
|
|
110
108
|
// "Warning: Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported."
|
|
111
109
|
resetReactNavigationContexts();
|
|
112
|
-
const
|
|
110
|
+
const stream = await server_node_1.default.renderToStaticNodeStream(<head_1.Head.Provider context={headContext}>
|
|
113
111
|
<native_1.ServerContainer ref={ref}>{element}</native_1.ServerContainer>
|
|
114
112
|
</head_1.Head.Provider>);
|
|
113
|
+
let html = '';
|
|
114
|
+
for await (const chunk of stream) {
|
|
115
|
+
html += chunk;
|
|
116
|
+
}
|
|
115
117
|
// Eval the CSS after the HTML is rendered so that the CSS is in the same order
|
|
116
|
-
const css =
|
|
118
|
+
const css = server_node_1.default.renderToStaticMarkup(getStyleElement());
|
|
117
119
|
let output = mixHeadComponentsWithStaticResults(headContext.helmet, html);
|
|
118
120
|
output = output.replace('</head>', `${css}</head>`);
|
|
119
121
|
const fonts = Font.getServerResources();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderStaticContent.js","sourceRoot":"","sources":["../../src/static/renderStaticContent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,+BAA6B;AAE7B,qDAA+E;AAC/E,6DAA+C;AAC/C,kDAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"renderStaticContent.js","sourceRoot":"","sources":["../../src/static/renderStaticContent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,+BAA6B;AAE7B,qDAA+E;AAC/E,6DAA+C;AAC/C,kDAA0B;AAC1B,wEAAmD;AACnD,uDAA+C;AAE/C,yDAAsD;AACtD,qCAAiC;AACjC,0CAAuC;AACvC,0EAAuE;AACvE,4CAAyC;AACzC,4DAAqF;AACrF,kCAA+B;AAC/B,oEAAiE;AAEjE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,iCAAiC,CAAC,CAAC;AAElE,8BAAW,CAAC,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,mBAAQ,CAAC,CAAC;AAErD,uDAAuD;AACvD,KAAK,UAAU,WAAW,CAAC,UAA2C,EAAE;IACtE,MAAM,SAAS,GAAG,IAAA,qBAAS,EAAC,UAAG,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAE1E,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;KACpC;IAED,6BAA6B;IAC7B,MAAM,IAAA,6CAAqB,EAAC,SAAS,CAAC,CAAC;IAEvC,OAAO,IAAA,mDAAwB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC;AA+GQ,kCAAW;AA7GpB;;;;;;GAMG;AACH,KAAK,UAAU,+BAA+B,CAC5C,UA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,EAAE,QAAQ,EAAE,CAAC;QACzC,IAAI,MAAM,EAAE;YACV,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;SAClD;KACF;IAED,aAAa;IACb,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC7E,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAE7E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * Copyright © 2023 650 Industries.\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 */\nimport '@expo/metro-runtime';\n\nimport { ServerContainer, ServerContainerRef } from '@react-navigation/native';\nimport * as Font from 'expo-font/build/server';\nimport React from 'react';\nimport ReactDOMServer from 'react-dom/server.node';\nimport { AppRegistry } from 'react-native-web';\n\nimport { getRootComponent } from './getRootComponent';\nimport { ctx } from '../../_ctx';\nimport { ExpoRoot } from '../ExpoRoot';\nimport { getReactNavigationConfig } from '../getReactNavigationConfig';\nimport { getRoutes } from '../getRoutes';\nimport { ExpoRouterServerManifestV1, getServerManifest } from '../getServerManifest';\nimport { Head } from '../head';\nimport { loadStaticParamsAsync } from '../loadStaticParamsAsync';\n\nconst debug = require('debug')('expo:router:renderStaticContent');\n\nAppRegistry.registerComponent('App', () => ExpoRoot);\n\n/** Get the linking manifest from a Node.js process. */\nasync function getManifest(options: Parameters<typeof getRoutes>[1] = {}) {\n const routeTree = getRoutes(ctx, { preserveApiRoutes: true, ...options });\n\n if (!routeTree) {\n throw new Error('No routes found');\n }\n\n // Evaluate all static params\n await loadStaticParamsAsync(routeTree);\n\n return getReactNavigationConfig(routeTree, false);\n}\n\n/**\n * Get the server manifest with all dynamic routes loaded with `generateStaticParams`.\n * Unlike the `expo-router/src/routes-manifest.ts` method, this requires loading the entire app in-memory, which\n * takes substantially longer and requires Metro bundling.\n *\n * This is used for the production manifest where we pre-render certain pages and should no longer treat them as dynamic.\n */\nasync function getBuildTimeServerManifestAsync(\n options: Parameters<typeof getRoutes>[1] = {}\n): Promise<ExpoRouterServerManifestV1> {\n const routeTree = getRoutes(ctx, options);\n\n if (!routeTree) {\n throw new Error('No routes found');\n }\n\n // Evaluate all static params\n await loadStaticParamsAsync(routeTree);\n\n return getServerManifest(routeTree);\n}\n\nfunction resetReactNavigationContexts() {\n // https://github.com/expo/router/discussions/588\n // https://github.com/react-navigation/react-navigation/blob/9fe34b445fcb86e5666f61e144007d7540f014fa/packages/elements/src/getNamedContext.tsx#LL3C1-L4C1\n\n // React Navigation is storing providers in a global, this is fine for the first static render\n // but subsequent static renders of Stack or Tabs will cause React to throw a warning. To prevent this warning, we'll reset the globals before rendering.\n const contexts = '__react_navigation__elements_contexts';\n global[contexts] = new Map<string, React.Context<any>>();\n}\n\nexport async function getStaticContent(location: URL): Promise<string> {\n const headContext: { helmet?: any } = {};\n\n const ref = React.createRef<ServerContainerRef>();\n\n const {\n // NOTE: The `element` that's returned adds two extra Views and\n // the seemingly unused `RootTagContext.Provider`.\n element,\n getStyleElement,\n } = AppRegistry.getApplication('App', {\n initialProps: {\n location,\n context: ctx,\n wrapper: ({ children }) => (\n <Root>\n <div id=\"root\">{children}</div>\n </Root>\n ),\n },\n });\n\n const Root = getRootComponent();\n\n // Clear any existing static resources from the global scope to attempt to prevent leaking between pages.\n // This could break if pages are rendered in parallel or if fonts are loaded outside of the React tree\n Font.resetServerContext();\n\n // This MUST be run before `ReactDOMServer.renderToString` to prevent\n // \"Warning: Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported.\"\n resetReactNavigationContexts();\n\n const stream = await ReactDOMServer.renderToStaticNodeStream(\n <Head.Provider context={headContext}>\n <ServerContainer ref={ref}>{element}</ServerContainer>\n </Head.Provider>\n );\n\n let html = '';\n\n for await (const chunk of stream) {\n html += chunk;\n }\n\n // Eval the CSS after the HTML is rendered so that the CSS is in the same order\n const css = ReactDOMServer.renderToStaticMarkup(getStyleElement());\n\n let output = mixHeadComponentsWithStaticResults(headContext.helmet, html);\n\n output = output.replace('</head>', `${css}</head>`);\n\n const fonts = Font.getServerResources();\n debug(`Pushing static fonts: (count: ${fonts.length})`, fonts);\n // debug('Push static fonts:', fonts)\n // Inject static fonts loaded with expo-font\n output = output.replace('</head>', `${fonts.join('')}</head>`);\n\n return '<!DOCTYPE html>' + output;\n}\n\nfunction mixHeadComponentsWithStaticResults(helmet: any, html: string) {\n // Head components\n for (const key of ['title', 'priority', 'meta', 'link', 'script', 'style'].reverse()) {\n const result = helmet?.[key]?.toString();\n if (result) {\n html = html.replace('<head>', `<head>${result}`);\n }\n }\n\n // attributes\n html = html.replace('<html ', `<html ${helmet?.htmlAttributes.toString()} `);\n html = html.replace('<body ', `<body ${helmet?.bodyAttributes.toString()} `);\n\n return html;\n}\n\n// Re-export for use in server\nexport { getManifest, getBuildTimeServerManifestAsync };\n"]}
|
|
@@ -39,9 +39,7 @@ function renderRouter(context = './app', { initialUrl = '/', ...options } = {})
|
|
|
39
39
|
// Reset the initial URL
|
|
40
40
|
(0, mocks_1.setInitialUrl)(initialUrl);
|
|
41
41
|
// Force the render to be synchronous
|
|
42
|
-
process.env.
|
|
43
|
-
process.env.EXPO_ROUTER_IMPORT_MODE_IOS = 'sync';
|
|
44
|
-
process.env.EXPO_ROUTER_IMPORT_MODE_ANDROID = 'sync';
|
|
42
|
+
process.env.EXPO_ROUTER_IMPORT_MODE = 'sync';
|
|
45
43
|
if (typeof context === 'string') {
|
|
46
44
|
ctx = (0, context_stubs_1.requireContext)(path_1.default.resolve(process.cwd(), context));
|
|
47
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;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port './expect';\n\nimport { render, RenderResult } from '@testing-library/react-native';\nimport path from 'path';\nimport React from 'react';\n\nimport {\n FileStub,\n inMemoryContext,\n requireContext,\n requireContextWithOverrides,\n} from './context-stubs';\nimport { setInitialUrl } from './mocks';\nimport { ExpoRoot } from '../ExpoRoot';\nimport { stateCache } from '../getLinkingConfig';\nimport { store } from '../global-state/router-store';\nimport { RequireContext } from '../types';\n\n// re-export everything\nexport * from '@testing-library/react-native';\n\ntype RenderRouterOptions = Parameters<typeof render>[1] & {\n initialUrl?: any;\n};\n\ntype Result = ReturnType<typeof render> & {\n getPathname(): string;\n getSegments(): string[];\n getSearchParams(): Record<string, string | string[]>;\n};\n\nfunction isOverrideContext(\n context: object\n): context is { appDir: string; overrides: Record<string, FileStub> } {\n return Boolean(typeof context === 'object' && 'appDir' in context);\n}\n\nexport function renderRouter(context?: string, options?: RenderRouterOptions): Result;\nexport function renderRouter(\n context: Record<string, FileStub>,\n options?: RenderRouterOptions\n): Result;\nexport function renderRouter(\n context: { appDir: string; overrides: Record<string, FileStub> },\n options?: RenderRouterOptions\n): Result;\nexport function renderRouter(\n context:\n | string\n | { appDir: string; overrides: Record<string, FileStub> }\n | Record<string, FileStub> = './app',\n { initialUrl = '/', ...options }: RenderRouterOptions = {}\n): Result {\n jest.useFakeTimers();\n\n let ctx: RequireContext;\n\n // Reset the initial URL\n\n setInitialUrl(initialUrl);\n\n // Force the render to be synchronous\n process.env.EXPO_ROUTER_IMPORT_MODE = 'sync';\n\n if (typeof context === 'string') {\n ctx = requireContext(path.resolve(process.cwd(), context));\n } else if (isOverrideContext(context)) {\n ctx = requireContextWithOverrides(context.appDir, context.overrides);\n } else {\n ctx = inMemoryContext(context);\n }\n\n stateCache.clear();\n\n let location: URL | undefined;\n\n if (typeof initialUrl === 'string') {\n location = new URL(initialUrl, 'test://');\n } else if (initialUrl instanceof URL) {\n location = initialUrl;\n }\n\n const result = render(<ExpoRoot context={ctx} location={location} />, {\n ...options,\n });\n\n return Object.assign(result, {\n getPathname(this: RenderResult): string {\n return store.routeInfoSnapshot().pathname;\n },\n getSegments(this: RenderResult): string[] {\n return store.routeInfoSnapshot().segments;\n },\n getSearchParams(this: RenderResult): Record<string, string | string[]> {\n return store.routeInfoSnapshot().params;\n },\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/testing-library/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/testing-library/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,4CAA4C,CAAC;AAsBpD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,QAE1C"}
|
|
@@ -4,11 +4,16 @@ exports.setInitialUrl = void 0;
|
|
|
4
4
|
require("@testing-library/jest-native/extend-expect");
|
|
5
5
|
// include this section and the NativeAnimatedHelper section for mocking react-native-reanimated
|
|
6
6
|
jest.mock('react-native-reanimated', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
try {
|
|
8
|
+
const Reanimated = require('react-native-reanimated/mock');
|
|
9
|
+
// The mock for `call` immediately calls the callback which is incorrect
|
|
10
|
+
// So we override it with a no-op
|
|
11
|
+
Reanimated.default.call = () => { };
|
|
12
|
+
return Reanimated;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
12
17
|
});
|
|
13
18
|
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
|
|
14
19
|
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
|