@reckona/mreact-router 0.0.119 → 0.0.121
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/README.md +1 -1
- package/dist/build.d.ts +3 -1
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +96 -45
- package/dist/build.js.map +1 -1
- package/dist/bundle-pipeline.d.ts +3 -3
- package/dist/bundle-pipeline.d.ts.map +1 -1
- package/dist/bundle-pipeline.js.map +1 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +15 -1
- package/dist/client.js.map +1 -1
- package/dist/module-runner.js +14 -6
- package/dist/module-runner.js.map +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +19 -2
- package/dist/render.js.map +1 -1
- package/package.json +11 -11
- package/src/build.ts +523 -369
- package/src/bundle-pipeline.ts +2 -2
- package/src/client.ts +34 -11
- package/src/module-runner.ts +26 -11
- package/src/render.ts +20 -2
package/README.md
CHANGED
|
@@ -324,7 +324,7 @@ For Cloudflare Workers, `mreact-router build --target=cloudflare` emits `.mreact
|
|
|
324
324
|
|
|
325
325
|
For Cloudflare Pages advanced mode, run `mreact-router package cloudflare-pages --from .mreact --out .mreact/pages` after `mreact-router build --target=cloudflare`, then deploy with `wrangler pages deploy .mreact/pages`. The package command creates a Pages output directory with bundled `_worker.js`, `_mreact/client/*` static route assets, root public assets, and `mreact-cloudflare-pages-artifact.json`. Pages provides the `ASSETS` binding to `_worker.js`; mreact's generated worker reads that binding and serves only generated client manifest assets, route-linked CSS, and public files. The package step bundles the generated Worker entry, route registry, route chunks, and router adapter code, so application deploy scripts do not need to copy `worker.mjs` manually or decide whether Wrangler should bundle package imports. If your Worker graph includes dependencies that import Node builtins such as `node:util` or bare `util`, configure Cloudflare Pages with the `nodejs_compat` compatibility flag so the packaged Worker can use Cloudflare's Node.js compatibility runtime.
|
|
326
326
|
|
|
327
|
-
User Vite plugins from the project config are forwarded into router bundle builds after the `mreact-router` plugin itself is removed, so MDX-style syntax transforms and custom content loaders can participate in server, client, Cloudflare, and prerender bundles. Client assets, route stylesheet assets imported by pages/layouts/templates, and copied public assets are served only when they appear in the generated manifest allow-list. Dynamic routes resolve modules through a build-time registry keyed by `route.file`, not by constructing module ids from request input. Generated Cloudflare route modules preserve app-router layout/template shells and named slots for both string and `stream = true` pages, including route-local `<Await>` boundaries and local server-component imports. Generated Cloudflare server route modules dispatch method exports such as `GET`, `POST`, and `ALL` with decoded dynamic params plus `context.env`, `context.context`, `context.request`, and `context.route`, so handlers can use Worker bindings directly. The Cloudflare adapter marks streamed HTML with `Cache-Control: no-transform` and `Content-Encoding: identity` so Workers compression does not gzip-buffer the first shell before placeholders can paint. Pass `onResponse` to add cross-cutting response headers to rendered, static, asset, reload, not-found, and error responses. If a generated Cloudflare route module cannot produce the `data-mreact-route-id` marker contract required by client navigation, the adapter returns a reload signal for `x-mreact-navigation: 1` requests so the browser performs a normal document navigation without first buffering the full HTML response.
|
|
327
|
+
User Vite plugins from the project config are forwarded into router bundle builds after the `mreact-router` plugin itself is removed, so MDX-style syntax transforms and custom content loaders can participate in server, client, Cloudflare, and prerender bundles. Vite `define` values are also forwarded into generated Cloudflare server bundles, including `import.meta.env.*` aliases and plain define identifiers used by loaders and route handlers. Client assets, route stylesheet assets imported by pages/layouts/templates, and copied public assets are served only when they appear in the generated manifest allow-list. Dynamic routes resolve modules through a build-time registry keyed by `route.file`, not by constructing module ids from request input. Generated Cloudflare route modules preserve app-router layout/template shells and named slots for both string and `stream = true` pages, including route-local `<Await>` boundaries and local server-component imports. Generated Cloudflare server route modules dispatch method exports such as `GET`, `POST`, and `ALL` with decoded dynamic params plus `context.env`, `context.context`, `context.request`, and `context.route`, so handlers can use Worker bindings directly. The Cloudflare adapter marks streamed HTML with `Cache-Control: no-transform` and `Content-Encoding: identity` so Workers compression does not gzip-buffer the first shell before placeholders can paint. Pass `onResponse` to add cross-cutting response headers to rendered, static, asset, reload, not-found, and error responses. If a generated Cloudflare route module cannot produce the `data-mreact-route-id` marker contract required by client navigation, the adapter returns a reload signal for `x-mreact-navigation: 1` requests so the browser performs a normal document navigation without first buffering the full HTML response.
|
|
328
328
|
|
|
329
329
|
For AWS Lambda, use `createPreloadedAwsLambdaRequestHandler()` with API Gateway
|
|
330
330
|
HTTP API v2 or Lambda Function URL payload format 2.0:
|
package/dist/build.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface BuildAppOptions extends AppRouterProjectOptions {
|
|
|
8
8
|
onBuildPhaseTiming?: ((timing: BuildAppPhaseTiming) => void) | undefined;
|
|
9
9
|
outDir: string;
|
|
10
10
|
targets?: readonly AppRouterBuildTarget[] | undefined;
|
|
11
|
-
viteConfig?: Pick<UserConfig, "plugins"> | undefined;
|
|
11
|
+
viteConfig?: Pick<UserConfig, "define" | "plugins"> | undefined;
|
|
12
12
|
}
|
|
13
13
|
export type BuildAppPhase = "scan" | "collectFiles" | "analyzeSources" | "validate" | "prepareOutput" | "publicAssets" | "serverActionManifest" | "serverModules" | "importPolicy" | "serverModuleArtifacts" | "clientBundles" | "navigationRuntime" | "prerender" | "cloudflare" | "writeManifests" | "adapterArtifacts";
|
|
14
14
|
export interface BuildAppPhaseTiming {
|
|
@@ -97,6 +97,7 @@ export interface BuiltRouteSourceAnalysisSummary {
|
|
|
97
97
|
authIncludesClaims: boolean;
|
|
98
98
|
cachePolicy?: RouteCachePolicy | undefined;
|
|
99
99
|
clientBoundaryImports: readonly string[];
|
|
100
|
+
clientBoundaryFallbackImports: readonly string[];
|
|
100
101
|
clientRoute: boolean;
|
|
101
102
|
hasLoader: boolean;
|
|
102
103
|
routeCode: string;
|
|
@@ -139,6 +140,7 @@ interface RouteRequestModuleBatchEntry {
|
|
|
139
140
|
}
|
|
140
141
|
export declare function __buildCloudflareRouteLoaderModuleBatchForTests(options: {
|
|
141
142
|
cacheDir?: string | undefined;
|
|
143
|
+
define?: UserConfig["define"] | undefined;
|
|
142
144
|
projectRoot: string;
|
|
143
145
|
routes: readonly {
|
|
144
146
|
filename: string;
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAG1B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,EAAqC,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AA2BnG,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAarD,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;IAC9D,kBAAkB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,SAAS,oBAAoB,EAAE,GAAG,SAAS,CAAC;IACtD,UAAU,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;CACjE;AAED,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,cAAc,GACd,gBAAgB,GAChB,UAAU,GACV,eAAe,GACf,cAAc,GACd,sBAAsB,GACtB,eAAe,GACf,cAAc,GACd,uBAAuB,GACvB,eAAe,GACf,mBAAmB,GACnB,WAAW,GACX,YAAY,GACZ,gBAAgB,GAChB,kBAAkB,CAAC;AAEvB,MAAM,WAA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CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAYlC;AA28BD,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,yBAAyB,CAAC,CA4CpC;AA6DD,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,qCAAqC,GAC7C,OAAO,CAAC,+BAA+B,CAAC,CAsD1C"}
|
package/dist/build.js
CHANGED
|
@@ -10,7 +10,7 @@ import { compilerModuleContextForSource, collectClientRouteReferences, createCli
|
|
|
10
10
|
import { buildClientRouteBatchOutput, buildNavigationRuntimeBundle, clientScriptForPath, routeIdForPath, } from "./navigation-runtime.js";
|
|
11
11
|
import { bundleAppRouterSourceModule, fileImportMetaUrlPlugin, importAppRouterSourceModule, } from "./module-runner.js";
|
|
12
12
|
import { scanAppRoutes } from "./routes.js";
|
|
13
|
-
import { appFileConventionForRootFilename
|
|
13
|
+
import { appFileConventionForRootFilename } from "./file-conventions.js";
|
|
14
14
|
import { resolveAppRouterProjectOptions, resolveBuildTargets, } from "./config.js";
|
|
15
15
|
import { routeCachePolicyFromSource } from "./cache.js";
|
|
16
16
|
import { bundleMiddlewareModuleCode, renderAppRequest } from "./render.js";
|
|
@@ -38,6 +38,7 @@ export async function buildApp(options) {
|
|
|
38
38
|
const routes = timingSink === undefined
|
|
39
39
|
? await scanAppRoutes({ appDir: project.routesDir })
|
|
40
40
|
: await timeBuildPhase(timingSink, "scan", () => scanAppRoutes({ appDir: project.routesDir }));
|
|
41
|
+
const viteDefine = options.viteConfig?.define;
|
|
41
42
|
const vitePlugins = options.viteConfig?.plugins;
|
|
42
43
|
const files = timingSink === undefined
|
|
43
44
|
? await collectBuildFiles(project.projectRoot, project.allowedSourceDirs, project.routesDir)
|
|
@@ -245,6 +246,7 @@ export async function buildApp(options) {
|
|
|
245
246
|
timingSink === undefined
|
|
246
247
|
? await writeCloudflareRouteModules({
|
|
247
248
|
cloudflareDir,
|
|
249
|
+
define: viteDefine,
|
|
248
250
|
files,
|
|
249
251
|
prerenderedRoutes,
|
|
250
252
|
projectRoot: project.projectRoot,
|
|
@@ -256,6 +258,7 @@ export async function buildApp(options) {
|
|
|
256
258
|
})
|
|
257
259
|
: await timeBuildPhase(timingSink, "cloudflare", () => writeCloudflareRouteModules({
|
|
258
260
|
cloudflareDir,
|
|
261
|
+
define: viteDefine,
|
|
259
262
|
files,
|
|
260
263
|
prerenderedRoutes,
|
|
261
264
|
projectRoot: project.projectRoot,
|
|
@@ -413,6 +416,7 @@ async function analyzeBuildRouteSources(options) {
|
|
|
413
416
|
{
|
|
414
417
|
...analyzeBuildSource(source, route.file),
|
|
415
418
|
clientBoundaryImports: clientInference.clientBoundaryImports,
|
|
419
|
+
clientBoundaryFallbackImports: clientInference.clientBoundaryFallbackImports,
|
|
416
420
|
clientRoute: clientInference.client,
|
|
417
421
|
file,
|
|
418
422
|
route,
|
|
@@ -781,7 +785,9 @@ async function findRuntimePackageJson(packageName, startDir) {
|
|
|
781
785
|
}
|
|
782
786
|
}
|
|
783
787
|
function isRuntimePackageSpecifier(specifier) {
|
|
784
|
-
if (specifier.startsWith(".") ||
|
|
788
|
+
if (specifier.startsWith(".") ||
|
|
789
|
+
specifier.startsWith("/") ||
|
|
790
|
+
/^[A-Za-z][A-Za-z0-9+.-]*:/.test(specifier)) {
|
|
785
791
|
return false;
|
|
786
792
|
}
|
|
787
793
|
const packageName = runtimePackageNameForSpecifier(specifier);
|
|
@@ -864,7 +870,9 @@ function isSourceModuleFile(file) {
|
|
|
864
870
|
return /\.(?:mreact\.tsx|tsx?|jsx?|mjs|mts|cjs|cts)$/.test(file);
|
|
865
871
|
}
|
|
866
872
|
function isAppRelativeFile(file, relativeRoutesDir) {
|
|
867
|
-
return relativeRoutesDir === "" ||
|
|
873
|
+
return (relativeRoutesDir === "" ||
|
|
874
|
+
file === relativeRoutesDir ||
|
|
875
|
+
file.startsWith(`${relativeRoutesDir}/`));
|
|
868
876
|
}
|
|
869
877
|
function moduleIdForBuildFile(file, relativeRoutesDir) {
|
|
870
878
|
return relativeRoutesDir === "" ? file : file.slice(relativeRoutesDir.length + 1);
|
|
@@ -918,9 +926,7 @@ async function copyAppFileConventionAssets(appDir, outDir) {
|
|
|
918
926
|
if (convention === undefined || convention.kind !== "asset") {
|
|
919
927
|
continue;
|
|
920
928
|
}
|
|
921
|
-
const outputPath = convention.path.startsWith("/")
|
|
922
|
-
? convention.path.slice(1)
|
|
923
|
-
: convention.path;
|
|
929
|
+
const outputPath = convention.path.startsWith("/") ? convention.path.slice(1) : convention.path;
|
|
924
930
|
await copyFile(join(appDir, entry.name), join(outDir, outputPath));
|
|
925
931
|
paths.push(convention.path);
|
|
926
932
|
}
|
|
@@ -1110,7 +1116,7 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1110
1116
|
metadataArtifactFiles.has(file)) {
|
|
1111
1117
|
if (loaderArtifactFiles.has(file)) {
|
|
1112
1118
|
const code = requestBatchOutputs.get(routeRequestArtifactBatchKey(file, "loader")) ??
|
|
1113
|
-
await bundleRouteLoaderModuleCode({
|
|
1119
|
+
(await bundleRouteLoaderModuleCode({
|
|
1114
1120
|
appDir: options.project.routesDir,
|
|
1115
1121
|
bundleCache: options.bundleCache,
|
|
1116
1122
|
cacheDir: options.cacheDir,
|
|
@@ -1118,7 +1124,7 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1118
1124
|
filename: absoluteFile,
|
|
1119
1125
|
importPolicy: requestModuleImportPolicy,
|
|
1120
1126
|
vitePlugins: options.vitePlugins,
|
|
1121
|
-
});
|
|
1127
|
+
}));
|
|
1122
1128
|
artifact.loader = {
|
|
1123
1129
|
code,
|
|
1124
1130
|
sourceHash: hashText(source),
|
|
@@ -1126,7 +1132,7 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1126
1132
|
}
|
|
1127
1133
|
if (metadataArtifactFiles.has(file)) {
|
|
1128
1134
|
const code = requestBatchOutputs.get(routeRequestArtifactBatchKey(file, "metadata")) ??
|
|
1129
|
-
await bundleRouteRequestModuleCode({
|
|
1135
|
+
(await bundleRouteRequestModuleCode({
|
|
1130
1136
|
appDir: options.project.routesDir,
|
|
1131
1137
|
bundleCache: options.bundleCache,
|
|
1132
1138
|
cacheDir: options.cacheDir,
|
|
@@ -1135,7 +1141,7 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1135
1141
|
importPolicy: requestModuleImportPolicy,
|
|
1136
1142
|
label: "Metadata",
|
|
1137
1143
|
vitePlugins: options.vitePlugins,
|
|
1138
|
-
});
|
|
1144
|
+
}));
|
|
1139
1145
|
artifact.routeMetadata = {
|
|
1140
1146
|
code,
|
|
1141
1147
|
sourceHash: hashText(source),
|
|
@@ -1145,7 +1151,7 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1145
1151
|
const batchedRequestCode = requestBatchOutputs.get(routeRequestArtifactBatchKey(file, "request"));
|
|
1146
1152
|
artifact.request = {
|
|
1147
1153
|
code: batchedRequestCode ??
|
|
1148
|
-
await buildRequestModuleArtifactCode({
|
|
1154
|
+
(await buildRequestModuleArtifactCode({
|
|
1149
1155
|
appDir: options.project.routesDir,
|
|
1150
1156
|
bundleCache: options.bundleCache,
|
|
1151
1157
|
cacheDir: options.cacheDir,
|
|
@@ -1154,7 +1160,7 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1154
1160
|
routeKind: route?.kind,
|
|
1155
1161
|
source,
|
|
1156
1162
|
vitePlugins: options.vitePlugins,
|
|
1157
|
-
}),
|
|
1163
|
+
})),
|
|
1158
1164
|
sourceHash: hashText(source),
|
|
1159
1165
|
};
|
|
1160
1166
|
}
|
|
@@ -1187,8 +1193,9 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1187
1193
|
vitePlugins: options.vitePlugins,
|
|
1188
1194
|
})
|
|
1189
1195
|
: undefined;
|
|
1190
|
-
const clientBoundaryImports = routeAnalysis?.clientBoundaryImports ??
|
|
1191
|
-
|
|
1196
|
+
const clientBoundaryImports = routeAnalysis?.clientBoundaryImports ?? clientInference?.clientBoundaryImports ?? [];
|
|
1197
|
+
const clientBoundaryFallbackImports = routeAnalysis?.clientBoundaryFallbackImports ??
|
|
1198
|
+
clientInference?.clientBoundaryFallbackImports ??
|
|
1192
1199
|
[];
|
|
1193
1200
|
for (const diagnostic of clientInference?.diagnostics ?? []) {
|
|
1194
1201
|
console.warn(formatClientRouteInferenceDiagnostic(diagnostic));
|
|
@@ -1203,6 +1210,7 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1203
1210
|
cache: options.serverTransformCache,
|
|
1204
1211
|
code,
|
|
1205
1212
|
clientBoundaryImports,
|
|
1213
|
+
clientBoundaryFallbackImports,
|
|
1206
1214
|
filename: join(options.projectRoot, file),
|
|
1207
1215
|
moduleContextCache: options.clientRouteInferenceCache,
|
|
1208
1216
|
serverOutput,
|
|
@@ -1281,6 +1289,7 @@ async function buildServerComponentBundleArtifactCode(options) {
|
|
|
1281
1289
|
async function transformServerRouteSource(options) {
|
|
1282
1290
|
const cacheKey = stableCacheKey({
|
|
1283
1291
|
clientBoundaryImports: options.clientBoundaryImports,
|
|
1292
|
+
clientBoundaryFallbackImports: options.clientBoundaryFallbackImports ?? [],
|
|
1284
1293
|
codeHash: hashText(options.code),
|
|
1285
1294
|
filename: resolve(options.filename),
|
|
1286
1295
|
serverOutput: options.serverOutput,
|
|
@@ -1299,6 +1308,7 @@ async function transformServerRouteSource(options) {
|
|
|
1299
1308
|
return transformCompilerModuleContext({
|
|
1300
1309
|
code: options.code,
|
|
1301
1310
|
clientBoundaryImports: options.clientBoundaryImports,
|
|
1311
|
+
clientBoundaryFallbackImports: options.clientBoundaryFallbackImports ?? [],
|
|
1302
1312
|
dev: false,
|
|
1303
1313
|
filename: options.filename,
|
|
1304
1314
|
moduleContext,
|
|
@@ -1313,8 +1323,11 @@ async function transformServerRouteSource(options) {
|
|
|
1313
1323
|
function builtRouteSourceAnalysisSummary(options) {
|
|
1314
1324
|
return {
|
|
1315
1325
|
authIncludesClaims: options.analysis.authIncludesClaims,
|
|
1316
|
-
...(options.analysis.cachePolicy === undefined
|
|
1326
|
+
...(options.analysis.cachePolicy === undefined
|
|
1327
|
+
? {}
|
|
1328
|
+
: { cachePolicy: options.analysis.cachePolicy }),
|
|
1317
1329
|
clientBoundaryImports: options.analysis.clientBoundaryImports,
|
|
1330
|
+
clientBoundaryFallbackImports: options.analysis.clientBoundaryFallbackImports,
|
|
1318
1331
|
clientRoute: options.analysis.clientRoute,
|
|
1319
1332
|
hasLoader: options.analysis.hasLoader,
|
|
1320
1333
|
routeCode: options.analysis.routeCode,
|
|
@@ -1533,9 +1546,9 @@ function isMiddlewareFile(appDir, file) {
|
|
|
1533
1546
|
return file === join(appDir, "middleware.ts") || file === join(appDir, "middleware.mreact.ts");
|
|
1534
1547
|
}
|
|
1535
1548
|
function hasMetadataExport(code) {
|
|
1536
|
-
return /\bexport\s+const\s+metadata\s*=/.test(code) ||
|
|
1549
|
+
return (/\bexport\s+const\s+metadata\s*=/.test(code) ||
|
|
1537
1550
|
/\bexport\s+(?:async\s+)?function\s+generateMetadata\b/.test(code) ||
|
|
1538
|
-
/\bexport\s*\{[^}]*\bgenerateMetadata\b[^}]*\}/.test(code);
|
|
1551
|
+
/\bexport\s*\{[^}]*\bgenerateMetadata\b[^}]*\}/.test(code));
|
|
1539
1552
|
}
|
|
1540
1553
|
async function readDeclaredProjectPackages(projectRoot) {
|
|
1541
1554
|
try {
|
|
@@ -1560,15 +1573,18 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1560
1573
|
const analysis = options.sourceAnalysis.byFile.get(routeFile);
|
|
1561
1574
|
return analysis === undefined
|
|
1562
1575
|
? []
|
|
1563
|
-
: [
|
|
1576
|
+
: [
|
|
1577
|
+
{
|
|
1564
1578
|
route,
|
|
1565
1579
|
routeFile,
|
|
1566
1580
|
routeId: routeIdForPath(route.path),
|
|
1567
|
-
}
|
|
1581
|
+
},
|
|
1582
|
+
];
|
|
1568
1583
|
}));
|
|
1569
1584
|
await mkdir(routesDir, { recursive: true });
|
|
1570
1585
|
const serverRouteModules = await buildCloudflareServerRouteModuleBatch({
|
|
1571
1586
|
cacheDir: options.cacheDir,
|
|
1587
|
+
define: options.define,
|
|
1572
1588
|
routes: requiredRoutes
|
|
1573
1589
|
.filter(({ route }) => route.kind === "server" || route.kind === "metadata")
|
|
1574
1590
|
.map(({ route, routeId }) => ({ filename: route.file, routeId })),
|
|
@@ -1577,8 +1593,10 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1577
1593
|
});
|
|
1578
1594
|
const loaderRouteModules = await buildCloudflareRouteLoaderModuleBatch({
|
|
1579
1595
|
cacheDir: options.cacheDir,
|
|
1596
|
+
define: options.define,
|
|
1580
1597
|
routes: requiredRoutes
|
|
1581
|
-
.filter(({ route, routeFile }) => route.kind === "page" &&
|
|
1598
|
+
.filter(({ route, routeFile }) => route.kind === "page" &&
|
|
1599
|
+
options.sourceAnalysis.byRouteFile.get(routeFile)?.hasLoader === true)
|
|
1582
1600
|
.map(({ route, routeId }) => ({ filename: route.file, routeId })),
|
|
1583
1601
|
root: options.projectRoot,
|
|
1584
1602
|
vitePlugins: options.vitePlugins,
|
|
@@ -1599,6 +1617,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1599
1617
|
const stringShellComponentRouteIds = new Set(stringShellComponentRoutes.map((route) => route.routeId));
|
|
1600
1618
|
const directComponentModules = await buildCloudflareServerComponentModuleBatch({
|
|
1601
1619
|
cacheDir: options.cacheDir,
|
|
1620
|
+
define: options.define,
|
|
1602
1621
|
projectRoot: options.projectRoot,
|
|
1603
1622
|
routes: directComponentRoutes,
|
|
1604
1623
|
serverModules: options.serverModules,
|
|
@@ -1607,6 +1626,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1607
1626
|
});
|
|
1608
1627
|
const stringShellComponentModules = await buildCloudflareStringRouteComponentModuleBatch({
|
|
1609
1628
|
cacheDir: options.cacheDir,
|
|
1629
|
+
define: options.define,
|
|
1610
1630
|
projectRoot: options.projectRoot,
|
|
1611
1631
|
routes: stringShellComponentRoutes,
|
|
1612
1632
|
serverModules: options.serverModules,
|
|
@@ -1658,6 +1678,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1658
1678
|
const componentOutput = serverOutput === "stream"
|
|
1659
1679
|
? await buildCloudflareStreamRouteComponentModule({
|
|
1660
1680
|
cacheDir: options.cacheDir,
|
|
1681
|
+
define: options.define,
|
|
1661
1682
|
filename: route.file,
|
|
1662
1683
|
projectRoot: options.projectRoot,
|
|
1663
1684
|
routesDir: options.routesDir,
|
|
@@ -1667,6 +1688,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1667
1688
|
})
|
|
1668
1689
|
: await buildCloudflareStringRouteComponentModule({
|
|
1669
1690
|
cacheDir: options.cacheDir,
|
|
1691
|
+
define: options.define,
|
|
1670
1692
|
filename: route.file,
|
|
1671
1693
|
projectRoot: options.projectRoot,
|
|
1672
1694
|
routesDir: options.routesDir,
|
|
@@ -1681,9 +1703,7 @@ async function writeCloudflareRouteModules(options) {
|
|
|
1681
1703
|
throw new Error("Missing bundled Cloudflare component module.");
|
|
1682
1704
|
}
|
|
1683
1705
|
const componentImport = `./${componentFile.split("/").pop() ?? componentFile}`;
|
|
1684
|
-
routeModuleExports = [
|
|
1685
|
-
cloudflarePageRouteFacadeModuleSource(componentImport),
|
|
1686
|
-
];
|
|
1706
|
+
routeModuleExports = [cloudflarePageRouteFacadeModuleSource(componentImport)];
|
|
1687
1707
|
}
|
|
1688
1708
|
catch (error) {
|
|
1689
1709
|
throw new Error(`Failed to build Cloudflare route module for ${routeFile}: ${errorMessage(error)}`);
|
|
@@ -1822,6 +1842,7 @@ async function buildCloudflareServerComponentModuleBatch(options) {
|
|
|
1822
1842
|
const bundleEntries = await Promise.all(options.routes.map(async (route) => {
|
|
1823
1843
|
const metadataModule = await buildCloudflareRouteMetadataExportModule({
|
|
1824
1844
|
cacheDir: options.cacheDir,
|
|
1845
|
+
define: options.define,
|
|
1825
1846
|
filename: route.filename,
|
|
1826
1847
|
hasMetadata: buildSourceAnalysisForFile(options.sourceAnalysis, options.projectRoot, route.filename)?.hasMetadata,
|
|
1827
1848
|
root: options.projectRoot,
|
|
@@ -1844,6 +1865,7 @@ async function buildCloudflareServerComponentModuleBatch(options) {
|
|
|
1844
1865
|
const output = await bundleRouterModules({
|
|
1845
1866
|
cacheDir: options.cacheDir,
|
|
1846
1867
|
chunkFileNames: "routes/chunks/[name].[hash].mjs",
|
|
1868
|
+
define: options.define,
|
|
1847
1869
|
entries: bundleEntries,
|
|
1848
1870
|
entryFileNames: "routes/[name].[hash].mjs",
|
|
1849
1871
|
minify: true,
|
|
@@ -1889,6 +1911,7 @@ async function buildCloudflareStringRouteComponentModuleBatch(options) {
|
|
|
1889
1911
|
const pageMetadataId = `mreact:metadata:${route.routeId}:page`;
|
|
1890
1912
|
const pageMetadataModule = await buildCloudflareRouteMetadataExportModule({
|
|
1891
1913
|
cacheDir: options.cacheDir,
|
|
1914
|
+
define: options.define,
|
|
1892
1915
|
filename: route.filename,
|
|
1893
1916
|
hasMetadata: buildSourceAnalysisForFile(options.sourceAnalysis, options.projectRoot, route.filename)?.hasMetadata,
|
|
1894
1917
|
root: options.projectRoot,
|
|
@@ -1908,6 +1931,7 @@ async function buildCloudflareStringRouteComponentModuleBatch(options) {
|
|
|
1908
1931
|
const shellMetadataId = `mreact:metadata:${route.routeId}:shell:${index}`;
|
|
1909
1932
|
const shellMetadataModule = await buildCloudflareRouteMetadataExportModule({
|
|
1910
1933
|
cacheDir: options.cacheDir,
|
|
1934
|
+
define: options.define,
|
|
1911
1935
|
filename: shell.file,
|
|
1912
1936
|
hasMetadata: buildSourceAnalysisForFile(options.sourceAnalysis, options.projectRoot, shell.file)?.hasMetadata,
|
|
1913
1937
|
root: options.projectRoot,
|
|
@@ -1939,6 +1963,7 @@ async function buildCloudflareStringRouteComponentModuleBatch(options) {
|
|
|
1939
1963
|
const output = await bundleRouterModules({
|
|
1940
1964
|
cacheDir: options.cacheDir,
|
|
1941
1965
|
chunkFileNames: "routes/chunks/[name].[hash].mjs",
|
|
1966
|
+
define: options.define,
|
|
1942
1967
|
entries: bundleEntries,
|
|
1943
1968
|
entryFileNames: "routes/[name].[hash].mjs",
|
|
1944
1969
|
minify: true,
|
|
@@ -2047,6 +2072,7 @@ ${cloudflareShellRuntimeSource()}`;
|
|
|
2047
2072
|
async function buildCloudflareServerComponentModule(options) {
|
|
2048
2073
|
const metadataModule = await buildCloudflareRouteMetadataExportModule({
|
|
2049
2074
|
cacheDir: options.cacheDir,
|
|
2075
|
+
define: options.define,
|
|
2050
2076
|
filename: options.filename,
|
|
2051
2077
|
hasMetadata: buildSourceAnalysisForFile(options.sourceAnalysis, options.projectRoot, options.filename)?.hasMetadata,
|
|
2052
2078
|
root: options.projectRoot,
|
|
@@ -2057,9 +2083,8 @@ async function buildCloudflareServerComponentModule(options) {
|
|
|
2057
2083
|
entry,
|
|
2058
2084
|
filename: `${options.filename}.mreact-cloudflare-component.js`,
|
|
2059
2085
|
cacheDir: options.cacheDir,
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
: new Map([["mreact:metadata", metadataModule]]),
|
|
2086
|
+
define: options.define,
|
|
2087
|
+
modules: metadataModule === undefined ? new Map() : new Map([["mreact:metadata", metadataModule]]),
|
|
2063
2088
|
plugins: [
|
|
2064
2089
|
cloudflareServerSourceTransformPlugin({
|
|
2065
2090
|
projectRoot: options.projectRoot,
|
|
@@ -2090,6 +2115,7 @@ async function buildCloudflareStringRouteComponentModule(options) {
|
|
|
2090
2115
|
if (shellFiles.length === 0) {
|
|
2091
2116
|
return buildCloudflareServerComponentModule({
|
|
2092
2117
|
cacheDir: options.cacheDir,
|
|
2118
|
+
define: options.define,
|
|
2093
2119
|
filename: options.filename,
|
|
2094
2120
|
projectRoot: options.projectRoot,
|
|
2095
2121
|
serverModules: options.serverModules,
|
|
@@ -2100,6 +2126,7 @@ async function buildCloudflareStringRouteComponentModule(options) {
|
|
|
2100
2126
|
}
|
|
2101
2127
|
const pageModule = await buildCloudflareComponentExportModule({
|
|
2102
2128
|
cacheDir: options.cacheDir,
|
|
2129
|
+
define: options.define,
|
|
2103
2130
|
filename: options.filename,
|
|
2104
2131
|
projectRoot: options.projectRoot,
|
|
2105
2132
|
serverModules: options.serverModules,
|
|
@@ -2109,6 +2136,7 @@ async function buildCloudflareStringRouteComponentModule(options) {
|
|
|
2109
2136
|
});
|
|
2110
2137
|
const shellModules = await Promise.all(shellFiles.map((shell) => buildCloudflareComponentExportModule({
|
|
2111
2138
|
cacheDir: options.cacheDir,
|
|
2139
|
+
define: options.define,
|
|
2112
2140
|
filename: shell.file,
|
|
2113
2141
|
projectRoot: options.projectRoot,
|
|
2114
2142
|
serverModules: options.serverModules,
|
|
@@ -2171,6 +2199,7 @@ ${cloudflareShellRuntimeSource()}`;
|
|
|
2171
2199
|
return bundleCloudflareVirtualModule({
|
|
2172
2200
|
entry,
|
|
2173
2201
|
cacheDir: options.cacheDir,
|
|
2202
|
+
define: options.define,
|
|
2174
2203
|
filename: `${options.filename}.mreact-cloudflare-string-route.js`,
|
|
2175
2204
|
modules: new Map([
|
|
2176
2205
|
["mreact:page", pageModule],
|
|
@@ -2185,6 +2214,7 @@ ${cloudflareShellRuntimeSource()}`;
|
|
|
2185
2214
|
async function buildCloudflareStreamRouteComponentModule(options) {
|
|
2186
2215
|
const pageModule = await buildCloudflareComponentExportModule({
|
|
2187
2216
|
cacheDir: options.cacheDir,
|
|
2217
|
+
define: options.define,
|
|
2188
2218
|
filename: options.filename,
|
|
2189
2219
|
projectRoot: options.projectRoot,
|
|
2190
2220
|
serverModules: options.serverModules,
|
|
@@ -2195,6 +2225,7 @@ async function buildCloudflareStreamRouteComponentModule(options) {
|
|
|
2195
2225
|
const shellFiles = await cloudflareShellFilesForPage(options.routesDir, options.filename);
|
|
2196
2226
|
const shellModules = await Promise.all(shellFiles.map((shell) => buildCloudflareComponentExportModule({
|
|
2197
2227
|
cacheDir: options.cacheDir,
|
|
2228
|
+
define: options.define,
|
|
2198
2229
|
filename: shell.file,
|
|
2199
2230
|
projectRoot: options.projectRoot,
|
|
2200
2231
|
serverModules: options.serverModules,
|
|
@@ -2275,6 +2306,7 @@ ${cloudflareShellRuntimeSource()}`;
|
|
|
2275
2306
|
return bundleCloudflareVirtualModule({
|
|
2276
2307
|
entry,
|
|
2277
2308
|
cacheDir: options.cacheDir,
|
|
2309
|
+
define: options.define,
|
|
2278
2310
|
filename: `${options.filename}.mreact-cloudflare-stream-route.js`,
|
|
2279
2311
|
modules: new Map([
|
|
2280
2312
|
["mreact:page", pageModule],
|
|
@@ -2584,6 +2616,7 @@ function escapeHtml(value) {
|
|
|
2584
2616
|
async function buildCloudflareComponentExportModule(options) {
|
|
2585
2617
|
const metadataModule = await buildCloudflareRouteMetadataExportModule({
|
|
2586
2618
|
cacheDir: options.cacheDir,
|
|
2619
|
+
define: options.define,
|
|
2587
2620
|
filename: options.filename,
|
|
2588
2621
|
hasMetadata: buildSourceAnalysisForFile(options.sourceAnalysis, options.projectRoot, options.filename)?.hasMetadata,
|
|
2589
2622
|
root: options.projectRoot,
|
|
@@ -2601,10 +2634,9 @@ export const slots = routeModule.slots;`;
|
|
|
2601
2634
|
return bundleCloudflareVirtualModule({
|
|
2602
2635
|
entry,
|
|
2603
2636
|
cacheDir: options.cacheDir,
|
|
2637
|
+
define: options.define,
|
|
2604
2638
|
filename: `${options.filename}.mreact-cloudflare-${options.serverOutput}-component.js`,
|
|
2605
|
-
modules: metadataModule === undefined
|
|
2606
|
-
? new Map()
|
|
2607
|
-
: new Map([["mreact:metadata", metadataModule]]),
|
|
2639
|
+
modules: metadataModule === undefined ? new Map() : new Map([["mreact:metadata", metadataModule]]),
|
|
2608
2640
|
plugins: [
|
|
2609
2641
|
cloudflareServerSourceTransformPlugin({
|
|
2610
2642
|
projectRoot: options.projectRoot,
|
|
@@ -2628,6 +2660,7 @@ async function writeCloudflareBatchedRouteModuleChunks(cloudflareDir, modules) {
|
|
|
2628
2660
|
async function buildCloudflareRouteLoaderModuleBatch(options) {
|
|
2629
2661
|
return await bundleCloudflareModuleBatch({
|
|
2630
2662
|
cacheDir: options.cacheDir,
|
|
2663
|
+
define: options.define,
|
|
2631
2664
|
entries: options.routes.map((route) => ({
|
|
2632
2665
|
code: cloudflareRouteLoaderModuleEntry(route.filename),
|
|
2633
2666
|
filename: `${route.filename}.mreact-cloudflare-loader.js`,
|
|
@@ -2641,6 +2674,7 @@ async function buildCloudflareRouteLoaderModuleBatch(options) {
|
|
|
2641
2674
|
export async function __buildCloudflareRouteLoaderModuleBatchForTests(options) {
|
|
2642
2675
|
const output = await buildCloudflareRouteLoaderModuleBatch({
|
|
2643
2676
|
cacheDir: options.cacheDir,
|
|
2677
|
+
define: options.define,
|
|
2644
2678
|
root: options.projectRoot,
|
|
2645
2679
|
routes: options.routes,
|
|
2646
2680
|
vitePlugins: options.vitePlugins,
|
|
@@ -2650,6 +2684,7 @@ export async function __buildCloudflareRouteLoaderModuleBatchForTests(options) {
|
|
|
2650
2684
|
async function buildCloudflareServerRouteModuleBatch(options) {
|
|
2651
2685
|
return await bundleCloudflareModuleBatch({
|
|
2652
2686
|
cacheDir: options.cacheDir,
|
|
2687
|
+
define: options.define,
|
|
2653
2688
|
entries: options.routes.map((route) => ({
|
|
2654
2689
|
code: cloudflareServerRouteModuleEntry(route.filename),
|
|
2655
2690
|
filename: `${route.filename}.mreact-cloudflare-server-route.js`,
|
|
@@ -2667,6 +2702,7 @@ async function bundleCloudflareModuleBatch(options) {
|
|
|
2667
2702
|
const output = await bundleRouterModules({
|
|
2668
2703
|
cacheDir: options.cacheDir,
|
|
2669
2704
|
chunkFileNames: "routes/chunks/[name].[hash].mjs",
|
|
2705
|
+
define: options.define,
|
|
2670
2706
|
entries: options.entries,
|
|
2671
2707
|
entryFileNames: "routes/[name].[hash].mjs",
|
|
2672
2708
|
minify: true,
|
|
@@ -2706,6 +2742,7 @@ export const metadata = routeMetadataModule.metadata;`;
|
|
|
2706
2742
|
return bundleCloudflareModule({
|
|
2707
2743
|
entry,
|
|
2708
2744
|
cacheDir: options.cacheDir,
|
|
2745
|
+
define: options.define,
|
|
2709
2746
|
filename: `${options.filename}.mreact-cloudflare-metadata.js`,
|
|
2710
2747
|
plugins: [cloudflareWorkspaceRuntimePlugin()],
|
|
2711
2748
|
resolveDir: dirname(options.filename),
|
|
@@ -2731,6 +2768,7 @@ async function bundleCloudflareModule(options) {
|
|
|
2731
2768
|
const output = await bundleRouterModule({
|
|
2732
2769
|
cacheDir: options.cacheDir,
|
|
2733
2770
|
code: options.entry,
|
|
2771
|
+
define: options.define,
|
|
2734
2772
|
filename: options.filename,
|
|
2735
2773
|
minify: true,
|
|
2736
2774
|
platform: "node",
|
|
@@ -2749,6 +2787,7 @@ async function bundleCloudflareModule(options) {
|
|
|
2749
2787
|
async function bundleCloudflareVirtualModule(options) {
|
|
2750
2788
|
return bundleCloudflareModule({
|
|
2751
2789
|
cacheDir: options.cacheDir,
|
|
2790
|
+
define: options.define,
|
|
2752
2791
|
entry: options.entry,
|
|
2753
2792
|
filename: options.filename,
|
|
2754
2793
|
plugins: [
|
|
@@ -2859,6 +2898,7 @@ async function transformCloudflareServerSource(options) {
|
|
|
2859
2898
|
const output = transformCompilerModuleContext({
|
|
2860
2899
|
code: options.source,
|
|
2861
2900
|
clientBoundaryImports: clientInference.clientBoundaryImports,
|
|
2901
|
+
clientBoundaryFallbackImports: clientInference.clientBoundaryFallbackImports,
|
|
2862
2902
|
dev: false,
|
|
2863
2903
|
filename: options.filename,
|
|
2864
2904
|
moduleContext,
|
|
@@ -2868,7 +2908,9 @@ async function transformCloudflareServerSource(options) {
|
|
|
2868
2908
|
});
|
|
2869
2909
|
const fatalDiagnostics = output.diagnostics.filter((diagnostic) => diagnostic.code !== "MR_UNSUPPORTED_SERVER_EVENT_HANDLER");
|
|
2870
2910
|
if (fatalDiagnostics.length > 0) {
|
|
2871
|
-
throw new Error(fatalDiagnostics
|
|
2911
|
+
throw new Error(fatalDiagnostics
|
|
2912
|
+
.map((diagnostic) => formatDiagnostic(options.filename, diagnostic))
|
|
2913
|
+
.join("\n"));
|
|
2872
2914
|
}
|
|
2873
2915
|
return output.code;
|
|
2874
2916
|
}
|
|
@@ -2900,9 +2942,18 @@ function cloudflareWorkspaceRuntimePlugin() {
|
|
|
2900
2942
|
"@reckona/mreact-compat/event-priority",
|
|
2901
2943
|
packageFile("react-compat", "@reckona/mreact-compat", "event-priority"),
|
|
2902
2944
|
],
|
|
2903
|
-
[
|
|
2904
|
-
|
|
2905
|
-
|
|
2945
|
+
[
|
|
2946
|
+
"@reckona/mreact-compat/flight",
|
|
2947
|
+
packageFile("react-compat", "@reckona/mreact-compat", "flight"),
|
|
2948
|
+
],
|
|
2949
|
+
[
|
|
2950
|
+
"@reckona/mreact-compat/hooks",
|
|
2951
|
+
packageFile("react-compat", "@reckona/mreact-compat", "hooks-entry"),
|
|
2952
|
+
],
|
|
2953
|
+
[
|
|
2954
|
+
"@reckona/mreact-compat/internal",
|
|
2955
|
+
packageFile("react-compat", "@reckona/mreact-compat", "internal"),
|
|
2956
|
+
],
|
|
2906
2957
|
[
|
|
2907
2958
|
"@reckona/mreact-compat/jsx-dev-runtime",
|
|
2908
2959
|
packageFile("react-compat", "@reckona/mreact-compat", "jsx-dev-runtime"),
|
|
@@ -2911,9 +2962,15 @@ function cloudflareWorkspaceRuntimePlugin() {
|
|
|
2911
2962
|
"@reckona/mreact-compat/jsx-runtime",
|
|
2912
2963
|
packageFile("react-compat", "@reckona/mreact-compat", "jsx-runtime"),
|
|
2913
2964
|
],
|
|
2914
|
-
[
|
|
2965
|
+
[
|
|
2966
|
+
"@reckona/mreact-compat/scheduler",
|
|
2967
|
+
packageFile("react-compat", "@reckona/mreact-compat", "scheduler"),
|
|
2968
|
+
],
|
|
2915
2969
|
["@reckona/mreact-query", packageFile("query", "@reckona/mreact-query", "index")],
|
|
2916
|
-
[
|
|
2970
|
+
[
|
|
2971
|
+
"@reckona/mreact-reactive-core",
|
|
2972
|
+
packageFile("reactive-core", "@reckona/mreact-reactive-core", "index"),
|
|
2973
|
+
],
|
|
2917
2974
|
[
|
|
2918
2975
|
"@reckona/mreact-router/adapters/cloudflare",
|
|
2919
2976
|
packageFile("router", "@reckona/mreact-router", "adapters/cloudflare"),
|
|
@@ -3123,9 +3180,7 @@ async function writeClientRouteBundles(options) {
|
|
|
3123
3180
|
await writeFile(join(mapBaseDir, sourceMap), map);
|
|
3124
3181
|
}
|
|
3125
3182
|
for (const asset of output.assets ?? []) {
|
|
3126
|
-
const source = typeof asset.source === "string"
|
|
3127
|
-
? asset.source
|
|
3128
|
-
: Buffer.from(asset.source).toString("utf8");
|
|
3183
|
+
const source = typeof asset.source === "string" ? asset.source : Buffer.from(asset.source).toString("utf8");
|
|
3129
3184
|
await mkdir(dirname(join(options.clientDir, asset.fileName)), { recursive: true });
|
|
3130
3185
|
await writeFile(join(options.clientDir, asset.fileName), source);
|
|
3131
3186
|
}
|
|
@@ -3244,9 +3299,7 @@ async function writeRouteCssAssetsForFiles(options) {
|
|
|
3244
3299
|
? (options.routeIds[0] ?? "index")
|
|
3245
3300
|
: `shared.${hashText(cssFiles.join("\0")).slice(0, 8)}`;
|
|
3246
3301
|
for (const [index, asset] of cssAssets.entries()) {
|
|
3247
|
-
const source = typeof asset.source === "string"
|
|
3248
|
-
? asset.source
|
|
3249
|
-
: Buffer.from(asset.source).toString("utf8");
|
|
3302
|
+
const source = typeof asset.source === "string" ? asset.source : Buffer.from(asset.source).toString("utf8");
|
|
3250
3303
|
const hash = createHash("sha256").update(source).digest("hex").slice(0, 8);
|
|
3251
3304
|
const cssFile = `assets/routes/${routeStem}${cssAssets.length === 1 ? "" : `.${index}`}.${hash}.css`;
|
|
3252
3305
|
await mkdir(dirname(join(options.clientDir, cssFile)), { recursive: true });
|
|
@@ -3520,6 +3573,7 @@ async function validateProductionRoutes(options) {
|
|
|
3520
3573
|
cache: options.serverTransformCache,
|
|
3521
3574
|
code: analysis.routeCode,
|
|
3522
3575
|
clientBoundaryImports: analysis.clientBoundaryImports,
|
|
3576
|
+
clientBoundaryFallbackImports: analysis.clientBoundaryFallbackImports,
|
|
3523
3577
|
filename: route.file,
|
|
3524
3578
|
moduleContextCache: options.clientRouteInferenceCache,
|
|
3525
3579
|
serverOutput: analysis.streamRoute ? "stream" : "string",
|
|
@@ -3544,10 +3598,7 @@ async function collectBuildFiles(projectRoot, allowedSourceDirs, appDir) {
|
|
|
3544
3598
|
}
|
|
3545
3599
|
return [{ file, relativeFile }];
|
|
3546
3600
|
});
|
|
3547
|
-
const fileContents = await mapWithBuildConcurrency(sourceFiles, async ({ file, relativeFile }) => [
|
|
3548
|
-
relativeFile,
|
|
3549
|
-
await readFile(file, "utf8"),
|
|
3550
|
-
]);
|
|
3601
|
+
const fileContents = await mapWithBuildConcurrency(sourceFiles, async ({ file, relativeFile }) => [relativeFile, await readFile(file, "utf8")]);
|
|
3551
3602
|
for (const [relativeFile, source] of fileContents) {
|
|
3552
3603
|
files[relativeFile] = source;
|
|
3553
3604
|
}
|