@reckona/mreact-router 0.0.190 → 0.0.191
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 +6 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +57 -12
- package/dist/build.js.map +1 -1
- package/dist/cli-options.d.ts +3 -0
- package/dist/cli-options.d.ts.map +1 -1
- package/dist/cli-options.js +42 -0
- package/dist/cli-options.js.map +1 -1
- package/dist/cli.js +12 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/build.ts +113 -16
- package/src/cli-options.ts +64 -0
- package/src/cli.ts +12 -0
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -392,7 +392,7 @@ export const handler = await createPreloadedAwsLambdaRequestHandler(options);
|
|
|
392
392
|
|
|
393
393
|
Production adapters enforce the app-router import policy when bundling loaders, middleware, route handlers, metadata, and server actions. `mreact-router build` writes `.mreact/server/import-policy.json` from server-side static imports. The built Node server used by `mreact-router start .mreact`, `renderBuiltAppRequest()`, and `createBuiltRequestRuntime()` reads that generated policy automatically and merges its runtime packages with any explicit policy options. Lambda handlers can use `importPolicy: "generated"`. You can still pass an explicit `importPolicy.allowedPackages` list when you need a hand-audited policy.
|
|
394
394
|
|
|
395
|
-
For Lambda deployments, build with `mreact-router build --target=aws-lambda` or `buildApp({ targets: ["aws-lambda"] })`. The target writes Node-compatible server/client output, `.mreact/server/import-policy.json`, and
|
|
395
|
+
For Lambda deployments, build with `mreact-router build --target=aws-lambda` or `buildApp({ targets: ["aws-lambda"] })`. The generated buffered and streaming handlers warm the same middleware policy during module initialization by default and then use request handlers with duplicate preload disabled. The artifact manifest records `mreact-handler.handler` and `mreact-streaming-handler.handler` separately. Select a broader or disabled initialization policy with `--aws-lambda-preload=hot-route-requests|all|none` or `buildApp({ awsLambdaPreload: "all", targets: ["aws-lambda"] })` only after measuring the packaged handler; pair `hot-route-requests` with `--aws-lambda-preload-routes=/,/login` or `awsLambdaPreloadRoutes`. `none` disables generated module preload but still materializes the writable runtime directory during generated handler import. The package command preserves the build-generated policy unless package options explicitly override it. The target writes Node-compatible server/client output, `.mreact/server/import-policy.json`, and generated Lambda entries while skipping `.mreact/cloudflare` route modules, so loaders and server helpers may import Node-only dependencies such as database drivers without being bundled for the Workers runtime.
|
|
396
396
|
|
|
397
397
|
Package Lambda deployments with `mreact-router package aws-lambda --from .mreact --out .lambda` instead of pointing deployment tooling at the full project checkout. AWS Lambda enforces a 250 MB unzipped deployment package limit, and the runtime only needs `.mreact/`, `mreact-handler.mjs`, `package.json` / lockfiles, and production `node_modules`; `src/`, tests, dev dependencies, build caches, and Vite/Vitest/Playwright tooling are not required. `mreact-router build --target=aws-lambda` keeps compiled server route artifacts in `.mreact/server/server-modules/*.json` instead of embedding them in one large server manifest, writes compiled module bodies as hashed `.mjs` files, and keeps request/control artifacts separate from render artifacts so loader redirects do not read page render bundles. AWS Lambda request/control artifacts bundle the generated import-policy packages they use for loaders, middleware, route handlers, and metadata, reducing first-hit package resolution on sparse Lambda traffic while leaving render-only, server action, custom handler, and adapter dependencies in production `node_modules`. `createAwsLambdaRequestHandler()` treats `outDir` as read-only and materializes generated runtime files under `/tmp/mreact-router/<hash>/runtime` by default, with a `node_modules` symlink back to the deployed package root. Direct `createAwsLambdaRequestHandler()` and `createAwsLambdaStreamingRequestHandler()` handlers start only middleware and shared runtime preload in the background by default, so all-route preload work does not compete with the first user request. If a request arrives before preload finishes, middleware is resolved first, middleware responses or redirects return without loading the matched page artifact, and continuing requests load only the matched route's artifact closure. Static middleware `config.matcher` and `config.id` values are checked before importing the middleware module, so unmatched health checks and route-local middleware skips avoid evaluating heavyweight middleware dependencies. Route request artifacts omit page render exports, and built loader and route metadata artifacts are split, so loader redirects do not evaluate page-only or metadata-only dependencies before render or metadata is needed. Loader redirects settle before page component server transforms and render imports for non-stream routes, stream routes without a loading boundary, and stream loading routes whose loader source contains router control-flow helpers such as `redirect()` or `notFound()`. `createPreloadedAwsLambdaRequestHandler()` validates the first event before it starts full preload. When a deployment intentionally accepts extra Lambda initialization work to reduce first-valid-request latency, call `await warmAwsLambdaRuntime(options)` during controlled initialization before creating the handler. Pass `runtimeDir` only when you need to control that writable cache location. With pnpm, run `pnpm --dir .lambda install --prod --frozen-lockfile --ignore-scripts --config.node-linker=hoisted`. pnpm's default isolated linker is symlink-heavy, so verify the artifact's symlink count with `find .lambda -type l | wc -l` and measure actual file bytes in addition to `du -sh .lambda` before upload. Packages listed in the generated import policy may still be needed by render-only modules, inferred server actions, custom handlers, or adapter code, so keep them installed in that production artifact.
|
|
398
398
|
|
package/dist/build.d.ts
CHANGED
|
@@ -5,10 +5,13 @@ import type { ModuleMetadata } from "@reckona/mreact-compiler";
|
|
|
5
5
|
import type { RouteCachePolicy } from "./cache.js";
|
|
6
6
|
import { type AppRouterImportPolicy } from "./import-policy.js";
|
|
7
7
|
import type { PluginOption, UserConfig } from "vite";
|
|
8
|
+
export type AwsLambdaGeneratedHandlerPreloadMode = "all" | "hot-route-requests" | "middleware" | "none";
|
|
8
9
|
/**
|
|
9
10
|
* Configures an app-router production build and its deployment targets.
|
|
10
11
|
*/
|
|
11
12
|
export interface BuildAppOptions extends AppRouterProjectOptions {
|
|
13
|
+
awsLambdaPreload?: AwsLambdaGeneratedHandlerPreloadMode | undefined;
|
|
14
|
+
awsLambdaPreloadRoutes?: readonly string[] | undefined;
|
|
12
15
|
onBuildProgress?: ((event: BuildAppProgressEvent) => void) | undefined;
|
|
13
16
|
onBuildPhaseTiming?: ((timing: BuildAppPhaseTiming) => void) | undefined;
|
|
14
17
|
outDir: string;
|
|
@@ -64,6 +67,7 @@ export interface AwsLambdaArtifactManifest {
|
|
|
64
67
|
}>;
|
|
65
68
|
handler: string;
|
|
66
69
|
runtime: "aws-lambda";
|
|
70
|
+
streamingHandler?: string | undefined;
|
|
67
71
|
totalBytes: number;
|
|
68
72
|
version: 1;
|
|
69
73
|
}
|
|
@@ -84,6 +88,8 @@ export interface CloudflarePagesArtifactManifest {
|
|
|
84
88
|
* Configures packaging of a built app-router output directory for AWS Lambda.
|
|
85
89
|
*/
|
|
86
90
|
export interface PackageAwsLambdaArtifactOptions {
|
|
91
|
+
awsLambdaPreload?: AwsLambdaGeneratedHandlerPreloadMode | undefined;
|
|
92
|
+
awsLambdaPreloadRoutes?: readonly string[] | undefined;
|
|
87
93
|
fromDir: string;
|
|
88
94
|
handlerEntry?: string | undefined;
|
|
89
95
|
outDir: string;
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AA8BjE,OAAO,KAAK,EAAE,QAAQ,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAE1E,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;AAmCnG,OAAO,KAAK,EAAU,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAc7D;;GAEG;AACH,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,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S,CAAC;IACjD,YAAY,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IACjD,WAAW,CAAC,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,CAAC;CACnD,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAclC;AAkJD,UAAU,4BAA4B;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,6BAA6B,CAAC;CACtC;AAED,KAAK,6BAA6B,GAAG,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC;AAwzD1E,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;AA0oCD;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,yBAAyB,CAAC,CAyDpC;AA6DD;;;;GAIG;AACH,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,qCAAqC,GAC7C,OAAO,CAAC,+BAA+B,CAAC,CAsD1C"}
|
package/dist/build.js
CHANGED
|
@@ -399,7 +399,11 @@ async function buildAppWithResolvedProject(options, project) {
|
|
|
399
399
|
}
|
|
400
400
|
if (shouldTrackBuildPhases === false) {
|
|
401
401
|
await Promise.all([
|
|
402
|
-
...(shouldBuildAwsLambda
|
|
402
|
+
...(shouldBuildAwsLambda
|
|
403
|
+
? [
|
|
404
|
+
writeAwsLambdaHandlerArtifact(options.outDir, options.awsLambdaPreload, options.awsLambdaPreloadRoutes),
|
|
405
|
+
]
|
|
406
|
+
: []),
|
|
403
407
|
...(shouldBuildCloudflare
|
|
404
408
|
? [
|
|
405
409
|
writeCloudflareWorkerArtifact({
|
|
@@ -415,7 +419,11 @@ async function buildAppWithResolvedProject(options, project) {
|
|
|
415
419
|
else {
|
|
416
420
|
await timeBuildPhase(timingSink, progressSink, "adapterArtifacts", async () => {
|
|
417
421
|
await Promise.all([
|
|
418
|
-
...(shouldBuildAwsLambda
|
|
422
|
+
...(shouldBuildAwsLambda
|
|
423
|
+
? [
|
|
424
|
+
writeAwsLambdaHandlerArtifact(options.outDir, options.awsLambdaPreload, options.awsLambdaPreloadRoutes),
|
|
425
|
+
]
|
|
426
|
+
: []),
|
|
419
427
|
...(shouldBuildCloudflare
|
|
420
428
|
? [
|
|
421
429
|
writeCloudflareWorkerArtifact({
|
|
@@ -563,8 +571,7 @@ async function readJsonBuildOutput(file) {
|
|
|
563
571
|
return JSON.parse(await readFile(file, "utf8"));
|
|
564
572
|
}
|
|
565
573
|
catch (error) {
|
|
566
|
-
if ((isNodeError(error) && error.code === "ENOENT") ||
|
|
567
|
-
error instanceof SyntaxError) {
|
|
574
|
+
if ((isNodeError(error) && error.code === "ENOENT") || error instanceof SyntaxError) {
|
|
568
575
|
return undefined;
|
|
569
576
|
}
|
|
570
577
|
throw error;
|
|
@@ -4571,10 +4578,15 @@ async function writeNavigationRuntimeBundle(clientDir, dropConsoleFunctions) {
|
|
|
4571
4578
|
await writeFile(join(clientDir, script), output.code);
|
|
4572
4579
|
return script;
|
|
4573
4580
|
}
|
|
4574
|
-
async function writeAwsLambdaHandlerArtifact(outDir) {
|
|
4581
|
+
async function writeAwsLambdaHandlerArtifact(outDir, preload, routes) {
|
|
4575
4582
|
const awsLambdaDir = join(outDir, "aws-lambda");
|
|
4576
4583
|
await mkdir(awsLambdaDir, { recursive: true });
|
|
4577
|
-
|
|
4584
|
+
const policy = { mode: preload ?? "middleware", ...(routes === undefined ? {} : { routes }) };
|
|
4585
|
+
await Promise.all([
|
|
4586
|
+
writeFile(join(awsLambdaDir, "mreact-handler.mjs"), awsLambdaHandlerSource("buffered", "..", policy.mode, policy.routes)),
|
|
4587
|
+
writeFile(join(awsLambdaDir, "mreact-streaming-handler.mjs"), awsLambdaHandlerSource("streaming", "..", policy.mode, policy.routes)),
|
|
4588
|
+
writeFile(join(awsLambdaDir, "preload-policy.json"), JSON.stringify(policy, null, 2)),
|
|
4589
|
+
]);
|
|
4578
4590
|
}
|
|
4579
4591
|
async function writeCloudflareWorkerArtifact(options) {
|
|
4580
4592
|
await writeFile(join(options.cloudflareDir, "worker.mjs"), [
|
|
@@ -4616,7 +4628,11 @@ export async function packageAwsLambdaArtifact(options) {
|
|
|
4616
4628
|
outDir: options.outDir,
|
|
4617
4629
|
});
|
|
4618
4630
|
if (options.handlerEntry === undefined) {
|
|
4619
|
-
await
|
|
4631
|
+
const builtPolicy = await readAwsLambdaGeneratedPreloadPolicy(options.fromDir);
|
|
4632
|
+
const preload = options.awsLambdaPreload ?? builtPolicy.mode;
|
|
4633
|
+
const routes = options.awsLambdaPreloadRoutes ?? builtPolicy.routes;
|
|
4634
|
+
await writeFile(join(options.outDir, "mreact-handler.mjs"), awsLambdaHandlerSource("buffered", ".mreact", preload, routes));
|
|
4635
|
+
await writeFile(join(options.outDir, "mreact-streaming-handler.mjs"), awsLambdaHandlerSource("streaming", ".mreact", preload, routes));
|
|
4620
4636
|
}
|
|
4621
4637
|
else {
|
|
4622
4638
|
await writeAwsLambdaCustomHandlerArtifact({
|
|
@@ -4633,6 +4649,9 @@ export async function packageAwsLambdaArtifact(options) {
|
|
|
4633
4649
|
files,
|
|
4634
4650
|
handler: "mreact-handler.handler",
|
|
4635
4651
|
runtime: "aws-lambda",
|
|
4652
|
+
...(options.handlerEntry === undefined
|
|
4653
|
+
? { streamingHandler: "mreact-streaming-handler.handler" }
|
|
4654
|
+
: {}),
|
|
4636
4655
|
totalBytes: files.reduce((total, file) => total + file.bytes, 0),
|
|
4637
4656
|
version: 1,
|
|
4638
4657
|
};
|
|
@@ -4796,21 +4815,47 @@ async function collectArtifactFiles(rootDir, relativeDir) {
|
|
|
4796
4815
|
}
|
|
4797
4816
|
return files.sort((left, right) => right.bytes - left.bytes || left.path.localeCompare(right.path));
|
|
4798
4817
|
}
|
|
4799
|
-
function awsLambdaHandlerSource(outDirRelativeToHandler) {
|
|
4818
|
+
function awsLambdaHandlerSource(kind, outDirRelativeToHandler, preload = "middleware", routes) {
|
|
4819
|
+
const createHandler = kind === "streaming"
|
|
4820
|
+
? "createAwsLambdaStreamingRequestHandler"
|
|
4821
|
+
: "createAwsLambdaRequestHandler";
|
|
4800
4822
|
return `import { fileURLToPath } from "node:url";
|
|
4801
4823
|
import { dirname, resolve } from "node:path";
|
|
4802
|
-
import {
|
|
4824
|
+
import { ${createHandler}, warmAwsLambdaRuntime } from "@reckona/mreact-router/adapters/aws-lambda";
|
|
4803
4825
|
|
|
4804
4826
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
4805
|
-
|
|
4806
|
-
export const handler = await createPreloadedAwsLambdaRequestHandler({
|
|
4827
|
+
const options = {
|
|
4807
4828
|
importPolicy: "generated",
|
|
4808
4829
|
outDir: resolve(here, ${JSON.stringify(outDirRelativeToHandler)}),
|
|
4809
|
-
preload: { mode: "
|
|
4830
|
+
preload: { mode: ${JSON.stringify(preload)}${routes === undefined ? "" : `, routes: ${JSON.stringify(routes)}`} },
|
|
4810
4831
|
timings: process.env.MREACT_ROUTER_TIMINGS === "1",
|
|
4832
|
+
};
|
|
4833
|
+
|
|
4834
|
+
await warmAwsLambdaRuntime(options);
|
|
4835
|
+
export const handler = ${createHandler}({
|
|
4836
|
+
...options,
|
|
4837
|
+
preload: { mode: "none" },
|
|
4811
4838
|
});
|
|
4812
4839
|
`;
|
|
4813
4840
|
}
|
|
4841
|
+
async function readAwsLambdaGeneratedPreloadPolicy(outDir) {
|
|
4842
|
+
const path = join(outDir, "aws-lambda", "preload-policy.json");
|
|
4843
|
+
try {
|
|
4844
|
+
return JSON.parse(await readFile(path, "utf8"));
|
|
4845
|
+
}
|
|
4846
|
+
catch (error) {
|
|
4847
|
+
if (isNodeErrorCode(error, "ENOENT")) {
|
|
4848
|
+
return { mode: "middleware" };
|
|
4849
|
+
}
|
|
4850
|
+
throw error;
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4853
|
+
function isNodeErrorCode(error, code) {
|
|
4854
|
+
return (typeof error === "object" &&
|
|
4855
|
+
error !== null &&
|
|
4856
|
+
"code" in error &&
|
|
4857
|
+
error.code === code);
|
|
4858
|
+
}
|
|
4814
4859
|
async function validateProductionRoutes(options) {
|
|
4815
4860
|
for (const route of options.routes) {
|
|
4816
4861
|
if (route.kind !== "page") {
|