vite-plugin-react-server 0.3.18 → 0.3.19
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 +119 -118
- package/bin/patch.mjs +8 -2
- package/dist/package.json +3 -3
- package/dist/plugin/checkFilesExist.d.ts.map +1 -1
- package/dist/plugin/checkFilesExist.js +6 -2
- package/dist/plugin/checkFilesExist.js.map +1 -1
- package/dist/plugin/collect-manifest-client-files.d.ts +23 -0
- package/dist/plugin/collect-manifest-client-files.d.ts.map +1 -0
- package/dist/plugin/collect-manifest-client-files.js +117 -0
- package/dist/plugin/collect-manifest-client-files.js.map +1 -0
- package/dist/plugin/components.d.ts +9 -9
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +50 -9
- package/dist/plugin/components.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +7 -6
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +8 -5
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getPaths.d.ts +0 -1
- package/dist/plugin/config/getPaths.d.ts.map +1 -1
- package/dist/plugin/config/getPaths.js +2 -7
- package/dist/plugin/config/getPaths.js.map +1 -1
- package/dist/plugin/config/mimeTypes.d.ts +2 -0
- package/dist/plugin/config/mimeTypes.d.ts.map +1 -0
- package/dist/plugin/config/mimeTypes.js +24 -0
- package/dist/plugin/config/mimeTypes.js.map +1 -0
- 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 +41 -28
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +1 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js +9 -5
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts +2 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +10 -5
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/copy-dir.js +23 -18
- package/dist/plugin/copy-dir.js.map +1 -0
- package/dist/plugin/helpers/createHandler.d.ts +22 -0
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -0
- package/dist/plugin/{react-server → helpers}/createHandler.js +36 -48
- package/dist/plugin/helpers/createHandler.js.map +1 -0
- package/dist/plugin/{react-server → helpers}/createRscStream.d.ts +2 -1
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -0
- package/dist/plugin/helpers/createRscStream.js +71 -0
- package/dist/plugin/helpers/createRscStream.js.map +1 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +12 -4
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +8 -5
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.js.map +1 -1
- package/dist/plugin/loader/react-loader.js +2 -2
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/preserver/plugin.d.ts.map +1 -1
- package/dist/plugin/preserver/plugin.js +49 -14
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +18 -76
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/index.d.ts.map +1 -1
- package/dist/plugin/react-server/index.js +2 -0
- package/dist/plugin/react-server/index.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts +2 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +53 -217
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-static/index.d.ts +2 -0
- package/dist/plugin/react-static/index.d.ts.map +1 -0
- package/dist/plugin/react-static/index.js +1 -0
- package/dist/plugin/react-static/plugin.d.ts +7 -0
- package/dist/plugin/react-static/plugin.d.ts.map +1 -0
- package/dist/plugin/react-static/plugin.js +199 -0
- package/dist/plugin/react-static/plugin.js.map +1 -0
- package/dist/plugin/resolvePage.d.ts.map +1 -1
- package/dist/plugin/resolvePage.js +9 -0
- package/dist/plugin/resolvePage.js.map +1 -1
- package/dist/plugin/root.d.ts +2 -0
- package/dist/plugin/root.d.ts.map +1 -0
- package/dist/plugin/root.js +12 -0
- package/dist/plugin/root.js.map +1 -0
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +32 -23
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/types.d.ts +1 -18
- package/dist/plugin/transformer/types.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +24 -6
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +0 -1
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.d.ts +30 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js +30 -2
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +3 -5
- 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 +8 -2
- 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 +2 -3
- package/dist/plugin/worker/html/renderPages.d.ts +8 -4
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +118 -83
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +89 -84
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/plugin.js +1 -2
- package/dist/plugin/worker/rsc/rsc-worker.development.js +13 -18
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +4 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/plugin/checkFilesExist.ts +7 -3
- package/plugin/collect-manifest-client-files.ts +152 -0
- package/plugin/components.tsx +55 -10
- package/plugin/config/defaults.tsx +69 -0
- package/plugin/config/getPaths.ts +1 -7
- package/plugin/config/mimeTypes.ts +17 -0
- package/plugin/config/resolveOptions.ts +48 -40
- package/plugin/config/resolvePages.ts +8 -4
- package/plugin/config/resolveUserConfig.ts +12 -9
- package/plugin/{react-server → helpers}/createHandler.ts +46 -63
- package/plugin/helpers/createRscStream.ts +81 -0
- package/plugin/helpers/getBundleManifest.ts +14 -5
- package/plugin/loader/createBuildLoader.ts +9 -6
- package/plugin/loader/css-loader.ts +0 -2
- package/plugin/loader/react-loader.ts +2 -2
- package/plugin/preserver/plugin.ts +64 -17
- package/plugin/react-client/plugin.ts +20 -91
- package/plugin/react-server/index.ts +2 -0
- package/plugin/react-server/plugin.ts +66 -293
- package/plugin/react-static/index.ts +1 -0
- package/plugin/react-static/plugin.ts +247 -0
- package/plugin/resolvePage.ts +9 -0
- package/plugin/root.ts +4 -0
- package/plugin/transformer/plugin.ts +40 -31
- package/plugin/transformer/types.ts +0 -19
- package/plugin/types.ts +25 -6
- package/plugin/worker/createWorker.ts +1 -1
- package/plugin/worker/html/README.md +63 -0
- package/plugin/worker/html/html-worker.development.tsx +89 -2
- package/plugin/worker/html/html-worker.production.tsx +8 -10
- package/plugin/worker/html/messageHandler.ts +8 -2
- package/plugin/worker/html/plugin.ts +2 -3
- package/plugin/worker/html/renderPages.ts +150 -114
- package/plugin/worker/rsc/README.md +58 -0
- package/plugin/worker/rsc/messageHandler.tsx +95 -111
- package/plugin/worker/rsc/plugin.ts +1 -2
- package/plugin/worker/rsc/rsc-worker.development.ts +12 -22
- package/plugin/worker/rsc/rsc-worker.production.ts +5 -1
- package/plugin/worker/rsc/state.ts +0 -3
- package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +114 -12
- package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +10571 -121
- package/tsconfig.json +2 -2
- package/dist/plugin/collect-css-manifest.d.ts +0 -4
- package/dist/plugin/collect-css-manifest.d.ts.map +0 -1
- package/dist/plugin/collect-css-manifest.js +0 -65
- package/dist/plugin/collect-css-manifest.js.map +0 -1
- package/dist/plugin/config/createModuleIdGenerator.d.ts +0 -11
- package/dist/plugin/config/createModuleIdGenerator.d.ts.map +0 -1
- package/dist/plugin/config/createModuleIdGenerator.js +0 -44
- package/dist/plugin/config/createModuleIdGenerator.js.map +0 -1
- package/dist/plugin/loader/createCssLoader.d.ts +0 -30
- package/dist/plugin/loader/createCssLoader.d.ts.map +0 -1
- package/dist/plugin/loader/createCssLoader.js +0 -35
- package/dist/plugin/loader/createPageLoader.d.ts +0 -24
- package/dist/plugin/loader/createPageLoader.d.ts.map +0 -1
- package/dist/plugin/loader/createPageLoader.js +0 -50
- package/dist/plugin/loader/rsc/messageHandler.d.ts +0 -2
- package/dist/plugin/loader/rsc/messageHandler.d.ts.map +0 -1
- package/dist/plugin/loader/rsc/messageHandler.js +0 -1
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +0 -2
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +0 -1
- package/dist/plugin/loader/rsc/rsc-worker.development.js +0 -1
- package/dist/plugin/react-server/createHandler.d.ts +0 -17
- package/dist/plugin/react-server/createHandler.d.ts.map +0 -1
- package/dist/plugin/react-server/createHandler.js.map +0 -1
- package/dist/plugin/react-server/createRscStream.d.ts.map +0 -1
- package/dist/plugin/react-server/createRscStream.js +0 -70
- package/dist/plugin/react-server/createRscStream.js.map +0 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts +0 -4
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +0 -1
- package/dist/plugin/react-server/createSsrHandler.js +0 -95
- package/dist/plugin/utils/logger.d.ts +0 -9
- package/dist/plugin/utils/logger.d.ts.map +0 -1
- package/dist/plugin/utils/logger.js +0 -68
- package/dist/plugin/utils/logger.js.map +0 -1
- package/plugin/collect-css-manifest.ts +0 -82
- package/plugin/config/createModuleIdGenerator.ts +0 -52
- package/plugin/config/defaults.ts +0 -51
- package/plugin/loader/createCssLoader.ts +0 -73
- package/plugin/loader/createPageLoader.ts +0 -103
- package/plugin/loader/rsc/messageHandler.tsx +0 -1
- package/plugin/loader/rsc/rsc-worker.development.ts +0 -1
- package/plugin/react-server/createRscStream.ts +0 -86
- package/plugin/react-server/createSsrHandler.ts +0 -125
- package/plugin/utils/logger.ts +0 -52
|
@@ -8,97 +8,102 @@ import { PassThrough } from 'node:stream';
|
|
|
8
8
|
import { parentPort } from 'node:worker_threads';
|
|
9
9
|
import React__default from 'react';
|
|
10
10
|
import { renderToPipeableStream } from 'react-server-dom-esm/server.node';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { addCssFile, cssFiles } from './state.js';
|
|
12
|
+
import { CssCollector } from '../../components.js';
|
|
13
13
|
|
|
14
|
-
const log = createLogger("rsc-worker");
|
|
15
|
-
function CssCollector({
|
|
16
|
-
children,
|
|
17
|
-
cssFiles: cssFiles2
|
|
18
|
-
}) {
|
|
19
|
-
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, Array.from(cssFiles2.entries()).map(([id, css]) => {
|
|
20
|
-
return /* @__PURE__ */ React__default.createElement("style", { key: id, "data-source": id }, css);
|
|
21
|
-
}), children);
|
|
22
|
-
}
|
|
23
14
|
async function messageHandler(message) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
moduleBasePath,
|
|
36
|
-
pipableStreamOptions
|
|
37
|
-
} = message;
|
|
38
|
-
try {
|
|
39
|
-
const [Component, propsModule] = await Promise.all([
|
|
40
|
-
import(join(projectRoot, pageImport)),
|
|
41
|
-
import(join(projectRoot, propsImport))
|
|
42
|
-
]);
|
|
43
|
-
const propsAtExport = propsModule[propsExportName];
|
|
44
|
-
const props = await Promise.resolve(
|
|
45
|
-
typeof propsAtExport === "function" ? propsAtExport(url) : propsAtExport
|
|
46
|
-
);
|
|
47
|
-
const PageComponent = Component[pageExportName];
|
|
48
|
-
const stream = renderToPipeableStream(
|
|
49
|
-
/* @__PURE__ */ React__default.createElement(CssCollector, { cssFiles }, /* @__PURE__ */ React__default.createElement(PageComponent, { ...props })),
|
|
15
|
+
switch (message.type) {
|
|
16
|
+
case "RSC_RENDER":
|
|
17
|
+
const {
|
|
18
|
+
id,
|
|
19
|
+
pageImport,
|
|
20
|
+
propsImport,
|
|
21
|
+
pageExportName,
|
|
22
|
+
propsExportName,
|
|
23
|
+
url,
|
|
24
|
+
outDir,
|
|
25
|
+
projectRoot,
|
|
50
26
|
moduleBaseURL,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
stream.pipe(passThrough);
|
|
74
|
-
passThrough.on("data", (chunk) => {
|
|
75
|
-
parentPort?.postMessage({
|
|
76
|
-
type: "RSC_CHUNK",
|
|
77
|
-
id,
|
|
78
|
-
chunk: chunk.toString(),
|
|
79
|
-
moduleRootPath: moduleBasePath,
|
|
27
|
+
moduleBasePath,
|
|
28
|
+
pipableStreamOptions
|
|
29
|
+
} = message;
|
|
30
|
+
try {
|
|
31
|
+
const [Component, propsModule] = await Promise.all([
|
|
32
|
+
import(join(projectRoot, pageImport)),
|
|
33
|
+
import(join(projectRoot, propsImport))
|
|
34
|
+
]);
|
|
35
|
+
const propsAtExport = propsModule[propsExportName];
|
|
36
|
+
const props = await Promise.resolve(
|
|
37
|
+
typeof propsAtExport === "function" ? propsAtExport(url) : propsAtExport
|
|
38
|
+
);
|
|
39
|
+
const PageComponent = Component[pageExportName];
|
|
40
|
+
const stream = renderToPipeableStream(
|
|
41
|
+
/* @__PURE__ */ React__default.createElement(
|
|
42
|
+
CssCollector,
|
|
43
|
+
{
|
|
44
|
+
cssFiles: Array.from(cssFiles.values()),
|
|
45
|
+
moduleBaseUrl: moduleBaseURL
|
|
46
|
+
},
|
|
47
|
+
/* @__PURE__ */ React__default.createElement(PageComponent, { ...props })
|
|
48
|
+
),
|
|
80
49
|
moduleBaseURL,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
50
|
+
{
|
|
51
|
+
onError: (error) => {
|
|
52
|
+
parentPort?.postMessage({
|
|
53
|
+
type: "ERROR",
|
|
54
|
+
id,
|
|
55
|
+
error: error instanceof Error ? error.message : String(error)
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
onPostpone: (reason) => {
|
|
59
|
+
parentPort?.postMessage({
|
|
60
|
+
type: "POSTPONE",
|
|
61
|
+
id,
|
|
62
|
+
reason
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
environmentName: "Server",
|
|
66
|
+
importMap: {
|
|
67
|
+
imports: {
|
|
68
|
+
...pipableStreamOptions?.importMap?.imports,
|
|
69
|
+
"/": moduleBasePath
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
...pipableStreamOptions
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
const passThrough = new PassThrough();
|
|
76
|
+
stream.pipe(passThrough);
|
|
77
|
+
passThrough.on("data", (chunk) => {
|
|
78
|
+
parentPort?.postMessage({
|
|
79
|
+
type: "RSC_CHUNK",
|
|
80
|
+
id,
|
|
81
|
+
chunk: chunk.toString(),
|
|
82
|
+
moduleRootPath: moduleBasePath,
|
|
83
|
+
moduleBaseURL,
|
|
84
|
+
outDir,
|
|
85
|
+
rscOutputPath: `${outDir}/${id}.rsc`,
|
|
86
|
+
cssFiles: Array.from(cssFiles.entries())
|
|
87
|
+
});
|
|
84
88
|
});
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
passThrough.on("end", () => {
|
|
90
|
+
parentPort?.postMessage({
|
|
91
|
+
type: "RSC_END",
|
|
92
|
+
id
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.trace(error);
|
|
87
97
|
parentPort?.postMessage({
|
|
88
|
-
type: "
|
|
89
|
-
id
|
|
98
|
+
type: "ERROR",
|
|
99
|
+
id,
|
|
100
|
+
error: error instanceof Error ? error.message : String(error)
|
|
90
101
|
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
id,
|
|
97
|
-
error: error instanceof Error ? error.message : String(error)
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
} else if (message.type === "CSS_FILE") {
|
|
101
|
-
addCssFile(message.id, message.cssFile);
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
case "CSS_FILE":
|
|
105
|
+
addCssFile(message.id, message.cssFile);
|
|
106
|
+
break;
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
109
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageHandler.js","sources":["../../../../plugin/worker/rsc/messageHandler.tsx"],"sourcesContent":["import { join } from \"node:path\";\nimport { PassThrough } from \"node:stream\";\nimport { parentPort } from \"node:worker_threads\";\nimport React from \"react\";\nimport {\n renderToPipeableStream,\n // @ts-ignore\n} from \"react-server-dom-esm/server.node\";\nimport
|
|
1
|
+
{"version":3,"file":"messageHandler.js","sources":["../../../../plugin/worker/rsc/messageHandler.tsx"],"sourcesContent":["import { join } from \"node:path\";\nimport { PassThrough } from \"node:stream\";\nimport { parentPort } from \"node:worker_threads\";\nimport React from \"react\";\nimport {\n renderToPipeableStream,\n // @ts-ignore\n} from \"react-server-dom-esm/server.node\";\nimport type {\n RscChunkMessage,\n RscEndMessage,\n RscWorkerMessage,\n} from \"../types.js\";\nimport { addCssFile, cssFiles } from \"./state.js\";\nimport { CssCollector } from \"../../components.js\";\n\nexport async function messageHandler(message: RscWorkerMessage) {\n switch (message.type) {\n case \"RSC_RENDER\":\n const {\n id,\n pageImport,\n propsImport,\n pageExportName,\n propsExportName,\n url,\n outDir,\n projectRoot,\n moduleBaseURL,\n moduleBasePath,\n pipableStreamOptions,\n } = message;\n\n try {\n // Load modules which will trigger CSS loading\n const [Component, propsModule] = await Promise.all([\n import(join(projectRoot, pageImport)),\n import(join(projectRoot, propsImport)),\n ]);\n\n const propsAtExport = propsModule[propsExportName];\n const props = await Promise.resolve(\n typeof propsAtExport === \"function\"\n ? propsAtExport(url)\n : propsAtExport\n );\n\n const PageComponent = Component[pageExportName];\n // Now render with collected CSS\n const stream = renderToPipeableStream(\n <CssCollector\n cssFiles={Array.from(cssFiles.values())}\n moduleBaseUrl={moduleBaseURL}\n >\n <PageComponent {...props} />\n </CssCollector>,\n moduleBaseURL,\n {\n onError: (error: Error) => {\n parentPort?.postMessage({\n type: \"ERROR\",\n id,\n error: error instanceof Error ? error.message : String(error),\n });\n },\n onPostpone: (reason: string) => {\n parentPort?.postMessage({\n type: \"POSTPONE\",\n id,\n reason,\n });\n },\n environmentName: \"Server\",\n importMap: {\n imports: {\n ...pipableStreamOptions?.importMap?.imports,\n \"/\": moduleBasePath,\n },\n },\n ...pipableStreamOptions,\n }\n );\n\n // Listen for data and end events\n const passThrough = new PassThrough();\n\n stream.pipe(passThrough);\n\n passThrough.on(\"data\", (chunk) => {\n // Send to parent\n parentPort?.postMessage({\n type: \"RSC_CHUNK\",\n id,\n chunk: chunk.toString(),\n moduleRootPath: moduleBasePath,\n moduleBaseURL,\n outDir,\n rscOutputPath: `${outDir}/${id}.rsc`,\n cssFiles: Array.from(cssFiles.entries()),\n } satisfies RscChunkMessage);\n });\n\n passThrough.on(\"end\", () => {\n parentPort?.postMessage({\n type: \"RSC_END\",\n id,\n } satisfies RscEndMessage);\n });\n } catch (error) {\n console.trace(error);\n parentPort?.postMessage({\n type: \"ERROR\",\n id,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n break;\n case \"CSS_FILE\":\n addCssFile(message.id, message.cssFile);\n break;\n }\n}\n"],"names":["React"],"mappings":";;;;;;;;;;;;;AAgBA,eAAsB,eAAe,OAA2B,EAAA;AAC9D,EAAA,QAAQ,QAAQ,IAAM;AAAA,IACpB,KAAK,YAAA;AACH,MAAM,MAAA;AAAA,QACJ,EAAA;AAAA,QACA,UAAA;AAAA,QACA,WAAA;AAAA,QACA,cAAA;AAAA,QACA,eAAA;AAAA,QACA,GAAA;AAAA,QACA,MAAA;AAAA,QACA,WAAA;AAAA,QACA,aAAA;AAAA,QACA,cAAA;AAAA,QACA;AAAA,OACE,GAAA,OAAA;AAEJ,MAAI,IAAA;AAEF,QAAA,MAAM,CAAC,SAAW,EAAA,WAAW,CAAI,GAAA,MAAM,QAAQ,GAAI,CAAA;AAAA,UACjD,OAAO,IAAK,CAAA,WAAA,EAAa,UAAU,CAAA,CAAA;AAAA,UACnC,OAAO,IAAK,CAAA,WAAA,EAAa,WAAW,CAAA;AAAA,SACrC,CAAA;AAED,QAAM,MAAA,aAAA,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I1D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAI1D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CA2EzE"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { resolve } from "path";
|
|
2
2
|
import { DEFAULT_CONFIG } from "../../config/defaults.js";
|
|
3
|
-
import {
|
|
3
|
+
import { pluginRoot } from "../../root.js";
|
|
4
4
|
export function reactRscWorkerPlugin(options) {
|
|
5
5
|
return {
|
|
6
6
|
name: "vite:react-rsc-worker",
|
|
7
7
|
config(config) {
|
|
8
8
|
const root = config.root ?? process.cwd();
|
|
9
|
-
const pluginRoot = getPluginRoot();
|
|
10
9
|
const rscWorkerPath = typeof options.rscWorkerPath === "string"
|
|
11
10
|
? resolve(root, options.rscWorkerPath)
|
|
12
11
|
: resolve(pluginRoot, DEFAULT_CONFIG.RSC_WORKER_PATH);
|
|
@@ -3,41 +3,36 @@
|
|
|
3
3
|
* Copyright (c) Nico Brinkkemper
|
|
4
4
|
* MIT License
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { parentPort, MessageChannel } from 'node:worker_threads';
|
|
7
7
|
import { messageHandler } from './messageHandler.js';
|
|
8
8
|
import { register } from 'node:module';
|
|
9
9
|
import { register as register$1 } from 'tsx/esm/api';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
|
-
import {
|
|
11
|
+
import { pluginRoot } from '../../root.js';
|
|
12
12
|
|
|
13
|
-
new MessageChannel();
|
|
14
13
|
if (!parentPort) {
|
|
15
14
|
throw new Error("This module must be run as a worker");
|
|
16
15
|
}
|
|
17
16
|
const reactLoaderChannel = new MessageChannel();
|
|
18
17
|
const cssLoaderChannel = new MessageChannel();
|
|
19
|
-
reactLoaderChannel.port2.on("message",
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
messageHandler(msg);
|
|
24
|
-
});
|
|
25
|
-
const loaderPath = "file://" + join(getPluginRoot(), "loader/react-loader.js");
|
|
26
|
-
const cssLoaderPath = "file://" + join(getPluginRoot(), "loader/css-loader.js");
|
|
27
|
-
console.log("[worker] Full loader path:", loaderPath);
|
|
18
|
+
reactLoaderChannel.port2.on("message", messageHandler);
|
|
19
|
+
cssLoaderChannel.port2.on("message", messageHandler);
|
|
20
|
+
const loaderPath = "file://" + join(pluginRoot, "loader/react-loader.js");
|
|
21
|
+
const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.js");
|
|
28
22
|
register(loaderPath, {
|
|
29
|
-
parentURL:
|
|
23
|
+
parentURL: pluginRoot,
|
|
30
24
|
data: { port: reactLoaderChannel.port1 },
|
|
31
25
|
transferList: [reactLoaderChannel.port1]
|
|
32
26
|
});
|
|
33
27
|
register(cssLoaderPath, {
|
|
34
|
-
parentURL:
|
|
28
|
+
parentURL: pluginRoot,
|
|
35
29
|
data: { port: cssLoaderChannel.port1 },
|
|
36
30
|
transferList: [cssLoaderChannel.port1]
|
|
37
31
|
});
|
|
38
32
|
register$1();
|
|
39
|
-
parentPort.on("message",
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
parentPort.on("message", messageHandler);
|
|
34
|
+
parentPort.postMessage({ type: "READY", env: process.env["NODE_ENV"] });
|
|
35
|
+
if (process.env["NODE_ENV"] !== "development") {
|
|
36
|
+
throw new Error("This module must be run in development mode");
|
|
37
|
+
}
|
|
43
38
|
//# sourceMappingURL=rsc-worker.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc-worker.development.js","sources":["../../../../plugin/worker/rsc/rsc-worker.development.ts"],"sourcesContent":["// no offical types for node:module available yet (23.7.0)\ndeclare module 'node:module' {\n export interface ImportAttributes {\n [key: string]: string | undefined;\n }\n\n export interface ResolveHookContext {\n conditions: string[];\n parentURL: string | undefined;\n importAttributes: ImportAttributes;\n }\n\n export interface LoadHookContext {\n conditions: string[];\n format: ModuleFormat | null | undefined;\n importAttributes: ImportAttributes;\n shortCircuit?: boolean;\n }\n\n export interface ResolveResult {\n url: string;\n shortCircuit: boolean;\n }\n\n export interface LoadResult {\n format: string;\n source: string | SharedArrayBuffer | Uint8Array;\n shortCircuit: boolean;\n }\n\n export interface HooksAPI {\n resolve?: (\n specifier: string,\n context: ResolveHookContext,\n nextResolve: (specifier: string, context: ResolveHookContext) => ResolveResult\n ) => ResolveResult;\n\n load?: (\n url: string,\n context: LoadHookContext,\n nextLoad: (url: string, context: LoadHookContext) => LoadResult\n ) => LoadResult;\n }\n\n export function registerHooks(hooks: HooksAPI): void;\n}\n//\nimport { parentPort, MessageChannel } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"rsc-worker.development.js","sources":["../../../../plugin/worker/rsc/rsc-worker.development.ts"],"sourcesContent":["// no offical types for node:module available yet (23.7.0)\ndeclare module 'node:module' {\n export interface ImportAttributes {\n [key: string]: string | undefined;\n }\n\n export interface ResolveHookContext {\n conditions: string[];\n parentURL: string | undefined;\n importAttributes: ImportAttributes;\n }\n\n export interface LoadHookContext {\n conditions: string[];\n format: ModuleFormat | null | undefined;\n importAttributes: ImportAttributes;\n shortCircuit?: boolean;\n }\n\n export interface ResolveResult {\n url: string;\n shortCircuit: boolean;\n }\n\n export interface LoadResult {\n format: string;\n source: string | SharedArrayBuffer | Uint8Array;\n shortCircuit: boolean;\n }\n\n export interface HooksAPI {\n resolve?: (\n specifier: string,\n context: ResolveHookContext,\n nextResolve: (specifier: string, context: ResolveHookContext) => ResolveResult\n ) => ResolveResult;\n\n load?: (\n url: string,\n context: LoadHookContext,\n nextLoad: (url: string, context: LoadHookContext) => LoadResult\n ) => LoadResult;\n }\n\n export function registerHooks(hooks: HooksAPI): void;\n}\n//\nimport { parentPort, MessageChannel } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\nimport { \n register,\n} from 'node:module';\nimport { register as registerTsx } from \"tsx/esm/api\";\nimport { join } from 'node:path';\nimport { pluginRoot } from \"../../root.js\";\n\n// Initialize worker\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// Create channels for each loader\nconst reactLoaderChannel = new MessageChannel();\nconst cssLoaderChannel = new MessageChannel();\n\n// Listen for messages from loaders\nreactLoaderChannel.port2.on('message', messageHandler);\ncssLoaderChannel.port2.on('message', messageHandler);\n\nconst loaderPath = 'file://' + join(pluginRoot, 'loader/react-loader.js');\nconst cssLoaderPath = 'file://' + join(pluginRoot, 'loader/css-loader.js');\n\n// Register react-loader\nregister(loaderPath, {\n parentURL: pluginRoot,\n data: { port: reactLoaderChannel.port1 },\n transferList: [reactLoaderChannel.port1]\n});\nregister(cssLoaderPath, {\n parentURL: pluginRoot,\n data: { port: cssLoaderChannel.port1 },\n transferList: [cssLoaderChannel.port1]\n});\n\n// Register loaders\nregisterTsx();\n\n// Set up message handling\nparentPort.on(\"message\", messageHandler);\n\n// Signal ready\nparentPort.postMessage({ type: \"READY\", env: process.env[\"NODE_ENV\"] });\n\nif (process.env[\"NODE_ENV\"] !== \"development\") {\n throw new Error(\"This module must be run in development mode\");\n}\n\n"],"names":["registerTsx"],"mappings":";;;;;;;;;;;;AAyDA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,MAAM,kBAAA,GAAqB,IAAI,cAAe,EAAA;AAC9C,MAAM,gBAAA,GAAmB,IAAI,cAAe,EAAA;AAG5C,kBAAmB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AACrD,gBAAiB,CAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,cAAc,CAAA;AAEnD,MAAM,UAAa,GAAA,SAAA,GAAY,IAAK,CAAA,UAAA,EAAY,wBAAwB,CAAA;AACxE,MAAM,aAAgB,GAAA,SAAA,GAAY,IAAK,CAAA,UAAA,EAAY,sBAAsB,CAAA;AAGzE,QAAA,CAAS,UAAY,EAAA;AAAA,EACnB,SAAW,EAAA,UAAA;AAAA,EACX,IAAM,EAAA,EAAE,IAAM,EAAA,kBAAA,CAAmB,KAAM,EAAA;AAAA,EACvC,YAAA,EAAc,CAAC,kBAAA,CAAmB,KAAK;AACzC,CAAC,CAAA;AACD,QAAA,CAAS,aAAe,EAAA;AAAA,EACtB,SAAW,EAAA,UAAA;AAAA,EACX,IAAM,EAAA,EAAE,IAAM,EAAA,gBAAA,CAAiB,KAAM,EAAA;AAAA,EACrC,YAAA,EAAc,CAAC,gBAAA,CAAiB,KAAK;AACvC,CAAC,CAAA;AAGDA,UAAY,EAAA;AAGZ,UAAW,CAAA,EAAA,CAAG,WAAW,cAAc,CAAA;AAGvC,UAAW,CAAA,WAAA,CAAY,EAAE,IAAM,EAAA,OAAA,EAAS,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,EAAG,CAAA;AAEtE,IAAI,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,KAAM,aAAe,EAAA;AAC7C,EAAM,MAAA,IAAI,MAAM,6CAA6C,CAAA;AAC/D"}
|
|
@@ -10,5 +10,8 @@ if (!parentPort) {
|
|
|
10
10
|
throw new Error("This module must be run as a worker");
|
|
11
11
|
}
|
|
12
12
|
parentPort.on("message", messageHandler);
|
|
13
|
-
parentPort.postMessage({ type: "READY", env: "
|
|
13
|
+
parentPort.postMessage({ type: "READY", env: process.env["NODE_ENV"] });
|
|
14
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
15
|
+
throw new Error("This module must be run in production mode");
|
|
16
|
+
}
|
|
14
17
|
//# sourceMappingURL=rsc-worker.production.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc-worker.production.js","sources":["../../../../plugin/worker/rsc/rsc-worker.production.ts"],"sourcesContent":["import { parentPort } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\n\n\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// Handle incoming messages\nparentPort.on(\"message\", messageHandler);\n\n// Signal ready\nparentPort.postMessage({ type: \"READY\", env: \"
|
|
1
|
+
{"version":3,"file":"rsc-worker.production.js","sources":["../../../../plugin/worker/rsc/rsc-worker.production.ts"],"sourcesContent":["import { parentPort } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\n\n\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// Handle incoming messages\nparentPort.on(\"message\", messageHandler);\n\n// Signal ready\nparentPort.postMessage({ type: \"READY\", env: process.env[\"NODE_ENV\"] });\n\nif (process.env[\"NODE_ENV\"] !== \"production\") {\n throw new Error(\"This module must be run in production mode\");\n}\n"],"names":[],"mappings":";;;;;;;;AAIA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,UAAW,CAAA,EAAA,CAAG,WAAW,cAAc,CAAA;AAGvC,UAAW,CAAA,WAAA,CAAY,EAAE,IAAM,EAAA,OAAA,EAAS,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,EAAG,CAAA;AAEtE,IAAI,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,KAAM,YAAc,EAAA;AAC5C,EAAM,MAAA,IAAI,MAAM,4CAA4C,CAAA;AAC9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/state.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,QAAQ,qBAA4B,CAAC;AAClD,eAAO,MAAM,WAAW,aAAoB,CAAC;AAC7C,eAAO,MAAM,iBAAiB,aAAoB,CAAC;AAEnD,wBAAgB,aAAa,SAE5B;AAED,wBAAgB,gBAAgB,SAE/B;AAED,wBAAgB,sBAAsB,SAErC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAErD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,QAExC;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,QAE9C;AAED,wBAAgB,aAAa,SAI5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sources":["../../../../plugin/worker/rsc/state.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"state.js","sources":["../../../../plugin/worker/rsc/state.ts"],"sourcesContent":["// Create shared CSS registry\nexport const cssFiles = new Map<string, string>();\nexport const clientFiles = new Set<string>();\nexport const serverActionFiles = new Set<string>();\n// Helper functions\nexport function clearCssFiles() {\n cssFiles.clear();\n}\n\nexport function clearClientFiles() {\n clientFiles.clear();\n}\n\nexport function clearServerActionFiles() {\n serverActionFiles.clear();\n}\n\nexport function addCssFile(id: string, cssFile: string) {\n cssFiles.set(id, cssFile);\n} \n\nexport function addClientFile(url: string) {\n clientFiles.add(url);\n}\n\nexport function addServerActionFile(url: string) {\n serverActionFiles.add(url);\n}\n\nexport function clearAllFiles() {\n clearCssFiles();\n clearClientFiles();\n clearServerActionFiles();\n} "],"names":[],"mappings":";;;;;AACa,MAAA,QAAA,uBAAe,GAAoB;AAgBhC,SAAA,UAAA,CAAW,IAAY,OAAiB,EAAA;AACtD,EAAS,QAAA,CAAA,GAAA,CAAI,IAAI,OAAO,CAAA;AAC1B;;;;"}
|