@reckona/mreact-router 0.0.152 → 0.0.154
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/actions.d.ts +10 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +6 -0
- package/dist/actions.js.map +1 -1
- package/dist/adapters/aws-lambda.d.ts +18 -0
- package/dist/adapters/aws-lambda.d.ts.map +1 -1
- package/dist/adapters/aws-lambda.js +18 -0
- package/dist/adapters/aws-lambda.js.map +1 -1
- package/dist/adapters/cloudflare.d.ts +33 -0
- package/dist/adapters/cloudflare.d.ts.map +1 -1
- package/dist/adapters/cloudflare.js +33 -0
- package/dist/adapters/cloudflare.js.map +1 -1
- package/dist/adapters/edge.d.ts +5 -0
- package/dist/adapters/edge.d.ts.map +1 -1
- package/dist/adapters/edge.js +5 -0
- package/dist/adapters/edge.js.map +1 -1
- package/dist/adapters/node.d.ts +5 -0
- package/dist/adapters/node.d.ts.map +1 -1
- package/dist/adapters/node.js +5 -0
- package/dist/adapters/node.js.map +1 -1
- package/dist/adapters/static.d.ts +5 -0
- package/dist/adapters/static.d.ts.map +1 -1
- package/dist/adapters/static.js +5 -0
- package/dist/adapters/static.js.map +1 -1
- package/dist/build.d.ts +15 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +85 -2
- package/dist/build.js.map +1 -1
- package/dist/cache.d.ts +15 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +15 -0
- package/dist/cache.js.map +1 -1
- package/dist/cookies.d.ts +16 -0
- package/dist/cookies.d.ts.map +1 -1
- package/dist/cookies.js +16 -0
- package/dist/cookies.js.map +1 -1
- package/dist/dev-server.d.ts +5 -0
- package/dist/dev-server.d.ts.map +1 -1
- package/dist/dev-server.js +5 -0
- package/dist/dev-server.js.map +1 -1
- package/dist/link.d.ts +10 -0
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +5 -0
- package/dist/link.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +39 -4
- package/dist/middleware.js.map +1 -1
- package/dist/module-runner.d.ts +6 -0
- package/dist/module-runner.d.ts.map +1 -1
- package/dist/module-runner.js +71 -0
- package/dist/module-runner.js.map +1 -1
- package/dist/navigation.d.ts +53 -0
- package/dist/navigation.d.ts.map +1 -1
- package/dist/navigation.js +48 -0
- package/dist/navigation.js.map +1 -1
- package/dist/render.d.ts +34 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +161 -27
- package/dist/render.js.map +1 -1
- package/dist/route-module-loader.d.ts +6 -1
- package/dist/route-module-loader.d.ts.map +1 -1
- package/dist/route-module-loader.js +8 -1
- package/dist/route-module-loader.js.map +1 -1
- package/dist/serve.d.ts +5 -0
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +5 -0
- package/dist/serve.js.map +1 -1
- package/dist/session.d.ts +19 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +19 -0
- package/dist/session.js.map +1 -1
- package/dist/typed-routes.d.ts +5 -0
- package/dist/typed-routes.d.ts.map +1 -1
- package/dist/typed-routes.js +5 -0
- package/dist/typed-routes.js.map +1 -1
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +1 -0
- package/dist/vite.js.map +1 -1
- package/package.json +11 -11
- package/src/actions.ts +18 -0
- package/src/adapters/aws-lambda.ts +18 -0
- package/src/adapters/cloudflare.ts +33 -0
- package/src/adapters/edge.ts +5 -0
- package/src/adapters/node.ts +5 -0
- package/src/adapters/static.ts +5 -0
- package/src/build.ts +118 -1
- package/src/cache.ts +15 -0
- package/src/cookies.ts +16 -0
- package/src/dev-server.ts +5 -0
- package/src/link.ts +10 -0
- package/src/middleware.ts +54 -4
- package/src/module-runner.ts +91 -0
- package/src/navigation.ts +53 -0
- package/src/render.ts +229 -25
- package/src/route-module-loader.ts +15 -0
- package/src/serve.ts +5 -0
- package/src/session.ts +19 -0
- package/src/typed-routes.ts +5 -0
- package/src/types.ts +15 -0
- package/src/vite.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static.js","sourceRoot":"","sources":["../../src/adapters/static.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAaxD,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAA4B;IAChE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CACzB,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,CACjD,CAAC;IACzB,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAC/B,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,CAChC,CAAC;IAC1C,MAAM,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,IAAI,EAAE,CAAC;IAC3D,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAE7E,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9D,MAAM,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAEpD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,M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,CAAC,GAAG,IAAI,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,+BAA+B,KAAK,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { cp, mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, join, resolve, sep } from \"node:path\";\nimport type { BuiltPrerenderedRoute, BuiltServerManifest } from \"../build.js\";\n\nexport interface StaticExportOptions {\n exportDir: string;\n outDir: string;\n paths?: readonly string[] | undefined;\n}\n\nexport interface StaticExportResult {\n routes: string[];\n}\n\nexport async function exportStaticApp(options: StaticExportOptions): Promise<StaticExportResult> {\n const manifest = JSON.parse(\n await readFile(join(options.outDir, \"server\", \"manifest.json\"), \"utf8\"),\n ) as BuiltServerManifest;\n const clientManifest = JSON.parse(\n await readFile(join(options.outDir, \"client\", \"manifest.json\"), \"utf8\"),\n ) as { publicAssets?: readonly string[] };\n const prerenderedRoutes = manifest.prerenderedRoutes ?? {};\n const routes = [...(options.paths ?? Object.keys(prerenderedRoutes))].sort();\n\n await rm(options.exportDir, { force: true, recursive: true });\n await mkdir(options.exportDir, { recursive: true });\n\n for (const route of routes) {\n const entry = prerenderedRoutes[route];\n\n if (entry === undefined) {\n throw new Error(`Cannot export non-prerendered route: ${route}`);\n }\n\n await writePrerenderedRoute(options.exportDir, route, entry);\n }\n\n await cp(join(options.outDir, \"client\"), join(options.exportDir, \"_mreact\", \"client\"), {\n recursive: true,\n });\n await copyPublicAssetsToExportRoot(\n join(options.outDir, \"client\"),\n options.exportDir,\n clientManifest.publicAssets ?? [],\n );\n\n return { routes };\n}\n\nasync function copyPublicAssetsToExportRoot(\n clientDir: string,\n exportDir: string,\n publicAssets: readonly string[],\n): Promise<void> {\n for (const asset of publicAssets) {\n if (\n !asset.startsWith(\"/\") ||\n asset.startsWith(\"//\") ||\n asset.includes(\"..\") ||\n asset === \"/_mreact\" ||\n asset.startsWith(\"/_mreact/\")\n ) {\n continue;\n }\n\n const relativeAsset = asset.slice(1);\n const destination = join(exportDir, relativeAsset);\n await mkdir(dirname(destination), { recursive: true });\n await cp(join(clientDir, relativeAsset), destination, { recursive: true });\n }\n}\n\nasync function writePrerenderedRoute(\n exportDir: string,\n route: string,\n entry: BuiltPrerenderedRoute,\n): Promise<void> {\n if (entry.status < 200 || entry.status >= 300) {\n throw new Error(`Cannot export route ${route} with status ${entry.status}.`);\n }\n\n const file = routeToHtmlFile(exportDir, route);\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, entry.html);\n}\n\nfunction routeToHtmlFile(exportDir: string, route: string): string {\n const pathname = route.split(\"?\")[0] ?? \"/\";\n const normalized = pathname.startsWith(\"/\") ? pathname.slice(1) : pathname;\n const relativeFile = normalized === \"\" ? \"index.html\" : join(normalized, \"index.html\");\n const root = resolve(exportDir);\n const file = resolve(root, relativeFile);\n\n if (file !== root && !file.startsWith(`${root}${sep}`)) {\n throw new Error(`unsafe static export route: ${route}`);\n }\n\n return file;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"static.js","sourceRoot":"","sources":["../../src/adapters/static.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAaxD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAA4B;IAChE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CACzB,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,CACjD,CAAC;IACzB,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAC/B,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,E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AAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;IAC5C,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC3E,MAAM,YAAY,GAAG,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IACvF,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAEzC,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,+BAA+B,KAAK,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { cp, mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, join, resolve, sep } from \"node:path\";\nimport type { BuiltPrerenderedRoute, BuiltServerManifest } from \"../build.js\";\n\nexport interface StaticExportOptions {\n exportDir: string;\n outDir: string;\n paths?: readonly string[] | undefined;\n}\n\nexport interface StaticExportResult {\n routes: string[];\n}\n\n/**\n * Exports prerendered app-router routes and client assets to a static filesystem directory.\n *\n * Only routes present in the built prerender manifest can be exported; the export directory is removed and recreated, and route paths are checked to prevent traversal outside it.\n */\nexport async function exportStaticApp(options: StaticExportOptions): Promise<StaticExportResult> {\n const manifest = JSON.parse(\n await readFile(join(options.outDir, \"server\", \"manifest.json\"), \"utf8\"),\n ) as BuiltServerManifest;\n const clientManifest = JSON.parse(\n await readFile(join(options.outDir, \"client\", \"manifest.json\"), \"utf8\"),\n ) as { publicAssets?: readonly string[] };\n const prerenderedRoutes = manifest.prerenderedRoutes ?? {};\n const routes = [...(options.paths ?? Object.keys(prerenderedRoutes))].sort();\n\n await rm(options.exportDir, { force: true, recursive: true });\n await mkdir(options.exportDir, { recursive: true });\n\n for (const route of routes) {\n const entry = prerenderedRoutes[route];\n\n if (entry === undefined) {\n throw new Error(`Cannot export non-prerendered route: ${route}`);\n }\n\n await writePrerenderedRoute(options.exportDir, route, entry);\n }\n\n await cp(join(options.outDir, \"client\"), join(options.exportDir, \"_mreact\", \"client\"), {\n recursive: true,\n });\n await copyPublicAssetsToExportRoot(\n join(options.outDir, \"client\"),\n options.exportDir,\n clientManifest.publicAssets ?? [],\n );\n\n return { routes };\n}\n\nasync function copyPublicAssetsToExportRoot(\n clientDir: string,\n exportDir: string,\n publicAssets: readonly string[],\n): Promise<void> {\n for (const asset of publicAssets) {\n if (\n !asset.startsWith(\"/\") ||\n asset.startsWith(\"//\") ||\n asset.includes(\"..\") ||\n asset === \"/_mreact\" ||\n asset.startsWith(\"/_mreact/\")\n ) {\n continue;\n }\n\n const relativeAsset = asset.slice(1);\n const destination = join(exportDir, relativeAsset);\n await mkdir(dirname(destination), { recursive: true });\n await cp(join(clientDir, relativeAsset), destination, { recursive: true });\n }\n}\n\nasync function writePrerenderedRoute(\n exportDir: string,\n route: string,\n entry: BuiltPrerenderedRoute,\n): Promise<void> {\n if (entry.status < 200 || entry.status >= 300) {\n throw new Error(`Cannot export route ${route} with status ${entry.status}.`);\n }\n\n const file = routeToHtmlFile(exportDir, route);\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, entry.html);\n}\n\nfunction routeToHtmlFile(exportDir: string, route: string): string {\n const pathname = route.split(\"?\")[0] ?? \"/\";\n const normalized = pathname.startsWith(\"/\") ? pathname.slice(1) : pathname;\n const relativeFile = normalized === \"\" ? \"index.html\" : join(normalized, \"index.html\");\n const root = resolve(exportDir);\n const file = resolve(root, relativeFile);\n\n if (file !== root && !file.startsWith(`${root}${sep}`)) {\n throw new Error(`unsafe static export route: ${route}`);\n }\n\n return file;\n}\n"]}
|
package/dist/build.d.ts
CHANGED
|
@@ -130,6 +130,11 @@ export interface BuiltPrerenderedRoute {
|
|
|
130
130
|
html: string;
|
|
131
131
|
status: number;
|
|
132
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Builds an app-router project into server, client, and optional deployment-target artifacts.
|
|
135
|
+
*
|
|
136
|
+
* Use this from custom build scripts when the CLI is too coarse-grained; the returned manifest paths describe the files written under `outDir`. The build reads route files, loaders, middleware, metadata, server actions, and client references, so callers should pass the same project root and source allow-list they expect to deploy.
|
|
137
|
+
*/
|
|
133
138
|
export declare function buildApp(options: BuildAppOptions): Promise<BuildAppResult>;
|
|
134
139
|
export declare function __mapWithBuildConcurrencyForTests<T, R>(items: readonly T[], map: (item: T, index: number) => Promise<R>, concurrency?: number): Promise<R[]>;
|
|
135
140
|
export declare function __writeServerModuleArtifactFilesForTests(serverDir: string, serverModules: Record<string, BuiltServerModuleArtifact>): Promise<{
|
|
@@ -161,7 +166,17 @@ export declare function __buildCloudflareRouteLoaderModuleBatchForTests(options:
|
|
|
161
166
|
}[];
|
|
162
167
|
vitePlugins?: readonly PluginOption[] | undefined;
|
|
163
168
|
}): Promise<Record<string, string>>;
|
|
169
|
+
/**
|
|
170
|
+
* Packages a built app-router output directory into the minimal AWS Lambda artifact layout.
|
|
171
|
+
*
|
|
172
|
+
* The package contains `.mreact`, a Lambda handler, project package metadata, production dependencies, and `mreact-lambda-artifact.json`; it intentionally excludes source files and development tooling that are not needed at runtime.
|
|
173
|
+
*/
|
|
164
174
|
export declare function packageAwsLambdaArtifact(options: PackageAwsLambdaArtifactOptions): Promise<AwsLambdaArtifactManifest>;
|
|
175
|
+
/**
|
|
176
|
+
* Packages a Cloudflare-target build for Cloudflare Pages advanced mode.
|
|
177
|
+
*
|
|
178
|
+
* The package writes `_worker.js`, generated client assets, public assets, and `mreact-cloudflare-pages-artifact.json`; deploy the output directory rather than the raw `.mreact` build tree.
|
|
179
|
+
*/
|
|
165
180
|
export declare function packageCloudflarePagesArtifact(options: PackageCloudflarePagesArtifactOptions): Promise<CloudflarePagesArtifactManifest>;
|
|
166
181
|
export {};
|
|
167
182
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAsDA,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;AAiCnG,OAAO,KAAK,EAAU,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAa7D,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;IAC9D,eAAe,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACvE,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;AA0CD,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,cAAc,GACd,gBAAgB,GAChB,UA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ID,UAAU,4BAA4B;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,QAAQ,GAAG,UAAU,CAAC;CAC9B;AAwuDD,wBAAsB,+CAA+C,CAAC,OAAO,EAAE;IAC7E,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,SAAS;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACzD,WAAW,CAAC,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,CAAC;CACnD,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAYlC;AA0mCD;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,yBAAyB,CAAC,CA4CpC;AA6DD;;;;GAIG;AACH,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,qCAAqC,GAC7C,OAAO,CAAC,+BAA+B,CAAC,CAsD1C"}
|
package/dist/build.js
CHANGED
|
@@ -8,7 +8,7 @@ import { collectStaticImportReferences, collectTopLevelValueExportNames, formatD
|
|
|
8
8
|
import { transformCompilerModuleContext } from "@reckona/mreact-compiler/internal";
|
|
9
9
|
import { compilerModuleContextForSource, collectClientRouteReferences, createClientRouteInferenceCache, detectClientNavigationHint, formatClientRouteInferenceDiagnostic, inferClientRouteModule, navigationRuntimeLinkDisabledDiagnostic, resolveNavigationRuntime, } from "./client-route-inference.js";
|
|
10
10
|
import { buildClientRouteBatchOutput, buildNavigationRuntimeBundle, clientScriptForPath, routeIdForPath, } from "./navigation-runtime.js";
|
|
11
|
-
import { bundleAppRouterSourceModule, fileImportMetaUrlPlugin, importAppRouterSourceModule, } from "./module-runner.js";
|
|
11
|
+
import { COMPAT_VENDOR_PLACEHOLDER_PREFIX, bundleAppRouterSourceModule, fileImportMetaUrlPlugin, importAppRouterSourceModule, resolveCompatVendorEntryFiles, sourceReferencesCompatVendorSpecifier, } from "./module-runner.js";
|
|
12
12
|
import { scanAppRoutes } from "./routes.js";
|
|
13
13
|
import { appFileConventionForRootFilename } from "./file-conventions.js";
|
|
14
14
|
import { resolveAppRouterProjectOptions, resolveBuildTargets, } from "./config.js";
|
|
@@ -61,6 +61,11 @@ async function collectBuildMiddlewareIds(appDir) {
|
|
|
61
61
|
}
|
|
62
62
|
return ids;
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Builds an app-router project into server, client, and optional deployment-target artifacts.
|
|
66
|
+
*
|
|
67
|
+
* Use this from custom build scripts when the CLI is too coarse-grained; the returned manifest paths describe the files written under `outDir`. The build reads route files, loaders, middleware, metadata, server actions, and client references, so callers should pass the same project root and source allow-list they expect to deploy.
|
|
68
|
+
*/
|
|
64
69
|
export async function buildApp(options) {
|
|
65
70
|
const timingSink = options.onBuildPhaseTiming;
|
|
66
71
|
const progressSink = options.onBuildProgress;
|
|
@@ -557,6 +562,60 @@ async function buildPublicAssetManifest(project, clientDir) {
|
|
|
557
562
|
]);
|
|
558
563
|
return [...new Set([...publicAssetPaths, ...appConventionPublicAssets])].sort();
|
|
559
564
|
}
|
|
565
|
+
const COMPAT_VENDOR_PLACEHOLDER_IMPORT_PATTERN = /(["'])mreact-compat-vendor:([\w-]+)\1/gu;
|
|
566
|
+
function rewriteCompatVendorPlaceholderImports(code) {
|
|
567
|
+
if (!code.includes(COMPAT_VENDOR_PLACEHOLDER_PREFIX)) {
|
|
568
|
+
return code;
|
|
569
|
+
}
|
|
570
|
+
// Module files live in server-modules/code/, vendor chunks in
|
|
571
|
+
// server-modules/chunks/, so the relative path is stable.
|
|
572
|
+
return code.replace(COMPAT_VENDOR_PLACEHOLDER_IMPORT_PATTERN, (_match, quote, entry) => `${quote}../chunks/compat.${entry}.mjs${quote}`);
|
|
573
|
+
}
|
|
574
|
+
function collectCompatVendorEntryUsage(artifacts) {
|
|
575
|
+
const usedEntries = new Set();
|
|
576
|
+
for (const [, artifact] of artifacts) {
|
|
577
|
+
for (const output of [artifact.string, artifact.stream]) {
|
|
578
|
+
const bundleCode = output?.bundleCode;
|
|
579
|
+
if (bundleCode === undefined || !bundleCode.includes(COMPAT_VENDOR_PLACEHOLDER_PREFIX)) {
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
for (const match of bundleCode.matchAll(COMPAT_VENDOR_PLACEHOLDER_IMPORT_PATTERN)) {
|
|
583
|
+
const entry = match[2];
|
|
584
|
+
if (entry !== undefined) {
|
|
585
|
+
usedEntries.add(entry);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return usedEntries;
|
|
591
|
+
}
|
|
592
|
+
// Bundles the react-compat server runtime once per build into shared chunks
|
|
593
|
+
// under server-modules/chunks/ so per-route server modules can import it via
|
|
594
|
+
// relative paths instead of inlining their own copy.
|
|
595
|
+
async function writeCompatVendorChunks(serverDir, usedEntries) {
|
|
596
|
+
const entryFiles = resolveCompatVendorEntryFiles(serverDir);
|
|
597
|
+
const entries = await Promise.all([...entryFiles]
|
|
598
|
+
.filter(([name]) => usedEntries.has(name))
|
|
599
|
+
.map(async ([name, filename]) => ({
|
|
600
|
+
code: await readFile(filename, "utf8"),
|
|
601
|
+
filename,
|
|
602
|
+
name,
|
|
603
|
+
})));
|
|
604
|
+
const firstEntry = entries[0];
|
|
605
|
+
if (firstEntry === undefined) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const output = await bundleRouterModules({
|
|
609
|
+
chunkFileNames: "compat-shared.[hash].mjs",
|
|
610
|
+
entries,
|
|
611
|
+
entryFileNames: "compat.[name].mjs",
|
|
612
|
+
platform: "node",
|
|
613
|
+
root: dirname(firstEntry.filename),
|
|
614
|
+
});
|
|
615
|
+
const chunksDir = join(serverDir, "server-modules", "chunks");
|
|
616
|
+
await mkdir(chunksDir, { recursive: true });
|
|
617
|
+
await Promise.all(output.chunks.map((chunk) => writeFile(join(chunksDir, chunk.fileName), chunk.code)));
|
|
618
|
+
}
|
|
560
619
|
async function writeServerModuleArtifactFiles(serverDir, serverModules, portableRuntimePackages = []) {
|
|
561
620
|
const files = {};
|
|
562
621
|
const renderFiles = {};
|
|
@@ -569,6 +628,10 @@ async function writeServerModuleArtifactFiles(serverDir, serverModules, portable
|
|
|
569
628
|
mkdir(join(modulesDir, "request"), { recursive: true }),
|
|
570
629
|
mkdir(join(modulesDir, "render"), { recursive: true }),
|
|
571
630
|
]);
|
|
631
|
+
const usedCompatVendorEntries = collectCompatVendorEntryUsage(artifactEntries);
|
|
632
|
+
if (usedCompatVendorEntries.size > 0) {
|
|
633
|
+
await writeCompatVendorChunks(serverDir, usedCompatVendorEntries);
|
|
634
|
+
}
|
|
572
635
|
const writtenArtifacts = await mapWithBuildConcurrency(artifactEntries, async ([file, artifact]) => {
|
|
573
636
|
const externalized = await externalizeServerModuleArtifactCode(serverDir, artifact, portableRuntimePackages);
|
|
574
637
|
const requestArtifact = requestServerModuleArtifact(externalized);
|
|
@@ -634,7 +697,7 @@ async function externalizeServerModuleOutputCode(serverDir, output, kind, portab
|
|
|
634
697
|
const sourceCode = kind === "bundle" ? output.bundleCode : output.code;
|
|
635
698
|
const moduleCode = sourceCode === undefined
|
|
636
699
|
? undefined
|
|
637
|
-
: rewritePortableRuntimePackageImports(sourceCode, portableRuntimePackages);
|
|
700
|
+
: rewriteCompatVendorPlaceholderImports(rewritePortableRuntimePackageImports(sourceCode, portableRuntimePackages));
|
|
638
701
|
if (moduleCode === undefined || moduleCode.length === 0) {
|
|
639
702
|
return output;
|
|
640
703
|
}
|
|
@@ -1183,6 +1246,10 @@ function routePathFromParams(route, params) {
|
|
|
1183
1246
|
}
|
|
1184
1247
|
async function buildServerModuleArtifacts(options) {
|
|
1185
1248
|
const routeByFile = new Map(options.routes.map((route) => [relative(options.projectRoot, route.file), route]));
|
|
1249
|
+
// One shared compat vendor chunk set replaces per-route inlining whenever
|
|
1250
|
+
// any app source references the react/compat specifier family.
|
|
1251
|
+
const externalizeCompatVendor = options.prebundleServerComponents &&
|
|
1252
|
+
Object.values(options.files).some(sourceReferencesCompatVendorSpecifier);
|
|
1186
1253
|
const loaderArtifactFiles = new Set();
|
|
1187
1254
|
const metadataArtifactFiles = new Set();
|
|
1188
1255
|
const requestArtifactFiles = new Set();
|
|
@@ -1363,6 +1430,10 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1363
1430
|
filename: join(options.projectRoot, file),
|
|
1364
1431
|
moduleContextCache: options.clientRouteInferenceCache,
|
|
1365
1432
|
serverOutput,
|
|
1433
|
+
...(serverOutput === "stream" &&
|
|
1434
|
+
(routeAnalysis?.clientRoute ?? clientInference?.client) === true
|
|
1435
|
+
? { serverAwaitHydration: true }
|
|
1436
|
+
: {}),
|
|
1366
1437
|
});
|
|
1367
1438
|
const fatalDiagnostics = output.diagnostics.filter((diagnostic) => diagnostic.code !== "MR_UNSUPPORTED_SERVER_EVENT_HANDLER");
|
|
1368
1439
|
if (fatalDiagnostics.length > 0) {
|
|
@@ -1392,6 +1463,7 @@ async function buildServerModuleArtifacts(options) {
|
|
|
1392
1463
|
bundleCode: await buildServerComponentBundleArtifactCode({
|
|
1393
1464
|
clientRouteInferenceCache: options.clientRouteInferenceCache,
|
|
1394
1465
|
code: output.code,
|
|
1466
|
+
externalizeCompatVendor,
|
|
1395
1467
|
filename: absoluteFile,
|
|
1396
1468
|
define: options.define,
|
|
1397
1469
|
root: options.projectRoot,
|
|
@@ -1424,6 +1496,7 @@ async function buildServerComponentBundleArtifactCode(options) {
|
|
|
1424
1496
|
return await bundleAppRouterSourceModule({
|
|
1425
1497
|
code: options.code,
|
|
1426
1498
|
define: options.define,
|
|
1499
|
+
externalizeCompatVendor: options.externalizeCompatVendor,
|
|
1427
1500
|
label: `server-component:${options.filename}`,
|
|
1428
1501
|
resolveDir: dirname(options.filename),
|
|
1429
1502
|
root: options.root,
|
|
@@ -4027,6 +4100,11 @@ async function writeCloudflareWorkerArtifact(options) {
|
|
|
4027
4100
|
``,
|
|
4028
4101
|
].join("\n"));
|
|
4029
4102
|
}
|
|
4103
|
+
/**
|
|
4104
|
+
* Packages a built app-router output directory into the minimal AWS Lambda artifact layout.
|
|
4105
|
+
*
|
|
4106
|
+
* The package contains `.mreact`, a Lambda handler, project package metadata, production dependencies, and `mreact-lambda-artifact.json`; it intentionally excludes source files and development tooling that are not needed at runtime.
|
|
4107
|
+
*/
|
|
4030
4108
|
export async function packageAwsLambdaArtifact(options) {
|
|
4031
4109
|
await assertRequiredBuildFile(join(options.fromDir, "server", "manifest.json"));
|
|
4032
4110
|
await assertRequiredBuildFile(join(options.fromDir, "server", "import-policy.json"));
|
|
@@ -4107,6 +4185,11 @@ async function assertAwsLambdaRuntimeDependencies(outDir) {
|
|
|
4107
4185
|
"or rerun with --skip-runtime-dependency-check only when a later deploy step installs them into .lambda/node_modules.",
|
|
4108
4186
|
].join(" "));
|
|
4109
4187
|
}
|
|
4188
|
+
/**
|
|
4189
|
+
* Packages a Cloudflare-target build for Cloudflare Pages advanced mode.
|
|
4190
|
+
*
|
|
4191
|
+
* The package writes `_worker.js`, generated client assets, public assets, and `mreact-cloudflare-pages-artifact.json`; deploy the output directory rather than the raw `.mreact` build tree.
|
|
4192
|
+
*/
|
|
4110
4193
|
export async function packageCloudflarePagesArtifact(options) {
|
|
4111
4194
|
const clientManifestPath = join(options.fromDir, "client", "manifest.json");
|
|
4112
4195
|
const workerPath = join(options.fromDir, "cloudflare", "worker.mjs");
|