/
routes-manifest.ts
42 lines (35 loc) · 1.09 KB
/
routes-manifest.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// This file runs in Node.js environments.
// no relative imports
import { getRoutes } from './getRoutes';
import { getServerManifest } from './getServerManifest';
import { RequireContext } from './types';
export type RouteInfo<TRegex = string> = {
file: string;
page: string;
namedRegex: TRegex;
routeKeys: { [named: string]: string };
};
export type ExpoRoutesManifestV1<TRegex = string> = {
apiRoutes: RouteInfo<TRegex>[];
htmlRoutes: RouteInfo<TRegex>[];
notFoundRoutes: RouteInfo<TRegex>[];
};
function createMockContextModule(map: string[] = []) {
const contextModule = (key) => ({ default() {} });
Object.defineProperty(contextModule, 'keys', {
value: () => map,
});
return contextModule as RequireContext;
}
export function createRoutesManifest(paths: string[]): ExpoRoutesManifestV1 | null {
// TODO: Drop this part for Node.js
const routeTree = getRoutes(createMockContextModule(paths), {
preserveApiRoutes: true,
ignoreRequireErrors: true,
ignoreEntryPoints: true,
});
if (!routeTree) {
return null;
}
return getServerManifest(routeTree);
}