@reckona/mreact-router 0.0.203 → 0.0.205
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 +53 -9
- package/dist/actions.d.ts +6 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +70 -10
- package/dist/actions.js.map +1 -1
- package/dist/adapters/aws-lambda.d.ts +15 -4
- package/dist/adapters/aws-lambda.d.ts.map +1 -1
- package/dist/adapters/aws-lambda.js +301 -63
- package/dist/adapters/aws-lambda.js.map +1 -1
- package/dist/adapters/cloudflare.d.ts +2 -1
- package/dist/adapters/cloudflare.d.ts.map +1 -1
- package/dist/adapters/cloudflare.js +18 -10
- package/dist/adapters/cloudflare.js.map +1 -1
- package/dist/adapters/edge.d.ts +1 -1
- package/dist/adapters/edge.d.ts.map +1 -1
- package/dist/adapters/edge.js.map +1 -1
- package/dist/adapters/node.d.ts +5 -3
- package/dist/adapters/node.d.ts.map +1 -1
- package/dist/adapters/node.js +2 -1
- package/dist/adapters/node.js.map +1 -1
- package/dist/adapters/static.d.ts.map +1 -1
- package/dist/adapters/static.js +24 -2
- package/dist/adapters/static.js.map +1 -1
- package/dist/build.d.ts +1 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +91 -5
- package/dist/build.js.map +1 -1
- package/dist/built-runtime.d.ts +2 -0
- package/dist/built-runtime.d.ts.map +1 -1
- package/dist/built-runtime.js +16 -0
- package/dist/built-runtime.js.map +1 -1
- package/dist/cache.d.ts +3 -1
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +211 -13
- package/dist/cache.js.map +1 -1
- package/dist/cli.js +12 -1
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +32 -1
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +21 -2
- package/dist/config.js.map +1 -1
- package/dist/csp.d.ts +1 -0
- package/dist/csp.d.ts.map +1 -1
- package/dist/csp.js +11 -6
- package/dist/csp.js.map +1 -1
- package/dist/dehydrate-policy.d.ts +3 -0
- package/dist/dehydrate-policy.d.ts.map +1 -0
- package/dist/dehydrate-policy.js +16 -0
- package/dist/dehydrate-policy.js.map +1 -0
- package/dist/dev-server.d.ts +7 -2
- package/dist/dev-server.d.ts.map +1 -1
- package/dist/dev-server.js +120 -11
- package/dist/dev-server.js.map +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +147 -7
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +22 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +22 -8
- package/dist/logger.js.map +1 -1
- package/dist/metadata.d.ts +8 -0
- package/dist/metadata.d.ts.map +1 -1
- package/dist/metadata.js +60 -22
- package/dist/metadata.js.map +1 -1
- package/dist/navigation-marker.d.ts.map +1 -1
- package/dist/navigation-marker.js +72 -9
- package/dist/navigation-marker.js.map +1 -1
- package/dist/navigation.d.ts +1 -0
- package/dist/navigation.d.ts.map +1 -1
- package/dist/navigation.js +1 -1
- package/dist/navigation.js.map +1 -1
- package/dist/node-server.d.ts +5 -2
- package/dist/node-server.d.ts.map +1 -1
- package/dist/node-server.js +75 -6
- package/dist/node-server.js.map +1 -1
- package/dist/prerender-entry.d.ts +14 -0
- package/dist/prerender-entry.d.ts.map +1 -1
- package/dist/prerender-entry.js +40 -3
- package/dist/prerender-entry.js.map +1 -1
- package/dist/render.d.ts +9 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +102 -123
- package/dist/render.js.map +1 -1
- package/dist/serve.d.ts +8 -2
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +22 -20
- package/dist/serve.js.map +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +52 -19
- package/dist/session.js.map +1 -1
- package/dist/upgrade.d.ts +59 -2
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +282 -1
- package/dist/upgrade.js.map +1 -1
- package/dist/vite-config.d.ts +2 -0
- package/dist/vite-config.d.ts.map +1 -1
- package/dist/vite-config.js +2 -0
- package/dist/vite-config.js.map +1 -1
- package/dist/vite.d.ts +4 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +117 -6
- package/dist/vite.js.map +1 -1
- package/package.json +11 -11
- package/src/actions.ts +81 -11
- package/src/adapters/aws-lambda.ts +426 -115
- package/src/adapters/cloudflare.ts +29 -13
- package/src/adapters/edge.ts +2 -0
- package/src/adapters/node.ts +8 -10
- package/src/adapters/static.ts +31 -2
- package/src/build.ts +117 -10
- package/src/built-runtime.ts +28 -0
- package/src/cache.ts +262 -15
- package/src/cli.ts +14 -1
- package/src/client.ts +32 -1
- package/src/config.ts +43 -6
- package/src/csp.ts +14 -11
- package/src/dehydrate-policy.ts +23 -0
- package/src/dev-server.ts +188 -15
- package/src/http.ts +172 -6
- package/src/index.ts +14 -1
- package/src/logger.ts +47 -10
- package/src/metadata.ts +125 -60
- package/src/navigation-marker.ts +79 -9
- package/src/navigation.ts +1 -1
- package/src/node-server.ts +128 -22
- package/src/prerender-entry.ts +52 -3
- package/src/render.ts +807 -753
- package/src/serve.ts +49 -56
- package/src/session.ts +56 -25
- package/src/upgrade.ts +402 -3
- package/src/vite-config.ts +6 -0
- package/src/vite.ts +157 -5
package/dist/config.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface AppRouterProjectOptions {
|
|
|
29
29
|
buildConcurrency?: number | undefined;
|
|
30
30
|
buildTargets?: readonly AppRouterBuildTarget[] | undefined;
|
|
31
31
|
clientSourceMaps?: AppRouterClientSourceMapOption | undefined;
|
|
32
|
+
/** Project-local server module exporting a named `dehydrateOptions` policy. */
|
|
33
|
+
dehydratePolicyModule?: string | undefined;
|
|
32
34
|
/**
|
|
33
35
|
* Legacy route root. When provided without routesDir/projectRoot, this keeps
|
|
34
36
|
* the historical "appDir is the whole app boundary" behavior.
|
|
@@ -52,6 +54,7 @@ export interface ResolvedAppRouterProject {
|
|
|
52
54
|
buildTargets: readonly AppRouterBuildTarget[];
|
|
53
55
|
clientSourceMaps: AppRouterClientSourceMapMode;
|
|
54
56
|
clientConsolePureFunctions?: readonly string[] | undefined;
|
|
57
|
+
dehydratePolicyModule?: string | undefined;
|
|
55
58
|
projectRoot: string;
|
|
56
59
|
publicAssetBaseUrl?: string | undefined;
|
|
57
60
|
publicDir: string;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,YAAY,GAAG,YAAY,CAAC;AAExE,eAAO,MAAM,4BAA4B;;;CAMxC,CAAC;AACF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AACjG;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;AACxE;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,OAAO,GAAG,4BAA4B,CAAC;AAEpF;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,iBAAiB,CAAC,EAAE,OAAO,GAAG,SAAS,4BAA4B,EAAE,GAAG,SAAS,CAAC;CACnF;AAED,MAAM,WAAW,uBAAuB;IACtC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,YAAY,CAAC,EAAE,SAAS,oBAAoB,EAAE,GAAG,SAAS,CAAC;IAC3D,gBAAgB,CAAC,EAAE,8BAA8B,GAAG,SAAS,CAAC;IAC9D;;;;;;;OAOG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,GAAG,SAAS,CAAC;IAC3D,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,uBAAuB,GAC/B,wBAAwB,CA2E1B;AA+BD,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,0BAA0B,CAAC,mBAAmB,CAAC,GACrD,SAAS,MAAM,EAAE,GAAG,SAAS,CAmB/B;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,8BAA8B,GAAG,SAAS,GAChD,4BAA4B,CAgB9B;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,SAAS,oBAAoB,EAAE,GAAG,SAAS,GACnD,SAAS,oBAAoB,EAAE,CAoBjC"}
|
package/dist/config.js
CHANGED
|
@@ -9,8 +9,9 @@ export function resolveAppRouterProjectOptions(options) {
|
|
|
9
9
|
options.projectRoot === undefined &&
|
|
10
10
|
options.routesDir === undefined) {
|
|
11
11
|
const appDir = resolve(options.appDir);
|
|
12
|
+
const allowedSourceDirs = (options.allowedSourceDirs ?? [appDir]).map((directory) => resolveProjectPath(appDir, directory, "allowedSourceDirs"));
|
|
12
13
|
return {
|
|
13
|
-
allowedSourceDirs
|
|
14
|
+
allowedSourceDirs,
|
|
14
15
|
...(options.assetBaseUrl === undefined ? {} : { assetBaseUrl: options.assetBaseUrl }),
|
|
15
16
|
...(options.buildConcurrency === undefined
|
|
16
17
|
? {}
|
|
@@ -18,6 +19,11 @@ export function resolveAppRouterProjectOptions(options) {
|
|
|
18
19
|
buildTargets: resolveBuildTargets(options.buildTargets),
|
|
19
20
|
clientSourceMaps: resolveClientSourceMapMode(options.clientSourceMaps),
|
|
20
21
|
...(clientConsolePureFunctions === undefined ? {} : { clientConsolePureFunctions }),
|
|
22
|
+
...(options.dehydratePolicyModule === undefined
|
|
23
|
+
? {}
|
|
24
|
+
: {
|
|
25
|
+
dehydratePolicyModule: resolvePolicyModule(appDir, options.dehydratePolicyModule, allowedSourceDirs),
|
|
26
|
+
}),
|
|
21
27
|
projectRoot: appDir,
|
|
22
28
|
...(options.publicAssetBaseUrl === undefined
|
|
23
29
|
? {}
|
|
@@ -29,8 +35,9 @@ export function resolveAppRouterProjectOptions(options) {
|
|
|
29
35
|
const projectRoot = resolve(options.projectRoot ?? process.cwd());
|
|
30
36
|
const routesDir = resolveProjectPath(projectRoot, options.routesDir ?? "src/app", "routesDir");
|
|
31
37
|
const defaultAllowedSourceDirs = options.routesDir === undefined ? ["src"] : [defaultAllowedSourceDir(projectRoot, routesDir)];
|
|
38
|
+
const allowedSourceDirs = (options.allowedSourceDirs ?? defaultAllowedSourceDirs).map((directory) => resolveProjectPath(projectRoot, directory, "allowedSourceDirs"));
|
|
32
39
|
return {
|
|
33
|
-
allowedSourceDirs
|
|
40
|
+
allowedSourceDirs,
|
|
34
41
|
...(options.assetBaseUrl === undefined ? {} : { assetBaseUrl: options.assetBaseUrl }),
|
|
35
42
|
...(options.buildConcurrency === undefined
|
|
36
43
|
? {}
|
|
@@ -38,6 +45,11 @@ export function resolveAppRouterProjectOptions(options) {
|
|
|
38
45
|
buildTargets: resolveBuildTargets(options.buildTargets),
|
|
39
46
|
clientSourceMaps: resolveClientSourceMapMode(options.clientSourceMaps),
|
|
40
47
|
...(clientConsolePureFunctions === undefined ? {} : { clientConsolePureFunctions }),
|
|
48
|
+
...(options.dehydratePolicyModule === undefined
|
|
49
|
+
? {}
|
|
50
|
+
: {
|
|
51
|
+
dehydratePolicyModule: resolvePolicyModule(projectRoot, options.dehydratePolicyModule, allowedSourceDirs),
|
|
52
|
+
}),
|
|
41
53
|
projectRoot,
|
|
42
54
|
...(options.publicAssetBaseUrl === undefined
|
|
43
55
|
? {}
|
|
@@ -46,6 +58,13 @@ export function resolveAppRouterProjectOptions(options) {
|
|
|
46
58
|
routesDir,
|
|
47
59
|
};
|
|
48
60
|
}
|
|
61
|
+
function resolvePolicyModule(projectRoot, modulePath, allowedSourceDirs) {
|
|
62
|
+
const resolvedModule = resolveProjectPath(projectRoot, modulePath, "dehydratePolicyModule");
|
|
63
|
+
if (!allowedSourceDirs.some((directory) => isInsideDirectory(directory, resolvedModule))) {
|
|
64
|
+
throw new Error(`mreactRouter dehydratePolicyModule must resolve inside allowedSourceDirs: ${resolvedModule}`);
|
|
65
|
+
}
|
|
66
|
+
return resolvedModule;
|
|
67
|
+
}
|
|
49
68
|
function defaultAllowedSourceDir(projectRoot, routesDir) {
|
|
50
69
|
const sourceRoot = dirname(routesDir);
|
|
51
70
|
return basename(routesDir) === "app" && sourceRoot !== projectRoot ? sourceRoot : routesDir;
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAO7E,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,UAAU,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC;IAChD,cAAc,EAAE,CAAC,MAAM,CAAC;CAIzB,CAAC;AAwDF,MAAM,UAAU,8BAA8B,CAC5C,OAAgC;IAEhC,MAAM,0BAA0B,GAAG,iCAAiC,CAClE,OAAO,CAAC,UAAU,EAAE,iBAAiB,CACtC,CAAC;IAEF,IACE,OAAO,CAAC,MAAM,KAAK,SAAS;QAC5B,OAAO,CAAC,WAAW,KAAK,SAAS;QACjC,OAAO,CAAC,SAAS,KAAK,SAAS,EAC/B,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEvC,OAAO;YACL,iBAAiB,EAAE,CAAC,OAAO,CAA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AAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,IAAY;IAC7C,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY,EAAE,IAAY;IACnD,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE1C,OAAO,YAAY,KAAK,EAAE,IAAI,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["import { basename, dirname, isAbsolute, relative, resolve } from \"node:path\";\n\n/**\n * Selects the deployment runtime artifacts emitted by an app-router build.\n */\nexport type AppRouterBuildTarget = \"node\" | \"cloudflare\" | \"aws-lambda\";\n\nexport const appRouterBuildTargetMetadata = {\n allTargets: [\"node\", \"cloudflare\", \"aws-lambda\"],\n defaultTargets: [\"node\"],\n} as const satisfies {\n allTargets: readonly AppRouterBuildTarget[];\n defaultTargets: readonly AppRouterBuildTarget[];\n};\n/**\n * Names a browser console method that can be stripped from client bundles.\n */\nexport type AppRouterClientConsoleMethod = \"debug\" | \"error\" | \"info\" | \"log\" | \"trace\" | \"warn\";\n/**\n * Controls how client bundle source maps are generated.\n */\nexport type AppRouterClientSourceMapMode = \"none\" | \"hidden\" | \"linked\";\n/**\n * Configures client source map output with a boolean shortcut or explicit mode.\n */\nexport type AppRouterClientSourceMapOption = boolean | AppRouterClientSourceMapMode;\n\n/**\n * Configures production-only app-router build behavior.\n */\nexport interface AppRouterProductionOptions {\n dropClientConsole?: boolean | readonly AppRouterClientConsoleMethod[] | undefined;\n}\n\nexport interface AppRouterProjectOptions {\n assetBaseUrl?: string | undefined;\n buildConcurrency?: number | undefined;\n buildTargets?: readonly AppRouterBuildTarget[] | undefined;\n clientSourceMaps?: AppRouterClientSourceMapOption | undefined;\n /**\n * Legacy route root. When provided without routesDir/projectRoot, this keeps\n * the historical \"appDir is the whole app boundary\" behavior.\n *\n * @deprecated Use projectRoot + routesDir instead. The legacy appDir shortcut\n * is kept for direct tests and older programmatic callers and is planned for\n * removal after 0.1.0.\n */\n appDir?: string | undefined;\n allowedSourceDirs?: readonly string[] | undefined;\n projectRoot?: string | undefined;\n production?: AppRouterProductionOptions | undefined;\n publicDir?: string | undefined;\n publicAssetBaseUrl?: string | undefined;\n routesDir?: string | undefined;\n}\n\nexport interface ResolvedAppRouterProject {\n allowedSourceDirs: readonly string[];\n assetBaseUrl?: string | undefined;\n buildConcurrency?: number | undefined;\n buildTargets: readonly AppRouterBuildTarget[];\n clientSourceMaps: AppRouterClientSourceMapMode;\n clientConsolePureFunctions?: readonly string[] | undefined;\n projectRoot: string;\n publicAssetBaseUrl?: string | undefined;\n publicDir: string;\n routesDir: string;\n}\n\nexport function resolveAppRouterProjectOptions(\n options: AppRouterProjectOptions,\n): ResolvedAppRouterProject {\n const clientConsolePureFunctions = resolveClientConsolePureFunctions(\n options.production?.dropClientConsole,\n );\n\n if (\n options.appDir !== undefined &&\n options.projectRoot === undefined &&\n options.routesDir === undefined\n ) {\n const appDir = resolve(options.appDir);\n\n return {\n allowedSourceDirs: (options.allowedSourceDirs ?? [appDir]).map((directory) =>\n resolveProjectPath(appDir, directory, \"allowedSourceDirs\"),\n ),\n ...(options.assetBaseUrl === undefined ? {} : { assetBaseUrl: options.assetBaseUrl }),\n ...(options.buildConcurrency === undefined\n ? {}\n : { buildConcurrency: options.buildConcurrency }),\n buildTargets: resolveBuildTargets(options.buildTargets),\n clientSourceMaps: resolveClientSourceMapMode(options.clientSourceMaps),\n ...(clientConsolePureFunctions === undefined ? {} : { clientConsolePureFunctions }),\n projectRoot: appDir,\n ...(options.publicAssetBaseUrl === undefined\n ? {}\n : { publicAssetBaseUrl: options.publicAssetBaseUrl }),\n publicDir: resolveProjectPath(appDir, options.publicDir ?? \"public\", \"publicDir\"),\n routesDir: appDir,\n };\n }\n\n const projectRoot = resolve(options.projectRoot ?? process.cwd());\n const routesDir = resolveProjectPath(projectRoot, options.routesDir ?? \"src/app\", \"routesDir\");\n const defaultAllowedSourceDirs =\n options.routesDir === undefined ? [\"src\"] : [defaultAllowedSourceDir(projectRoot, routesDir)];\n\n return {\n allowedSourceDirs: (options.allowedSourceDirs ?? defaultAllowedSourceDirs).map((directory) =>\n resolveProjectPath(projectRoot, directory, \"allowedSourceDirs\"),\n ),\n ...(options.assetBaseUrl === undefined ? {} : { assetBaseUrl: options.assetBaseUrl }),\n ...(options.buildConcurrency === undefined\n ? {}\n : { buildConcurrency: options.buildConcurrency }),\n buildTargets: resolveBuildTargets(options.buildTargets),\n clientSourceMaps: resolveClientSourceMapMode(options.clientSourceMaps),\n ...(clientConsolePureFunctions === undefined ? {} : { clientConsolePureFunctions }),\n projectRoot,\n ...(options.publicAssetBaseUrl === undefined\n ? {}\n : { publicAssetBaseUrl: options.publicAssetBaseUrl }),\n publicDir: resolveProjectPath(projectRoot, options.publicDir ?? \"public\", \"publicDir\"),\n routesDir,\n };\n}\n\nfunction defaultAllowedSourceDir(projectRoot: string, routesDir: string): string {\n const sourceRoot = dirname(routesDir);\n return basename(routesDir) === \"app\" && sourceRoot !== projectRoot ? sourceRoot : routesDir;\n}\n\nconst defaultDroppedClientConsoleMethods = [\"debug\", \"info\", \"log\"] as const;\nconst supportedClientConsoleMethods = new Set<AppRouterClientConsoleMethod>([\n \"debug\",\n \"error\",\n \"info\",\n \"log\",\n \"trace\",\n \"warn\",\n]);\n\nexport function resolveClientConsolePureFunctions(\n value: AppRouterProductionOptions[\"dropClientConsole\"],\n): readonly string[] | undefined {\n if (value === undefined || value === false) {\n return undefined;\n }\n\n const methods = value === true ? defaultDroppedClientConsoleMethods : value;\n const uniqueMethods = [...new Set(methods)];\n\n for (const method of uniqueMethods) {\n if (!supportedClientConsoleMethods.has(method)) {\n throw new Error(\n `Unsupported mreactRouter production.dropClientConsole method ${JSON.stringify(method)}. Expected \"debug\", \"error\", \"info\", \"log\", \"trace\", or \"warn\".`,\n );\n }\n }\n\n return uniqueMethods.length === 0\n ? undefined\n : uniqueMethods.map((method) => `console.${method}`);\n}\n\nexport function resolveClientSourceMapMode(\n value: AppRouterClientSourceMapOption | undefined,\n): AppRouterClientSourceMapMode {\n if (value === undefined || value === false || value === \"none\") {\n return \"none\";\n }\n\n if (value === true || value === \"linked\") {\n return \"linked\";\n }\n\n if (value === \"hidden\") {\n return \"hidden\";\n }\n\n throw new Error(\n `Unsupported mreactRouter clientSourceMaps value ${JSON.stringify(value)}. Expected false, true, \"none\", \"hidden\", or \"linked\".`,\n );\n}\n\nexport function resolveBuildTargets(\n targets: readonly AppRouterBuildTarget[] | undefined,\n): readonly AppRouterBuildTarget[] {\n if (targets === undefined) {\n return appRouterBuildTargetMetadata.defaultTargets;\n }\n\n const uniqueTargets = [...new Set(targets)];\n\n if (uniqueTargets.length === 0) {\n throw new Error(\"mreactRouter buildTargets must include at least one target.\");\n }\n\n for (const target of uniqueTargets) {\n if (!appRouterBuildTargetMetadata.allTargets.some((supported) => supported === target)) {\n throw new Error(\n `Unsupported mreactRouter build target ${JSON.stringify(target)}. Expected \"node\", \"cloudflare\", or \"aws-lambda\".`,\n );\n }\n }\n\n return uniqueTargets;\n}\n\nfunction resolveProjectPath(root: string, path: string, optionName: string): string {\n const resolvedPath = resolvePath(root, path);\n\n if (!isInsideDirectory(root, resolvedPath)) {\n throw new Error(\n `mreactRouter ${optionName} must resolve inside projectRoot. projectRoot: ${root}; ${optionName}: ${resolvedPath}`,\n );\n }\n\n return resolvedPath;\n}\n\nfunction resolvePath(root: string, path: string): string {\n return isAbsolute(path) ? resolve(path) : resolve(root, path);\n}\n\nfunction isInsideDirectory(root: string, path: string): boolean {\n const relativePath = relative(root, path);\n\n return relativePath === \"\" || (!relativePath.startsWith(\"..\") && !isAbsolute(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AkB,CAAC,IAAY,EAAE,IAAY,EAAE,UAAkB;IACxE,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE7C,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CACb,gBAAgB,UAAU,kDAAkD,IAAI,KAAK,UAAU,KAAK,YAAY,EAAE,CACnH,CAAC;IACJ,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,IAAY;IAC7C,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY,EAAE,IAAY;IACnD,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE1C,OAAO,YAAY,KAAK,EAAE,IAAI,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["import { basename, dirname, isAbsolute, relative, resolve } from \"node:path\";\n\n/**\n * Selects the deployment runtime artifacts emitted by an app-router build.\n */\nexport type AppRouterBuildTarget = \"node\" | \"cloudflare\" | \"aws-lambda\";\n\nexport const appRouterBuildTargetMetadata = {\n allTargets: [\"node\", \"cloudflare\", \"aws-lambda\"],\n defaultTargets: [\"node\"],\n} as const satisfies {\n allTargets: readonly AppRouterBuildTarget[];\n defaultTargets: readonly AppRouterBuildTarget[];\n};\n/**\n * Names a browser console method that can be stripped from client bundles.\n */\nexport type AppRouterClientConsoleMethod = \"debug\" | \"error\" | \"info\" | \"log\" | \"trace\" | \"warn\";\n/**\n * Controls how client bundle source maps are generated.\n */\nexport type AppRouterClientSourceMapMode = \"none\" | \"hidden\" | \"linked\";\n/**\n * Configures client source map output with a boolean shortcut or explicit mode.\n */\nexport type AppRouterClientSourceMapOption = boolean | AppRouterClientSourceMapMode;\n\n/**\n * Configures production-only app-router build behavior.\n */\nexport interface AppRouterProductionOptions {\n dropClientConsole?: boolean | readonly AppRouterClientConsoleMethod[] | undefined;\n}\n\nexport interface AppRouterProjectOptions {\n assetBaseUrl?: string | undefined;\n buildConcurrency?: number | undefined;\n buildTargets?: readonly AppRouterBuildTarget[] | undefined;\n clientSourceMaps?: AppRouterClientSourceMapOption | undefined;\n /** Project-local server module exporting a named `dehydrateOptions` policy. */\n dehydratePolicyModule?: string | undefined;\n /**\n * Legacy route root. When provided without routesDir/projectRoot, this keeps\n * the historical \"appDir is the whole app boundary\" behavior.\n *\n * @deprecated Use projectRoot + routesDir instead. The legacy appDir shortcut\n * is kept for direct tests and older programmatic callers and is planned for\n * removal after 0.1.0.\n */\n appDir?: string | undefined;\n allowedSourceDirs?: readonly string[] | undefined;\n projectRoot?: string | undefined;\n production?: AppRouterProductionOptions | undefined;\n publicDir?: string | undefined;\n publicAssetBaseUrl?: string | undefined;\n routesDir?: string | undefined;\n}\n\nexport interface ResolvedAppRouterProject {\n allowedSourceDirs: readonly string[];\n assetBaseUrl?: string | undefined;\n buildConcurrency?: number | undefined;\n buildTargets: readonly AppRouterBuildTarget[];\n clientSourceMaps: AppRouterClientSourceMapMode;\n clientConsolePureFunctions?: readonly string[] | undefined;\n dehydratePolicyModule?: string | undefined;\n projectRoot: string;\n publicAssetBaseUrl?: string | undefined;\n publicDir: string;\n routesDir: string;\n}\n\nexport function resolveAppRouterProjectOptions(\n options: AppRouterProjectOptions,\n): ResolvedAppRouterProject {\n const clientConsolePureFunctions = resolveClientConsolePureFunctions(\n options.production?.dropClientConsole,\n );\n\n if (\n options.appDir !== undefined &&\n options.projectRoot === undefined &&\n options.routesDir === undefined\n ) {\n const appDir = resolve(options.appDir);\n const allowedSourceDirs = (options.allowedSourceDirs ?? [appDir]).map((directory) =>\n resolveProjectPath(appDir, directory, \"allowedSourceDirs\"),\n );\n\n return {\n allowedSourceDirs,\n ...(options.assetBaseUrl === undefined ? {} : { assetBaseUrl: options.assetBaseUrl }),\n ...(options.buildConcurrency === undefined\n ? {}\n : { buildConcurrency: options.buildConcurrency }),\n buildTargets: resolveBuildTargets(options.buildTargets),\n clientSourceMaps: resolveClientSourceMapMode(options.clientSourceMaps),\n ...(clientConsolePureFunctions === undefined ? {} : { clientConsolePureFunctions }),\n ...(options.dehydratePolicyModule === undefined\n ? {}\n : {\n dehydratePolicyModule: resolvePolicyModule(\n appDir,\n options.dehydratePolicyModule,\n allowedSourceDirs,\n ),\n }),\n projectRoot: appDir,\n ...(options.publicAssetBaseUrl === undefined\n ? {}\n : { publicAssetBaseUrl: options.publicAssetBaseUrl }),\n publicDir: resolveProjectPath(appDir, options.publicDir ?? \"public\", \"publicDir\"),\n routesDir: appDir,\n };\n }\n\n const projectRoot = resolve(options.projectRoot ?? process.cwd());\n const routesDir = resolveProjectPath(projectRoot, options.routesDir ?? \"src/app\", \"routesDir\");\n const defaultAllowedSourceDirs =\n options.routesDir === undefined ? [\"src\"] : [defaultAllowedSourceDir(projectRoot, routesDir)];\n const allowedSourceDirs = (options.allowedSourceDirs ?? defaultAllowedSourceDirs).map(\n (directory) => resolveProjectPath(projectRoot, directory, \"allowedSourceDirs\"),\n );\n\n return {\n allowedSourceDirs,\n ...(options.assetBaseUrl === undefined ? {} : { assetBaseUrl: options.assetBaseUrl }),\n ...(options.buildConcurrency === undefined\n ? {}\n : { buildConcurrency: options.buildConcurrency }),\n buildTargets: resolveBuildTargets(options.buildTargets),\n clientSourceMaps: resolveClientSourceMapMode(options.clientSourceMaps),\n ...(clientConsolePureFunctions === undefined ? {} : { clientConsolePureFunctions }),\n ...(options.dehydratePolicyModule === undefined\n ? {}\n : {\n dehydratePolicyModule: resolvePolicyModule(\n projectRoot,\n options.dehydratePolicyModule,\n allowedSourceDirs,\n ),\n }),\n projectRoot,\n ...(options.publicAssetBaseUrl === undefined\n ? {}\n : { publicAssetBaseUrl: options.publicAssetBaseUrl }),\n publicDir: resolveProjectPath(projectRoot, options.publicDir ?? \"public\", \"publicDir\"),\n routesDir,\n };\n}\n\nfunction resolvePolicyModule(\n projectRoot: string,\n modulePath: string,\n allowedSourceDirs: readonly string[],\n): string {\n const resolvedModule = resolveProjectPath(projectRoot, modulePath, \"dehydratePolicyModule\");\n if (!allowedSourceDirs.some((directory) => isInsideDirectory(directory, resolvedModule))) {\n throw new Error(\n `mreactRouter dehydratePolicyModule must resolve inside allowedSourceDirs: ${resolvedModule}`,\n );\n }\n return resolvedModule;\n}\n\nfunction defaultAllowedSourceDir(projectRoot: string, routesDir: string): string {\n const sourceRoot = dirname(routesDir);\n return basename(routesDir) === \"app\" && sourceRoot !== projectRoot ? sourceRoot : routesDir;\n}\n\nconst defaultDroppedClientConsoleMethods = [\"debug\", \"info\", \"log\"] as const;\nconst supportedClientConsoleMethods = new Set<AppRouterClientConsoleMethod>([\n \"debug\",\n \"error\",\n \"info\",\n \"log\",\n \"trace\",\n \"warn\",\n]);\n\nexport function resolveClientConsolePureFunctions(\n value: AppRouterProductionOptions[\"dropClientConsole\"],\n): readonly string[] | undefined {\n if (value === undefined || value === false) {\n return undefined;\n }\n\n const methods = value === true ? defaultDroppedClientConsoleMethods : value;\n const uniqueMethods = [...new Set(methods)];\n\n for (const method of uniqueMethods) {\n if (!supportedClientConsoleMethods.has(method)) {\n throw new Error(\n `Unsupported mreactRouter production.dropClientConsole method ${JSON.stringify(method)}. Expected \"debug\", \"error\", \"info\", \"log\", \"trace\", or \"warn\".`,\n );\n }\n }\n\n return uniqueMethods.length === 0\n ? undefined\n : uniqueMethods.map((method) => `console.${method}`);\n}\n\nexport function resolveClientSourceMapMode(\n value: AppRouterClientSourceMapOption | undefined,\n): AppRouterClientSourceMapMode {\n if (value === undefined || value === false || value === \"none\") {\n return \"none\";\n }\n\n if (value === true || value === \"linked\") {\n return \"linked\";\n }\n\n if (value === \"hidden\") {\n return \"hidden\";\n }\n\n throw new Error(\n `Unsupported mreactRouter clientSourceMaps value ${JSON.stringify(value)}. Expected false, true, \"none\", \"hidden\", or \"linked\".`,\n );\n}\n\nexport function resolveBuildTargets(\n targets: readonly AppRouterBuildTarget[] | undefined,\n): readonly AppRouterBuildTarget[] {\n if (targets === undefined) {\n return appRouterBuildTargetMetadata.defaultTargets;\n }\n\n const uniqueTargets = [...new Set(targets)];\n\n if (uniqueTargets.length === 0) {\n throw new Error(\"mreactRouter buildTargets must include at least one target.\");\n }\n\n for (const target of uniqueTargets) {\n if (!appRouterBuildTargetMetadata.allTargets.some((supported) => supported === target)) {\n throw new Error(\n `Unsupported mreactRouter build target ${JSON.stringify(target)}. Expected \"node\", \"cloudflare\", or \"aws-lambda\".`,\n );\n }\n }\n\n return uniqueTargets;\n}\n\nfunction resolveProjectPath(root: string, path: string, optionName: string): string {\n const resolvedPath = resolvePath(root, path);\n\n if (!isInsideDirectory(root, resolvedPath)) {\n throw new Error(\n `mreactRouter ${optionName} must resolve inside projectRoot. projectRoot: ${root}; ${optionName}: ${resolvedPath}`,\n );\n }\n\n return resolvedPath;\n}\n\nfunction resolvePath(root: string, path: string): string {\n return isAbsolute(path) ? resolve(path) : resolve(root, path);\n}\n\nfunction isInsideDirectory(root: string, path: string): boolean {\n const relativePath = relative(root, path);\n\n return relativePath === \"\" || (!relativePath.startsWith(\"..\") && !isAbsolute(relativePath));\n}\n"]}
|
package/dist/csp.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export interface ContentSecurityPolicyInput {
|
|
|
5
5
|
remove?: readonly string[];
|
|
6
6
|
replace?: Record<string, readonly string[] | string>;
|
|
7
7
|
}
|
|
8
|
+
export declare function responseHeadersContainCspNonce(headers: Headers): boolean;
|
|
8
9
|
export declare function contentSecurityPolicy(csp: ContentSecurityPolicyInput | undefined): string | undefined;
|
|
9
10
|
//# sourceMappingURL=csp.d.ts.map
|
package/dist/csp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csp.d.ts","sourceRoot":"","sources":["../src/csp.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,0BAA0B;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC;CACtD;
|
|
1
|
+
{"version":3,"file":"csp.d.ts","sourceRoot":"","sources":["../src/csp.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,0BAA0B;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC;CACtD;AAED,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CASxE;AAsCD,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,0BAA0B,GAAG,SAAS,GAC1C,MAAM,GAAG,SAAS,CAoCpB"}
|
package/dist/csp.js
CHANGED
|
@@ -9,6 +9,15 @@
|
|
|
9
9
|
// Allowed directive value shape: no `;`, no quote, no whitespace, no ASCII
|
|
10
10
|
// control characters. Quoted-keyword forms (`'self'`, `'nonce-...'`,
|
|
11
11
|
// `'sha256-...'`, etc.) are accepted via the `'...'` allow-list pattern.
|
|
12
|
+
export function responseHeadersContainCspNonce(headers) {
|
|
13
|
+
for (const name of ["content-security-policy", "content-security-policy-report-only"]) {
|
|
14
|
+
const value = headers.get(name);
|
|
15
|
+
if (value !== null && /(?:^|[\s;,])'nonce-[^']+'(?=$|[\s;,])/i.test(value)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
12
21
|
const VALID_NONCE = /^[A-Za-z0-9+/=_-]+$/;
|
|
13
22
|
const VALID_DIRECTIVE_NAME = /^[a-z][a-z0-9-]*$/i;
|
|
14
23
|
// One CSP "source expression". Reject anything containing `;`, quote,
|
|
@@ -31,11 +40,7 @@ function isValidDirectiveValue(value) {
|
|
|
31
40
|
}
|
|
32
41
|
for (let index = 0; index < value.length; index += 1) {
|
|
33
42
|
const code = value.charCodeAt(index);
|
|
34
|
-
if (code <= 0x20 ||
|
|
35
|
-
code === 0x22 ||
|
|
36
|
-
code === 0x27 ||
|
|
37
|
-
code === 0x3b ||
|
|
38
|
-
code === 0x7f) {
|
|
43
|
+
if (code <= 0x20 || code === 0x22 || code === 0x27 || code === 0x3b || code === 0x7f) {
|
|
39
44
|
return false;
|
|
40
45
|
}
|
|
41
46
|
}
|
|
@@ -65,6 +70,6 @@ export function contentSecurityPolicy(csp) {
|
|
|
65
70
|
}
|
|
66
71
|
serialized.push(`${name} ${values.join(" ")}`);
|
|
67
72
|
}
|
|
68
|
-
return serialized.join("; ");
|
|
73
|
+
return serialized.length === 0 ? undefined : serialized.join("; ");
|
|
69
74
|
}
|
|
70
75
|
//# sourceMappingURL=csp.js.map
|
package/dist/csp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csp.js","sourceRoot":"","sources":["../src/csp.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,EAAE;AACF,wEAAwE;AACxE,sEAAsE;AACtE,yEAAyE;AACzE,qEAAqE;AACrE,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3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,CAAC,KAAK,GAAG,CAAC,CAAC;QACtC,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrE,CAAC","sourcesContent":["// CSP header serializer used by the App Router metadata pipeline.\n//\n// Validates both nonce and directive values before string-concatenating\n// them into the Content-Security-Policy header. Background: directive\n// concatenation with `; ` and quoted-source concatenation with `' '` are\n// trivially escapable if untrusted strings reach the metadata field.\n//\n// Allowed nonce shape: base64 / base64url alphabet only (`+/=` and `-_=`).\n// Allowed directive value shape: no `;`, no quote, no whitespace, no ASCII\n// control characters. Quoted-keyword forms (`'self'`, `'nonce-...'`,\n// `'sha256-...'`, etc.) are accepted via the `'...'` allow-list pattern.\n\nexport interface ContentSecurityPolicyInput {\n disable?: boolean;\n directives?: Record<string, readonly string[] | string>;\n nonce?: string;\n remove?: readonly string[];\n replace?: Record<string, readonly string[] | string>;\n}\n\nexport function responseHeadersContainCspNonce(headers: Headers): boolean {\n for (const name of [\"content-security-policy\", \"content-security-policy-report-only\"]) {\n const value = headers.get(name);\n if (value !== null && /(?:^|[\\s;,])'nonce-[^']+'(?=$|[\\s;,])/i.test(value)) {\n return true;\n }\n }\n\n return false;\n}\n\nconst VALID_NONCE = /^[A-Za-z0-9+/=_-]+$/;\nconst VALID_DIRECTIVE_NAME = /^[a-z][a-z0-9-]*$/i;\n// One CSP \"source expression\". Reject anything containing `;`, quote,\n// whitespace, or ASCII control characters. Quoted keywords like\n// `'self'`, `'unsafe-inline'`, `'nonce-XYZ='` are accepted via the\n// alternate `'...'` shape.\nconst VALID_QUOTED_DIRECTIVE_VALUE = /^'[A-Za-z0-9+/=_:.-]+'$/;\n\nfunction isValidNonce(nonce: string): boolean {\n return VALID_NONCE.test(nonce);\n}\n\nfunction isValidDirectiveName(name: string): boolean {\n return VALID_DIRECTIVE_NAME.test(name);\n}\n\nfunction isValidDirectiveValue(value: string): boolean {\n if (VALID_QUOTED_DIRECTIVE_VALUE.test(value)) {\n return true;\n }\n\n if (value.length === 0) {\n return false;\n }\n\n for (let index = 0; index < value.length; index += 1) {\n const code = value.charCodeAt(index);\n\n if (code <= 0x20 || code === 0x22 || code === 0x27 || code === 0x3b || code === 0x7f) {\n return false;\n }\n }\n\n return true;\n}\n\nexport function contentSecurityPolicy(\n csp: ContentSecurityPolicyInput | undefined,\n): string | undefined {\n if (csp?.disable === true || csp?.directives === undefined) {\n return undefined;\n }\n\n if (csp.nonce !== undefined && !isValidNonce(csp.nonce)) {\n throw new TypeError(\n `invalid CSP nonce: ${JSON.stringify(csp.nonce)} - must be base64 / base64url`,\n );\n }\n\n const serialized: string[] = [];\n\n for (const [name, value] of Object.entries(csp.directives)) {\n if (!isValidDirectiveName(name)) {\n throw new TypeError(`invalid CSP directive name: ${JSON.stringify(name)}`);\n }\n\n const rawValues = Array.isArray(value) ? [...value] : [value];\n\n for (const rawValue of rawValues) {\n if (typeof rawValue !== \"string\" || !isValidDirectiveValue(rawValue)) {\n throw new TypeError(`invalid CSP directive value for ${name}: ${JSON.stringify(rawValue)}`);\n }\n }\n\n const values = [...rawValues];\n\n if (csp.nonce !== undefined && (name === \"script-src\" || name === \"style-src\")) {\n values.push(`'nonce-${csp.nonce}'`);\n }\n\n serialized.push(`${name} ${values.join(\" \")}`);\n }\n\n return serialized.length === 0 ? undefined : serialized.join(\"; \");\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dehydrate-policy.d.ts","sourceRoot":"","sources":["../src/dehydrate-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,MAAM,GACZ,gBAAgB,CAiBlB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function dehydrateOptionsFromModule(module, label) {
|
|
2
|
+
if (module === null || typeof module !== "object" || !("dehydrateOptions" in module)) {
|
|
3
|
+
throw new Error(`${label} must export a named dehydrateOptions object.`);
|
|
4
|
+
}
|
|
5
|
+
const dehydrateOptions = module.dehydrateOptions;
|
|
6
|
+
if (dehydrateOptions === null || typeof dehydrateOptions !== "object") {
|
|
7
|
+
throw new Error(`${label} must export a named dehydrateOptions object.`);
|
|
8
|
+
}
|
|
9
|
+
const shouldDehydrateQuery = dehydrateOptions
|
|
10
|
+
.shouldDehydrateQuery;
|
|
11
|
+
if (shouldDehydrateQuery !== undefined && typeof shouldDehydrateQuery !== "function") {
|
|
12
|
+
throw new Error(`${label} dehydrateOptions.shouldDehydrateQuery must be a function.`);
|
|
13
|
+
}
|
|
14
|
+
return dehydrateOptions;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=dehydrate-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dehydrate-policy.js","sourceRoot":"","sources":["../src/dehydrate-policy.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,0BAA0B,CACxC,MAAe,EACf,KAAa;IAEb,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,kBAAkB,IAAI,MAAM,CAAC,EAAE,CAAC;QACrF,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,+CAA+C,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,gBAAgB,GAAI,MAAyC,CAAC,gBAAgB,CAAC;IACrF,IAAI,gBAAgB,KAAK,IAAI,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,+CAA+C,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,oBAAoB,GAAI,gBAAuD;SAClF,oBAAoB,CAAC;IACxB,IAAI,oBAAoB,KAAK,SAAS,IAAI,OAAO,oBAAoB,KAAK,UAAU,EAAE,CAAC;QACrF,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,4DAA4D,CAAC,CAAC;IACxF,CAAC;IAED,OAAO,gBAAoC,CAAC;AAC9C,CAAC","sourcesContent":["import type { DehydrateOptions } from \"@reckona/mreact-query\";\n\nexport function dehydrateOptionsFromModule(\n module: unknown,\n label: string,\n): DehydrateOptions {\n if (module === null || typeof module !== \"object\" || !(\"dehydrateOptions\" in module)) {\n throw new Error(`${label} must export a named dehydrateOptions object.`);\n }\n\n const dehydrateOptions = (module as { dehydrateOptions?: unknown }).dehydrateOptions;\n if (dehydrateOptions === null || typeof dehydrateOptions !== \"object\") {\n throw new Error(`${label} must export a named dehydrateOptions object.`);\n }\n\n const shouldDehydrateQuery = (dehydrateOptions as { shouldDehydrateQuery?: unknown })\n .shouldDehydrateQuery;\n if (shouldDehydrateQuery !== undefined && typeof shouldDehydrateQuery !== \"function\") {\n throw new Error(`${label} dehydrateOptions.shouldDehydrateQuery must be a function.`);\n }\n\n return dehydrateOptions as DehydrateOptions;\n}\n"]}
|
package/dist/dev-server.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { type Server } from "node:http";
|
|
2
|
+
import type { DehydrateOptions } from "@reckona/mreact-query";
|
|
2
3
|
import { type UserConfig } from "vite";
|
|
3
4
|
import type { AppRouterServerActionOptions } from "./actions.js";
|
|
4
5
|
import { type AppRouterCache } from "./cache.js";
|
|
5
6
|
import { type AppRouterProjectOptions } from "./config.js";
|
|
6
7
|
import type { AppRouterImportPolicy } from "./import-policy.js";
|
|
7
8
|
import { type AppRouterLogger } from "./logger.js";
|
|
8
|
-
import type
|
|
9
|
+
import { type HttpUpgradeOriginPolicy, type ManagedHttpUpgradeHandler } from "./upgrade.js";
|
|
9
10
|
/**
|
|
10
11
|
* Configures the Vite-powered app-router development server.
|
|
11
12
|
*/
|
|
12
13
|
export interface StartDevServerOptions extends AppRouterProjectOptions {
|
|
14
|
+
dehydrateOptions?: DehydrateOptions | undefined;
|
|
13
15
|
port?: number | undefined;
|
|
14
16
|
hostname?: string;
|
|
15
17
|
importPolicy?: AppRouterImportPolicy | undefined;
|
|
@@ -18,7 +20,10 @@ export interface StartDevServerOptions extends AppRouterProjectOptions {
|
|
|
18
20
|
serverActions?: AppRouterServerActionOptions | undefined;
|
|
19
21
|
verboseErrors?: boolean | undefined;
|
|
20
22
|
viteConfig?: UserConfig | undefined;
|
|
21
|
-
onUpgrade?:
|
|
23
|
+
onUpgrade?: ManagedHttpUpgradeHandler | undefined;
|
|
24
|
+
upgradeCloseTimeoutMs?: number | undefined;
|
|
25
|
+
upgradeDecisionTimeoutMs?: number | undefined;
|
|
26
|
+
upgradeOriginPolicy?: HttpUpgradeOriginPolicy | undefined;
|
|
22
27
|
}
|
|
23
28
|
/**
|
|
24
29
|
* Starts the local app-router development server with Vite middleware and route compilation.
|
package/dist/dev-server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAKtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAoC,KAAK,UAAU,EAAsB,MAAM,MAAM,CAAC;AAC7F,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAkC,KAAK,uBAAuB,EAAE,MAAM,aAAa,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-
import {
|
|
3
|
+
import { isIP } from "node:net";
|
|
4
|
+
import { posix, resolve } from "node:path";
|
|
4
5
|
import { createServer as createViteServer } from "vite";
|
|
5
6
|
import { createMemoryRouteCache } from "./cache.js";
|
|
6
7
|
import { resolveAppRouterProjectOptions } from "./config.js";
|
|
7
8
|
import { createAppRouterVitePlugin } from "./vite.js";
|
|
8
9
|
import { loadMreactRouterViteConfigDetails, } from "./vite-config.js";
|
|
9
10
|
import { emitRouterLog, logDurationMs, logNow, nodeRequestPath, } from "./logger.js";
|
|
11
|
+
import { assertValidHttpUpgradeOriginPolicy, closeServerWithUpgrades, createManagedHttpUpgradeLifecycle, validateHttpUpgradeOrigin, } from "./upgrade.js";
|
|
10
12
|
/**
|
|
11
13
|
* Starts the local app-router development server with Vite middleware and route compilation.
|
|
12
14
|
*
|
|
@@ -20,6 +22,9 @@ export async function startDevServer(options) {
|
|
|
20
22
|
const userViteServerConfig = typeof userViteConfig.server === "object" ? userViteConfig.server : {};
|
|
21
23
|
const userHmrConfig = typeof userViteServerConfig.hmr === "object" ? userViteServerConfig.hmr : {};
|
|
22
24
|
const port = options.port ?? resolved.serverPort ?? 3001;
|
|
25
|
+
const upgradeCloseTimeoutMs = finiteNonNegativeTimeout(options.upgradeCloseTimeoutMs, 1_000, "upgradeCloseTimeoutMs");
|
|
26
|
+
const upgradeDecisionTimeoutMs = finiteNonNegativeTimeout(options.upgradeDecisionTimeoutMs, 1_000, "upgradeDecisionTimeoutMs");
|
|
27
|
+
assertValidHttpUpgradeOriginPolicy(options.upgradeOriginPolicy);
|
|
23
28
|
const routeCache = options.routeCache ?? createMemoryRouteCache();
|
|
24
29
|
const declaredPackages = await readDeclaredProjectPackages(project.projectRoot);
|
|
25
30
|
const configImportPolicy = resolved.importPolicy;
|
|
@@ -35,6 +40,7 @@ export async function startDevServer(options) {
|
|
|
35
40
|
],
|
|
36
41
|
};
|
|
37
42
|
let vite;
|
|
43
|
+
let actualPort = port;
|
|
38
44
|
const server = createServer((incoming, outgoing) => {
|
|
39
45
|
const logger = options.logger;
|
|
40
46
|
const startedAt = logger === undefined ? undefined : logNow();
|
|
@@ -76,8 +82,17 @@ export async function startDevServer(options) {
|
|
|
76
82
|
outgoing.end("Not Found");
|
|
77
83
|
});
|
|
78
84
|
});
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
const upgradeLifecycle = options.onUpgrade === undefined
|
|
86
|
+
? undefined
|
|
87
|
+
: createManagedHttpUpgradeLifecycle({
|
|
88
|
+
decisionTimeoutMs: upgradeDecisionTimeoutMs,
|
|
89
|
+
handler: options.onUpgrade,
|
|
90
|
+
isOriginAllowed: (request) => validateDevUpgradeOrigin(request, options.upgradeOriginPolicy, hostname, actualPort, vite),
|
|
91
|
+
logger: options.logger,
|
|
92
|
+
shouldBypass: (request) => isViteHmrUpgradeRequest(request, vite),
|
|
93
|
+
});
|
|
94
|
+
if (upgradeLifecycle !== undefined) {
|
|
95
|
+
server.on("upgrade", upgradeLifecycle.handle);
|
|
81
96
|
}
|
|
82
97
|
vite = await createViteServer({
|
|
83
98
|
...userViteConfig,
|
|
@@ -93,6 +108,8 @@ export async function startDevServer(options) {
|
|
|
93
108
|
...(userViteConfig.plugins ?? []),
|
|
94
109
|
createAppRouterVitePlugin({
|
|
95
110
|
allowedSourceDirs: project.allowedSourceDirs,
|
|
111
|
+
dehydrateOptions: options.dehydrateOptions ?? resolved.dehydrateOptions,
|
|
112
|
+
dehydratePolicyModule: project.dehydratePolicyModule,
|
|
96
113
|
projectRoot: project.projectRoot,
|
|
97
114
|
publicDir: project.publicDir,
|
|
98
115
|
routesDir: project.routesDir,
|
|
@@ -111,18 +128,105 @@ export async function startDevServer(options) {
|
|
|
111
128
|
throw error;
|
|
112
129
|
}
|
|
113
130
|
const address = server.address();
|
|
114
|
-
|
|
131
|
+
actualPort = typeof address === "object" && address !== null ? address.port : port;
|
|
132
|
+
let closePromise;
|
|
115
133
|
return {
|
|
116
134
|
server,
|
|
117
|
-
url: `http://${hostname
|
|
118
|
-
close:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
135
|
+
url: `http://${formatNodeAuthority(hostname, actualPort)}`,
|
|
136
|
+
close: () => {
|
|
137
|
+
closePromise ??= (async () => {
|
|
138
|
+
upgradeLifecycle?.beginClose();
|
|
139
|
+
const httpClose = upgradeLifecycle === undefined
|
|
140
|
+
? new Promise((resolve, reject) => {
|
|
141
|
+
server.close((error) => (error ? reject(error) : resolve()));
|
|
142
|
+
})
|
|
143
|
+
: closeServerWithUpgrades({
|
|
144
|
+
lifecycle: upgradeLifecycle,
|
|
145
|
+
server,
|
|
146
|
+
timeoutMs: upgradeCloseTimeoutMs,
|
|
147
|
+
});
|
|
148
|
+
const results = await Promise.allSettled([vite?.close(), httpClose]);
|
|
149
|
+
const errors = results.flatMap((result) => result.status === "rejected" ? [result.reason] : []);
|
|
150
|
+
if (errors.length > 0) {
|
|
151
|
+
throw new AggregateError(errors, "Failed to close the mreact development server.");
|
|
152
|
+
}
|
|
153
|
+
})();
|
|
154
|
+
return closePromise;
|
|
123
155
|
},
|
|
124
156
|
};
|
|
125
157
|
}
|
|
158
|
+
function validateDevUpgradeOrigin(request, policy, hostname, port, vite) {
|
|
159
|
+
if (!isDevUpgradeHostAllowed(request.headers.host, vite?.config.server.allowedHosts)) {
|
|
160
|
+
return { ok: false, reason: "disallowed-origin" };
|
|
161
|
+
}
|
|
162
|
+
if (policy === "unchecked") {
|
|
163
|
+
return { ok: true, origin: request.headers.origin };
|
|
164
|
+
}
|
|
165
|
+
if (typeof policy === "object") {
|
|
166
|
+
return validateHttpUpgradeOrigin(request, policy);
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
return validateHttpUpgradeOrigin(request, {
|
|
170
|
+
allowedOrigins: [`http://${request.headers.host ?? formatNodeAuthority(hostname, port)}`],
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return { ok: false, reason: "malformed-origin" };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function isDevUpgradeHostAllowed(hostHeader, allowedHosts) {
|
|
178
|
+
if (allowedHosts === true || hostHeader === undefined) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
const host = hostHeader.trim();
|
|
182
|
+
if (host.startsWith("[")) {
|
|
183
|
+
const closingBracket = host.indexOf("]");
|
|
184
|
+
return closingBracket > 0 && isIP(host.slice(1, closingBracket)) === 6;
|
|
185
|
+
}
|
|
186
|
+
const colon = host.indexOf(":");
|
|
187
|
+
const hostname = colon === -1 ? host : host.slice(0, colon);
|
|
188
|
+
if (isIP(hostname) === 4 || hostname === "localhost" || hostname.endsWith(".localhost")) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
return (allowedHosts ?? []).some((allowedHost) => allowedHost === hostname ||
|
|
192
|
+
(allowedHost.startsWith(".") &&
|
|
193
|
+
(allowedHost.slice(1) === hostname || hostname.endsWith(allowedHost))));
|
|
194
|
+
}
|
|
195
|
+
function formatNodeAuthority(hostname, port) {
|
|
196
|
+
const host = hostname.includes(":") && !hostname.startsWith("[") ? `[${hostname}]` : hostname;
|
|
197
|
+
return `${host}:${port}`;
|
|
198
|
+
}
|
|
199
|
+
function isViteHmrUpgradeRequest(request, vite) {
|
|
200
|
+
if (vite === undefined) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
const protocol = request.headers["sec-websocket-protocol"];
|
|
204
|
+
if (protocol !== "vite-hmr" && protocol !== "vite-ping") {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
const hmr = vite.config.server.hmr;
|
|
208
|
+
if (hmr === false) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
const hmrPath = typeof hmr === "object" ? hmr.path : undefined;
|
|
212
|
+
const expectedPath = hmrPath === undefined ? vite.config.base : posix.join(vite.config.base, hmrPath);
|
|
213
|
+
try {
|
|
214
|
+
return new URL(request.url ?? "/", "http://mreact.local").pathname === expectedPath;
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function finiteNonNegativeTimeout(value, fallback, name) {
|
|
221
|
+
const timeout = value ?? fallback;
|
|
222
|
+
if (!Number.isFinite(timeout) ||
|
|
223
|
+
timeout < 0 ||
|
|
224
|
+
!Number.isSafeInteger(timeout) ||
|
|
225
|
+
timeout > 2_147_483_647) {
|
|
226
|
+
throw new TypeError(`${name} must be a finite non-negative safe integer no greater than 2147483647.`);
|
|
227
|
+
}
|
|
228
|
+
return timeout;
|
|
229
|
+
}
|
|
126
230
|
function listenDevHttpServer(server, port, hostname) {
|
|
127
231
|
return new Promise((resolve, reject) => {
|
|
128
232
|
const onError = (error) => {
|
|
@@ -156,6 +260,9 @@ async function resolveStartDevServerProject(options) {
|
|
|
156
260
|
}
|
|
157
261
|
const config = await loadOptionalMreactRouterViteConfig(resolve(options.projectRoot ?? process.cwd()));
|
|
158
262
|
return {
|
|
263
|
+
...(config?.dehydrateOptions === undefined
|
|
264
|
+
? {}
|
|
265
|
+
: { dehydrateOptions: config.dehydrateOptions }),
|
|
159
266
|
...(config?.importPolicy === undefined ? {} : { importPolicy: config.importPolicy }),
|
|
160
267
|
project: resolveAppRouterProjectOptions({
|
|
161
268
|
...config?.project,
|
|
@@ -208,7 +315,9 @@ function sendDevServerError(outgoing, error, options) {
|
|
|
208
315
|
outgoing.statusCode = 500;
|
|
209
316
|
outgoing.setHeader("content-type", "text/plain; charset=utf-8");
|
|
210
317
|
outgoing.end(options.verboseErrors === true
|
|
211
|
-
? error instanceof Error
|
|
318
|
+
? error instanceof Error
|
|
319
|
+
? error.stack
|
|
320
|
+
: String(error)
|
|
212
321
|
: "Internal Server Error");
|
|
213
322
|
}
|
|
214
323
|
//# sourceMappingURL=dev-server.js.map
|