vite-plugin-react-server 0.3.9 → 0.3.11
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/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/package.json +2 -4
- package/dist/plugin/assertServerCondition.d.ts +5 -1
- package/dist/plugin/assertServerCondition.d.ts.map +1 -1
- package/dist/plugin/assertServerCondition.js +1 -3
- package/dist/plugin/checkFilesExist.js +10 -7
- package/dist/plugin/checkFilesExist.js.map +1 -1
- package/dist/plugin/components.js +1 -1
- package/dist/plugin/components.js.map +1 -1
- package/dist/plugin/config/createModuleIdGenerator.d.ts +11 -0
- package/dist/plugin/config/createModuleIdGenerator.d.ts.map +1 -0
- package/dist/plugin/config/createModuleIdGenerator.js +44 -0
- package/dist/plugin/config/createModuleIdGenerator.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +31 -19
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +22 -27
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +202 -16
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +2 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts +2 -2
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +161 -50
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts +20 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -0
- package/dist/plugin/helpers/getBundleManifest.js +43 -0
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -0
- package/dist/plugin/helpers/getModuleManifest.d.ts +5 -0
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getModuleManifest.js +20 -21
- package/dist/plugin/helpers/inputNormalizer.d.ts +15 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +122 -16
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +2 -1
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizerWorker.js +10 -7
- package/dist/plugin/helpers/tryManifest.d.ts +2 -0
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +1 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +6 -2
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +35 -10
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/createPageLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createPageLoader.js +0 -7
- package/dist/plugin/plugin.d.ts +0 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +2 -1
- package/dist/plugin/preserver/plugin.d.ts.map +1 -1
- package/dist/plugin/preserver/plugin.js +3 -2
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/index.d.ts +2 -1
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +19 -1
- package/dist/plugin/react-client/index.js.map +1 -0
- package/dist/plugin/react-client/plugin.d.ts +2 -2
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +106 -10
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/createHandler.d.ts +2 -2
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createHandler.js +5 -5
- package/dist/plugin/react-server/createHandler.js.map +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
- package/dist/plugin/react-server/createRscStream.js +15 -1
- package/dist/plugin/react-server/createRscStream.js.map +1 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts +2 -2
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createSsrHandler.js +5 -12
- package/dist/plugin/react-server/index.js +18 -9
- package/dist/plugin/react-server/index.js.map +1 -0
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +133 -127
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.d.ts +2 -1
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +52 -72
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/transformer-client-components.d.ts +12 -3
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +1 -1
- package/dist/plugin/transformer/transformer-client-components.js +71 -10
- package/dist/plugin/transformer/transformer-client-components.js.map +1 -1
- package/dist/plugin/transformer/transformer-server-actions.d.ts +3 -3
- package/dist/plugin/transformer/transformer-server-actions.d.ts.map +1 -1
- package/dist/plugin/transformer/transformer-server-actions.js +80 -66
- package/dist/plugin/transformer/types.d.ts +4 -0
- package/dist/plugin/transformer/types.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +51 -20
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +37 -23
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/html/plugin.js +10 -5
- package/dist/plugin/worker/html/renderPages.d.ts +7 -6
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +112 -57
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/loader.d.ts +1 -11
- package/dist/plugin/worker/loader.d.ts.map +1 -1
- package/dist/plugin/worker/loader.js +2 -2
- package/dist/plugin/worker/loader.js.map +1 -1
- package/dist/plugin/worker/plugin.d.ts +10 -1
- package/dist/plugin/worker/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/plugin.js +10 -1
- package/dist/plugin/worker/types.d.ts +17 -4
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.d.ts +1 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -3
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -4
- package/plugin/assertServerCondition.ts +2 -3
- package/plugin/checkFilesExist.ts +10 -10
- package/plugin/components.tsx +1 -1
- package/plugin/config/createModuleIdGenerator.ts +52 -0
- package/plugin/config/defaults.ts +24 -15
- package/plugin/config/resolveOptions.ts +253 -25
- package/plugin/config/resolvePages.ts +1 -1
- package/plugin/config/resolveUserConfig.ts +197 -62
- package/plugin/helpers/getBundleManifest.ts +75 -0
- package/plugin/helpers/getModuleManifest.ts +5 -0
- package/plugin/helpers/inputNormalizer.ts +175 -26
- package/plugin/helpers/inputNormalizerWorker.ts +13 -8
- package/plugin/helpers/tryManifest.ts +2 -0
- package/plugin/loader/createBuildLoader.ts +54 -10
- package/plugin/loader/createPageLoader.ts +1 -7
- package/plugin/plugin.ts +2 -1
- package/plugin/preserver/plugin.ts +2 -1
- package/plugin/react-client/index.ts +12 -1
- package/plugin/react-client/plugin.ts +127 -12
- package/plugin/react-server/createHandler.ts +7 -13
- package/plugin/react-server/createRscStream.ts +14 -2
- package/plugin/react-server/createSsrHandler.ts +7 -26
- package/plugin/react-server/plugin.ts +176 -144
- package/plugin/transformer/plugin.ts +69 -94
- package/plugin/transformer/transformer-client-components.ts +98 -24
- package/plugin/transformer/transformer-server-actions.ts +22 -7
- package/plugin/transformer/types.ts +4 -0
- package/plugin/types.ts +118 -64
- package/plugin/worker/html/messageHandler.ts +46 -31
- package/plugin/worker/html/plugin.ts +15 -11
- package/plugin/worker/html/renderPages.ts +175 -88
- package/plugin/worker/loader.ts +4 -13
- package/plugin/worker/plugin.ts +10 -1
- package/plugin/worker/types.ts +24 -3
- package/dist/node_modules/magic-string/dist/magic-string.es.js +0 -1283
- package/dist/node_modules/magic-string/dist/magic-string.es.js.map +0 -1
- package/dist/plugin/build/createClientBuildConfig.d.ts +0 -3
- package/dist/plugin/build/createClientBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createClientBuildConfig.js +0 -14
- package/dist/plugin/build/createServerBuildConfig.d.ts +0 -12
- package/dist/plugin/build/createServerBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createServerBuildConfig.js +0 -40
- package/dist/plugin/build/createSharedBuildConfig.d.ts +0 -5
- package/dist/plugin/build/createSharedBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createSharedBuildConfig.js +0 -28
- package/dist/plugin/build/mergeInputs.d.ts +0 -9
- package/dist/plugin/build/mergeInputs.d.ts.map +0 -1
- package/dist/plugin/build/mergeInputs.js +0 -56
- package/dist/plugin/config/moduleIdDefault.d.ts +0 -8
- package/dist/plugin/config/moduleIdDefault.d.ts.map +0 -1
- package/dist/plugin/config/moduleIdDefault.js +0 -23
- package/dist/plugin/config/moduleIdDefault.js.map +0 -1
- package/dist/plugin/helpers/getModuleManifest.js.map +0 -1
- package/dist/plugin/react-server/createDevMiddleware.d.ts +0 -8
- package/dist/plugin/react-server/createDevMiddleware.d.ts.map +0 -1
- package/dist/plugin/react-server/createDevMiddleware.js +0 -68
- package/dist/plugin/react-server/createDevServer.d.ts +0 -4
- package/dist/plugin/react-server/createDevServer.d.ts.map +0 -1
- package/dist/plugin/react-server/createDevServer.js +0 -4
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts +0 -10
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +0 -1
- package/dist/plugin/react-server/createReactNodeStreamer.js +0 -7
- package/dist/plugin/transformer/transformer-server-actions.js.map +0 -1
- package/plugin/build/createClientBuildConfig.ts +0 -21
- package/plugin/build/createServerBuildConfig.ts +0 -66
- package/plugin/build/createSharedBuildConfig.ts +0 -35
- package/plugin/build/mergeInputs.ts +0 -58
- package/plugin/config/moduleIdDefault.ts +0 -23
- package/plugin/react-server/createDevMiddleware.ts +0 -91
- package/plugin/react-server/createDevServer.ts +0 -9
- package/plugin/react-server/createReactNodeStreamer.ts +0 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../../plugin/preserver/plugin.ts"],"sourcesContent":["import type { Node } from \"estree\";\nimport MagicString from \"magic-string\";\nimport type { StreamPluginOptions } from \"../types.js\";\n\nconst REACT_DIRECTIVES = new Set([\"use client\", \"use server\"]);\n\nexport function reactPreservePlugin(_options: StreamPluginOptions): import(\"vite\").Plugin {\n const meta: Record<string, Set<string>> = {};\n\n return {\n name: \"vite-plugin-react-server:preserve-directives\",\n enforce: \"post\",\n\n transform: {\n order: \"post\", // Ensure this runs last in transform phase\n handler(code: string, id: string) {\n // Skip node_modules and vite files\n if (id.includes(\"node_modules\") || id.includes(\"vite/dist\")) {\n return null;\n }\n\n let ast: Node;\n try {\n ast = this.parse(code, {\n allowReturnOutsideFunction: true,\n jsx: true,\n }) as Node;\n } catch (e) {\n console.warn(`[PreservePlugin] Failed to parse ${id}`, e);\n return null;\n }\n\n if (ast.type !== \"Program\") {\n return null;\n }\n\n const magicString = new MagicString(code);\n let hasChanged = false;\n\n // Only look at top-level directives\n for (const node of ast.body) {\n if (node.type !== \"ExpressionStatement\") {\n break;\n }\n\n let directive: string | null = null;\n if (\"directive\" in node) {\n directive = node.directive;\n } else if (\n node.expression.type === \"Literal\" &&\n typeof node.expression.value === \"string\" &&\n REACT_DIRECTIVES.has(node.expression.value)\n ) {\n directive = node.expression.value;\n }\n\n if (directive) {\n meta[id] ||= new Set<string>();\n meta[id].add(directive);\n\n if (\"start\" in node && \"end\" in node) {\n magicString.remove(node.start as number, node.end as number);\n hasChanged = true;\n }\n }\n }\n\n if (!hasChanged) {\n return null;\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap({ hires: true }),\n meta: {\n directives: Array.from(meta[id] || []),\n },\n };\n },\n },\n\n renderChunk(code, chunk) {\n const chunkDirectives = new Set<string>();\n\n // Collect directives from all modules in chunk\n for (const id of chunk.moduleIds) {\n if (meta[id]) {\n meta[id].forEach((d) => chunkDirectives.add(d));\n }\n }\n\n if (chunkDirectives.size) {\n const magicString = new MagicString(code);\n magicString.prepend(\n Array.from(chunkDirectives)\n .map((d) => `\"${d}\";`)\n .join(\"\\n\") + \"\\n\"\n );\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap({ hires: true }),\n };\n }\n\n return null;\n },\n };\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../../plugin/preserver/plugin.ts"],"sourcesContent":["import type { Node } from \"estree\";\nimport MagicString from \"magic-string\";\nimport type { StreamPluginOptions } from \"../types.js\";\nimport { DEFAULT_CONFIG } from \"../config/defaults.js\";\n\nconst REACT_DIRECTIVES = new Set([\"use client\", \"use server\"]);\n\nexport function reactPreservePlugin(_options: StreamPluginOptions): import(\"vite\").Plugin {\n const meta: Record<string, Set<string>> = {};\n\n return {\n name: \"vite-plugin-react-server:preserve-directives\",\n enforce: \"post\",\n\n transform: {\n order: \"post\", // Ensure this runs last in transform phase\n handler(code: string, id: string) {\n // Skip node_modules and vite files\n if (id.includes(\"node_modules\") || id.includes(\"vite/dist\") || !id.match(DEFAULT_CONFIG.FILE_REGEX)) {\n return null;\n }\n\n let ast: Node;\n try {\n ast = this.parse(code, {\n allowReturnOutsideFunction: true,\n jsx: true,\n }) as Node;\n } catch (e) {\n console.warn(`[PreservePlugin] Failed to parse ${id}`, e);\n return null;\n }\n\n if (ast.type !== \"Program\") {\n return null;\n }\n\n const magicString = new MagicString(code);\n let hasChanged = false;\n\n // Only look at top-level directives\n for (const node of ast.body) {\n if (node.type !== \"ExpressionStatement\") {\n break;\n }\n\n let directive: string | null = null;\n if (\"directive\" in node) {\n directive = node.directive;\n } else if (\n node.expression.type === \"Literal\" &&\n typeof node.expression.value === \"string\" &&\n REACT_DIRECTIVES.has(node.expression.value)\n ) {\n directive = node.expression.value;\n }\n\n if (directive) {\n meta[id] ||= new Set<string>();\n meta[id].add(directive);\n\n if (\"start\" in node && \"end\" in node) {\n magicString.remove(node.start as number, node.end as number);\n hasChanged = true;\n }\n }\n }\n\n if (!hasChanged) {\n return null;\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap({ hires: true }),\n meta: {\n directives: Array.from(meta[id] || []),\n },\n };\n },\n },\n\n renderChunk(code, chunk) {\n const chunkDirectives = new Set<string>();\n\n // Collect directives from all modules in chunk\n for (const id of chunk.moduleIds) {\n if (meta[id]) {\n meta[id].forEach((d) => chunkDirectives.add(d));\n }\n }\n\n if (chunkDirectives.size) {\n const magicString = new MagicString(code);\n magicString.prepend(\n Array.from(chunkDirectives)\n .map((d) => `\"${d}\";`)\n .join(\"\\n\") + \"\\n\"\n );\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap({ hires: true }),\n };\n }\n\n return null;\n },\n };\n}\n"],"names":[],"mappings":";;;;;;;;AAKA,MAAM,mCAAuB,IAAA,GAAA,CAAI,CAAC,YAAA,EAAc,YAAY,CAAC,CAAA;AAEtD,SAAS,oBAAoB,QAAsD,EAAA;AACxF,EAAA,MAAM,OAAoC,EAAC;AAE3C,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,8CAAA;AAAA,IACN,OAAS,EAAA,MAAA;AAAA,IAET,SAAW,EAAA;AAAA,MACT,KAAO,EAAA,MAAA;AAAA;AAAA,MACP,OAAA,CAA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I,CAAI,GAAA;AAAA,SAClB;AAEA,QAAO,OAAA;AAAA,UACL,IAAA,EAAM,YAAY,QAAS,EAAA;AAAA,UAC3B,KAAK,WAAY,CAAA,WAAA,CAAY,EAAE,KAAA,EAAO,MAAM;AAAA,SAC9C;AAAA;AAGF,MAAO,OAAA,IAAA;AAAA;AACT,GACF;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../plugin/react-client/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../plugin/react-client/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,wBAAgB,qBAAqB,CAAC,OAAO,GAAS,mBAAmB,GAAG,OAAO,MAAM,EAAE,MAAM,EAAE,CAMhG"}
|
|
@@ -1 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { reactTransformPlugin } from '../transformer/plugin.js';
|
|
7
|
+
import { reactClientPlugin } from './plugin.js';
|
|
8
|
+
import { reactPreservePlugin } from '../preserver/plugin.js';
|
|
9
|
+
|
|
10
|
+
function vitePluginReactClient(options = {}) {
|
|
11
|
+
return [
|
|
12
|
+
reactPreservePlugin(),
|
|
13
|
+
reactClientPlugin(options),
|
|
14
|
+
reactTransformPlugin(options)
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { vitePluginReactClient };
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../plugin/react-client/index.ts"],"sourcesContent":["import { reactPreservePlugin } from \"../plugin.js\";\nimport { reactTransformPlugin } from \"../transformer/plugin.js\";\nimport type { StreamPluginOptions } from \"../types.js\";\nimport { reactClientPlugin } from \"./plugin.js\";\n\nexport function vitePluginReactClient(options = {} as StreamPluginOptions): import(\"vite\").Plugin[] {\n return [\n reactPreservePlugin(options),\n reactClientPlugin(options),\n reactTransformPlugin(options),\n ];\n } "],"names":[],"mappings":";;;;;;;;;AAKgB,SAAA,qBAAA,CAAsB,OAAU,GAAA,EAAoD,EAAA;AAChG,EAAO,OAAA;AAAA,IACL,oBAA2B,CAAA;AAAA,IAC3B,kBAAkB,OAAO,CAAA;AAAA,IACzB,qBAAqB,OAAO;AAAA,GAC9B;AACF;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Plugin } from "vite";
|
|
2
2
|
import type { StreamPluginOptions } from "../types.js";
|
|
3
|
-
export declare function reactClientPlugin(options: StreamPluginOptions):
|
|
3
|
+
export declare function reactClientPlugin(options: StreamPluginOptions): Plugin;
|
|
4
4
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../plugin/react-client/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../plugin/react-client/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,MAAM,EAAuB,MAAM,MAAM,CAAC;AACvE,OAAO,KAAK,EAGV,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAcrB,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAgItE"}
|
|
@@ -3,29 +3,125 @@
|
|
|
3
3
|
* Copyright (c) Nico Brinkkemper
|
|
4
4
|
* MIT License
|
|
5
5
|
*/
|
|
6
|
+
import 'vite';
|
|
6
7
|
import { resolveOptions } from '../config/resolveOptions.js';
|
|
7
8
|
import { resolveUserConfig } from '../config/resolveUserConfig.js';
|
|
9
|
+
import { stat, readFile, mkdir, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { join, dirname } from 'node:path';
|
|
11
|
+
import { getBundleManifest } from '../helpers/getBundleManifest.js';
|
|
12
|
+
import { checkFilesExist } from '../checkFilesExist.js';
|
|
13
|
+
import { resolvePages } from '../config/resolvePages.js';
|
|
8
14
|
|
|
9
15
|
let userOptions;
|
|
16
|
+
let userConfig;
|
|
17
|
+
let clientManifest = {};
|
|
18
|
+
let resolvedConfig;
|
|
19
|
+
let root;
|
|
20
|
+
let loader = (id) => import(id);
|
|
10
21
|
function reactClientPlugin(options) {
|
|
11
|
-
const resolvedOptions = resolveOptions(options);
|
|
22
|
+
const resolvedOptions = resolveOptions(options, true);
|
|
12
23
|
if (resolvedOptions.type === "error") {
|
|
13
24
|
throw resolvedOptions.error;
|
|
14
25
|
}
|
|
15
26
|
userOptions = resolvedOptions.userOptions;
|
|
27
|
+
root = userOptions.projectRoot;
|
|
28
|
+
console.log("[vite:react-client] Initial setup:", {
|
|
29
|
+
projectRoot: userOptions.projectRoot,
|
|
30
|
+
root,
|
|
31
|
+
clientEntry: userOptions.clientEntry
|
|
32
|
+
});
|
|
16
33
|
return {
|
|
17
|
-
name: "vite:react-
|
|
18
|
-
async config(config) {
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
name: "vite:react-client",
|
|
35
|
+
async config(config, configEnv) {
|
|
36
|
+
if (typeof config.root === "string" && config.root !== root && config.root !== process.cwd() && config.root !== "") {
|
|
37
|
+
root = config.root;
|
|
38
|
+
console.log("[vite:react-client] Root updated:", root);
|
|
39
|
+
}
|
|
40
|
+
const pages = await resolvePages(userOptions.build.pages);
|
|
41
|
+
if (pages.type === "error") {
|
|
42
|
+
throw pages.error;
|
|
43
|
+
}
|
|
44
|
+
const files = await checkFilesExist(pages.pages, userOptions, root);
|
|
45
|
+
const resolvedConfig2 = resolveUserConfig({
|
|
46
|
+
isClient: true,
|
|
21
47
|
config,
|
|
22
|
-
configEnv
|
|
23
|
-
userOptions
|
|
48
|
+
configEnv,
|
|
49
|
+
userOptions,
|
|
50
|
+
files
|
|
51
|
+
});
|
|
52
|
+
if (resolvedConfig2.type === "error") {
|
|
53
|
+
throw resolvedConfig2.error;
|
|
54
|
+
}
|
|
55
|
+
userConfig = resolvedConfig2.userConfig;
|
|
56
|
+
return userConfig;
|
|
57
|
+
},
|
|
58
|
+
configResolved(config) {
|
|
59
|
+
resolvedConfig = config;
|
|
60
|
+
},
|
|
61
|
+
async generateBundle(options2, bundle) {
|
|
62
|
+
clientManifest = getBundleManifest(this, bundle);
|
|
63
|
+
const manifestPath = join(
|
|
64
|
+
root,
|
|
65
|
+
resolvedConfig.environments["client"].build.outDir,
|
|
66
|
+
resolvedConfig.environments["client"].build.manifest
|
|
67
|
+
);
|
|
68
|
+
await mkdir(dirname(manifestPath), { recursive: true });
|
|
69
|
+
return await writeFile(
|
|
70
|
+
manifestPath,
|
|
71
|
+
JSON.stringify(clientManifest, null, 2)
|
|
72
|
+
);
|
|
73
|
+
},
|
|
74
|
+
async configurePreviewServer(server) {
|
|
75
|
+
if (typeof loader !== "function") {
|
|
76
|
+
loader = (id) => import(id);
|
|
77
|
+
}
|
|
78
|
+
server.middlewares.use(async (req, res, next) => {
|
|
79
|
+
console.log("req.url", req.url);
|
|
80
|
+
if (req.url && req.url.endsWith(".js")) {
|
|
81
|
+
process.env["NODE_PATH"] ?? process.cwd();
|
|
82
|
+
try {
|
|
83
|
+
const stats = await stat(req.url);
|
|
84
|
+
if (stats.isFile()) {
|
|
85
|
+
const content = await readFile(req.url, "utf-8");
|
|
86
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
87
|
+
res.end(content);
|
|
88
|
+
} else {
|
|
89
|
+
next();
|
|
90
|
+
}
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error("error", error);
|
|
93
|
+
next();
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
next();
|
|
97
|
+
}
|
|
24
98
|
});
|
|
25
|
-
|
|
26
|
-
|
|
99
|
+
},
|
|
100
|
+
// setup dev server
|
|
101
|
+
async configureServer(server) {
|
|
102
|
+
if (typeof loader !== "function") {
|
|
103
|
+
loader = server.ssrLoadModule;
|
|
27
104
|
}
|
|
28
|
-
|
|
105
|
+
server.middlewares.use(async (req, res, next) => {
|
|
106
|
+
console.log("req.url", req.url);
|
|
107
|
+
if (req.url && req.url.endsWith(".js")) {
|
|
108
|
+
const filePath = join(root, req.url);
|
|
109
|
+
try {
|
|
110
|
+
const stats = await stat(filePath);
|
|
111
|
+
if (stats.isFile()) {
|
|
112
|
+
const content = await readFile(filePath, "utf-8");
|
|
113
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
114
|
+
res.end(content);
|
|
115
|
+
} else {
|
|
116
|
+
next();
|
|
117
|
+
}
|
|
118
|
+
} catch (error) {
|
|
119
|
+
next();
|
|
120
|
+
}
|
|
121
|
+
} else if (req.url && req.url.endsWith(".rsc")) {
|
|
122
|
+
throw new Error("Not implemented");
|
|
123
|
+
}
|
|
124
|
+
});
|
|
29
125
|
}
|
|
30
126
|
};
|
|
31
127
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../../plugin/react-client/plugin.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../../plugin/react-client/plugin.ts"],"sourcesContent":["import { type Manifest, type Plugin, type ResolvedConfig } from \"vite\";\nimport type {\n ResolvedUserConfig,\n ResolvedUserOptions,\n StreamPluginOptions,\n} from \"../types.js\";\nimport { resolveOptions } from \"../config/resolveOptions.js\";\nimport { resolveUserConfig } from \"../config/resolveUserConfig.js\";\nimport { mkdir, readFile, stat, writeFile } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { getBundleManifest } from \"../helpers/getBundleManifest.js\";\nimport { checkFilesExist } from \"../checkFilesExist.js\";\nimport { resolvePages } from \"../config/resolvePages.js\";\nlet userOptions: ResolvedUserOptions;\nlet userConfig: ResolvedUserConfig;\nlet clientManifest: Manifest = {};\nlet resolvedConfig: ResolvedConfig;\nlet root: string;\nlet loader: ((id: string) => Promise<Record<string, any>>) = (id: string) => import(id);\nexport function reactClientPlugin(options: StreamPluginOptions): Plugin {\n const resolvedOptions = resolveOptions(options, true);\n if (resolvedOptions.type === \"error\") {\n throw resolvedOptions.error;\n }\n userOptions = resolvedOptions.userOptions;\n root = userOptions.projectRoot;\n\n console.log(\"[vite:react-client] Initial setup:\", {\n projectRoot: userOptions.projectRoot,\n root: root,\n clientEntry: userOptions.clientEntry\n });\n\n return {\n name: \"vite:react-client\",\n\n async config(config, configEnv) {\n\n if(typeof config.root === \"string\" &&\n config.root !== root &&\n config.root !== process.cwd() &&\n config.root !== \"\") {\n root = config.root;\n console.log(\"[vite:react-client] Root updated:\", root);\n }\n\n const pages = await resolvePages(userOptions.build.pages);\n if(pages.type === \"error\") {\n throw pages.error;\n }\n\n const files = await checkFilesExist(pages.pages, userOptions, root);\n\n\n const resolvedConfig = resolveUserConfig({\n isClient: true,\n config,\n configEnv,\n userOptions,\n files\n });\n\n if (resolvedConfig.type === \"error\") {\n throw resolvedConfig.error;\n }\n\n userConfig = resolvedConfig.userConfig;\n return userConfig;\n },\n\n configResolved(config) {\n resolvedConfig = config;\n },\n\n async generateBundle(options, bundle) {\n // Create manifest entries for each chunk\n clientManifest = getBundleManifest(this, bundle, undefined);\n\n // Write manifest immediately after generation\n const manifestPath = join(\n root,\n resolvedConfig.environments['client'].build.outDir as string,\n resolvedConfig.environments['client'].build.manifest as string\n );\n await mkdir(dirname(manifestPath), { recursive: true });\n\n return await writeFile(\n manifestPath,\n JSON.stringify(clientManifest, null, 2)\n );\n },\n \n async configurePreviewServer(server) {\n if (typeof loader !== \"function\") {\n loader = (id: string) => import(id);\n }\n server.middlewares.use(async (req, res, next) => {\n console.log('req.url', req.url);\n if (req.url && req.url.endsWith('.js')) {\n const nodeRoot = process.env['NODE_PATH'] ?? process.cwd();\n \n try {\n const stats = await stat(req.url);\n if (stats.isFile()) {\n const content = await readFile(req.url, 'utf-8');\n res.setHeader('Content-Type', 'application/javascript');\n res.end(content);\n } else {\n next();\n }\n } catch (error) {\n console.error('error', error);\n next();\n }\n } else {\n next();\n }\n });\n },\n // setup dev server\n async configureServer(server) {\n if (typeof loader !== \"function\") {\n loader = server.ssrLoadModule;\n }\n server.middlewares.use(async (req, res, next) => {\n console.log('req.url', req.url);\n if (req.url && req.url.endsWith('.js')) {\n const filePath = join(root, req.url);\n try {\n const stats = await stat(filePath);\n if (stats.isFile()) {\n const content = await readFile(filePath, 'utf-8');\n res.setHeader('Content-Type', 'application/javascript');\n res.end(content);\n } else {\n next();\n }\n } catch (error) {\n next();\n }\n } else if(req.url && req.url.endsWith('.rsc')) {\n // stream the rsc stream\n throw new Error('Not implemented');\n }\n });\n }\n };\n}\n"],"names":["resolvedConfig","options"],"mappings":";;;;;;;;;;;;;;AAaA,IAAI,WAAA;AACJ,IAAI,UAAA;AACJ,IAAI,iBAA2B,EAAC;AAChC,IAAI,cAAA;AACJ,IAAI,IAAA;AACJ,IAAI,MAAA,GAAyD,CAAC,EAAA,KAAe,OAAO,EAAA,CAAA;AAC7E,SAAS,kBAAkB,OAAsC,EAAA;AACtE,EAAM,MAAA,eAAA,GAAkB,cAAe,CAAA,OAAA,EAAS,IAAI,CAAA;AACpD,EAAI,IAAA,eAAA,CAAgB,SAAS,OAAS,EAAA;AACpC,IAAA,MAAM,eAAgB,CAAA,KAAA;AAAA;AAExB,EAAA,WAAA,GAAc,eAAgB,CAAA,WAAA;AAC9B,EAAA,IAAA,GAAO,WAAY,CAAA,WAAA;AAEnB,EAAA,OAAA,CAAQ,IAAI,oCAAsC,EAAA;AAAA,IAChD,aAAa,WAAY,CAAA,WAAA;AAAA,IACzB,IAAA;AAAA,IACA,aAAa,WAAY,CAAA;AAAA,GAC1B,CAAA;AAED,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,mBAAA;AAAA,IAEN,MAAM,MAAO,CAAA,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,UAAK,IAAA,EAAA;AAAA;AACP,OACD,CAAA;AAAA,KACH;AAAA;AAAA,IAEA,MAAM,gBAAgB,MAAQ,EAAA;AAC5B,MAAI,IAAA,OAAO,WAAW,UAAY,EAAA;AAChC,QAAA,MAAA,GAAS,MAAO,CAAA,aAAA;AAAA;AAElB,MAAA,MAAA,CAAO,WAAY,CAAA,GAAA,CAAI,OAAO,GAAA,EAAK,KAAK,IAAS,KAAA;AAC/C,QAAQ,OAAA,CAAA,GAAA,CAAI,SAAW,EAAA,GAAA,CAAI,GAAG,CAAA;AAC9B,QAAA,IAAI,IAAI,GAAO,IAAA,GAAA,CAAI,GAAI,CAAA,QAAA,CAAS,KAAK,CAAG,EAAA;AACtC,UAAA,MAAM,QAAW,GAAA,IAAA,CAAK,IAAM,EAAA,GAAA,CAAI,GAAG,CAAA;AACnC,UAAI,IAAA;AACF,YAAM,MAAA,KAAA,GAAQ,MAAM,IAAA,CAAK,QAAQ,CAAA;AACjC,YAAI,IAAA,KAAA,CAAM,QAAU,EAAA;AAClB,cAAA,MAAM,OAAU,GAAA,MAAM,QAAS,CAAA,QAAA,EAAU,OAAO,CAAA;AAChD,cAAI,GAAA,CAAA,SAAA,CAAU,gBAAgB,wBAAwB,CAAA;AACtD,cAAA,GAAA,CAAI,IAAI,OAAO,CAAA;AAAA,aACV,MAAA;AACL,cAAK,IAAA,EAAA;AAAA;AACP,mBACO,KAAO,EAAA;AACd,YAAK,IAAA,EAAA;AAAA;AACP,mBACQ,GAAI,CAAA,GAAA,IAAO,IAAI,GAAI,CAAA,QAAA,CAAS,MAAM,CAAG,EAAA;AAE7C,UAAM,MAAA,IAAI,MAAM,iBAAiB,CAAA;AAAA;AACnC,OACD,CAAA;AAAA;AACH,GACF;AACF;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PipeableStream } from "react-dom/server";
|
|
2
|
-
import type { CreateHandlerOptions,
|
|
2
|
+
import type { CreateHandlerOptions, ResolvedUserOptions } from "../types.js";
|
|
3
3
|
type CreateHandlerResult = {
|
|
4
4
|
type: "success";
|
|
5
5
|
controller: AbortController;
|
|
@@ -12,6 +12,6 @@ type CreateHandlerResult = {
|
|
|
12
12
|
} | {
|
|
13
13
|
type: "skip";
|
|
14
14
|
};
|
|
15
|
-
export declare function createHandler<T>(url: string, pluginOptions:
|
|
15
|
+
export declare function createHandler<T>(url: string, pluginOptions: ResolvedUserOptions, streamOptions: CreateHandlerOptions<T>): Promise<CreateHandlerResult>;
|
|
16
16
|
export {};
|
|
17
17
|
//# sourceMappingURL=createHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHandler.d.ts","sourceRoot":"","sources":["../../../plugin/react-server/createHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AASvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG7E,KAAK,mBAAmB,GACpB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,GAAG,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACzG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAOrB,wBAAsB,aAAa,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"createHandler.d.ts","sourceRoot":"","sources":["../../../plugin/react-server/createHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AASvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG7E,KAAK,mBAAmB,GACpB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,GAAG,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACzG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAOrB,wBAAsB,aAAa,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,mBAAmB,EAClC,aAAa,EAAE,oBAAoB,CAAC,CAAC,CAAC,GACrC,OAAO,CAAC,mBAAmB,CAAC,CAmI9B"}
|
|
@@ -20,10 +20,10 @@ async function createHandler(url, pluginOptions, streamOptions) {
|
|
|
20
20
|
const propsPath = typeof pluginOptions.props === "function" ? pluginOptions.props(url) : pluginOptions.props;
|
|
21
21
|
const pagePath = typeof pluginOptions.Page === "function" ? pluginOptions.Page(url) : pluginOptions.Page;
|
|
22
22
|
const cssModules = /* @__PURE__ */ new Set();
|
|
23
|
-
if (!(streamOptions.
|
|
24
|
-
throw new Error("Missing manifest or moduleGraph, pass it to options.");
|
|
25
|
-
const getCss = streamOptions.
|
|
26
|
-
streamOptions.
|
|
23
|
+
if (!(streamOptions.serverManifest || streamOptions.moduleGraph))
|
|
24
|
+
throw new Error("Missing server manifest or moduleGraph, pass it to options.");
|
|
25
|
+
const getCss = streamOptions.serverManifest ? (id) => collectManifestCss(
|
|
26
|
+
streamOptions.serverManifest,
|
|
27
27
|
root,
|
|
28
28
|
id,
|
|
29
29
|
streamOptions.onCssFile
|
|
@@ -89,7 +89,7 @@ async function createHandler(url, pluginOptions, streamOptions) {
|
|
|
89
89
|
Html,
|
|
90
90
|
Page,
|
|
91
91
|
props,
|
|
92
|
-
moduleBasePath:
|
|
92
|
+
moduleBasePath: "",
|
|
93
93
|
logger: streamOptions.logger ?? createLogger(),
|
|
94
94
|
cssFiles: Array.from(cssModules),
|
|
95
95
|
pipableStreamOptions: streamOptions.pipableStreamOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHandler.js","sources":["../../../plugin/react-server/createHandler.ts"],"sourcesContent":["import type { PipeableStream } from \"react-dom/server\";\nimport { createLogger } from \"vite\";\nimport {\n collectManifestCss,\n collectModuleGraphCss,\n} from \"../collect-css-manifest.js\";\nimport { DEFAULT_CONFIG } from \"../config/defaults.js\";\nimport { resolvePage } from \"../resolvePage.js\";\nimport { resolveProps } from \"../resolveProps.js\";\nimport type { CreateHandlerOptions,
|
|
1
|
+
{"version":3,"file":"createHandler.js","sources":["../../../plugin/react-server/createHandler.ts"],"sourcesContent":["import type { PipeableStream } from \"react-dom/server\";\nimport { createLogger } from \"vite\";\nimport {\n collectManifestCss,\n collectModuleGraphCss,\n} from \"../collect-css-manifest.js\";\nimport { DEFAULT_CONFIG } from \"../config/defaults.js\";\nimport { resolvePage } from \"../resolvePage.js\";\nimport { resolveProps } from \"../resolveProps.js\";\nimport type { CreateHandlerOptions, ResolvedUserOptions } from \"../types.js\";\nimport { createRscStream } from \"./createRscStream.js\";\n\ntype CreateHandlerResult = \n | { type: \"success\"; controller: AbortController; stream: PipeableStream; assets: any; clientPath: string }\n | { type: \"error\"; error: Error }\n | { type: \"skip\" };\n\ninterface HandlerAssets {\n css: Set<string>;\n clientPath: string;\n}\n\nexport async function createHandler<T>(\n url: string,\n pluginOptions: ResolvedUserOptions,\n streamOptions: CreateHandlerOptions<T>\n): Promise<CreateHandlerResult> {\n const root = pluginOptions.projectRoot ?? process.cwd();\n\n const Html = pluginOptions.Html ?? DEFAULT_CONFIG.HTML;\n const pageExportName =\n pluginOptions.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT;\n const propsExportName =\n pluginOptions.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT;\n const controller = new AbortController();\n\n const cssFiles = streamOptions.cssFiles;\n const propsPath =\n typeof pluginOptions.props === \"function\"\n ? pluginOptions.props(url)\n : pluginOptions.props;\n const pagePath =\n typeof pluginOptions.Page === \"function\"\n ? pluginOptions.Page(url)\n : pluginOptions.Page;\n\n const cssModules = new Set<string>();\n\n if (!(streamOptions.serverManifest || streamOptions.moduleGraph))\n throw new Error(\"Missing server manifest or moduleGraph, pass it to options.\");\n\n const getCss = streamOptions.serverManifest\n ? (id: string) =>\n collectManifestCss(\n streamOptions.serverManifest!,\n root,\n id,\n streamOptions.onCssFile\n )\n : (id: string) => collectModuleGraphCss(streamOptions.moduleGraph!, id);\n\n const loadWithCss = async (id: string) => {\n try {\n const mod = await streamOptions.loader(id);\n const pageCss = await Promise.resolve(getCss(id));\n Array.from(pageCss.keys()).forEach((css) => cssModules.add(css));\n return mod as Record<string, any>;\n } catch (e: any) {\n if (e.message?.includes(\"module runner has been closed\")) {\n return { type: \"skip\" } as Record<string, any>;\n } else {\n return { type: \"error\", error: e } as Record<string, any>;\n }\n }\n };\n\n const PropsModule = await resolveProps({\n propsModule: await loadWithCss(propsPath ?? pagePath),\n path: String(propsPath ?? pagePath),\n exportName: propsExportName,\n url,\n });\n if (PropsModule.type === \"error\")\n return { type: PropsModule.type, error: PropsModule?.error };\n if (PropsModule.type === \"skip\") return { type: PropsModule.type };\n const props = PropsModule[propsExportName as keyof typeof PropsModule] as any;\n if (props?.type === \"error\") return { type: props.type, error: props.error };\n if (props?.type === \"skip\") return { type: props.type };\n\n const PageModule = await resolvePage({\n pageModule: await loadWithCss(pagePath),\n path: pagePath,\n exportName: pageExportName,\n url,\n });\n if (PageModule.type === \"error\")\n return { type: PageModule.type, error: PageModule.error };\n if (PageModule.type === \"skip\") return { type: PageModule.type };\n const Page = PageModule[pageExportName as keyof typeof PageModule] as any;\n if (Page?.type === \"error\") return { type: Page.type, error: Page.error };\n if (Page?.type === \"skip\") return { type: Page.type };\n if (!(typeof Page === \"function\")) {\n return {\n type: \"error\",\n error: new Error(\"Invalid Page component: \" + pagePath, {\n cause: Page,\n }),\n };\n }\n if (!(typeof props === \"object\")) {\n return {\n type: \"error\",\n error: new Error(\"Invalid props: \" + propsPath, {\n cause: props,\n }),\n } \n }\n\n // Add any additional CSS files\n if (streamOptions.cssFiles) {\n streamOptions.cssFiles.forEach((css) => cssModules.add(css));\n }\n\n const stream = createRscStream({\n Html: Html,\n Page: Page,\n props: props,\n moduleBasePath: '',\n logger: streamOptions.logger ?? createLogger(),\n cssFiles: Array.from(cssModules),\n route: url,\n url,\n pipableStreamOptions: streamOptions.pipableStreamOptions,\n htmlProps: {\n pageProps: props,\n route: url,\n url: url,\n },\n });\n\n if (!stream) {\n console.log(\"[createHandler] No stream created for route:\", url);\n return { type: \"skip\" as const };\n }\n\n const assets: HandlerAssets = {\n css: new Set(cssFiles ?? []),\n clientPath: pagePath ?? ''\n };\n\n return {\n type: \"success\",\n controller,\n stream,\n assets,\n clientPath: assets.clientPath,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAsBsB,eAAA,aAAA,CACpB,GACA,EAAA,aAAA,EACA,aAC8B,EAAA;AAC9B,EAAA,MAAM,IAAO,GAAA,aAAA,CAAc,WAAe,IAAA,OAAA,CAAQ,GAAI,EAAA;AAEtD,EAAM,MAAA,IAAA,GAAO,aAAc,CAAA,IAAA,IAAQ,cAAe,CAAA,IAAA;AAClD,EAAM,MAAA,cAAA,GACJ,aAAc,CAAA,cAAA,IAAkB,cAAe,CAAA,WAAA;AACjD,EAAM,MAAA,eAAA,GACJ,aAAc,CAAA,eAAA,IAAmB,cAAe,CAAA,YAAA;AAClD,EAAM,MAAA,UAAA,GAAa,IAAI,eAAgB,EAAA;AAEvC,EAAA,MAAM,WAAW,aAAc,CAAA,QAAA;AAC/B,EAAM,MAAA,SAAA,GACJ,OAAO,aAAc,CAAA,KAAA,KAAU,aAC3B,aAAc,CAAA,KAAA,CAAM,GAAG,CAAA,GACvB,aAAc,CAAA,KAAA;AACpB,EAAM,MAAA,QAAA,GACJ,OAAO,aAAc,CAAA,IAAA,KAAS,aAC1B,aAAc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EAAA,IAAI,GAAI,CAAA,QAAA,IAAY,EAAE,CAAA;AAAA,IAC3B,YAAY,QAAY,IAAA;AAAA,GAC1B;AAEA,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,UAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA,YAAY,MAAO,CAAA;AAAA,GACrB;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRscStream.d.ts","sourceRoot":"","sources":["../../../plugin/react-server/createRscStream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,wBAAgB,eAAe,CAC7B,aAAa,EAAE,gBAAgB,GAC9B,cAAc,
|
|
1
|
+
{"version":3,"file":"createRscStream.d.ts","sourceRoot":"","sources":["../../../plugin/react-server/createRscStream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,wBAAgB,eAAe,CAC7B,aAAa,EAAE,gBAAgB,GAC9B,cAAc,CAmDhB"}
|
|
@@ -25,12 +25,19 @@ function createRscStream(streamOptions) {
|
|
|
25
25
|
moduleBasePath
|
|
26
26
|
})
|
|
27
27
|
) : [];
|
|
28
|
+
const htmlIsFragment = Html == React.Fragment;
|
|
29
|
+
console.log("[vite:plugin-react-server] Creating RSC stream with options:", {
|
|
30
|
+
moduleBasePath,
|
|
31
|
+
importMap: pipableStreamOptions?.importMap,
|
|
32
|
+
moduleRootPath: moduleBasePath
|
|
33
|
+
// Make sure this matches client component paths
|
|
34
|
+
});
|
|
28
35
|
return renderToPipeableStream(
|
|
29
36
|
React.createElement(
|
|
30
37
|
Html,
|
|
31
38
|
{
|
|
32
39
|
key: "html",
|
|
33
|
-
...htmlProps
|
|
40
|
+
...htmlIsFragment ? {} : htmlProps
|
|
34
41
|
},
|
|
35
42
|
React.createElement(Page, { key: "page", ...props }),
|
|
36
43
|
...css
|
|
@@ -40,6 +47,13 @@ function createRscStream(streamOptions) {
|
|
|
40
47
|
onError: logger?.error ?? console.error,
|
|
41
48
|
onPostpone: logger?.info ?? console.info,
|
|
42
49
|
environmentName: "Server",
|
|
50
|
+
importMap: {
|
|
51
|
+
imports: {
|
|
52
|
+
...pipableStreamOptions?.importMap?.imports,
|
|
53
|
+
// Make sure paths are absolute and match module resolution
|
|
54
|
+
"/": moduleBasePath
|
|
55
|
+
}
|
|
56
|
+
},
|
|
43
57
|
...pipableStreamOptions
|
|
44
58
|
}
|
|
45
59
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRscStream.js","sources":["../../../plugin/react-server/createRscStream.ts"],"sourcesContent":["import * as React from \"react\";\nimport type { PipeableStream } from \"react-dom/server\";\n// @ts-ignore\nimport { renderToPipeableStream } from \"react-server-dom-esm/server.node\";\nimport { CssCollector } from \"../components.js\";\nimport type { RscStreamOptions } from \"../types.js\";\n\nexport function createRscStream(\n streamOptions: RscStreamOptions\n): PipeableStream {\n const {\n Html,\n Page,\n props,\n logger,\n cssFiles,\n moduleBasePath,\n pipableStreamOptions,\n htmlProps,\n } = streamOptions;\n
|
|
1
|
+
{"version":3,"file":"createRscStream.js","sources":["../../../plugin/react-server/createRscStream.ts"],"sourcesContent":["import * as React from \"react\";\nimport type { PipeableStream } from \"react-dom/server\";\n// @ts-ignore\nimport { renderToPipeableStream } from \"react-server-dom-esm/server.node\";\nimport { CssCollector } from \"../components.js\";\nimport type { RscStreamOptions } from \"../types.js\";\n\nexport function createRscStream(\n streamOptions: RscStreamOptions\n): PipeableStream {\n const {\n Html,\n Page,\n props,\n logger,\n cssFiles,\n moduleBasePath,\n pipableStreamOptions,\n htmlProps,\n } = streamOptions;\n const css = Array.isArray(cssFiles)\n ? cssFiles.map((css, index) =>\n React.createElement(CssCollector, {\n key: `css-${index}`,\n url: css.startsWith(\"/\") ? css : `/${css}`,\n moduleBasePath,\n })\n )\n : [];\n const htmlIsFragment = Html == React.Fragment;\n console.log(\"[vite:plugin-react-server] Creating RSC stream with options:\", {\n moduleBasePath,\n importMap: pipableStreamOptions?.importMap,\n moduleRootPath: moduleBasePath // Make sure this matches client component paths\n });\n return renderToPipeableStream(\n React.createElement(\n Html,\n {\n key: \"html\",\n ...(htmlIsFragment ? {} : htmlProps)\n },\n React.createElement(Page, { key: \"page\", ...props }),\n ...css\n ),\n moduleBasePath,\n {\n onError: logger?.error ?? console.error,\n onPostpone: logger?.info ?? console.info,\n environmentName: \"Server\",\n importMap: {\n imports: {\n ...pipableStreamOptions?.importMap?.imports,\n // Make sure paths are absolute and match module resolution\n '/': moduleBasePath\n }\n },\n ...pipableStreamOptions\n }\n );\n}\n"],"names":["css"],"mappings":";;;;;;;;;AAOO,SAAS,gBACd,aACgB,EAAA;AAChB,EAAM,MAAA;AAAA,IACJ,IAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,MAAA;AAAA,IACA,QAAA;AAAA,IACA,cAAA;AAAA,IACA,oBAAA;AAAA,IACA;AAAA,GACE,GAAA,aAAA;AACJ,EAAA,MAAM,GAAM,GAAA,KAAA,CAAM,OAAQ,CAAA,QAAQ,IAC9B,QAAS,CAAA,GAAA;AAAA,IAAI,CAACA,IAAAA,EAAK,KACjB,KAAA,KAAA,CAAM,cAAc,YAAc,EAAA;AAAA,MAChC,GAAA,EAAK,OAAO,KAAK,CAAA,CAAA;AAAA,MACjB,KAAKA,IAAI,CAAA,UAAA,CAAW,GAAG,CAAIA,GAAAA,IAAAA,GAAM,IAAIA,IAAG,CAAA,CAAA;AAAA,MACxC;AAAA,KACD;AAAA,MAEH,EAAC;AACL,EAAM,MAAA,cAAA,GAAiB,QAAQ,KAAM,CAAA,QAAA;AACrC,EAAA,OAAA,CAAQ,IAAI,8DAAgE,EAAA;AAAA,IAC1E,cAAA;AAAA,IACA,WAAW,oBAAsB,EAAA,SAAA;AAAA,IACjC,cAAgB,EAAA;AAAA;AAAA,GACjB,CAAA;AACD,EAAO,OAAA,sBAAA;AAAA,IACL,KAAM,CAAA,aAAA;AAAA,MACJ,IAAA;AAAA,MACA;AAAA,QACE,GAAK,EAAA,MAAA;AAAA,QACL,GAAI,cAAiB,GAAA,EAAK,GAAA;AAAA,OAC5B;AAAA,MACA,KAAA,CAAM,cAAc,IAAM,EAAA,EAAE,KAAK,MAAQ,EAAA,GAAG,OAAO,CAAA;AAAA,MACnD,GAAG;AAAA,KACL;AAAA,IACA,cAAA;AAAA,IACA;AAAA,MACE,OAAA,EAAS,MAAQ,EAAA,KAAA,IAAS,OAAQ,CAAA,KAAA;AAAA,MAClC,UAAA,EAAY,MAAQ,EAAA,IAAA,IAAQ,OAAQ,CAAA,IAAA;AAAA,MACpC,eAAiB,EAAA,QAAA;AAAA,MACjB,SAAW,EAAA;AAAA,QACT,OAAS,EAAA;AAAA,UACP,GAAG,sBAAsB,SAAW,EAAA,OAAA;AAAA;AAAA,UAEpC,GAAK,EAAA;AAAA;AACP,OACF;AAAA,MACA,GAAG;AAAA;AACL,GACF;AACF;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type ViteDevServer } from "vite";
|
|
2
|
-
import type { RequestHandler,
|
|
3
|
-
export declare function createSsrHandler(options:
|
|
2
|
+
import type { RequestHandler, ResolvedUserOptions } from "../types.js";
|
|
3
|
+
export declare function createSsrHandler(options: ResolvedUserOptions, server: ViteDevServer): RequestHandler;
|
|
4
4
|
//# sourceMappingURL=createSsrHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSsrHandler.d.ts","sourceRoot":"","sources":["../../../plugin/react-server/createSsrHandler.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"createSsrHandler.d.ts","sourceRoot":"","sources":["../../../plugin/react-server/createSsrHandler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAEzD,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAKvE,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,aAAa,GACpB,cAAc,CA+GhB"}
|
|
@@ -4,7 +4,7 @@ import { Worker } from "node:worker_threads";
|
|
|
4
4
|
import {} from "vite";
|
|
5
5
|
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
6
6
|
import { createHandler } from "./createHandler.js";
|
|
7
|
-
export function createSsrHandler(options, server
|
|
7
|
+
export function createSsrHandler(options, server) {
|
|
8
8
|
const worker = new Worker(options?.htmlWorkerPath
|
|
9
9
|
? resolve(server.config.root, options?.htmlWorkerPath)
|
|
10
10
|
: DEFAULT_CONFIG.HTML_WORKER_PATH, {
|
|
@@ -21,14 +21,7 @@ export function createSsrHandler(options, server, _clientComponents) {
|
|
|
21
21
|
}
|
|
22
22
|
try {
|
|
23
23
|
const result = await createHandler(req.url ?? "", {
|
|
24
|
-
|
|
25
|
-
props: options.props,
|
|
26
|
-
build: options.build,
|
|
27
|
-
Html: options.Html,
|
|
28
|
-
pageExportName: options.pageExportName,
|
|
29
|
-
propsExportName: options.propsExportName,
|
|
30
|
-
moduleBase: options.moduleBase,
|
|
31
|
-
moduleBasePath: options.moduleBasePath,
|
|
24
|
+
...options,
|
|
32
25
|
projectRoot: server.config.root,
|
|
33
26
|
}, {
|
|
34
27
|
loader: server.ssrLoadModule.bind(server),
|
|
@@ -75,9 +68,9 @@ export function createSsrHandler(options, server, _clientComponents) {
|
|
|
75
68
|
// Don't need file paths in dev mode
|
|
76
69
|
outDir: "",
|
|
77
70
|
htmlOutputPath: "",
|
|
78
|
-
pipableStreamOptions: {
|
|
79
|
-
|
|
80
|
-
},
|
|
71
|
+
pipableStreamOptions: options.pipableStreamOptions ?? {},
|
|
72
|
+
clientManifest: {},
|
|
73
|
+
serverManifest: {},
|
|
81
74
|
});
|
|
82
75
|
worker.once("message", (msg) => {
|
|
83
76
|
if (msg.type === "ERROR") {
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { reactPreservePlugin } from '../preserver/plugin.js';
|
|
7
|
+
import { reactTransformPlugin } from '../transformer/plugin.js';
|
|
8
|
+
import { reactServerPlugin } from './plugin.js';
|
|
9
|
+
|
|
10
|
+
function vitePluginReactServer(options = {}) {
|
|
11
|
+
return [
|
|
12
|
+
reactTransformPlugin(options),
|
|
13
|
+
reactServerPlugin(options),
|
|
14
|
+
reactPreservePlugin()
|
|
15
|
+
];
|
|
10
16
|
}
|
|
17
|
+
|
|
18
|
+
export { vitePluginReactServer };
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../plugin/react-server/index.ts"],"sourcesContent":["import { reactPreservePlugin } from \"../preserver/plugin.js\";\nimport { reactTransformPlugin } from \"../transformer/plugin.js\";\nimport type { StreamPluginOptions } from \"../types.js\";\nimport { reactServerPlugin } from \"./plugin.js\";\n\nexport function vitePluginReactServer(options = {} as StreamPluginOptions): import(\"vite\").Plugin[] {\n return [\n reactTransformPlugin(options),\n reactServerPlugin(options),\n reactPreservePlugin(options),\n ];\n } "],"names":[],"mappings":";;;;;;;;;AAKgB,SAAA,qBAAA,CAAsB,OAAU,GAAA,EAAoD,EAAA;AAChG,EAAO,OAAA;AAAA,IACL,qBAAqB,OAAO,CAAA;AAAA,IAC5B,kBAAkB,OAAO,CAAA;AAAA,IACzB,oBAA2B;AAAA,GAC7B;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../plugin/react-server/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../plugin/react-server/plugin.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAGV,qBAAqB,EAGtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAcvD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,mBAAmB,GAC3B,OAAO,MAAM,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,qBAAqB,CAAC;IAC5B,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,CAAC,CA4aD"}
|