@reckona/mreact-router 0.0.175 → 0.0.176

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.
Files changed (64) hide show
  1. package/dist/adapters/cloudflare.d.ts.map +1 -1
  2. package/dist/adapters/cloudflare.js +5 -49
  3. package/dist/adapters/cloudflare.js.map +1 -1
  4. package/dist/build.d.ts +1 -0
  5. package/dist/build.d.ts.map +1 -1
  6. package/dist/build.js +90 -0
  7. package/dist/build.js.map +1 -1
  8. package/dist/built-assets.d.ts +11 -0
  9. package/dist/built-assets.d.ts.map +1 -0
  10. package/dist/built-assets.js +130 -0
  11. package/dist/built-assets.js.map +1 -0
  12. package/dist/built-runtime.d.ts +53 -0
  13. package/dist/built-runtime.d.ts.map +1 -0
  14. package/dist/built-runtime.js +178 -0
  15. package/dist/built-runtime.js.map +1 -0
  16. package/dist/built-server-module-artifacts.d.ts +19 -0
  17. package/dist/built-server-module-artifacts.d.ts.map +1 -0
  18. package/dist/built-server-module-artifacts.js +217 -0
  19. package/dist/built-server-module-artifacts.js.map +1 -0
  20. package/dist/client-manifest-assets.d.ts +16 -0
  21. package/dist/client-manifest-assets.d.ts.map +1 -0
  22. package/dist/client-manifest-assets.js +60 -0
  23. package/dist/client-manifest-assets.js.map +1 -0
  24. package/dist/client.d.ts.map +1 -1
  25. package/dist/client.js +31 -3
  26. package/dist/client.js.map +1 -1
  27. package/dist/node-server.d.ts +29 -0
  28. package/dist/node-server.d.ts.map +1 -0
  29. package/dist/node-server.js +81 -0
  30. package/dist/node-server.js.map +1 -0
  31. package/dist/render.d.ts +9 -0
  32. package/dist/render.d.ts.map +1 -1
  33. package/dist/render.js +20 -41
  34. package/dist/render.js.map +1 -1
  35. package/dist/route-dispatch.d.ts +2 -0
  36. package/dist/route-dispatch.d.ts.map +1 -0
  37. package/dist/route-dispatch.js +16 -0
  38. package/dist/route-dispatch.js.map +1 -0
  39. package/dist/route-loader-runtime.d.ts +22 -0
  40. package/dist/route-loader-runtime.d.ts.map +1 -0
  41. package/dist/route-loader-runtime.js +30 -0
  42. package/dist/route-loader-runtime.js.map +1 -0
  43. package/dist/routes.d.ts +2 -0
  44. package/dist/routes.d.ts.map +1 -1
  45. package/dist/routes.js +48 -1
  46. package/dist/routes.js.map +1 -1
  47. package/dist/serve.d.ts +4 -3
  48. package/dist/serve.d.ts.map +1 -1
  49. package/dist/serve.js +84 -582
  50. package/dist/serve.js.map +1 -1
  51. package/package.json +11 -11
  52. package/src/adapters/cloudflare.ts +5 -60
  53. package/src/build.ts +143 -0
  54. package/src/built-assets.ts +164 -0
  55. package/src/built-runtime.ts +312 -0
  56. package/src/built-server-module-artifacts.ts +340 -0
  57. package/src/client-manifest-assets.ts +92 -0
  58. package/src/client.ts +31 -3
  59. package/src/node-server.ts +129 -0
  60. package/src/render.ts +38 -60
  61. package/src/route-dispatch.ts +17 -0
  62. package/src/route-loader-runtime.ts +54 -0
  63. package/src/routes.ts +70 -1
  64. package/src/serve.ts +105 -863
@@ -0,0 +1,11 @@
1
+ import type { ClientRouteManifestEntry } from "./client-route-inference.js";
2
+ export declare function readBuiltClientAsset(outDir: string, pathname: string, allowedPaths: ReadonlySet<string>): Promise<Response>;
3
+ export declare function builtClientAssetPathname(request: Request, url: URL): string | undefined;
4
+ export declare function builtClientAssetPaths(manifest: {
5
+ assets?: readonly string[] | undefined;
6
+ routes: readonly ClientRouteManifestEntry[];
7
+ }): ReadonlySet<string>;
8
+ export declare function readBuiltPublicAsset(outDir: string, pathname: string): Promise<Response | undefined>;
9
+ export declare function clearBuiltPublicAssetCacheForTest(): void;
10
+ export declare function getBuiltPublicAssetCacheSizeForTest(): number;
11
+ //# sourceMappingURL=built-assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"built-assets.d.ts","sourceRoot":"","sources":["../src/built-assets.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAY5E,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,OAAO,CAAC,QAAQ,CAAC,CAiBnB;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAOvF;AA4BD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE;IAC9C,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACvC,MAAM,EAAE,SAAS,wBAAwB,EAAE,CAAC;CAC7C,GAAG,WAAW,CAAC,MAAM,CAAC,CAEtB;AAED,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAmC/B;AAED,wBAAgB,iCAAiC,IAAI,IAAI,CAExD;AAED,wBAAgB,mCAAmC,IAAI,MAAM,CAE5D"}
@@ -0,0 +1,130 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { isAbsolute, join, normalize, sep } from "node:path";
3
+ import { clientManifestAssetPaths } from "./client-manifest-assets.js";
4
+ import { bytesResponse, rawNodeRequestUrl } from "./http.js";
5
+ const builtPublicAssetCache = new Map();
6
+ export async function readBuiltClientAsset(outDir, pathname, allowedPaths) {
7
+ const clientPrefix = "/_mreact/client/";
8
+ const normalized = safeBuiltClientAssetPath(pathname.slice(clientPrefix.length));
9
+ if (normalized === undefined || !allowedPaths.has(normalized)) {
10
+ return new Response("Not Found", { status: 404 });
11
+ }
12
+ try {
13
+ const code = await readFile(join(outDir, "client", normalized), "utf8");
14
+ return new Response(code, {
15
+ headers: clientAssetHeaders(normalized),
16
+ });
17
+ }
18
+ catch {
19
+ return new Response("Not Found", { status: 404 });
20
+ }
21
+ }
22
+ export function builtClientAssetPathname(request, url) {
23
+ const rawUrl = rawNodeRequestUrl(request);
24
+ const rawPathname = rawUrl?.split(/[?#]/, 1)[0];
25
+ const pathname = rawPathname === undefined || rawPathname === "" ? url.pathname : rawPathname;
26
+ const normalizedPathname = pathname.startsWith("/") ? pathname : `/${pathname}`;
27
+ return normalizedPathname.startsWith("/_mreact/client/") ? normalizedPathname : undefined;
28
+ }
29
+ function safeBuiltClientAssetPath(relativePath) {
30
+ let decoded;
31
+ try {
32
+ decoded = decodeURIComponent(relativePath);
33
+ }
34
+ catch {
35
+ return undefined;
36
+ }
37
+ if (decoded.includes("\\") || decoded.includes("\0")) {
38
+ return undefined;
39
+ }
40
+ if (decoded.split("/").some((segment) => segment === "..")) {
41
+ return undefined;
42
+ }
43
+ const normalized = normalize(decoded);
44
+ if (isAbsolute(normalized) || normalized === ".." || normalized.startsWith(`..${sep}`)) {
45
+ return undefined;
46
+ }
47
+ return normalized;
48
+ }
49
+ export function builtClientAssetPaths(manifest) {
50
+ return clientManifestAssetPaths(manifest);
51
+ }
52
+ export async function readBuiltPublicAsset(outDir, pathname) {
53
+ const relativePath = pathname.startsWith("/") ? pathname.slice(1) : pathname;
54
+ if (relativePath === "") {
55
+ return undefined;
56
+ }
57
+ const normalized = normalize(relativePath);
58
+ if (isAbsolute(normalized) || normalized === ".." || normalized.startsWith("../")) {
59
+ return undefined;
60
+ }
61
+ try {
62
+ const cacheKey = `${outDir}\0${normalized}`;
63
+ const cached = builtPublicAssetCache.get(cacheKey);
64
+ if (cached !== undefined) {
65
+ return bytesResponse(cached.bytes, {
66
+ headers: cached.headers,
67
+ });
68
+ }
69
+ const bytes = await readFile(join(outDir, "client", "public", normalized));
70
+ const headers = publicAssetHeaders(normalized);
71
+ builtPublicAssetCache.set(cacheKey, {
72
+ bytes,
73
+ headers,
74
+ });
75
+ return bytesResponse(bytes, { headers });
76
+ }
77
+ catch {
78
+ return undefined;
79
+ }
80
+ }
81
+ export function clearBuiltPublicAssetCacheForTest() {
82
+ builtPublicAssetCache.clear();
83
+ }
84
+ export function getBuiltPublicAssetCacheSizeForTest() {
85
+ return builtPublicAssetCache.size;
86
+ }
87
+ function clientAssetHeaders(pathname) {
88
+ if (pathname === "manifest.json") {
89
+ return {
90
+ "cache-control": "no-cache",
91
+ "content-type": "application/json; charset=utf-8",
92
+ };
93
+ }
94
+ return {
95
+ "cache-control": "public, max-age=31536000, immutable",
96
+ "content-type": pathname.endsWith(".css")
97
+ ? "text/css; charset=utf-8"
98
+ : "text/javascript; charset=utf-8",
99
+ };
100
+ }
101
+ function publicAssetHeaders(pathname) {
102
+ return {
103
+ "cache-control": "public, max-age=3600",
104
+ "content-type": publicAssetContentType(pathname),
105
+ };
106
+ }
107
+ function publicAssetContentType(pathname) {
108
+ if (pathname.endsWith(".css"))
109
+ return "text/css; charset=utf-8";
110
+ if (pathname.endsWith(".html"))
111
+ return "text/html; charset=utf-8";
112
+ if (pathname.endsWith(".js"))
113
+ return "text/javascript; charset=utf-8";
114
+ if (pathname.endsWith(".json"))
115
+ return "application/json; charset=utf-8";
116
+ if (pathname.endsWith(".svg"))
117
+ return "image/svg+xml";
118
+ if (pathname.endsWith(".png"))
119
+ return "image/png";
120
+ if (pathname.endsWith(".jpg") || pathname.endsWith(".jpeg"))
121
+ return "image/jpeg";
122
+ if (pathname.endsWith(".webp"))
123
+ return "image/webp";
124
+ if (pathname.endsWith(".ico"))
125
+ return "image/x-icon";
126
+ if (pathname.endsWith(".txt"))
127
+ return "text/plain; charset=utf-8";
128
+ return "application/octet-stream";
129
+ }
130
+ //# sourceMappingURL=built-assets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"built-assets.js","sourceRoot":"","sources":["../src/built-assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,iBA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Q,CAAC,MAAM,CAAC;QAAE,OAAO,2BAA2B,CAAC;IAElE,OAAO,0BAA0B,CAAC;AACpC,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { isAbsolute, join, normalize, sep } from \"node:path\";\nimport type { ClientRouteManifestEntry } from \"./client-route-inference.js\";\nimport { clientManifestAssetPaths } from \"./client-manifest-assets.js\";\nimport { bytesResponse, rawNodeRequestUrl } from \"./http.js\";\n\nconst builtPublicAssetCache = new Map<\n string,\n {\n bytes: Uint8Array;\n headers: HeadersInit;\n }\n>();\n\nexport async function readBuiltClientAsset(\n outDir: string,\n pathname: string,\n allowedPaths: ReadonlySet<string>,\n): Promise<Response> {\n const clientPrefix = \"/_mreact/client/\";\n const normalized = safeBuiltClientAssetPath(pathname.slice(clientPrefix.length));\n\n if (normalized === undefined || !allowedPaths.has(normalized)) {\n return new Response(\"Not Found\", { status: 404 });\n }\n\n try {\n const code = await readFile(join(outDir, \"client\", normalized), \"utf8\");\n\n return new Response(code, {\n headers: clientAssetHeaders(normalized),\n });\n } catch {\n return new Response(\"Not Found\", { status: 404 });\n }\n}\n\nexport function builtClientAssetPathname(request: Request, url: URL): string | undefined {\n const rawUrl = rawNodeRequestUrl(request);\n const rawPathname = rawUrl?.split(/[?#]/, 1)[0];\n const pathname = rawPathname === undefined || rawPathname === \"\" ? url.pathname : rawPathname;\n const normalizedPathname = pathname.startsWith(\"/\") ? pathname : `/${pathname}`;\n\n return normalizedPathname.startsWith(\"/_mreact/client/\") ? normalizedPathname : undefined;\n}\n\nfunction safeBuiltClientAssetPath(relativePath: string): string | undefined {\n let decoded: string;\n\n try {\n decoded = decodeURIComponent(relativePath);\n } catch {\n return undefined;\n }\n\n if (decoded.includes(\"\\\\\") || decoded.includes(\"\\0\")) {\n return undefined;\n }\n\n if (decoded.split(\"/\").some((segment) => segment === \"..\")) {\n return undefined;\n }\n\n const normalized = normalize(decoded);\n\n if (isAbsolute(normalized) || normalized === \"..\" || normalized.startsWith(`..${sep}`)) {\n return undefined;\n }\n\n return normalized;\n}\n\nexport function builtClientAssetPaths(manifest: {\n assets?: readonly string[] | undefined;\n routes: readonly ClientRouteManifestEntry[];\n}): ReadonlySet<string> {\n return clientManifestAssetPaths(manifest);\n}\n\nexport async function readBuiltPublicAsset(\n outDir: string,\n pathname: string,\n): Promise<Response | undefined> {\n const relativePath = pathname.startsWith(\"/\") ? pathname.slice(1) : pathname;\n\n if (relativePath === \"\") {\n return undefined;\n }\n\n const normalized = normalize(relativePath);\n\n if (isAbsolute(normalized) || normalized === \"..\" || normalized.startsWith(\"../\")) {\n return undefined;\n }\n\n try {\n const cacheKey = `${outDir}\\0${normalized}`;\n const cached = builtPublicAssetCache.get(cacheKey);\n\n if (cached !== undefined) {\n return bytesResponse(cached.bytes, {\n headers: cached.headers,\n });\n }\n\n const bytes = await readFile(join(outDir, \"client\", \"public\", normalized));\n const headers = publicAssetHeaders(normalized);\n\n builtPublicAssetCache.set(cacheKey, {\n bytes,\n headers,\n });\n\n return bytesResponse(bytes, { headers });\n } catch {\n return undefined;\n }\n}\n\nexport function clearBuiltPublicAssetCacheForTest(): void {\n builtPublicAssetCache.clear();\n}\n\nexport function getBuiltPublicAssetCacheSizeForTest(): number {\n return builtPublicAssetCache.size;\n}\n\nfunction clientAssetHeaders(pathname: string): HeadersInit {\n if (pathname === \"manifest.json\") {\n return {\n \"cache-control\": \"no-cache\",\n \"content-type\": \"application/json; charset=utf-8\",\n };\n }\n\n return {\n \"cache-control\": \"public, max-age=31536000, immutable\",\n \"content-type\": pathname.endsWith(\".css\")\n ? \"text/css; charset=utf-8\"\n : \"text/javascript; charset=utf-8\",\n };\n}\n\nfunction publicAssetHeaders(pathname: string): HeadersInit {\n return {\n \"cache-control\": \"public, max-age=3600\",\n \"content-type\": publicAssetContentType(pathname),\n };\n}\n\nfunction publicAssetContentType(pathname: string): string {\n if (pathname.endsWith(\".css\")) return \"text/css; charset=utf-8\";\n if (pathname.endsWith(\".html\")) return \"text/html; charset=utf-8\";\n if (pathname.endsWith(\".js\")) return \"text/javascript; charset=utf-8\";\n if (pathname.endsWith(\".json\")) return \"application/json; charset=utf-8\";\n if (pathname.endsWith(\".svg\")) return \"image/svg+xml\";\n if (pathname.endsWith(\".png\")) return \"image/png\";\n if (pathname.endsWith(\".jpg\") || pathname.endsWith(\".jpeg\")) return \"image/jpeg\";\n if (pathname.endsWith(\".webp\")) return \"image/webp\";\n if (pathname.endsWith(\".ico\")) return \"image/x-icon\";\n if (pathname.endsWith(\".txt\")) return \"text/plain; charset=utf-8\";\n\n return \"application/octet-stream\";\n}\n"]}
@@ -0,0 +1,53 @@
1
+ import type { BuiltPrerenderedRoute } from "./build.js";
2
+ import type { BuiltServerModuleArtifactRuntime } from "./built-server-module-artifacts.js";
3
+ import type { AppRouterImportPolicy } from "./import-policy.js";
4
+ import { type AppRoute, type RouteMatcher } from "./routes.js";
5
+ export interface BuiltRuntime extends BuiltServerModuleArtifactRuntime {
6
+ allowedSourceDirs: readonly string[];
7
+ assetBaseUrl?: string | undefined;
8
+ clientAssetPaths: ReadonlySet<string>;
9
+ clientScripts: ReadonlyMap<string, string>;
10
+ clientStylesByFile: ReadonlyMap<string, readonly string[]>;
11
+ clientStyles: ReadonlyMap<string, readonly string[]>;
12
+ generatedImportPolicy?: AppRouterImportPolicy | undefined;
13
+ hasMiddleware: boolean;
14
+ navigationScripts: ReadonlyMap<string, string>;
15
+ projectRoot: string;
16
+ publicAssetBaseUrl?: string | undefined;
17
+ prerenderableRoutes: ReadonlySet<string>;
18
+ prerenderLocks: Map<string, Promise<Response>>;
19
+ prerenderedRoutes: Map<string, BuiltPrerenderedRoute>;
20
+ routeMatcher: RouteMatcher;
21
+ routes: readonly AppRoute[];
22
+ serverActionReferencesByFile: ReadonlyMap<string, readonly {
23
+ end: number;
24
+ expression: string;
25
+ expressionEnd: number;
26
+ expressionStart: number;
27
+ moduleId: string;
28
+ exportName: string;
29
+ inferred: boolean;
30
+ sourceHash: string;
31
+ start: number;
32
+ }[]>;
33
+ serverActionManifest?: readonly {
34
+ moduleId: string;
35
+ exportName: string;
36
+ inferred?: boolean;
37
+ }[] | undefined;
38
+ serverModuleCacheVersion: string;
39
+ }
40
+ export declare function materializeBuiltRuntime(options: {
41
+ clientManifestText: string;
42
+ clientManifestPath: string;
43
+ importPolicyPath: string;
44
+ importPolicyText: string | undefined;
45
+ onMaterialize?: (() => void) | undefined;
46
+ outDir: string;
47
+ runtimeDir: string;
48
+ serverManifestText: string;
49
+ serverManifestPath: string;
50
+ }): Promise<BuiltRuntime>;
51
+ export declare function readBuiltImportPolicyText(outDir: string): Promise<string | undefined>;
52
+ export declare function mergeBuiltRuntimeImportPolicy(runtime: BuiltRuntime, importPolicy: AppRouterImportPolicy | undefined): AppRouterImportPolicy | undefined;
53
+ //# sourceMappingURL=built-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"built-runtime.d.ts","sourceRoot":"","sources":["../src/built-runtime.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qBAAqB,EAGtB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAE3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAsB,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAEnF,MAAM,WAAW,YAAa,SAAQ,gCAAgC;IACpE,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,kBAAkB,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC3D,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,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G,SAAS,CAAC;IACrC,aAAa,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;CAC5B,GAAG,OAAO,CAAC,YAAY,CAAC,CA2IxB;AAED,wBAAsB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAY3F;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,YAAY,EACrB,YAAY,EAAE,qBAAqB,GAAG,SAAS,GAC9C,qBAAqB,GAAG,SAAS,CAqBnC"}
@@ -0,0 +1,178 @@
1
+ import { createHash } from "node:crypto";
2
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { dirname, isAbsolute, join, normalize } from "node:path";
4
+ import { builtClientAssetPaths } from "./built-assets.js";
5
+ import { createRouteMatcher } from "./routes.js";
6
+ export async function materializeBuiltRuntime(options) {
7
+ options.onMaterialize?.();
8
+ const serverManifest = parseBuiltJsonArtifact(options.serverManifestText, options.serverManifestPath, "built app server manifest");
9
+ const clientManifest = parseBuiltJsonArtifact(options.clientManifestText, options.clientManifestPath, "built app client manifest");
10
+ const appDir = await materializeBuiltServerApp(options.runtimeDir, serverManifest);
11
+ const projectRoot = appDir;
12
+ const routesDir = join(projectRoot, serverManifest.routesDir ?? "");
13
+ const routes = serverManifest.routes.map((route) => ({
14
+ ...route,
15
+ file: join(projectRoot, route.file),
16
+ }));
17
+ const prerenderedRoutes = new Map(Object.entries(serverManifest.prerenderedRoutes ?? {}));
18
+ const prerenderableRoutes = new Set(prerenderedRoutes.keys());
19
+ const prerenderLocks = new Map();
20
+ const serverModules = new Map(Object.entries(serverManifest.serverModules ?? {}).map(([file, artifact]) => [
21
+ join(appDir, file),
22
+ artifact,
23
+ ]));
24
+ const serverModuleClosureFiles = new Map(Object.entries(serverManifest.serverModuleClosureFiles ?? {}).map(([file, closure]) => [
25
+ join(appDir, safeManifestFilePath(file)),
26
+ closure.map((closureFile) => join(appDir, safeManifestFilePath(closureFile))),
27
+ ]));
28
+ const serverModuleFiles = new Map(Object.entries(serverManifest.serverModuleFiles ?? {}).map(([file, artifactFile]) => [
29
+ join(appDir, file),
30
+ join(options.outDir, "server", safeManifestFilePath(artifactFile)),
31
+ ]));
32
+ const serverModuleRequestFiles = new Map(Object.entries(serverManifest.serverModuleRequestFiles ?? {}).map(([file, artifactFile]) => [
33
+ join(appDir, file),
34
+ join(options.outDir, "server", safeManifestFilePath(artifactFile)),
35
+ ]));
36
+ const serverModuleRenderFiles = new Map(Object.entries(serverManifest.serverModuleRenderFiles ?? {}).map(([file, artifactFile]) => [
37
+ join(appDir, file),
38
+ join(options.outDir, "server", safeManifestFilePath(artifactFile)),
39
+ ]));
40
+ const serverSourceFiles = new Map(Object.entries(serverManifest.files).map(([file, source]) => [join(appDir, file), source]));
41
+ const serverActionReferencesByFile = new Map(Object.entries(serverManifest.routeServerActionReferences ?? {}).map(([file, references]) => [
42
+ join(appDir, file),
43
+ references,
44
+ ]));
45
+ const routeMatcher = createRouteMatcher(routes, serverManifest.routeMatcher);
46
+ const clientScripts = new Map(clientManifest.routes.flatMap((route) => route.client && route.script !== undefined ? [[route.path, route.script]] : []));
47
+ const clientStyles = new Map(clientManifest.routes.flatMap((route) => route.css !== undefined && route.css.length > 0 ? [[route.path, route.css]] : []));
48
+ const clientStylesByFile = new Map((clientManifest.styles ?? []).flatMap((style) => style.css !== undefined && style.css.length > 0
49
+ ? [[join(routesDir, style.file), style.css]]
50
+ : []));
51
+ const navigationScripts = new Map(clientManifest.routes.flatMap((route) => route.navigation === true && route.navigationScript !== undefined
52
+ ? [[route.path, route.navigationScript]]
53
+ : []));
54
+ const hasMiddleware = serverSourceFiles.has(join(routesDir, "middleware.ts")) ||
55
+ serverSourceFiles.has(join(routesDir, "middleware.mreact.ts"));
56
+ const serverModuleCacheVersion = createHash("sha256")
57
+ .update(options.serverManifestText)
58
+ .update("\0")
59
+ .update(options.clientManifestText)
60
+ .digest("hex")
61
+ .slice(0, 16);
62
+ const allowedSourceDirs = (serverManifest.allowedSourceDirs ?? [""]).map((directory) => join(projectRoot, directory));
63
+ const generatedImportPolicy = builtGeneratedImportPolicy(options.importPolicyText, options.importPolicyPath);
64
+ return {
65
+ appDir: routesDir,
66
+ allowedSourceDirs,
67
+ ...(serverManifest.assetBaseUrl === undefined
68
+ ? {}
69
+ : { assetBaseUrl: serverManifest.assetBaseUrl }),
70
+ clientAssetPaths: builtClientAssetPaths(clientManifest),
71
+ clientScripts,
72
+ clientStylesByFile,
73
+ clientStyles,
74
+ ...(generatedImportPolicy === undefined ? {} : { generatedImportPolicy }),
75
+ hasMiddleware,
76
+ navigationScripts,
77
+ projectRoot,
78
+ ...(serverManifest.publicAssetBaseUrl === undefined
79
+ ? {}
80
+ : { publicAssetBaseUrl: serverManifest.publicAssetBaseUrl }),
81
+ prerenderableRoutes,
82
+ prerenderLocks,
83
+ prerenderedRoutes,
84
+ routeMatcher,
85
+ routes,
86
+ serverActionReferencesByFile,
87
+ ...(serverManifest.serverActionManifest === undefined
88
+ ? {}
89
+ : { serverActionManifest: serverManifest.serverActionManifest }),
90
+ serverModuleArtifactLoads: new Map(),
91
+ serverModuleClosureFiles,
92
+ serverModuleFiles,
93
+ serverModuleRenderFiles,
94
+ serverModuleRequestFiles,
95
+ serverModules,
96
+ serverModuleCacheVersion,
97
+ serverSourceFiles,
98
+ };
99
+ }
100
+ export async function readBuiltImportPolicyText(outDir) {
101
+ const policyPath = join(outDir, "server", "import-policy.json");
102
+ try {
103
+ return await readFile(policyPath, "utf8");
104
+ }
105
+ catch (error) {
106
+ if (isMissingFileError(error)) {
107
+ return undefined;
108
+ }
109
+ throw builtArtifactReadError("built app import policy", policyPath, error);
110
+ }
111
+ }
112
+ export function mergeBuiltRuntimeImportPolicy(runtime, importPolicy) {
113
+ const generatedImportPolicy = runtime.generatedImportPolicy;
114
+ if (generatedImportPolicy === undefined) {
115
+ return importPolicy;
116
+ }
117
+ const allowedPackages = [
118
+ ...new Set([
119
+ ...(generatedImportPolicy.allowedPackages ?? []),
120
+ ...(importPolicy?.allowedPackages ?? []),
121
+ ]),
122
+ ];
123
+ return {
124
+ ...(allowedPackages.length === 0 ? {} : { allowedPackages }),
125
+ ...(importPolicy?.allowedSourceDirs === undefined
126
+ ? {}
127
+ : { allowedSourceDirs: importPolicy.allowedSourceDirs }),
128
+ ...(importPolicy?.projectRoot === undefined ? {} : { projectRoot: importPolicy.projectRoot }),
129
+ };
130
+ }
131
+ function builtGeneratedImportPolicy(importPolicyText, importPolicyPath) {
132
+ if (importPolicyText === undefined) {
133
+ return undefined;
134
+ }
135
+ const artifact = parseBuiltJsonArtifact(importPolicyText, importPolicyPath, "built app import policy");
136
+ const runtimePackages = Array.isArray(artifact.runtimePackages)
137
+ ? artifact.runtimePackages.filter((name) => typeof name === "string")
138
+ : [];
139
+ return runtimePackages.length === 0 ? undefined : { allowedPackages: runtimePackages };
140
+ }
141
+ async function materializeBuiltServerApp(runtimeDir, manifest) {
142
+ const appDir = join(runtimeDir, "app");
143
+ await rm(appDir, { force: true, recursive: true });
144
+ await Promise.all(Object.entries(manifest.files).map(async ([file, code]) => {
145
+ const outputFile = join(appDir, safeManifestFilePath(file));
146
+ await mkdir(dirname(outputFile), { recursive: true });
147
+ await writeFile(outputFile, code);
148
+ }));
149
+ return appDir;
150
+ }
151
+ function isMissingFileError(error) {
152
+ return (typeof error === "object" &&
153
+ error !== null &&
154
+ "code" in error &&
155
+ error.code === "ENOENT");
156
+ }
157
+ function builtArtifactReadError(label, artifactPath, error) {
158
+ const prefix = isMissingFileError(error) ? "Missing" : "Unable to read";
159
+ const detail = error instanceof Error && error.message !== "" ? `: ${error.message}` : "";
160
+ return new Error(`${prefix} ${label}: ${artifactPath}${detail}`, { cause: error });
161
+ }
162
+ function parseBuiltJsonArtifact(text, artifactPath, label) {
163
+ try {
164
+ return JSON.parse(text);
165
+ }
166
+ catch (error) {
167
+ const detail = error instanceof Error && error.message !== "" ? `: ${error.message}` : "";
168
+ throw new Error(`Invalid ${label}: ${artifactPath}${detail}`, { cause: error });
169
+ }
170
+ }
171
+ function safeManifestFilePath(pathname) {
172
+ const normalized = normalize(pathname);
173
+ if (isAbsolute(normalized) || normalized === ".." || normalized.startsWith("../")) {
174
+ throw new Error(`Invalid built app manifest file path: ${pathname}`);
175
+ }
176
+ return normalized;
177
+ }
178
+ //# sourceMappingURL=built-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"built-runtime.js","sourceRoot":"","sources":["../src/built-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAMjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAI1D,OAAO,EAAE,kBAAkB,EAAoC,MAAM,aAAa,CAAC;AAqCnF,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAU7C;IACC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;IAC1B,MAAM,cAAc,GAAG,sBAAsB,CAC3C,OAAO,CAAC,kBAAkB,EAC1B,OAAO,CAAC,kBAAkB,EAC1B,2BAA2B,CAC5B,CAAC;IACF,MAAM,cAAc,GAAG,sBAAsB,CAI1C,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,EAAE,2BAA2B,CAAC,CAAC;IACxF,MAAM,MAAM,GAAG,MAAM,yBAAyB,CAAC,OAAO,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACnF,MAAM,WAAW,GAAG,MAAM,CAAC;IA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CAAC,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE1F,OAAO,IAAI,KAAK,CAAC,GAAG,MAAM,IAAI,KAAK,KAAK,YAAY,GAAG,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AACrF,CAAC;AAED,SAAS,sBAAsB,CAAI,IAAY,EAAE,YAAoB,EAAE,KAAa;IAClF,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAE1F,MAAM,IAAI,KAAK,CAAC,WAAW,KAAK,KAAK,YAAY,GAAG,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAClF,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAgB;IAC5C,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAEvC,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAClF,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, isAbsolute, join, normalize } from \"node:path\";\nimport type {\n BuiltPrerenderedRoute,\n BuiltServerManifest,\n BuiltServerModuleArtifact,\n} from \"./build.js\";\nimport { builtClientAssetPaths } from \"./built-assets.js\";\nimport type { BuiltServerModuleArtifactRuntime } from \"./built-server-module-artifacts.js\";\nimport type { ClientRouteManifestEntry } from \"./client-route-inference.js\";\nimport type { AppRouterImportPolicy } from \"./import-policy.js\";\nimport { createRouteMatcher, type AppRoute, type RouteMatcher } from \"./routes.js\";\n\nexport interface BuiltRuntime extends BuiltServerModuleArtifactRuntime {\n allowedSourceDirs: readonly string[];\n assetBaseUrl?: string | undefined;\n clientAssetPaths: ReadonlySet<string>;\n clientScripts: ReadonlyMap<string, string>;\n clientStylesByFile: ReadonlyMap<string, readonly string[]>;\n clientStyles: ReadonlyMap<string, readonly string[]>;\n generatedImportPolicy?: AppRouterImportPolicy | undefined;\n hasMiddleware: boolean;\n navigationScripts: ReadonlyMap<string, string>;\n projectRoot: string;\n publicAssetBaseUrl?: string | undefined;\n prerenderableRoutes: ReadonlySet<string>;\n prerenderLocks: Map<string, Promise<Response>>;\n prerenderedRoutes: Map<string, BuiltPrerenderedRoute>;\n routeMatcher: RouteMatcher;\n routes: readonly AppRoute[];\n serverActionReferencesByFile: ReadonlyMap<\n string,\n readonly {\n end: number;\n expression: string;\n expressionEnd: number;\n expressionStart: number;\n moduleId: string;\n exportName: string;\n inferred: boolean;\n sourceHash: string;\n start: number;\n }[]\n >;\n serverActionManifest?: readonly { moduleId: string; exportName: string; inferred?: boolean }[] | undefined;\n serverModuleCacheVersion: string;\n}\n\nexport async function materializeBuiltRuntime(options: {\n clientManifestText: string;\n clientManifestPath: string;\n importPolicyPath: string;\n importPolicyText: string | undefined;\n onMaterialize?: (() => void) | undefined;\n outDir: string;\n runtimeDir: string;\n serverManifestText: string;\n serverManifestPath: string;\n}): Promise<BuiltRuntime> {\n options.onMaterialize?.();\n const serverManifest = parseBuiltJsonArtifact<BuiltServerManifest>(\n options.serverManifestText,\n options.serverManifestPath,\n \"built app server manifest\",\n );\n const clientManifest = parseBuiltJsonArtifact<{\n assets?: readonly string[];\n routes: ClientRouteManifestEntry[];\n styles?: Array<{ css?: readonly string[]; file: string }>;\n }>(options.clientManifestText, options.clientManifestPath, \"built app client manifest\");\n const appDir = await materializeBuiltServerApp(options.runtimeDir, serverManifest);\n const projectRoot = appDir;\n const routesDir = join(projectRoot, serverManifest.routesDir ?? \"\");\n const routes = serverManifest.routes.map((route) => ({\n ...route,\n file: join(projectRoot, route.file),\n }));\n const prerenderedRoutes = new Map(Object.entries(serverManifest.prerenderedRoutes ?? {}));\n const prerenderableRoutes = new Set(prerenderedRoutes.keys());\n const prerenderLocks = new Map<string, Promise<Response>>();\n const serverModules = new Map<string, BuiltServerModuleArtifact>(\n Object.entries(serverManifest.serverModules ?? {}).map(([file, artifact]) => [\n join(appDir, file),\n artifact,\n ]),\n );\n const serverModuleClosureFiles = new Map<string, readonly string[]>(\n Object.entries(serverManifest.serverModuleClosureFiles ?? {}).map(([file, closure]) => [\n join(appDir, safeManifestFilePath(file)),\n closure.map((closureFile) => join(appDir, safeManifestFilePath(closureFile))),\n ]),\n );\n const serverModuleFiles = new Map(\n Object.entries(serverManifest.serverModuleFiles ?? {}).map(([file, artifactFile]) => [\n join(appDir, file),\n join(options.outDir, \"server\", safeManifestFilePath(artifactFile)),\n ]),\n );\n const serverModuleRequestFiles = new Map(\n Object.entries(serverManifest.serverModuleRequestFiles ?? {}).map(([file, artifactFile]) => [\n join(appDir, file),\n join(options.outDir, \"server\", safeManifestFilePath(artifactFile)),\n ]),\n );\n const serverModuleRenderFiles = new Map(\n Object.entries(serverManifest.serverModuleRenderFiles ?? {}).map(([file, artifactFile]) => [\n join(appDir, file),\n join(options.outDir, \"server\", safeManifestFilePath(artifactFile)),\n ]),\n );\n const serverSourceFiles = new Map(\n Object.entries(serverManifest.files).map(([file, source]) => [join(appDir, file), source]),\n );\n const serverActionReferencesByFile = new Map(\n Object.entries(serverManifest.routeServerActionReferences ?? {}).map(([file, references]) => [\n join(appDir, file),\n references,\n ]),\n );\n const routeMatcher = createRouteMatcher(routes, serverManifest.routeMatcher);\n const clientScripts = new Map(\n clientManifest.routes.flatMap((route) =>\n route.client && route.script !== undefined ? [[route.path, route.script]] : [],\n ),\n );\n const clientStyles = new Map(\n clientManifest.routes.flatMap((route) =>\n route.css !== undefined && route.css.length > 0 ? [[route.path, route.css]] : [],\n ),\n );\n const clientStylesByFile = new Map(\n (clientManifest.styles ?? []).flatMap((style) =>\n style.css !== undefined && style.css.length > 0\n ? [[join(routesDir, style.file), style.css] as const]\n : [],\n ),\n );\n const navigationScripts = new Map(\n clientManifest.routes.flatMap((route) =>\n route.navigation === true && route.navigationScript !== undefined\n ? [[route.path, route.navigationScript]]\n : [],\n ),\n );\n const hasMiddleware =\n serverSourceFiles.has(join(routesDir, \"middleware.ts\")) ||\n serverSourceFiles.has(join(routesDir, \"middleware.mreact.ts\"));\n const serverModuleCacheVersion = createHash(\"sha256\")\n .update(options.serverManifestText)\n .update(\"\\0\")\n .update(options.clientManifestText)\n .digest(\"hex\")\n .slice(0, 16);\n\n const allowedSourceDirs = (serverManifest.allowedSourceDirs ?? [\"\"]).map((directory) =>\n join(projectRoot, directory),\n );\n const generatedImportPolicy = builtGeneratedImportPolicy(\n options.importPolicyText,\n options.importPolicyPath,\n );\n\n return {\n appDir: routesDir,\n allowedSourceDirs,\n ...(serverManifest.assetBaseUrl === undefined\n ? {}\n : { assetBaseUrl: serverManifest.assetBaseUrl }),\n clientAssetPaths: builtClientAssetPaths(clientManifest),\n clientScripts,\n clientStylesByFile,\n clientStyles,\n ...(generatedImportPolicy === undefined ? {} : { generatedImportPolicy }),\n hasMiddleware,\n navigationScripts,\n projectRoot,\n ...(serverManifest.publicAssetBaseUrl === undefined\n ? {}\n : { publicAssetBaseUrl: serverManifest.publicAssetBaseUrl }),\n prerenderableRoutes,\n prerenderLocks,\n prerenderedRoutes,\n routeMatcher,\n routes,\n serverActionReferencesByFile,\n ...(serverManifest.serverActionManifest === undefined\n ? {}\n : { serverActionManifest: serverManifest.serverActionManifest }),\n serverModuleArtifactLoads: new Map(),\n serverModuleClosureFiles,\n serverModuleFiles,\n serverModuleRenderFiles,\n serverModuleRequestFiles,\n serverModules,\n serverModuleCacheVersion,\n serverSourceFiles,\n };\n}\n\nexport async function readBuiltImportPolicyText(outDir: string): Promise<string | undefined> {\n const policyPath = join(outDir, \"server\", \"import-policy.json\");\n\n try {\n return await readFile(policyPath, \"utf8\");\n } catch (error) {\n if (isMissingFileError(error)) {\n return undefined;\n }\n\n throw builtArtifactReadError(\"built app import policy\", policyPath, error);\n }\n}\n\nexport function mergeBuiltRuntimeImportPolicy(\n runtime: BuiltRuntime,\n importPolicy: AppRouterImportPolicy | undefined,\n): AppRouterImportPolicy | undefined {\n const generatedImportPolicy = runtime.generatedImportPolicy;\n\n if (generatedImportPolicy === undefined) {\n return importPolicy;\n }\n\n const allowedPackages = [\n ...new Set([\n ...(generatedImportPolicy.allowedPackages ?? []),\n ...(importPolicy?.allowedPackages ?? []),\n ]),\n ];\n\n return {\n ...(allowedPackages.length === 0 ? {} : { allowedPackages }),\n ...(importPolicy?.allowedSourceDirs === undefined\n ? {}\n : { allowedSourceDirs: importPolicy.allowedSourceDirs }),\n ...(importPolicy?.projectRoot === undefined ? {} : { projectRoot: importPolicy.projectRoot }),\n };\n}\n\nfunction builtGeneratedImportPolicy(\n importPolicyText: string | undefined,\n importPolicyPath: string,\n): AppRouterImportPolicy | undefined {\n if (importPolicyText === undefined) {\n return undefined;\n }\n\n const artifact = parseBuiltJsonArtifact<{\n runtimePackages?: unknown;\n }>(importPolicyText, importPolicyPath, \"built app import policy\");\n const runtimePackages = Array.isArray(artifact.runtimePackages)\n ? artifact.runtimePackages.filter((name): name is string => typeof name === \"string\")\n : [];\n\n return runtimePackages.length === 0 ? undefined : { allowedPackages: runtimePackages };\n}\n\nasync function materializeBuiltServerApp(\n runtimeDir: string,\n manifest: BuiltServerManifest,\n): Promise<string> {\n const appDir = join(runtimeDir, \"app\");\n\n await rm(appDir, { force: true, recursive: true });\n await Promise.all(\n Object.entries(manifest.files).map(async ([file, code]) => {\n const outputFile = join(appDir, safeManifestFilePath(file));\n\n await mkdir(dirname(outputFile), { recursive: true });\n await writeFile(outputFile, code);\n }),\n );\n\n return appDir;\n}\n\nfunction isMissingFileError(error: unknown): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n (error as { code?: unknown }).code === \"ENOENT\"\n );\n}\n\nfunction builtArtifactReadError(label: string, artifactPath: string, error: unknown): Error {\n const prefix = isMissingFileError(error) ? \"Missing\" : \"Unable to read\";\n const detail = error instanceof Error && error.message !== \"\" ? `: ${error.message}` : \"\";\n\n return new Error(`${prefix} ${label}: ${artifactPath}${detail}`, { cause: error });\n}\n\nfunction parseBuiltJsonArtifact<T>(text: string, artifactPath: string, label: string): T {\n try {\n return JSON.parse(text) as T;\n } catch (error) {\n const detail = error instanceof Error && error.message !== \"\" ? `: ${error.message}` : \"\";\n\n throw new Error(`Invalid ${label}: ${artifactPath}${detail}`, { cause: error });\n }\n}\n\nfunction safeManifestFilePath(pathname: string): string {\n const normalized = normalize(pathname);\n\n if (isAbsolute(normalized) || normalized === \"..\" || normalized.startsWith(\"../\")) {\n throw new Error(`Invalid built app manifest file path: ${pathname}`);\n }\n\n return normalized;\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import type { BuiltServerModuleArtifact } from "./build.js";
2
+ export interface BuiltServerModuleArtifactRuntime {
3
+ appDir: string;
4
+ serverModuleArtifactLoads: Map<string, Promise<void>>;
5
+ serverModuleClosureFiles: Map<string, readonly string[]>;
6
+ serverModuleFiles: ReadonlyMap<string, string>;
7
+ serverModuleRenderFiles: ReadonlyMap<string, string>;
8
+ serverModuleRequestFiles: ReadonlyMap<string, string>;
9
+ serverModules: Map<string, BuiltServerModuleArtifact>;
10
+ serverSourceFiles: ReadonlyMap<string, string>;
11
+ }
12
+ export type BuiltServerModuleArtifactKind = "all" | "render" | "request";
13
+ export declare function loadBuiltServerModuleArtifacts(runtime: BuiltServerModuleArtifactRuntime, files: Iterable<string>, kind?: BuiltServerModuleArtifactKind): Promise<void>;
14
+ export declare function allBuiltServerModuleFiles(runtime: BuiltServerModuleArtifactRuntime): Iterable<string>;
15
+ export declare function loadBuiltServerModuleArtifactsForRequest(runtime: BuiltServerModuleArtifactRuntime, routeFile: string | undefined, options?: {
16
+ includeRender?: boolean | undefined;
17
+ includeShells?: boolean | undefined;
18
+ }): Promise<void>;
19
+ //# sourceMappingURL=built-server-module-artifacts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"built-server-module-artifacts.d.ts","sourceRoot":"","sources":["../src/built-server-module-artifacts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,gCAAgC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACtD,wBAAwB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IACzD,iBAAiB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,uBAAuB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrD,wBAAwB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtD,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;IACtD,iBAAiB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChD;AAED,MAAM,MAAM,6BAA6B,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzE,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,gCAAgC,EACzC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EACvB,IAAI,GAAE,6BAAqC,GAC1C,OAAO,CAAC,IAAI,CAAC,CAIf;AA2DD,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,gCAAgC,GACxC,QAAQ,CAAC,MAAM,CAAC,C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