@reckona/mreact-router 0.0.75 → 0.0.76
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 +6 -2
- package/dist/build.d.ts +15 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +65 -4
- package/dist/build.js.map +1 -1
- package/dist/bundle-pipeline.d.ts +1 -0
- package/dist/bundle-pipeline.d.ts.map +1 -1
- package/dist/bundle-pipeline.js +1 -0
- package/dist/bundle-pipeline.js.map +1 -1
- package/dist/cli-options.d.ts +4 -0
- package/dist/cli-options.d.ts.map +1 -1
- package/dist/cli-options.js +40 -6
- package/dist/cli-options.js.map +1 -1
- package/dist/cli.js +19 -10
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/build.ts +103 -4
- package/src/bundle-pipeline.ts +2 -0
- package/src/cli-options.ts +52 -6
- package/src/cli.ts +21 -11
- package/src/index.ts +3 -1
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ removal after `0.1.0`.
|
|
|
48
48
|
|
|
49
49
|
Production client source maps are disabled by default. Set `clientSourceMaps: "linked"` to emit public `.js.map` files beside route scripts and include `sourceMappingURL` comments, or set `clientSourceMaps: "hidden"` to emit upload-only maps under `.mreact/source-maps/client/` without exposing them in the client manifest. The CLI accepts the same modes with `mreact-router build --client-source-maps=hidden`, `linked`, or `none`.
|
|
50
50
|
|
|
51
|
-
`mreact-router dev` reads the same config, preserves route-agnostic Vite plugins and CSS settings, and uses `server.port` from `vite.config.ts` when `PORT` is
|
|
51
|
+
`mreact-router dev` reads the same config, preserves route-agnostic Vite plugins and CSS settings, and uses `server.port` from `vite.config.ts` when neither `--port` nor `PORT` is set. Use `mreact-router dev --port 15174` for one-off E2E or local port overrides without creating a separate Vite config. This keeps Vite CSS transforms, Playwright `webServer` setups, and local dev commands on the same configured port.
|
|
52
52
|
|
|
53
53
|
For TypeScript projects that type-check route modules directly, include the
|
|
54
54
|
app-router global declarations so route files can use `<Slot />` without a
|
|
@@ -309,7 +309,11 @@ export default function Page() {
|
|
|
309
309
|
|
|
310
310
|
The build manifest records this separately from `client: true`, emits a shared navigation runtime asset, prefetches client route scripts when present, and falls back to `x-mreact-navigation: 1` HTML prefetches for server-only targets.
|
|
311
311
|
|
|
312
|
-
For Cloudflare Workers, `mreact-router build --target=cloudflare` emits `.mreact/cloudflare/worker.mjs`, `.mreact/cloudflare/route-modules.mjs`, and per-route module chunks for non-prerendered and dynamic App Router pages plus `route.ts` server routes and metadata conventions, so deployments do not need a hand-written Worker entrypoint or Vite-only `import.meta.glob()` transforms.
|
|
312
|
+
For Cloudflare Workers, `mreact-router build --target=cloudflare` emits `.mreact/cloudflare/worker.mjs`, `.mreact/cloudflare/route-modules.mjs`, and per-route module chunks for non-prerendered and dynamic App Router pages plus `route.ts` server routes and metadata conventions, so deployments do not need a hand-written Worker entrypoint or Vite-only `import.meta.glob()` transforms. Deploy that output with a Worker config whose `main` is `.mreact/cloudflare/worker.mjs` and whose `ASSETS` binding points at `.mreact/client`.
|
|
313
|
+
|
|
314
|
+
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 manifest-listed route assets 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.
|
|
315
|
+
|
|
316
|
+
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.
|
|
313
317
|
|
|
314
318
|
For AWS Lambda, use `createPreloadedAwsLambdaRequestHandler()` with API Gateway
|
|
315
319
|
HTTP API v2 or Lambda Function URL payload format 2.0:
|
package/dist/build.d.ts
CHANGED
|
@@ -26,10 +26,24 @@ export interface AwsLambdaArtifactManifest {
|
|
|
26
26
|
totalBytes: number;
|
|
27
27
|
version: 1;
|
|
28
28
|
}
|
|
29
|
+
export interface CloudflarePagesArtifactManifest {
|
|
30
|
+
files: Array<{
|
|
31
|
+
bytes: number;
|
|
32
|
+
path: string;
|
|
33
|
+
}>;
|
|
34
|
+
runtime: "cloudflare-pages";
|
|
35
|
+
totalBytes: number;
|
|
36
|
+
version: 1;
|
|
37
|
+
worker: "_worker.js";
|
|
38
|
+
}
|
|
29
39
|
export interface PackageAwsLambdaArtifactOptions {
|
|
30
40
|
fromDir: string;
|
|
31
41
|
outDir: string;
|
|
32
42
|
}
|
|
43
|
+
export interface PackageCloudflarePagesArtifactOptions {
|
|
44
|
+
fromDir: string;
|
|
45
|
+
outDir: string;
|
|
46
|
+
}
|
|
33
47
|
export interface BuiltServerManifest {
|
|
34
48
|
allowedSourceDirs?: readonly string[];
|
|
35
49
|
assetBaseUrl?: string;
|
|
@@ -96,4 +110,5 @@ export interface BuiltPrerenderedRoute {
|
|
|
96
110
|
}
|
|
97
111
|
export declare function buildApp(options: BuildAppOptions): Promise<BuildAppResult>;
|
|
98
112
|
export declare function packageAwsLambdaArtifact(options: PackageAwsLambdaArtifactOptions): Promise<AwsLambdaArtifactManifest>;
|
|
113
|
+
export declare function packageCloudflarePagesArtifact(options: PackageCloudflarePagesArtifactOptions): Promise<CloudflarePagesArtifactManifest>;
|
|
99
114
|
//# 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":"AAgCA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C,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;AA0BnD,OAAO,KAAK,EAAgB,UAAU,EAAE,MAAM,MAAM,CAAC;AAOrD,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,SAAS,oBAAoB,EAAE,GAAG,SAAS,CAAC;IACtD,UAAU,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,SAAS,CAAC;CACtD;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,QAAQ,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAClC,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,OAAO,EAAE,CAAC,C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M,CAAC;IACb,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAID,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAiLhF;AA++ED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,yBAAyB,CAAC,CAgCpC;AAED,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,qCAAqC,GAC7C,OAAO,CAAC,+BAA+B,CAAC,CAqD1C"}
|
package/dist/build.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { copyFile, cp, mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
3
3
|
import { builtinModules } from "node:module";
|
|
4
|
-
import { dirname, join, relative, sep } from "node:path";
|
|
4
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { collectStaticImportReferences, collectTopLevelValueExportNames, formatDiagnostic, hasModuleDirective, transform, } from "@reckona/mreact-compiler";
|
|
6
6
|
import { transformCompilerModuleContext } from "@reckona/mreact-compiler/internal";
|
|
7
7
|
import { buildClientRouteBatchOutput, buildNavigationRuntimeBundle, clientScriptForPath, compilerModuleContextForSource, collectClientRouteReferences, createClientRouteInferenceCache, detectClientNavigationHint, detectNavigationRuntimeHint, formatClientRouteInferenceDiagnostic, inferClientRouteModule, routeIdForPath, } from "./client.js";
|
|
@@ -1779,6 +1779,10 @@ function cloudflareWorkspaceRuntimePlugin() {
|
|
|
1779
1779
|
["@reckona/mreact-compat/scheduler", packageFile("react-compat", "@reckona/mreact-compat", "scheduler")],
|
|
1780
1780
|
["@reckona/mreact-query", packageFile("query", "@reckona/mreact-query", "index")],
|
|
1781
1781
|
["@reckona/mreact-reactive-core", packageFile("reactive-core", "@reckona/mreact-reactive-core", "index")],
|
|
1782
|
+
[
|
|
1783
|
+
"@reckona/mreact-router/adapters/cloudflare",
|
|
1784
|
+
packageFile("router", "@reckona/mreact-router", "adapters/cloudflare"),
|
|
1785
|
+
],
|
|
1782
1786
|
["@reckona/mreact-router/link", routerLinkPath],
|
|
1783
1787
|
["@reckona/mreact-router/runtime-state", routerRuntimeStatePath],
|
|
1784
1788
|
["@reckona/mreact-router/session", packageFile("router", "@reckona/mreact-router", "session")],
|
|
@@ -2096,7 +2100,7 @@ export async function packageAwsLambdaArtifact(options) {
|
|
|
2096
2100
|
outDir: options.outDir,
|
|
2097
2101
|
});
|
|
2098
2102
|
await writeFile(join(options.outDir, "mreact-handler.mjs"), awsLambdaHandlerSource(".mreact"));
|
|
2099
|
-
const files = await
|
|
2103
|
+
const files = await collectArtifactFiles(options.outDir, "");
|
|
2100
2104
|
const manifest = {
|
|
2101
2105
|
files,
|
|
2102
2106
|
handler: "mreact-handler.handler",
|
|
@@ -2107,6 +2111,48 @@ export async function packageAwsLambdaArtifact(options) {
|
|
|
2107
2111
|
await writeFile(join(options.outDir, "mreact-lambda-artifact.json"), JSON.stringify(manifest, null, 2));
|
|
2108
2112
|
return manifest;
|
|
2109
2113
|
}
|
|
2114
|
+
export async function packageCloudflarePagesArtifact(options) {
|
|
2115
|
+
const clientManifestPath = join(options.fromDir, "client", "manifest.json");
|
|
2116
|
+
const workerPath = join(options.fromDir, "cloudflare", "worker.mjs");
|
|
2117
|
+
await assertRequiredBuildFile(clientManifestPath);
|
|
2118
|
+
await assertRequiredBuildFile(workerPath);
|
|
2119
|
+
await assertRequiredBuildFile(join(options.fromDir, "cloudflare", "route-modules.mjs"));
|
|
2120
|
+
assertPackageOutputDoesNotReplaceBuildOutput(options);
|
|
2121
|
+
const clientManifest = JSON.parse(await readFile(clientManifestPath, "utf8"));
|
|
2122
|
+
await rm(options.outDir, { force: true, recursive: true });
|
|
2123
|
+
await mkdir(options.outDir, { recursive: true });
|
|
2124
|
+
await cp(join(options.fromDir, "client"), join(options.outDir, "_mreact", "client"), {
|
|
2125
|
+
force: true,
|
|
2126
|
+
recursive: true,
|
|
2127
|
+
});
|
|
2128
|
+
await copyCloudflarePagesPublicAssets({
|
|
2129
|
+
clientDir: join(options.fromDir, "client"),
|
|
2130
|
+
outDir: options.outDir,
|
|
2131
|
+
publicAssets: clientManifest.publicAssets ?? [],
|
|
2132
|
+
});
|
|
2133
|
+
const bundledWorker = await bundleRouterModule({
|
|
2134
|
+
code: await readFile(workerPath, "utf8"),
|
|
2135
|
+
filename: workerPath,
|
|
2136
|
+
minify: true,
|
|
2137
|
+
modulePreload: false,
|
|
2138
|
+
outfile: "_worker.js",
|
|
2139
|
+
platform: "browser",
|
|
2140
|
+
plugins: [cloudflareWorkspaceRuntimePlugin()],
|
|
2141
|
+
preserveExports: true,
|
|
2142
|
+
target: "es2022",
|
|
2143
|
+
});
|
|
2144
|
+
await writeFile(join(options.outDir, "_worker.js"), bundledWorker.code);
|
|
2145
|
+
const files = await collectArtifactFiles(options.outDir, "");
|
|
2146
|
+
const manifest = {
|
|
2147
|
+
files,
|
|
2148
|
+
runtime: "cloudflare-pages",
|
|
2149
|
+
totalBytes: files.reduce((total, file) => total + file.bytes, 0),
|
|
2150
|
+
version: 1,
|
|
2151
|
+
worker: "_worker.js",
|
|
2152
|
+
};
|
|
2153
|
+
await writeFile(join(options.outDir, "mreact-cloudflare-pages-artifact.json"), JSON.stringify(manifest, null, 2));
|
|
2154
|
+
return manifest;
|
|
2155
|
+
}
|
|
2110
2156
|
async function assertRequiredBuildFile(path) {
|
|
2111
2157
|
try {
|
|
2112
2158
|
const info = await stat(path);
|
|
@@ -2119,6 +2165,21 @@ async function assertRequiredBuildFile(path) {
|
|
|
2119
2165
|
}
|
|
2120
2166
|
throw new Error(`Missing required mreact build artifact: ${path}`);
|
|
2121
2167
|
}
|
|
2168
|
+
function assertPackageOutputDoesNotReplaceBuildOutput(options) {
|
|
2169
|
+
if (resolve(options.fromDir) === resolve(options.outDir)) {
|
|
2170
|
+
throw new Error("Package output directory must be different from the mreact build output directory.");
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
async function copyCloudflarePagesPublicAssets(options) {
|
|
2174
|
+
for (const asset of options.publicAssets) {
|
|
2175
|
+
if (!asset.startsWith("/") || asset.startsWith("//") || asset.includes("..")) {
|
|
2176
|
+
continue;
|
|
2177
|
+
}
|
|
2178
|
+
const relativeAsset = asset.slice(1);
|
|
2179
|
+
await mkdir(dirname(join(options.outDir, relativeAsset)), { recursive: true });
|
|
2180
|
+
await copyFile(join(options.clientDir, relativeAsset), join(options.outDir, relativeAsset));
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2122
2183
|
async function copyAwsLambdaProjectMetadata(options) {
|
|
2123
2184
|
for (const file of [
|
|
2124
2185
|
"package.json",
|
|
@@ -2138,14 +2199,14 @@ async function copyAwsLambdaProjectMetadata(options) {
|
|
|
2138
2199
|
}
|
|
2139
2200
|
}
|
|
2140
2201
|
}
|
|
2141
|
-
async function
|
|
2202
|
+
async function collectArtifactFiles(rootDir, relativeDir) {
|
|
2142
2203
|
const entries = await readdir(join(rootDir, relativeDir), { withFileTypes: true });
|
|
2143
2204
|
const files = [];
|
|
2144
2205
|
for (const entry of entries) {
|
|
2145
2206
|
const relativePath = relativeDir === "" ? entry.name : `${relativeDir}/${entry.name}`;
|
|
2146
2207
|
const absolutePath = join(rootDir, relativePath);
|
|
2147
2208
|
if (entry.isDirectory()) {
|
|
2148
|
-
files.push(...(await
|
|
2209
|
+
files.push(...(await collectArtifactFiles(rootDir, relativePath)));
|
|
2149
2210
|
continue;
|
|
2150
2211
|
}
|
|
2151
2212
|
if (entry.isFile()) {
|