@agent-native/core 0.79.11 → 0.79.12
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/corpus/core/CHANGELOG.md +6 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/deploy/build.ts +321 -15
- package/dist/deploy/build.d.ts +26 -1
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +226 -14
- package/dist/deploy/build.js.map +1 -1
- package/dist/file-upload/actions/upload-image.d.ts +2 -2
- package/dist/notifications/routes.d.ts +2 -2
- package/dist/observability/routes.d.ts +7 -7
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/package.json +1 -1
package/corpus/core/CHANGELOG.md
CHANGED
package/corpus/core/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-native/core",
|
|
3
|
-
"version": "0.79.
|
|
3
|
+
"version": "0.79.12",
|
|
4
4
|
"description": "Framework for agent-native application development — where AI agents and UI share SQL state, actions, and context",
|
|
5
5
|
"homepage": "https://github.com/BuilderIO/agent-native#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -101,6 +101,34 @@ export const CLOUDFLARE_WORKER_ESBUILD_EXTERNALS = [
|
|
|
101
101
|
"fsevents",
|
|
102
102
|
];
|
|
103
103
|
|
|
104
|
+
export interface GenerateWorkerEntryOptions {
|
|
105
|
+
includeReactRouterSsr?: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface ReactRouterAssetManifest {
|
|
109
|
+
entry: ReactRouterAssetManifestEntry;
|
|
110
|
+
routes: Record<string, ReactRouterAssetManifestRoute>;
|
|
111
|
+
url: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface ReactRouterAssetManifestEntry {
|
|
115
|
+
module: string;
|
|
116
|
+
imports?: string[];
|
|
117
|
+
css?: string[];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface ReactRouterAssetManifestRoute {
|
|
121
|
+
id: string;
|
|
122
|
+
module: string;
|
|
123
|
+
imports?: string[];
|
|
124
|
+
css?: string[];
|
|
125
|
+
hasLoader?: boolean;
|
|
126
|
+
clientActionModule?: string;
|
|
127
|
+
clientLoaderModule?: string;
|
|
128
|
+
clientMiddlewareModule?: string;
|
|
129
|
+
hydrateFallbackModule?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
104
132
|
function normalizeConfiguredAppBasePath(): string {
|
|
105
133
|
return normalizeAppBasePath(
|
|
106
134
|
process.env.VITE_APP_BASE_PATH || process.env.APP_BASE_PATH,
|
|
@@ -200,7 +228,9 @@ export function generateWorkerEntry(
|
|
|
200
228
|
workspaceCore: WorkspaceCoreExports | null = null,
|
|
201
229
|
immutableAssetPaths: string[] = [],
|
|
202
230
|
builtAppBasePath = normalizeConfiguredAppBasePath(),
|
|
231
|
+
options: GenerateWorkerEntryOptions = {},
|
|
203
232
|
): string {
|
|
233
|
+
const includeReactRouterSsr = options.includeReactRouterSsr ?? true;
|
|
204
234
|
const routeImports: string[] = [];
|
|
205
235
|
const routeRegistrations: string[] = [];
|
|
206
236
|
|
|
@@ -322,8 +352,8 @@ export function generateWorkerEntry(
|
|
|
322
352
|
return `
|
|
323
353
|
// Auto-generated worker entry point for ${preset}
|
|
324
354
|
import { H3, defineEventHandler, readBody, toResponse } from "h3";
|
|
325
|
-
import { createRequestHandler } from "react-router";
|
|
326
|
-
import * as serverBuild from "./server-build.js";
|
|
355
|
+
${includeReactRouterSsr ? 'import { createRequestHandler } from "react-router";' : ""}
|
|
356
|
+
${includeReactRouterSsr ? 'import * as serverBuild from "./server-build.js";' : ""}
|
|
327
357
|
|
|
328
358
|
function normalizeAppBasePath(value) {
|
|
329
359
|
if (!value || value === "/") return "";
|
|
@@ -653,6 +683,52 @@ function requestWithPathname(request, pathname) {
|
|
|
653
683
|
return new Request(url, request);
|
|
654
684
|
}
|
|
655
685
|
|
|
686
|
+
function isStaticAppShellRequest(request) {
|
|
687
|
+
if (request.method !== "GET" && request.method !== "HEAD") return false;
|
|
688
|
+
const p = stripAppBasePath(new URL(request.url).pathname);
|
|
689
|
+
if (
|
|
690
|
+
p.startsWith("/.well-known/") ||
|
|
691
|
+
p.startsWith("/_agent-native/") ||
|
|
692
|
+
isApiPath(p) ||
|
|
693
|
+
p === "/favicon.ico" ||
|
|
694
|
+
p === "/favicon.png" ||
|
|
695
|
+
/\\.\\w+$/.test(p)
|
|
696
|
+
) {
|
|
697
|
+
return false;
|
|
698
|
+
}
|
|
699
|
+
return true;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
async function fetchStaticAppShell(request, env) {
|
|
703
|
+
if (!env?.ASSETS || !isStaticAppShellRequest(request)) return null;
|
|
704
|
+
const basePath = getAppBasePath();
|
|
705
|
+
const p = stripAppBasePath(new URL(request.url).pathname);
|
|
706
|
+
const shellRequest = requestWithPathname(
|
|
707
|
+
requestWithMethod(request, "GET"),
|
|
708
|
+
"/index.html",
|
|
709
|
+
);
|
|
710
|
+
let response;
|
|
711
|
+
try {
|
|
712
|
+
response = await env.ASSETS.fetch(shellRequest);
|
|
713
|
+
} catch {
|
|
714
|
+
return null;
|
|
715
|
+
}
|
|
716
|
+
if (response.status === 404) return null;
|
|
717
|
+
if (request.method === "HEAD") {
|
|
718
|
+
return rewriteMountedResponse(
|
|
719
|
+
new Response(null, {
|
|
720
|
+
status: response.status,
|
|
721
|
+
statusText: response.statusText,
|
|
722
|
+
headers: response.headers,
|
|
723
|
+
}),
|
|
724
|
+
basePath,
|
|
725
|
+
p,
|
|
726
|
+
request,
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
return rewriteMountedResponse(response, basePath, p, request);
|
|
730
|
+
}
|
|
731
|
+
|
|
656
732
|
// API route handlers
|
|
657
733
|
${routeImports.join("\n")}
|
|
658
734
|
|
|
@@ -708,7 +784,9 @@ ${routeRegistrations.join("\n")}
|
|
|
708
784
|
// Register action routes (/_agent-native/actions/*)
|
|
709
785
|
${actionRegistrations.join("\n")}
|
|
710
786
|
|
|
711
|
-
|
|
787
|
+
${
|
|
788
|
+
includeReactRouterSsr
|
|
789
|
+
? ` // SSR catch-all for React Router
|
|
712
790
|
const rrHandler = createRequestHandler(() => serverBuild);
|
|
713
791
|
app.all("/**", defineEventHandler(async (event) => {
|
|
714
792
|
const basePath = getAppBasePath();
|
|
@@ -739,7 +817,9 @@ ${actionRegistrations.join("\n")}
|
|
|
739
817
|
);
|
|
740
818
|
}
|
|
741
819
|
return rewriteMountedResponse(await rrHandler(request), basePath, p, request);
|
|
742
|
-
}))
|
|
820
|
+
}));`
|
|
821
|
+
: ""
|
|
822
|
+
}
|
|
743
823
|
|
|
744
824
|
_handler = app.fetch.bind(app);
|
|
745
825
|
return _handler;
|
|
@@ -778,12 +858,227 @@ export default {
|
|
|
778
858
|
}
|
|
779
859
|
|
|
780
860
|
const handler = await getHandler();
|
|
781
|
-
|
|
861
|
+
const response = await handler(requestWithMountedApiPrefixStripped(request));
|
|
862
|
+
${
|
|
863
|
+
includeReactRouterSsr
|
|
864
|
+
? " return response;"
|
|
865
|
+
: ` if (response.status === 404) {
|
|
866
|
+
const shellResponse = await fetchStaticAppShell(request, env);
|
|
867
|
+
if (shellResponse) return shellResponse;
|
|
868
|
+
}
|
|
869
|
+
return response;`
|
|
870
|
+
}
|
|
782
871
|
}
|
|
783
872
|
};
|
|
784
873
|
`;
|
|
785
874
|
}
|
|
786
875
|
|
|
876
|
+
function escapeHtmlAttribute(value: string): string {
|
|
877
|
+
return value
|
|
878
|
+
.replaceAll("&", "&")
|
|
879
|
+
.replaceAll('"', """)
|
|
880
|
+
.replaceAll("<", "<")
|
|
881
|
+
.replaceAll(">", ">");
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function findReactRouterManifest(distDir: string): ReactRouterAssetManifest {
|
|
885
|
+
const assetsDir = path.join(distDir, "assets");
|
|
886
|
+
const manifestFile = fs
|
|
887
|
+
.readdirSync(assetsDir)
|
|
888
|
+
.find((file) => /^manifest-[\w-]+\.js$/.test(file));
|
|
889
|
+
if (!manifestFile) {
|
|
890
|
+
throw new Error(`React Router client manifest not found in ${assetsDir}`);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
const source = fs.readFileSync(path.join(assetsDir, manifestFile), "utf8");
|
|
894
|
+
const match = source.match(/^window\.__reactRouterManifest=(.*);?\s*$/);
|
|
895
|
+
if (!match) {
|
|
896
|
+
throw new Error(`Could not parse React Router manifest ${manifestFile}`);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
return JSON.parse(match[1].replace(/;$/, "")) as ReactRouterAssetManifest;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
function collectModulePreloads(
|
|
903
|
+
manifest: ReactRouterAssetManifest,
|
|
904
|
+
route: ReactRouterAssetManifestRoute,
|
|
905
|
+
): string[] {
|
|
906
|
+
const paths = new Set<string>();
|
|
907
|
+
const add = (value: string | undefined) => {
|
|
908
|
+
if (value) paths.add(value);
|
|
909
|
+
};
|
|
910
|
+
add(manifest.url);
|
|
911
|
+
add(manifest.entry.module);
|
|
912
|
+
manifest.entry.imports?.forEach(add);
|
|
913
|
+
add(route.module);
|
|
914
|
+
route.imports?.forEach(add);
|
|
915
|
+
add(route.clientActionModule);
|
|
916
|
+
add(route.clientLoaderModule);
|
|
917
|
+
add(route.clientMiddlewareModule);
|
|
918
|
+
add(route.hydrateFallbackModule);
|
|
919
|
+
return [...paths];
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
function collectStylesheetLinks(
|
|
923
|
+
manifest: ReactRouterAssetManifest,
|
|
924
|
+
route: ReactRouterAssetManifestRoute,
|
|
925
|
+
): string[] {
|
|
926
|
+
return [...new Set([...(manifest.entry.css ?? []), ...(route.css ?? [])])];
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
function generateRouteModuleImportScript(
|
|
930
|
+
manifest: ReactRouterAssetManifest,
|
|
931
|
+
route: ReactRouterAssetManifestRoute,
|
|
932
|
+
): string {
|
|
933
|
+
const modules = [
|
|
934
|
+
["route0", route.module],
|
|
935
|
+
["route0_clientAction", route.clientActionModule],
|
|
936
|
+
["route0_clientLoader", route.clientLoaderModule],
|
|
937
|
+
["route0_clientMiddleware", route.clientMiddlewareModule],
|
|
938
|
+
["route0_hydrateFallback", route.hydrateFallbackModule],
|
|
939
|
+
] as const;
|
|
940
|
+
const imports = modules
|
|
941
|
+
.filter(([, modulePath]) => modulePath)
|
|
942
|
+
.map(
|
|
943
|
+
([name, modulePath]) =>
|
|
944
|
+
`import * as ${name} from ${JSON.stringify(modulePath)};`,
|
|
945
|
+
);
|
|
946
|
+
const parts = modules
|
|
947
|
+
.filter(([, modulePath]) => modulePath)
|
|
948
|
+
.map(([name]) => `...${name}`);
|
|
949
|
+
|
|
950
|
+
return [
|
|
951
|
+
`import ${JSON.stringify(manifest.url)};`,
|
|
952
|
+
...imports,
|
|
953
|
+
`window.__reactRouterRouteModules = {${JSON.stringify(route.id)}:{${parts.join(",")}}};`,
|
|
954
|
+
`import(${JSON.stringify(manifest.entry.module)});`,
|
|
955
|
+
].join("\n");
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
const EMPTY_REACT_ROUTER_TURBO_STREAM =
|
|
959
|
+
'[{"_1":2,"_3":-5,"_4":-5},"loaderData",{},"actionData","errors"]\n';
|
|
960
|
+
|
|
961
|
+
// Manifest fallbacks cannot execute server loaders, so root loaders get the
|
|
962
|
+
// framework's default locale shape to keep hydration from reading undefined.
|
|
963
|
+
const DEFAULT_ROOT_LOADER_REACT_ROUTER_TURBO_STREAM =
|
|
964
|
+
'[{"_1":2,"_3":-5,"_4":-5},"loaderData",{"_5":6},"actionData","errors","root",{"_7":8,"_9":10,"_11":12,"_13":14},"locale","en-US","preference",{"_7":15},"dir","ltr","messages",{},"system"]\n';
|
|
965
|
+
|
|
966
|
+
export function generateCloudflarePagesStaticShellFromManifest(
|
|
967
|
+
manifest: ReactRouterAssetManifest,
|
|
968
|
+
basePath = normalizeConfiguredAppBasePath(),
|
|
969
|
+
): string {
|
|
970
|
+
const rootRoute = manifest.routes.root;
|
|
971
|
+
if (!rootRoute) {
|
|
972
|
+
throw new Error("React Router manifest is missing the root route");
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
const modulePreloads = collectModulePreloads(manifest, rootRoute)
|
|
976
|
+
.map(
|
|
977
|
+
(href) =>
|
|
978
|
+
`<link rel="modulepreload" href="${escapeHtmlAttribute(href)}"/>`,
|
|
979
|
+
)
|
|
980
|
+
.join("");
|
|
981
|
+
const stylesheets = collectStylesheetLinks(manifest, rootRoute)
|
|
982
|
+
.map(
|
|
983
|
+
(href) => `<link rel="stylesheet" href="${escapeHtmlAttribute(href)}"/>`,
|
|
984
|
+
)
|
|
985
|
+
.join("");
|
|
986
|
+
const routeModuleScript = generateRouteModuleImportScript(
|
|
987
|
+
manifest,
|
|
988
|
+
rootRoute,
|
|
989
|
+
);
|
|
990
|
+
const context = {
|
|
991
|
+
basename: basePath || "/",
|
|
992
|
+
future: { unstable_optimizeDeps: false },
|
|
993
|
+
routeDiscovery: { mode: "initial" },
|
|
994
|
+
ssr: true,
|
|
995
|
+
isSpaMode: true,
|
|
996
|
+
};
|
|
997
|
+
const encodedInitialState = rootRoute.hasLoader
|
|
998
|
+
? DEFAULT_ROOT_LOADER_REACT_ROUTER_TURBO_STREAM
|
|
999
|
+
: EMPTY_REACT_ROUTER_TURBO_STREAM;
|
|
1000
|
+
|
|
1001
|
+
return `<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/><link rel="manifest" href="/manifest.json"/><link rel="icon" type="image/svg+xml" href="/favicon.svg"/>${modulePreloads}${stylesheets}</head><body><div style="display:flex;align-items:center;justify-content:center;height:100vh;width:100%"><svg role="status" aria-label="Loading" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="animation:an-spin 1s linear infinite;opacity:0.7"><path d="M21 12a9 9 0 1 1-6.219-8.56"></path></svg><style>@keyframes an-spin { to { transform: rotate(360deg) } } @media (prefers-color-scheme: dark) { html { background: #09090b; color: #fafafa } }</style></div><script>window.__reactRouterContext = ${JSON.stringify(context)};window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());</script><script type="module" async="">${routeModuleScript}</script><!--$--><script>window.__reactRouterContext.streamController.enqueue(${JSON.stringify(encodedInitialState)});</script><!--$--><script>window.__reactRouterContext.streamController.close();</script><!--/$--><!--/$--></body></html>`;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
function writeCloudflarePagesStaticShell({
|
|
1005
|
+
serverDir,
|
|
1006
|
+
distDir,
|
|
1007
|
+
tmpDir,
|
|
1008
|
+
}: {
|
|
1009
|
+
serverDir: string;
|
|
1010
|
+
distDir: string;
|
|
1011
|
+
tmpDir: string;
|
|
1012
|
+
}): void {
|
|
1013
|
+
const serverEntry = path.join(serverDir, "index.js");
|
|
1014
|
+
if (!fs.existsSync(serverEntry)) {
|
|
1015
|
+
throw new Error(`React Router server build not found at ${serverEntry}`);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
const outFile = path.join(distDir, "index.html");
|
|
1019
|
+
const renderScript = path.join(tmpDir, "render-cloudflare-static-shell.mjs");
|
|
1020
|
+
const basePath = normalizeConfiguredAppBasePath();
|
|
1021
|
+
fs.writeFileSync(
|
|
1022
|
+
renderScript,
|
|
1023
|
+
`
|
|
1024
|
+
import fs from "node:fs";
|
|
1025
|
+
import { createRequire } from "node:module";
|
|
1026
|
+
import { pathToFileURL } from "node:url";
|
|
1027
|
+
|
|
1028
|
+
const cwd = ${JSON.stringify(cwd)};
|
|
1029
|
+
const serverEntry = ${JSON.stringify(serverEntry)};
|
|
1030
|
+
const outFile = ${JSON.stringify(outFile)};
|
|
1031
|
+
const basePath = ${JSON.stringify(basePath)};
|
|
1032
|
+
|
|
1033
|
+
const requireFromApp = createRequire(cwd + "/package.json");
|
|
1034
|
+
const reactRouterEntry = requireFromApp.resolve("react-router");
|
|
1035
|
+
const { createRequestHandler } = await import(pathToFileURL(reactRouterEntry).href);
|
|
1036
|
+
const serverBuild = await import(pathToFileURL(serverEntry).href);
|
|
1037
|
+
const handler = createRequestHandler(serverBuild, "production");
|
|
1038
|
+
const pathname = basePath ? basePath + "/" : "/";
|
|
1039
|
+
const response = await handler(
|
|
1040
|
+
new Request(new URL(pathname, "https://agent-native.local"), {
|
|
1041
|
+
headers: { "X-React-Router-SPA-Mode": "yes" },
|
|
1042
|
+
}),
|
|
1043
|
+
);
|
|
1044
|
+
const html = await response.text();
|
|
1045
|
+
|
|
1046
|
+
if (!html || !html.includes("__reactRouterContext") || !html.includes("entry.client")) {
|
|
1047
|
+
throw new Error("React Router did not render a usable Cloudflare Pages static shell");
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
fs.writeFileSync(outFile, html);
|
|
1051
|
+
process.exit(0);
|
|
1052
|
+
`,
|
|
1053
|
+
);
|
|
1054
|
+
|
|
1055
|
+
try {
|
|
1056
|
+
execFileSync(process.execPath, [renderScript], {
|
|
1057
|
+
cwd,
|
|
1058
|
+
env: {
|
|
1059
|
+
...process.env,
|
|
1060
|
+
NODE_ENV: process.env.NODE_ENV || "production",
|
|
1061
|
+
IS_RR_BUILD_REQUEST: "yes",
|
|
1062
|
+
},
|
|
1063
|
+
stdio: "inherit",
|
|
1064
|
+
});
|
|
1065
|
+
console.log("[deploy] Wrote Cloudflare Pages static app shell.");
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1068
|
+
console.warn(
|
|
1069
|
+
`[deploy] React Router static shell render failed; using manifest fallback. ${message}`,
|
|
1070
|
+
);
|
|
1071
|
+
fs.writeFileSync(
|
|
1072
|
+
outFile,
|
|
1073
|
+
generateCloudflarePagesStaticShellFromManifest(
|
|
1074
|
+
findReactRouterManifest(distDir),
|
|
1075
|
+
basePath,
|
|
1076
|
+
),
|
|
1077
|
+
);
|
|
1078
|
+
console.log("[deploy] Wrote Cloudflare Pages static app shell fallback.");
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
787
1082
|
/**
|
|
788
1083
|
* Build for Cloudflare Pages.
|
|
789
1084
|
* Output structure:
|
|
@@ -816,6 +1111,10 @@ async function buildCloudflarePages() {
|
|
|
816
1111
|
// Copy client assets to dist/
|
|
817
1112
|
copyDir(clientDir, distDir);
|
|
818
1113
|
|
|
1114
|
+
const tmpDir = path.join(cwd, ".deploy-tmp");
|
|
1115
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
1116
|
+
writeCloudflarePagesStaticShell({ serverDir, distDir, tmpDir });
|
|
1117
|
+
|
|
819
1118
|
// Exclude _worker.js from being served as a public asset
|
|
820
1119
|
fs.writeFileSync(path.join(distDir, ".assetsignore"), "_worker.js\n");
|
|
821
1120
|
|
|
@@ -841,6 +1140,7 @@ async function buildCloudflarePages() {
|
|
|
841
1140
|
const actions = await discoverActionFiles(cwd);
|
|
842
1141
|
const missingDefaults = await getMissingDefaultPlugins(cwd);
|
|
843
1142
|
const workspaceCore = await getWorkspaceCoreExports(cwd);
|
|
1143
|
+
const includeReactRouterSsr = false;
|
|
844
1144
|
|
|
845
1145
|
const workspaceSlotCount = workspaceCore
|
|
846
1146
|
? Object.keys(workspaceCore.plugins).length
|
|
@@ -858,6 +1158,8 @@ async function buildCloudflarePages() {
|
|
|
858
1158
|
actions,
|
|
859
1159
|
workspaceCore,
|
|
860
1160
|
immutableAssetPaths,
|
|
1161
|
+
normalizeConfiguredAppBasePath(),
|
|
1162
|
+
{ includeReactRouterSsr },
|
|
861
1163
|
);
|
|
862
1164
|
|
|
863
1165
|
// Create _worker.js output directory
|
|
@@ -867,23 +1169,27 @@ async function buildCloudflarePages() {
|
|
|
867
1169
|
// Write the worker entry
|
|
868
1170
|
const entryFile = path.join(workerOutDir, "index.js");
|
|
869
1171
|
|
|
870
|
-
// Rewrite the server-build import to point at the copied files
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
1172
|
+
// Rewrite the server-build import to point at the copied files when this
|
|
1173
|
+
// worker intentionally includes React Router SSR.
|
|
1174
|
+
const adjustedEntry = includeReactRouterSsr
|
|
1175
|
+
? entrySource.replace(
|
|
1176
|
+
`import * as serverBuild from "./server-build.js";`,
|
|
1177
|
+
`import * as serverBuild from "./server/index.js";`,
|
|
1178
|
+
)
|
|
1179
|
+
: entrySource;
|
|
875
1180
|
|
|
876
1181
|
// Write a temp file for esbuild to bundle everything into a single worker entry.
|
|
877
|
-
//
|
|
878
|
-
|
|
879
|
-
|
|
1182
|
+
// When React Router SSR is enabled, the server build is copied to tmp so
|
|
1183
|
+
// esbuild can resolve it. Cloudflare Pages currently uses a static app shell
|
|
1184
|
+
// instead so the worker stays under the platform bundle size limit.
|
|
880
1185
|
// Name the entry "index.js" so esbuild outputs index.js in the outdir,
|
|
881
1186
|
// matching the _worker.js/index.js entry point that Cloudflare Pages expects.
|
|
882
1187
|
const tmpEntry = path.join(tmpDir, "index.js");
|
|
883
1188
|
fs.writeFileSync(tmpEntry, adjustedEntry);
|
|
884
1189
|
|
|
885
|
-
|
|
886
|
-
|
|
1190
|
+
if (includeReactRouterSsr) {
|
|
1191
|
+
copyDir(serverDir, path.join(tmpDir, "server"));
|
|
1192
|
+
}
|
|
887
1193
|
|
|
888
1194
|
// Create a require shim so CJS require("fs") calls resolve via ESM imports.
|
|
889
1195
|
// This is injected via esbuild --inject to replace its broken __require shim.
|
package/dist/deploy/build.d.ts
CHANGED
|
@@ -16,6 +16,30 @@ import { type DiscoveredRoute, type DiscoveredAction } from "./route-discovery.j
|
|
|
16
16
|
import { type WorkspaceCoreExports } from "./workspace-core.js";
|
|
17
17
|
export declare const NITRO_RUNTIME_IGNORE_PATTERNS: string[];
|
|
18
18
|
export declare const CLOUDFLARE_WORKER_ESBUILD_EXTERNALS: string[];
|
|
19
|
+
export interface GenerateWorkerEntryOptions {
|
|
20
|
+
includeReactRouterSsr?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface ReactRouterAssetManifest {
|
|
23
|
+
entry: ReactRouterAssetManifestEntry;
|
|
24
|
+
routes: Record<string, ReactRouterAssetManifestRoute>;
|
|
25
|
+
url: string;
|
|
26
|
+
}
|
|
27
|
+
interface ReactRouterAssetManifestEntry {
|
|
28
|
+
module: string;
|
|
29
|
+
imports?: string[];
|
|
30
|
+
css?: string[];
|
|
31
|
+
}
|
|
32
|
+
interface ReactRouterAssetManifestRoute {
|
|
33
|
+
id: string;
|
|
34
|
+
module: string;
|
|
35
|
+
imports?: string[];
|
|
36
|
+
css?: string[];
|
|
37
|
+
hasLoader?: boolean;
|
|
38
|
+
clientActionModule?: string;
|
|
39
|
+
clientLoaderModule?: string;
|
|
40
|
+
clientMiddlewareModule?: string;
|
|
41
|
+
hydrateFallbackModule?: string;
|
|
42
|
+
}
|
|
19
43
|
export declare function generateProvidedPluginsNitroPluginSource(pluginStems: string[]): string;
|
|
20
44
|
type RouteRules = Record<string, {
|
|
21
45
|
headers?: Record<string, string>;
|
|
@@ -30,7 +54,8 @@ export declare function addImmutableAssetRouteRulesForClientBuild(routeRules: Ro
|
|
|
30
54
|
* `@agent-native/core/server`. This is the middle layer of the three-layer
|
|
31
55
|
* inheritance model: app local > workspace core > framework default.
|
|
32
56
|
*/
|
|
33
|
-
export declare function generateWorkerEntry(routes: DiscoveredRoute[], pluginPaths: string[], defaultPluginStems?: string[], actions?: DiscoveredAction[], workspaceCore?: WorkspaceCoreExports | null, immutableAssetPaths?: string[], builtAppBasePath?: string): string;
|
|
57
|
+
export declare function generateWorkerEntry(routes: DiscoveredRoute[], pluginPaths: string[], defaultPluginStems?: string[], actions?: DiscoveredAction[], workspaceCore?: WorkspaceCoreExports | null, immutableAssetPaths?: string[], builtAppBasePath?: string, options?: GenerateWorkerEntryOptions): string;
|
|
58
|
+
export declare function generateCloudflarePagesStaticShellFromManifest(manifest: ReactRouterAssetManifest, basePath?: string): string;
|
|
34
59
|
export declare function getNodeBuiltinNames(): string[];
|
|
35
60
|
export declare function copyDir(src: string, dest: string, ancestorRealPaths?: Set<string>): void;
|
|
36
61
|
type ServerlessFfmpegStaticArch = "arm64" | "x64";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/deploy/build.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;GAYG;AAmCH,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AAI7B,eAAO,MAAM,6BAA6B,UAiBzC,CAAC;AAEF,eAAO,MAAM,mCAAmC,UAiB/C,CAAC;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/deploy/build.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;GAYG;AAmCH,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AAI7B,eAAO,MAAM,6BAA6B,UAiBzC,CAAC;AAEF,eAAO,MAAM,mCAAmC,UAiB/C,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,UAAU,wBAAwB;IAChC,KAAK,EAAE,6BAA6B,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;IACtD,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,6BAA6B;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,U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