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
package/plugin/types.ts
CHANGED
|
@@ -1,40 +1,57 @@
|
|
|
1
|
-
import type { ComponentType } from
|
|
2
|
-
import type {
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
import type { RenderToPipeableStreamOptions } from "react-dom/server";
|
|
3
|
+
import type { PreRenderedChunk } from "rollup";
|
|
4
|
+
import type { PreRenderedAsset } from "rollup";
|
|
5
|
+
import type {
|
|
3
6
|
UserConfig,
|
|
4
7
|
BuildOptions,
|
|
5
8
|
InlineConfig,
|
|
6
9
|
AliasOptions,
|
|
7
10
|
Connect,
|
|
8
|
-
|
|
11
|
+
ResolveOptions,
|
|
12
|
+
} from "vite";
|
|
13
|
+
import type { PipeableStreamOptions } from "./worker/types.js";
|
|
9
14
|
|
|
10
15
|
// Input can be a string path, React component, tuple, or array
|
|
11
|
-
export type NormalizerInput =
|
|
16
|
+
export type NormalizerInput = unknown;
|
|
12
17
|
|
|
13
18
|
export type InputNormalizer = (input: NormalizerInput) => [string, string];
|
|
14
19
|
|
|
15
|
-
export type InputNormalizerWorker = (
|
|
20
|
+
export type InputNormalizerWorker = (
|
|
21
|
+
input: NormalizerInput
|
|
22
|
+
) => Promise<[string, string]>;
|
|
16
23
|
|
|
17
|
-
export type ResolvedUserConfig = Required<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
>
|
|
24
|
+
export type ResolvedUserConfig = Required<
|
|
25
|
+
Pick<UserConfig, "root" | "mode" | "build" | "resolve">
|
|
26
|
+
> &
|
|
27
|
+
Omit<UserConfig, "root" | "mode" | "build" | "resolve"> & {
|
|
28
|
+
resolve: {alias:AliasOptions} & ResolveOptions;
|
|
29
|
+
} & {
|
|
30
|
+
build: NonNullable<
|
|
31
|
+
Required<
|
|
32
|
+
Pick<
|
|
33
|
+
BuildOptions,
|
|
34
|
+
| "target"
|
|
35
|
+
| "outDir"
|
|
36
|
+
| "assetsDir"
|
|
37
|
+
| "ssr"
|
|
38
|
+
| "ssrEmitAssets"
|
|
39
|
+
| "ssrManifest"
|
|
40
|
+
| "manifest"
|
|
41
|
+
| "rollupOptions"
|
|
42
|
+
>
|
|
43
|
+
>
|
|
44
|
+
> &
|
|
45
|
+
Omit<
|
|
46
|
+
BuildOptions,
|
|
47
|
+
| "target"
|
|
48
|
+
| "outDir"
|
|
49
|
+
| "assetsDir"
|
|
50
|
+
| "ssr"
|
|
51
|
+
| "ssrEmitAssets"
|
|
52
|
+
| "ssrManifest"
|
|
53
|
+
| "manifest"
|
|
54
|
+
>;
|
|
38
55
|
};
|
|
39
56
|
|
|
40
57
|
// Client plugin options
|
|
@@ -65,46 +82,75 @@ export type ResolvedUserOptions = Required<
|
|
|
65
82
|
| "propsExportName"
|
|
66
83
|
| "collectCss"
|
|
67
84
|
| "collectAssets"
|
|
68
|
-
| "assetsDir"
|
|
69
85
|
| "htmlWorkerPath"
|
|
70
86
|
| "rscWorkerPath"
|
|
71
87
|
| "loaderPath"
|
|
72
88
|
| "clientEntry"
|
|
73
89
|
| "serverEntry"
|
|
74
90
|
| "moduleBaseExceptions"
|
|
91
|
+
| "pipableStreamOptions"
|
|
92
|
+
| "moduleId"
|
|
75
93
|
>
|
|
76
94
|
> & {
|
|
77
95
|
build: NonNullable<Required<StreamPluginOptions["build"]>>;
|
|
78
|
-
autoDiscover:
|
|
96
|
+
autoDiscover: {
|
|
97
|
+
modulePattern: (path: string) => boolean;
|
|
98
|
+
cssPattern: (path: string) => boolean;
|
|
99
|
+
jsonPattern: (path: string) => boolean;
|
|
100
|
+
clientComponents: (path: string) => boolean;
|
|
101
|
+
propsPattern: (path: string) => boolean;
|
|
102
|
+
pagePattern: (path: string) => boolean;
|
|
103
|
+
serverFunctions: (path: string) => boolean;
|
|
104
|
+
cssModulePattern: (path: string) => boolean;
|
|
105
|
+
vendorPattern: (path: string) => boolean;
|
|
106
|
+
};
|
|
79
107
|
};
|
|
80
108
|
|
|
81
|
-
export type createBuildConfigFn<C extends "react-client" | "react-server"> =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
109
|
+
export type createBuildConfigFn<C extends "react-client" | "react-server"> =
|
|
110
|
+
(input: {
|
|
111
|
+
condition: C;
|
|
112
|
+
userOptions: ResolvedUserOptions;
|
|
113
|
+
userConfig: ResolvedUserConfig;
|
|
114
|
+
mode: "production" | "development" | "test";
|
|
115
|
+
inputNormalizer: C extends "react-server"
|
|
116
|
+
? InputNormalizerWorker
|
|
117
|
+
: InputNormalizerWorker;
|
|
118
|
+
}) => C extends "react-server"
|
|
119
|
+
? Promise<InlineConfig>
|
|
120
|
+
: Promise<InlineConfig>;
|
|
88
121
|
|
|
89
122
|
export interface StreamPluginOptions {
|
|
90
123
|
projectRoot?: string;
|
|
91
|
-
assetsDir?: string;
|
|
92
124
|
moduleBase: string;
|
|
93
125
|
moduleBasePath?: string;
|
|
94
126
|
moduleBaseURL?: string;
|
|
95
127
|
clientEntry?: string;
|
|
96
128
|
serverEntry?: string;
|
|
97
129
|
// Auto-discovery (zero-config)
|
|
98
|
-
autoDiscover?:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
130
|
+
autoDiscover?:
|
|
131
|
+
| {
|
|
132
|
+
// default: /\.(m|c)?(j|t)sx?$/
|
|
133
|
+
modulePattern?: string | RegExp | ((path: string) => boolean);
|
|
134
|
+
// default: [Pp]age.tsx
|
|
135
|
+
pagePattern?: string | RegExp | ((path: string) => boolean);
|
|
136
|
+
// default: [Pp]rops.ts
|
|
137
|
+
propsPattern?: string | RegExp | ((path: string) => boolean);
|
|
138
|
+
// default: "use client" and .client./\.(m|c)?(j|t)sx?$/
|
|
139
|
+
clientComponents?: string | RegExp | ((path: string) => boolean);
|
|
140
|
+
// default: "use server" and .server./\.(m|c)?(j|t)sx?$/
|
|
141
|
+
serverFunctions?: string | RegExp | ((path: string) => boolean);
|
|
142
|
+
// default: /\.css$/
|
|
143
|
+
cssPattern?: string | RegExp | ((path: string) => boolean);
|
|
144
|
+
// default: /\.json$/
|
|
145
|
+
jsonPattern?: string | RegExp | ((path: string) => boolean);
|
|
146
|
+
// default: /\.html$/
|
|
147
|
+
htmlPattern?: string | RegExp | ((path: string) => boolean);
|
|
148
|
+
// default: /\.css\.js/
|
|
149
|
+
cssModulePattern?: string | RegExp | ((path: string) => boolean);
|
|
150
|
+
// default: /node_modules|(_virtual)/
|
|
151
|
+
vendorPattern?: string | RegExp | ((path: string) => boolean);
|
|
152
|
+
}
|
|
153
|
+
| undefined;
|
|
108
154
|
// Manual configuration
|
|
109
155
|
Page: string | ((url: string) => string);
|
|
110
156
|
props?: undefined | string | ((url: string) => string);
|
|
@@ -125,17 +171,19 @@ export interface StreamPluginOptions {
|
|
|
125
171
|
collectAssets?: boolean;
|
|
126
172
|
build?: BuildConfig;
|
|
127
173
|
moduleBaseExceptions?: string[];
|
|
128
|
-
|
|
174
|
+
pipableStreamOptions?: PipeableStreamOptions;
|
|
175
|
+
moduleId?: (id: string, ssr: boolean) => string;
|
|
129
176
|
}
|
|
130
177
|
|
|
131
178
|
export interface CreateHandlerOptions<T = any> {
|
|
132
179
|
loader: (id: string) => Promise<T>;
|
|
133
|
-
|
|
180
|
+
clientManifest?: import("vite").Manifest;
|
|
181
|
+
serverManifest?: import("vite").Manifest;
|
|
134
182
|
moduleGraph?: import("vite").ModuleGraph;
|
|
135
183
|
cssFiles?: string[];
|
|
136
184
|
onCssFile?: (path: string) => void;
|
|
137
185
|
logger?: import("vite").Logger;
|
|
138
|
-
pipableStreamOptions?:
|
|
186
|
+
pipableStreamOptions?: PipeableStreamOptions;
|
|
139
187
|
}
|
|
140
188
|
|
|
141
189
|
export type ModuleLoader = (
|
|
@@ -172,7 +220,7 @@ export interface RscStreamOptions {
|
|
|
172
220
|
htmlProps: any;
|
|
173
221
|
route: string;
|
|
174
222
|
url: string;
|
|
175
|
-
pipableStreamOptions?:
|
|
223
|
+
pipableStreamOptions?: PipeableStreamOptions;
|
|
176
224
|
moduleBasePath: string;
|
|
177
225
|
}
|
|
178
226
|
|
|
@@ -198,9 +246,17 @@ export interface BuildOutput {
|
|
|
198
246
|
|
|
199
247
|
export interface BuildConfig {
|
|
200
248
|
pages: string[] | (() => Promise<string[]> | string[]);
|
|
249
|
+
assetsDir?: string;
|
|
201
250
|
client?: string; // Output directory for client files
|
|
202
251
|
server?: string; // Output directory for server files
|
|
203
252
|
static?: string; // Output directory for static environment - works in both
|
|
253
|
+
api?: string; // Output directory for API files
|
|
254
|
+
outDir?: string;
|
|
255
|
+
hash?: string;
|
|
256
|
+
preserveModulesRoot?: boolean;
|
|
257
|
+
entryFile?: (n: PreRenderedChunk) => string;
|
|
258
|
+
chunkFile?: (n: PreRenderedChunk) => string;
|
|
259
|
+
assetFile?: (n: PreRenderedAsset) => string;
|
|
204
260
|
}
|
|
205
261
|
|
|
206
262
|
export interface RscResolver {
|
|
@@ -276,30 +332,28 @@ export interface BuildTiming {
|
|
|
276
332
|
total?: number;
|
|
277
333
|
}
|
|
278
334
|
|
|
279
|
-
|
|
280
335
|
export type CheckFilesExistReturn = {
|
|
281
|
-
propsMap: Map<string,string
|
|
282
|
-
propsSet: Set<string
|
|
283
|
-
pageMap: Map<string,string
|
|
284
|
-
pageSet: Set<string
|
|
285
|
-
}
|
|
336
|
+
propsMap: Map<string, string>;
|
|
337
|
+
propsSet: Set<string>;
|
|
338
|
+
pageMap: Map<string, string>;
|
|
339
|
+
pageSet: Set<string>;
|
|
340
|
+
};
|
|
286
341
|
|
|
287
342
|
// Add strict type checking for worker messages
|
|
288
|
-
export type WorkerMessage =
|
|
289
|
-
| { type:
|
|
290
|
-
| { type:
|
|
291
|
-
| { type:
|
|
292
|
-
| { type:
|
|
293
|
-
| { type:
|
|
343
|
+
export type WorkerMessage =
|
|
344
|
+
| { type: "READY" }
|
|
345
|
+
| { type: "ERROR"; error: string | Error }
|
|
346
|
+
| { type: "RSC_CHUNK"; id: string; chunk: Buffer }
|
|
347
|
+
| { type: "RSC_END"; id: string }
|
|
348
|
+
| { type: "SHUTDOWN" };
|
|
294
349
|
|
|
295
350
|
// Add branded types for safety
|
|
296
351
|
export type ModuleId = string & { readonly __brand: unique symbol };
|
|
297
352
|
export type PagePath = string & { readonly __brand: unique symbol };
|
|
298
353
|
|
|
299
|
-
|
|
300
354
|
export type HtmlProps = {
|
|
301
355
|
pageProps: any;
|
|
302
356
|
route: string;
|
|
303
357
|
url: string;
|
|
304
358
|
cssFiles: string[];
|
|
305
|
-
}
|
|
359
|
+
};
|
|
@@ -1,30 +1,49 @@
|
|
|
1
1
|
import { PassThrough } from "node:stream";
|
|
2
2
|
import { parentPort } from "node:worker_threads";
|
|
3
3
|
import type { HtmlRenderState, HtmlWorkerMessage } from "../types.js";
|
|
4
|
-
import ReactDOMServer from "react-dom/server";
|
|
4
|
+
import * as ReactDOMServer from "react-dom/server";
|
|
5
5
|
import React from "react";
|
|
6
6
|
import {
|
|
7
7
|
createFromNodeStream,
|
|
8
8
|
// @ts-ignore
|
|
9
9
|
} from "react-server-dom-esm/client.node";
|
|
10
|
+
import { join } from "path";
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import { existsSync } from "node:fs";
|
|
10
13
|
|
|
11
14
|
// Track active renders and streams
|
|
12
15
|
const activeRenders = new Map<string, HtmlRenderState>();
|
|
16
|
+
const htmlContent = new Map<string, string>();
|
|
17
|
+
const htmlPromises = new Map<string, Promise<string>>();
|
|
13
18
|
|
|
14
19
|
export const messageHandler = async (message: HtmlWorkerMessage) => {
|
|
15
20
|
try {
|
|
16
21
|
switch (message.type) {
|
|
17
22
|
case "RSC_CHUNK": {
|
|
18
|
-
const {
|
|
19
|
-
|
|
23
|
+
const {
|
|
24
|
+
id,
|
|
25
|
+
chunk,
|
|
26
|
+
moduleRootPath,
|
|
27
|
+
moduleBaseURL,
|
|
28
|
+
outDir,
|
|
29
|
+
pipableStreamOptions,
|
|
30
|
+
clientManifest = {},
|
|
31
|
+
serverManifest = {},
|
|
32
|
+
htmlOutputPath,
|
|
33
|
+
} = message;
|
|
20
34
|
|
|
35
|
+
const render = activeRenders.get(id);
|
|
21
36
|
if (!render) {
|
|
22
37
|
activeRenders.set(id, {
|
|
23
38
|
chunks: [chunk],
|
|
24
39
|
id,
|
|
25
40
|
complete: false,
|
|
26
41
|
rendered: false,
|
|
27
|
-
|
|
42
|
+
moduleRootPath,
|
|
43
|
+
moduleBaseURL,
|
|
44
|
+
outDir,
|
|
45
|
+
htmlOutputPath: htmlOutputPath ?? join(outDir, 'index.html'),
|
|
46
|
+
pipableStreamOptions: pipableStreamOptions,
|
|
28
47
|
});
|
|
29
48
|
} else {
|
|
30
49
|
render.chunks = [...render.chunks, chunk];
|
|
@@ -39,6 +58,9 @@ export const messageHandler = async (message: HtmlWorkerMessage) => {
|
|
|
39
58
|
throw new Error(`No render state found for ${id}`);
|
|
40
59
|
}
|
|
41
60
|
|
|
61
|
+
// Mark this render as complete
|
|
62
|
+
render.complete = true;
|
|
63
|
+
|
|
42
64
|
// Create a PassThrough stream to handle the chunks
|
|
43
65
|
const rscStream = new PassThrough();
|
|
44
66
|
|
|
@@ -47,18 +69,18 @@ export const messageHandler = async (message: HtmlWorkerMessage) => {
|
|
|
47
69
|
rscStream.write(chunk);
|
|
48
70
|
}
|
|
49
71
|
rscStream.end();
|
|
50
|
-
|
|
72
|
+
|
|
51
73
|
// Create React elements from stream
|
|
52
|
-
const reactElements = createFromNodeStream(
|
|
74
|
+
const reactElements = await createFromNodeStream(
|
|
53
75
|
rscStream,
|
|
54
76
|
render.moduleRootPath,
|
|
55
|
-
|
|
77
|
+
'localhost'
|
|
56
78
|
);
|
|
57
79
|
|
|
58
80
|
// Create a promise that resolves when HTML is complete
|
|
59
81
|
const htmlPromise = new Promise<string>((resolve) => {
|
|
60
|
-
let html = "";
|
|
61
82
|
const collectStream = new PassThrough();
|
|
83
|
+
let html = '';
|
|
62
84
|
|
|
63
85
|
collectStream.on("data", (chunk) => {
|
|
64
86
|
html += chunk.toString();
|
|
@@ -66,8 +88,14 @@ export const messageHandler = async (message: HtmlWorkerMessage) => {
|
|
|
66
88
|
|
|
67
89
|
collectStream.on("end", () => {
|
|
68
90
|
resolve(html);
|
|
91
|
+
render.rendered = true;
|
|
92
|
+
parentPort?.postMessage({
|
|
93
|
+
type: "ALL_READY",
|
|
94
|
+
id,
|
|
95
|
+
html,
|
|
96
|
+
outputPath: render.htmlOutputPath,
|
|
97
|
+
});
|
|
69
98
|
});
|
|
70
|
-
|
|
71
99
|
// Render to pipeable stream
|
|
72
100
|
const stream = ReactDOMServer.renderToPipeableStream(
|
|
73
101
|
reactElements as React.ReactNode,
|
|
@@ -75,24 +103,7 @@ export const messageHandler = async (message: HtmlWorkerMessage) => {
|
|
|
75
103
|
...render.pipableStreamOptions,
|
|
76
104
|
onShellReady() {
|
|
77
105
|
parentPort?.postMessage({ type: "SHELL_READY", id });
|
|
78
|
-
}
|
|
79
|
-
async onAllReady() {
|
|
80
|
-
const finalHtml = await htmlPromise;
|
|
81
|
-
parentPort?.postMessage({
|
|
82
|
-
type: "HTML_READY",
|
|
83
|
-
id,
|
|
84
|
-
html: finalHtml,
|
|
85
|
-
outputPath: render.htmlOutputPath,
|
|
86
|
-
});
|
|
87
|
-
parentPort?.postMessage({ type: "ALL_READY", id });
|
|
88
|
-
},
|
|
89
|
-
onError(error) {
|
|
90
|
-
parentPort?.postMessage({
|
|
91
|
-
type: "ERROR",
|
|
92
|
-
id,
|
|
93
|
-
error: error instanceof Error ? error.message : String(error),
|
|
94
|
-
});
|
|
95
|
-
},
|
|
106
|
+
}
|
|
96
107
|
}
|
|
97
108
|
);
|
|
98
109
|
|
|
@@ -100,16 +111,20 @@ export const messageHandler = async (message: HtmlWorkerMessage) => {
|
|
|
100
111
|
stream.pipe(collectStream);
|
|
101
112
|
});
|
|
102
113
|
|
|
114
|
+
htmlPromises.set(id, htmlPromise);
|
|
115
|
+
|
|
116
|
+
// Clean up resources
|
|
117
|
+
rscStream.destroy();
|
|
118
|
+
activeRenders.delete(id);
|
|
119
|
+
htmlContent.delete(id);
|
|
120
|
+
htmlPromises.delete(id);
|
|
103
121
|
break;
|
|
104
122
|
}
|
|
105
123
|
}
|
|
106
124
|
} catch (error) {
|
|
107
125
|
parentPort?.postMessage({
|
|
108
126
|
type: "ERROR",
|
|
109
|
-
id:
|
|
110
|
-
message.type === "RSC_CHUNK" || message.type === "RSC_END"
|
|
111
|
-
? message.id
|
|
112
|
-
: "",
|
|
127
|
+
id: message.type === "RSC_CHUNK" || message.type === "RSC_END" ? message.id : "",
|
|
113
128
|
error: error instanceof Error ? error.message : String(error),
|
|
114
129
|
});
|
|
115
130
|
}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import type { Plugin } from "vite";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import type { ModuleFormat } from 'rollup';
|
|
4
|
-
import type { StreamPluginOptions } from "../../types.js";
|
|
1
|
+
import type { Plugin, UserConfig } from "vite";
|
|
2
|
+
import { join, resolve } from "path";
|
|
3
|
+
import type { ModuleFormat, RollupOptions } from 'rollup';
|
|
4
|
+
import type { ResolvedUserOptions, StreamPluginOptions } from "../../types.js";
|
|
5
5
|
import { DEFAULT_CONFIG } from "../../config/defaults.js";
|
|
6
6
|
import { getPluginRoot } from "../../config/getPaths.js";
|
|
7
|
+
import { resolveOptions } from "../../config/resolveOptions.js";
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
let userOptions: ResolvedUserOptions;
|
|
9
10
|
export function reactHtmlWorkerPlugin(options: StreamPluginOptions): Plugin {
|
|
11
|
+
const resolvedUserOptions = resolveOptions(options);
|
|
12
|
+
if(resolvedUserOptions.type === 'error') {
|
|
13
|
+
throw resolvedUserOptions.error
|
|
14
|
+
}
|
|
15
|
+
userOptions = resolvedUserOptions.userOptions;
|
|
10
16
|
return {
|
|
11
17
|
name: "vite:react-html-worker",
|
|
12
18
|
config(config) {
|
|
@@ -25,18 +31,16 @@ export function reactHtmlWorkerPlugin(options: StreamPluginOptions): Plugin {
|
|
|
25
31
|
},
|
|
26
32
|
output: {
|
|
27
33
|
format,
|
|
28
|
-
dir:
|
|
34
|
+
dir: join(userOptions.build.outDir, userOptions.build.server),
|
|
29
35
|
entryFileNames: '[name].js',
|
|
30
36
|
preserveModules: true,
|
|
37
|
+
preserveModulesRoot: userOptions.build.preserveModulesRoot === true ? userOptions.moduleBase : undefined,
|
|
31
38
|
// Add manifest entry
|
|
32
39
|
manualChunks: {
|
|
33
40
|
'html-worker': [htmlWorkerPath]
|
|
34
|
-
},
|
|
35
|
-
resolve: {
|
|
36
|
-
conditions: ['react-server'],
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
|
-
};
|
|
43
|
+
} satisfies RollupOptions;
|
|
40
44
|
|
|
41
45
|
return {
|
|
42
46
|
build: {
|
|
@@ -79,7 +83,7 @@ export function reactHtmlWorkerPlugin(options: StreamPluginOptions): Plugin {
|
|
|
79
83
|
minify: false,
|
|
80
84
|
sourcemap: true,
|
|
81
85
|
}
|
|
82
|
-
};
|
|
86
|
+
} satisfies UserConfig;
|
|
83
87
|
},
|
|
84
88
|
// Add this to ensure entry is in manifest
|
|
85
89
|
generateBundle(_, bundle) {
|