vite-plugin-react-server 0.3.10 → 0.3.12
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 +16 -14
- 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.d.ts +2 -2
- package/dist/plugin/checkFilesExist.d.ts.map +1 -1
- package/dist/plugin/checkFilesExist.js +43 -58
- package/dist/plugin/checkFilesExist.js.map +1 -1
- package/dist/plugin/collect-css-manifest.d.ts.map +1 -1
- package/dist/plugin/collect-css-manifest.js +5 -0
- package/dist/plugin/collect-css-manifest.js.map +1 -1
- package/dist/plugin/components.js +10 -15
- 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 +27 -24
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +26 -31
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getPaths.js +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 +223 -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 +149 -50
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts +25 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -0
- package/dist/plugin/helpers/getBundleManifest.js +72 -0
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts +14 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +128 -16
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts +3 -1
- 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 +37 -9
- 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/loader/css-loader.d.ts +16 -0
- package/dist/plugin/loader/css-loader.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.js +70 -0
- package/dist/plugin/loader/css-loader.js.map +1 -0
- package/dist/plugin/loader/react-loader.d.ts +17 -0
- package/dist/plugin/loader/react-loader.d.ts.map +1 -0
- package/dist/plugin/loader/react-loader.js +647 -0
- package/dist/plugin/loader/react-loader.js.map +1 -0
- package/dist/plugin/loader/rsc/messageHandler.d.ts +2 -0
- package/dist/plugin/loader/rsc/messageHandler.d.ts.map +1 -0
- package/dist/plugin/loader/rsc/messageHandler.js +1 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +2 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +1 -0
- package/dist/plugin/loader/rsc/rsc-worker.development.js +1 -0
- 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 +283 -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 +15 -9
- package/dist/plugin/react-server/createHandler.js.map +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts +15 -3
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
- package/dist/plugin/react-server/createRscStream.js +53 -36
- 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 +147 -137
- 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 +68 -75
- package/dist/plugin/transformer/plugin.js.map +1 -1
- 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 +56 -20
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/utils/logger.d.ts +9 -0
- package/dist/plugin/utils/logger.d.ts.map +1 -0
- package/dist/plugin/utils/logger.js +68 -0
- package/dist/plugin/utils/logger.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +1 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +23 -36
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +5 -1
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +33 -28
- 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 +147 -93
- 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/rsc/index.d.ts +1 -3
- package/dist/plugin/worker/rsc/index.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/index.js +1 -9
- package/dist/plugin/worker/rsc/index.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts +3 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.js +107 -0
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -0
- package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/plugin.js +74 -80
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +32 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js +43 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.js +4 -106
- package/dist/plugin/worker/rsc/rsc-worker.production.d.ts +2 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.js +14 -0
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -0
- package/dist/plugin/worker/rsc/state.d.ts +11 -0
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/state.js +12 -0
- package/dist/plugin/worker/rsc/state.js.map +1 -0
- package/dist/plugin/worker/types.d.ts +62 -35
- 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 +16 -14
- package/plugin/assertServerCondition.ts +2 -3
- package/plugin/checkFilesExist.ts +46 -66
- package/plugin/collect-css-manifest.ts +5 -1
- package/plugin/config/createModuleIdGenerator.ts +52 -0
- package/plugin/config/defaults.ts +27 -20
- package/plugin/config/resolveOptions.ts +311 -25
- package/plugin/config/resolvePages.ts +1 -1
- package/plugin/config/resolveUserConfig.ts +195 -61
- package/plugin/helpers/getBundleManifest.ts +113 -0
- package/plugin/helpers/inputNormalizer.ts +186 -25
- package/plugin/helpers/tryManifest.ts +3 -1
- package/plugin/loader/createBuildLoader.ts +50 -9
- package/plugin/loader/createPageLoader.ts +1 -7
- package/plugin/loader/css-loader.ts +96 -0
- package/plugin/loader/react-loader.ts +945 -0
- package/plugin/loader/rsc/messageHandler.tsx +1 -0
- package/plugin/loader/rsc/rsc-worker.development.ts +1 -0
- 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 +351 -11
- package/plugin/react-server/createHandler.ts +16 -18
- package/plugin/react-server/createRscStream.ts +75 -42
- package/plugin/react-server/createSsrHandler.ts +7 -26
- package/plugin/react-server/plugin.ts +192 -155
- package/plugin/transformer/plugin.ts +70 -104
- package/plugin/transformer/types.ts +4 -0
- package/plugin/types/global.d.ts +8 -0
- package/plugin/types.ts +120 -64
- package/plugin/utils/logger.ts +52 -0
- package/plugin/worker/createWorker.ts +43 -44
- package/plugin/worker/html/html-worker.production.tsx +7 -2
- package/plugin/worker/html/messageHandler.ts +42 -35
- package/plugin/worker/html/plugin.ts +15 -11
- package/plugin/worker/html/renderPages.ts +177 -123
- package/plugin/worker/loader.ts +4 -13
- package/plugin/worker/plugin.ts +10 -1
- package/plugin/worker/rsc/index.ts +4 -13
- package/plugin/worker/rsc/messageHandler.tsx +143 -0
- package/plugin/worker/rsc/plugin.ts +38 -37
- package/plugin/worker/rsc/rsc-worker.development.ts +107 -0
- package/plugin/worker/rsc/rsc-worker.production.ts +13 -0
- package/plugin/worker/rsc/rsc-worker.tsx +5 -128
- package/plugin/worker/rsc/state.ts +37 -0
- package/plugin/worker/types.ts +83 -38
- package/scripts/check-react-version.mjs +17 -7
- package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +143 -4170
- package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +14271 -90079
- 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/components.js.map +0 -1
- 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/createClientInputNormalizer.d.ts +0 -8
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createClientInputNormalizer.js +0 -35
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts +0 -9
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createServerInputNormalizer.js +0 -37
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +0 -7
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +0 -1
- package/dist/plugin/helpers/createStaticInputNormalizer.js +0 -18
- package/dist/plugin/helpers/getModuleManifest.d.ts +0 -12
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +0 -1
- package/dist/plugin/helpers/getModuleManifest.js +0 -24
- package/dist/plugin/helpers/getModuleManifest.js.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +0 -11
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +0 -1
- package/dist/plugin/helpers/inputNormalizerWorker.js +0 -30
- package/dist/plugin/helpers/normalizedRelativePath.d.ts +0 -11
- package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +0 -1
- package/dist/plugin/helpers/normalizedRelativePath.js +0 -36
- package/dist/plugin/helpers/resolveFilePath.d.ts +0 -13
- package/dist/plugin/helpers/resolveFilePath.d.ts.map +0 -1
- package/dist/plugin/helpers/resolveFilePath.js +0 -74
- package/dist/plugin/helpers/resolveWorkerModule.d.ts +0 -6
- package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +0 -1
- package/dist/plugin/helpers/resolveWorkerModule.js +0 -24
- package/dist/plugin/helpers/validateModuleBase.d.ts +0 -3
- package/dist/plugin/helpers/validateModuleBase.d.ts.map +0 -1
- package/dist/plugin/helpers/validateModuleBase.js +0 -16
- package/dist/plugin/helpers/validateResolvedConfig.d.ts +0 -3
- package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +0 -1
- package/dist/plugin/helpers/validateResolvedConfig.js +0 -17
- 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-client-components.d.ts +0 -21
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-client-components.js +0 -61
- package/dist/plugin/transformer/transformer-client-components.js.map +0 -1
- package/dist/plugin/transformer/transformer-server-actions.d.ts +0 -29
- package/dist/plugin/transformer/transformer-server-actions.d.ts.map +0 -1
- package/dist/plugin/transformer/transformer-server-actions.js +0 -76
- package/dist/plugin/transformer/transformer-server-actions.js.map +0 -1
- package/dist/plugin/worker/rsc/createRscStream.d.ts +0 -5
- package/dist/plugin/worker/rsc/createRscStream.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/createRscStream.js +0 -39
- package/dist/plugin/worker/rsc/createRscStream.js.map +0 -1
- package/dist/plugin/worker/rsc/development.d.ts +0 -5
- package/dist/plugin/worker/rsc/development.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/development.js +0 -13
- package/dist/plugin/worker/rsc/development.js.map +0 -1
- package/dist/plugin/worker/rsc/plugin.js.map +0 -1
- package/dist/plugin/worker/rsc/production.d.ts +0 -5
- package/dist/plugin/worker/rsc/production.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/production.js +0 -13
- package/dist/plugin/worker/rsc/production.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/helpers/createClientInputNormalizer.ts +0 -48
- package/plugin/helpers/createServerInputNormalizer.ts +0 -52
- package/plugin/helpers/createStaticInputNormalizer.ts +0 -26
- package/plugin/helpers/getModuleManifest.ts +0 -31
- package/plugin/helpers/inputNormalizerWorker.ts +0 -47
- package/plugin/helpers/normalizedRelativePath.ts +0 -59
- package/plugin/helpers/resolveFilePath.ts +0 -108
- package/plugin/helpers/resolveWorkerModule.ts +0 -41
- package/plugin/helpers/validateModuleBase.ts +0 -30
- package/plugin/helpers/validateResolvedConfig.ts +0 -21
- package/plugin/react-server/createDevMiddleware.ts +0 -91
- package/plugin/react-server/createDevServer.ts +0 -9
- package/plugin/react-server/createReactNodeStreamer.ts +0 -26
- package/plugin/transformer/transformer-client-components.ts +0 -94
- package/plugin/transformer/transformer-server-actions.ts +0 -110
- package/plugin/worker/rsc/createRscStream.ts +0 -42
- package/plugin/worker/rsc/development.ts +0 -6
- package/plugin/worker/rsc/production.ts +0 -6
- package/scripts/react-server-dom-esm+0.0.1.patch +0 -24775
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { createWriteStream } from "node:fs";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { parentPort } from "node:worker_threads";
|
|
5
|
+
import { PassThrough } from "node:stream";
|
|
6
|
+
import {
|
|
7
|
+
renderToPipeableStream,
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
} from "react-server-dom-esm/server.node";
|
|
10
|
+
import type {
|
|
11
|
+
RscChunkMessage,
|
|
12
|
+
RscEndMessage,
|
|
13
|
+
RscWorkerMessage,
|
|
14
|
+
} from "../types.js";
|
|
15
|
+
import { createLogger } from "../../utils/logger.js";
|
|
16
|
+
import {
|
|
17
|
+
cssFiles,
|
|
18
|
+
clientFiles,
|
|
19
|
+
serverActionFiles,
|
|
20
|
+
addCssFile,
|
|
21
|
+
clearCssFiles,
|
|
22
|
+
} from "./state.js";
|
|
23
|
+
import type { WriteStream } from "node:fs";
|
|
24
|
+
import React from "react";
|
|
25
|
+
|
|
26
|
+
const log = createLogger("rsc-worker");
|
|
27
|
+
|
|
28
|
+
// CSS collector component
|
|
29
|
+
function CssCollector({
|
|
30
|
+
children,
|
|
31
|
+
cssFiles,
|
|
32
|
+
}: {
|
|
33
|
+
children: React.ReactNode;
|
|
34
|
+
cssFiles: Map<string, string>;
|
|
35
|
+
}) {
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
{Array.from(cssFiles.entries()).map(([id, css]) => {
|
|
39
|
+
return (
|
|
40
|
+
<style key={id} data-source={id}>
|
|
41
|
+
{css}
|
|
42
|
+
</style>
|
|
43
|
+
);
|
|
44
|
+
})}
|
|
45
|
+
{children}
|
|
46
|
+
</>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function messageHandler(message: RscWorkerMessage) {
|
|
51
|
+
|
|
52
|
+
if (message.type === "RSC_RENDER") {
|
|
53
|
+
const {
|
|
54
|
+
id,
|
|
55
|
+
pageImport,
|
|
56
|
+
propsImport,
|
|
57
|
+
pageExportName,
|
|
58
|
+
propsExportName,
|
|
59
|
+
url,
|
|
60
|
+
outDir,
|
|
61
|
+
projectRoot,
|
|
62
|
+
moduleBaseURL,
|
|
63
|
+
moduleBasePath,
|
|
64
|
+
pipableStreamOptions,
|
|
65
|
+
} = message;
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
// Load modules which will trigger CSS loading
|
|
69
|
+
const [Component, propsModule] = await Promise.all([
|
|
70
|
+
import(join(projectRoot, pageImport)),
|
|
71
|
+
import(join(projectRoot, propsImport)),
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
const propsAtExport = propsModule[propsExportName];
|
|
75
|
+
const props = await Promise.resolve(
|
|
76
|
+
typeof propsAtExport === "function" ? propsAtExport(url) : propsAtExport
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const PageComponent = Component[pageExportName];
|
|
80
|
+
// Now render with collected CSS
|
|
81
|
+
const stream = renderToPipeableStream(
|
|
82
|
+
<CssCollector cssFiles={cssFiles}>
|
|
83
|
+
<PageComponent {...props} />
|
|
84
|
+
</CssCollector>,
|
|
85
|
+
moduleBaseURL,
|
|
86
|
+
{
|
|
87
|
+
onError: (error: Error) => {
|
|
88
|
+
log.error(`Stream error at ${id}:`, error);
|
|
89
|
+
parentPort?.postMessage({
|
|
90
|
+
type: "ERROR",
|
|
91
|
+
id,
|
|
92
|
+
error: error instanceof Error ? error.message : String(error),
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
onPostpone: log?.info ?? console.info,
|
|
96
|
+
environmentName: "Server",
|
|
97
|
+
importMap: {
|
|
98
|
+
imports: {
|
|
99
|
+
...pipableStreamOptions?.importMap?.imports,
|
|
100
|
+
"/": moduleBasePath,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
...pipableStreamOptions,
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
// Listen for data and end events
|
|
108
|
+
const passThrough = new PassThrough();
|
|
109
|
+
|
|
110
|
+
stream.pipe(passThrough);
|
|
111
|
+
|
|
112
|
+
passThrough.on("data", (chunk) => {
|
|
113
|
+
// Send to parent
|
|
114
|
+
parentPort?.postMessage({
|
|
115
|
+
type: "RSC_CHUNK",
|
|
116
|
+
id,
|
|
117
|
+
chunk: chunk.toString(),
|
|
118
|
+
moduleRootPath: moduleBasePath,
|
|
119
|
+
moduleBaseURL,
|
|
120
|
+
outDir,
|
|
121
|
+
rscOutputPath: `${outDir}/${id}.rsc`,
|
|
122
|
+
cssFiles: Array.from(cssFiles.entries()),
|
|
123
|
+
} satisfies RscChunkMessage);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
passThrough.on("end", () => {
|
|
127
|
+
parentPort?.postMessage({
|
|
128
|
+
type: "RSC_END",
|
|
129
|
+
id,
|
|
130
|
+
} satisfies RscEndMessage);
|
|
131
|
+
});
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.trace(error);
|
|
134
|
+
parentPort?.postMessage({
|
|
135
|
+
type: "ERROR",
|
|
136
|
+
id,
|
|
137
|
+
error: error instanceof Error ? error.message : String(error),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
} else if (message.type === "CSS_FILE") {
|
|
141
|
+
addCssFile(message.id, message.cssFile);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
import { resolve } from "path";
|
|
3
|
-
import type { ModuleFormat } from
|
|
3
|
+
import type { ModuleFormat } from "rollup";
|
|
4
4
|
import type { StreamPluginOptions } from "../../types.js";
|
|
5
5
|
import { DEFAULT_CONFIG } from "../../config/defaults.js";
|
|
6
6
|
import { getPluginRoot } from "../../config/getPaths.js";
|
|
@@ -11,72 +11,73 @@ export function reactRscWorkerPlugin(options: StreamPluginOptions): Plugin {
|
|
|
11
11
|
config(config) {
|
|
12
12
|
const root = config.root ?? process.cwd();
|
|
13
13
|
const pluginRoot = getPluginRoot();
|
|
14
|
-
const rscWorkerPath =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const rscWorkerPath =
|
|
15
|
+
typeof options.rscWorkerPath === "string"
|
|
16
|
+
? resolve(root, options.rscWorkerPath)
|
|
17
|
+
: resolve(pluginRoot, DEFAULT_CONFIG.RSC_WORKER_PATH);
|
|
18
|
+
|
|
19
|
+
const format: ModuleFormat = "esm";
|
|
19
20
|
|
|
20
21
|
// Single worker output for server build
|
|
21
22
|
const workerConfig = {
|
|
22
23
|
input: {
|
|
23
|
-
|
|
24
|
+
"rsc-worker": rscWorkerPath,
|
|
24
25
|
},
|
|
25
26
|
output: {
|
|
26
27
|
format,
|
|
27
|
-
dir: options.build?.server ??
|
|
28
|
-
entryFileNames:
|
|
28
|
+
dir: options.build?.server ?? "dist/server", // Output to server directory
|
|
29
|
+
entryFileNames: "[name].js",
|
|
29
30
|
preserveModules: true,
|
|
30
31
|
manualChunks: {
|
|
31
|
-
|
|
32
|
+
"rsc-worker": [rscWorkerPath],
|
|
32
33
|
},
|
|
33
34
|
resolve: {
|
|
34
|
-
conditions: [
|
|
35
|
-
}
|
|
36
|
-
}
|
|
35
|
+
conditions: ["react-server"],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
return {
|
|
40
41
|
build: {
|
|
41
42
|
rollupOptions: {
|
|
42
|
-
preserveEntrySignatures:
|
|
43
|
+
preserveEntrySignatures: "strict",
|
|
43
44
|
input: {
|
|
44
45
|
...workerConfig.input,
|
|
45
|
-
...(typeof config.build?.rollupOptions?.input ===
|
|
46
|
-
? config.build?.rollupOptions?.input
|
|
46
|
+
...(typeof config.build?.rollupOptions?.input === "object"
|
|
47
|
+
? config.build?.rollupOptions?.input
|
|
47
48
|
: {}),
|
|
48
49
|
},
|
|
49
50
|
external: [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
"vite",
|
|
52
|
+
"rollup",
|
|
53
|
+
"react",
|
|
54
|
+
"react-dom",
|
|
55
|
+
"react-dom/server",
|
|
56
|
+
"react-server-dom-esm",
|
|
57
|
+
"react-server-dom-esm/client.node",
|
|
58
|
+
"react-server-dom-esm/server.node",
|
|
59
|
+
"react-server-dom-esm/node-loader",
|
|
60
|
+
"source-map",
|
|
61
|
+
"acorn-loose",
|
|
62
|
+
"webpack-sources",
|
|
63
|
+
"stream",
|
|
64
|
+
"util",
|
|
65
|
+
"crypto",
|
|
66
|
+
"async_hooks",
|
|
67
|
+
"fs",
|
|
68
|
+
"path",
|
|
69
|
+
"worker_threads",
|
|
69
70
|
// if we use node: paths in our code, it should always be catched by below rule.
|
|
70
71
|
/^node:.*/,
|
|
71
72
|
],
|
|
72
73
|
output: {
|
|
73
74
|
...workerConfig.output,
|
|
74
|
-
}
|
|
75
|
+
},
|
|
75
76
|
},
|
|
76
77
|
manifest: true, // Ensure manifest is generated
|
|
77
78
|
minify: false,
|
|
78
79
|
sourcemap: true,
|
|
79
|
-
}
|
|
80
|
+
},
|
|
80
81
|
};
|
|
81
82
|
},
|
|
82
83
|
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// no offical types for node:module available yet (23.7.0)
|
|
2
|
+
declare module 'node:module' {
|
|
3
|
+
export interface ImportAttributes {
|
|
4
|
+
[key: string]: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ResolveHookContext {
|
|
8
|
+
conditions: string[];
|
|
9
|
+
parentURL: string | undefined;
|
|
10
|
+
importAttributes: ImportAttributes;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface LoadHookContext {
|
|
14
|
+
conditions: string[];
|
|
15
|
+
format: ModuleFormat | null | undefined;
|
|
16
|
+
importAttributes: ImportAttributes;
|
|
17
|
+
shortCircuit?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ResolveResult {
|
|
21
|
+
url: string;
|
|
22
|
+
shortCircuit: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface LoadResult {
|
|
26
|
+
format: string;
|
|
27
|
+
source: string | SharedArrayBuffer | Uint8Array;
|
|
28
|
+
shortCircuit: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface HooksAPI {
|
|
32
|
+
resolve?: (
|
|
33
|
+
specifier: string,
|
|
34
|
+
context: ResolveHookContext,
|
|
35
|
+
nextResolve: (specifier: string, context: ResolveHookContext) => ResolveResult
|
|
36
|
+
) => ResolveResult;
|
|
37
|
+
|
|
38
|
+
load?: (
|
|
39
|
+
url: string,
|
|
40
|
+
context: LoadHookContext,
|
|
41
|
+
nextLoad: (url: string, context: LoadHookContext) => LoadResult
|
|
42
|
+
) => LoadResult;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function registerHooks(hooks: HooksAPI): void;
|
|
46
|
+
}
|
|
47
|
+
//
|
|
48
|
+
import { parentPort, MessageChannel } from "node:worker_threads";
|
|
49
|
+
import { messageHandler } from "./messageHandler.js";
|
|
50
|
+
import { createLogger } from "../../utils/logger.js";
|
|
51
|
+
import {
|
|
52
|
+
registerHooks,
|
|
53
|
+
register,
|
|
54
|
+
type ResolveHookContext,
|
|
55
|
+
} from 'node:module';
|
|
56
|
+
import { register as registerTsx } from "tsx/esm/api";
|
|
57
|
+
import { join } from 'node:path';
|
|
58
|
+
import { getPluginRoot } from "../../config/getPaths.js";
|
|
59
|
+
|
|
60
|
+
const ports = new MessageChannel();
|
|
61
|
+
// Initialize worker
|
|
62
|
+
if (!parentPort) {
|
|
63
|
+
throw new Error("This module must be run as a worker");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Create channels for each loader
|
|
67
|
+
const reactLoaderChannel = new MessageChannel();
|
|
68
|
+
const cssLoaderChannel = new MessageChannel();
|
|
69
|
+
|
|
70
|
+
// Listen for messages from loaders
|
|
71
|
+
reactLoaderChannel.port2.on('message', (msg) => {
|
|
72
|
+
messageHandler(msg);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
cssLoaderChannel.port2.on('message', (msg) => {
|
|
76
|
+
messageHandler(msg);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const loaderPath = 'file://' + join(getPluginRoot(), 'loader/react-loader.js');
|
|
80
|
+
const cssLoaderPath = 'file://' + join(getPluginRoot(), 'loader/css-loader.js');
|
|
81
|
+
console.log('[worker] Full loader path:', loaderPath);
|
|
82
|
+
|
|
83
|
+
// Register react-loader
|
|
84
|
+
register(loaderPath, {
|
|
85
|
+
parentURL: getPluginRoot(),
|
|
86
|
+
data: { port: reactLoaderChannel.port1 },
|
|
87
|
+
transferList: [reactLoaderChannel.port1]
|
|
88
|
+
});
|
|
89
|
+
register(cssLoaderPath, {
|
|
90
|
+
parentURL: getPluginRoot(),
|
|
91
|
+
data: { port: cssLoaderChannel.port1 },
|
|
92
|
+
transferList: [cssLoaderChannel.port1]
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Register loaders
|
|
96
|
+
registerTsx();
|
|
97
|
+
|
|
98
|
+
// Set up message handling
|
|
99
|
+
parentPort.on("message", (message) => {
|
|
100
|
+
messageHandler(message);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Signal ready
|
|
104
|
+
parentPort.postMessage({ type: "READY", env: "development" });
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { parentPort } from "node:worker_threads";
|
|
2
|
+
import { messageHandler } from "./messageHandler.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
if (!parentPort) {
|
|
6
|
+
throw new Error("This module must be run as a worker");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Handle incoming messages
|
|
10
|
+
parentPort.on("message", messageHandler);
|
|
11
|
+
|
|
12
|
+
// Signal ready
|
|
13
|
+
parentPort.postMessage({ type: "READY", env: "production" });
|
|
@@ -1,128 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
registerClientReference,
|
|
8
|
-
registerServerReference
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
} from "react-server-dom-esm/server.node";
|
|
11
|
-
|
|
12
|
-
import type {
|
|
13
|
-
RscRenderState,
|
|
14
|
-
RscWorkerMessage,
|
|
15
|
-
RscWorkerResponse
|
|
16
|
-
} from "../types.js";
|
|
17
|
-
import { createRscStream } from "./createRscStream.js";
|
|
18
|
-
|
|
19
|
-
if (!parentPort) {
|
|
20
|
-
throw new Error("This module must be run as a worker");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Track active renders
|
|
24
|
-
const activeRenders = new Map<string, RscRenderState>();
|
|
25
|
-
const activeStreams = new Map<string, ReturnType<typeof createRscStream>>();
|
|
26
|
-
const activeWrites = new Map<string, Writable>();
|
|
27
|
-
|
|
28
|
-
async function shutdown() {
|
|
29
|
-
console.log("[RSC Worker] Shutting down forcefully");
|
|
30
|
-
for (const stream of activeStreams.values()) {
|
|
31
|
-
stream.abort();
|
|
32
|
-
}
|
|
33
|
-
for (const writeStream of activeWrites.values()) {
|
|
34
|
-
writeStream.destroy();
|
|
35
|
-
}
|
|
36
|
-
process.exit(0);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function sendMessage(message: RscWorkerResponse) {
|
|
40
|
-
parentPort?.postMessage(message);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Handle incoming messages
|
|
44
|
-
parentPort.on("message", async (message: RscWorkerMessage) => {
|
|
45
|
-
if (message.type === "SHUTDOWN") {
|
|
46
|
-
await shutdown();
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
switch (message.type) {
|
|
52
|
-
case "RSC_RENDER": {
|
|
53
|
-
const { id, pageImport, propsImport, outDir, moduleRootPath, moduleBaseURL, pipableStreamOptions } = message;
|
|
54
|
-
|
|
55
|
-
// Skip if already rendered
|
|
56
|
-
if (activeRenders.has(id)) return;
|
|
57
|
-
|
|
58
|
-
// Create render state
|
|
59
|
-
const renderState: RscRenderState = {
|
|
60
|
-
id,
|
|
61
|
-
outDir,
|
|
62
|
-
moduleRootPath,
|
|
63
|
-
moduleBaseURL,
|
|
64
|
-
rscOutputPath: `${outDir}/${id}.rsc`,
|
|
65
|
-
componentImport: pageImport,
|
|
66
|
-
propsImport,
|
|
67
|
-
pipableStreamOptions
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// Ensure output directory exists
|
|
71
|
-
await mkdir(dirname(renderState.rscOutputPath), { recursive: true });
|
|
72
|
-
const writeStream = createWriteStream(renderState.rscOutputPath);
|
|
73
|
-
|
|
74
|
-
// Create stream
|
|
75
|
-
const stream = createRscStream(renderState, writeStream, parentPort);
|
|
76
|
-
|
|
77
|
-
// Track active streams
|
|
78
|
-
activeRenders.set(id, renderState);
|
|
79
|
-
activeStreams.set(id, stream);
|
|
80
|
-
activeWrites.set(id, writeStream);
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
case "RSC_END": {
|
|
85
|
-
const { id } = message;
|
|
86
|
-
activeRenders.delete(id);
|
|
87
|
-
activeStreams.delete(id);
|
|
88
|
-
activeWrites.delete(id);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
case "CLIENT_REFERENCE": {
|
|
93
|
-
const { id, location, key } = message;
|
|
94
|
-
const ref = registerClientReference(id, location, key);
|
|
95
|
-
sendMessage({
|
|
96
|
-
type: "CLIENT_REFERENCE",
|
|
97
|
-
id,
|
|
98
|
-
location,
|
|
99
|
-
key,
|
|
100
|
-
ref
|
|
101
|
-
});
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
case "SERVER_REFERENCE": {
|
|
106
|
-
const { id, location, key } = message;
|
|
107
|
-
const ref = registerServerReference(id, location, key);
|
|
108
|
-
sendMessage({
|
|
109
|
-
type: "SERVER_REFERENCE",
|
|
110
|
-
id,
|
|
111
|
-
location,
|
|
112
|
-
key,
|
|
113
|
-
ref
|
|
114
|
-
});
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
} catch (error) {
|
|
119
|
-
sendMessage({
|
|
120
|
-
type: "ERROR",
|
|
121
|
-
id: message.type === "RSC_RENDER" ? message.id : "",
|
|
122
|
-
error: error instanceof Error ? error.message : String(error)
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Signal ready
|
|
128
|
-
parentPort.postMessage({ type: "READY" });
|
|
1
|
+
await(
|
|
2
|
+
process.env["NODE_ENV"] === "production"
|
|
3
|
+
? import("./rsc-worker.production.js")
|
|
4
|
+
: import("./rsc-worker.development.js")
|
|
5
|
+
);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createLogger } from "../../utils/logger.js";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// Create shared CSS registry
|
|
5
|
+
export const cssFiles = new Map<string, string>();
|
|
6
|
+
export const clientFiles = new Set<string>();
|
|
7
|
+
export const serverActionFiles = new Set<string>();
|
|
8
|
+
// Helper functions
|
|
9
|
+
export function clearCssFiles() {
|
|
10
|
+
cssFiles.clear();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function clearClientFiles() {
|
|
14
|
+
clientFiles.clear();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function clearServerActionFiles() {
|
|
18
|
+
serverActionFiles.clear();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function addCssFile(id: string, cssFile: string) {
|
|
22
|
+
cssFiles.set(id, cssFile);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function addClientFile(url: string) {
|
|
26
|
+
clientFiles.add(url);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function addServerActionFile(url: string) {
|
|
30
|
+
serverActionFiles.add(url);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function clearAllFiles() {
|
|
34
|
+
clearCssFiles();
|
|
35
|
+
clearClientFiles();
|
|
36
|
+
clearServerActionFiles();
|
|
37
|
+
}
|