vite-plugin-react-server 0.1.0
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/LICENSE +21 -0
- package/README.md +289 -0
- package/dist/build/createBuildConfig.d.ts +12 -0
- package/dist/build/createBuildConfig.d.ts.map +1 -0
- package/dist/build/createBuildConfig.js +55 -0
- package/dist/build/createBuildConfig.js.map +1 -0
- package/dist/checkFilesExist.d.ts +8 -0
- package/dist/checkFilesExist.d.ts.map +1 -0
- package/dist/checkFilesExist.js +61 -0
- package/dist/checkFilesExist.js.map +1 -0
- package/dist/collect-css-manifest.d.ts +4 -0
- package/dist/collect-css-manifest.d.ts.map +1 -0
- package/dist/collect-css-manifest.js +57 -0
- package/dist/collect-css-manifest.js.map +1 -0
- package/dist/components.d.ts +13 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +13 -0
- package/dist/components.js.map +1 -0
- package/dist/copy-dir.d.ts +4 -0
- package/dist/copy-dir.d.ts.map +1 -0
- package/dist/getEnv.d.ts +19 -0
- package/dist/getEnv.d.ts.map +1 -0
- package/dist/getEnv.js +76 -0
- package/dist/getEnv.js.map +1 -0
- package/dist/helpers/normalizedRelativePath.d.ts +9 -0
- package/dist/helpers/normalizedRelativePath.d.ts.map +1 -0
- package/dist/helpers/normalizedRelativePath.js +31 -0
- package/dist/helpers/normalizedRelativePath.js.map +1 -0
- package/dist/helpers/tryManifest.d.ts +8 -0
- package/dist/helpers/tryManifest.d.ts.map +1 -0
- package/dist/html/createPageLoader.d.ts +26 -0
- package/dist/html/createPageLoader.d.ts.map +1 -0
- package/dist/html/createPageLoader.js +70 -0
- package/dist/html/createPageLoader.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +6 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/module-graph.d.ts +10 -0
- package/dist/module-graph.d.ts.map +1 -0
- package/dist/options.d.ts +86 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +251 -0
- package/dist/options.js.map +1 -0
- package/dist/plugin.d.ts +8 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +31 -0
- package/dist/plugin.js.map +1 -0
- package/dist/react-client/plugin.d.ts +4 -0
- package/dist/react-client/plugin.d.ts.map +1 -0
- package/dist/react-client/plugin.js +28 -0
- package/dist/react-client/plugin.js.map +1 -0
- package/dist/react-server/createDevMiddleware.d.ts +8 -0
- package/dist/react-server/createDevMiddleware.d.ts.map +1 -0
- package/dist/react-server/createDevServer.d.ts +4 -0
- package/dist/react-server/createDevServer.d.ts.map +1 -0
- package/dist/react-server/createHandler.d.ts +23 -0
- package/dist/react-server/createHandler.d.ts.map +1 -0
- package/dist/react-server/createHandler.js +110 -0
- package/dist/react-server/createHandler.js.map +1 -0
- package/dist/react-server/createReactNodeStreamer.d.ts +10 -0
- package/dist/react-server/createReactNodeStreamer.d.ts.map +1 -0
- package/dist/react-server/createRscStream.d.ts +4 -0
- package/dist/react-server/createRscStream.d.ts.map +1 -0
- package/dist/react-server/createRscStream.js +47 -0
- package/dist/react-server/createRscStream.js.map +1 -0
- package/dist/react-server/createSsrHandler.d.ts +4 -0
- package/dist/react-server/createSsrHandler.d.ts.map +1 -0
- package/dist/react-server/plugin.d.ts +8 -0
- package/dist/react-server/plugin.d.ts.map +1 -0
- package/dist/react-server/plugin.js +298 -0
- package/dist/react-server/plugin.js.map +1 -0
- package/dist/resolvePage.d.ts +19 -0
- package/dist/resolvePage.d.ts.map +1 -0
- package/dist/resolvePage.js +44 -0
- package/dist/resolvePage.js.map +1 -0
- package/dist/resolveProps.d.ts +19 -0
- package/dist/resolveProps.d.ts.map +1 -0
- package/dist/resolveProps.js +90 -0
- package/dist/resolveProps.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/transformer/index.d.ts +28 -0
- package/dist/transformer/index.d.ts.map +1 -0
- package/dist/transformer/index.js +54 -0
- package/dist/transformer/index.js.map +1 -0
- package/dist/transformer/preserveDirectives.d.ts +4 -0
- package/dist/transformer/preserveDirectives.d.ts.map +1 -0
- package/dist/transformer/preserveDirectives.js +72 -0
- package/dist/transformer/preserveDirectives.js.map +1 -0
- package/dist/transformer/preserver.d.ts +2 -0
- package/dist/transformer/preserver.d.ts.map +1 -0
- package/dist/transformer/transformer.d.ts +30 -0
- package/dist/transformer/transformer.d.ts.map +1 -0
- package/dist/transformer/transformer.js +80 -0
- package/dist/transformer/transformer.js.map +1 -0
- package/dist/transformer/types.d.ts +15 -0
- package/dist/transformer/types.d.ts.map +1 -0
- package/dist/types.d.ts +197 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/worker/createHtmlStream.d.ts +7 -0
- package/dist/worker/createHtmlStream.d.ts.map +1 -0
- package/dist/worker/createWorker.d.ts +3 -0
- package/dist/worker/createWorker.d.ts.map +1 -0
- package/dist/worker/createWorker.js +33 -0
- package/dist/worker/createWorker.js.map +1 -0
- package/dist/worker/loader.d.ts +15 -0
- package/dist/worker/loader.d.ts.map +1 -0
- package/dist/worker/renderPages.d.ts +18 -0
- package/dist/worker/renderPages.d.ts.map +1 -0
- package/dist/worker/renderPages.js +99 -0
- package/dist/worker/renderPages.js.map +1 -0
- package/dist/worker/types.d.ts +31 -0
- package/dist/worker/types.d.ts.map +1 -0
- package/dist/worker/worker.d.ts +7 -0
- package/dist/worker/worker.d.ts.map +1 -0
- package/package.json +116 -0
- package/src/build/createBuildConfig.ts +74 -0
- package/src/checkFilesExist.ts +67 -0
- package/src/collect-css-manifest.ts +76 -0
- package/src/components.tsx +14 -0
- package/src/copy-dir.ts +27 -0
- package/src/getEnv.ts +135 -0
- package/src/helpers/normalizedRelativePath.ts +59 -0
- package/src/helpers/tryManifest.ts +23 -0
- package/src/html/createPageLoader.ts +99 -0
- package/src/index.ts +4 -0
- package/src/manifest.ts +24 -0
- package/src/module-graph.ts +48 -0
- package/src/options.ts +351 -0
- package/src/plugin.ts +31 -0
- package/src/react-client/plugin.ts +34 -0
- package/src/react-server/createDevMiddleware.ts +75 -0
- package/src/react-server/createDevServer.ts +10 -0
- package/src/react-server/createHandler.ts +144 -0
- package/src/react-server/createReactNodeStreamer.ts +25 -0
- package/src/react-server/createRscStream.ts +52 -0
- package/src/react-server/createSsrHandler.ts +147 -0
- package/src/react-server/plugin.ts +349 -0
- package/src/resolvePage.ts +65 -0
- package/src/resolveProps.ts +122 -0
- package/src/server.tsx +0 -0
- package/src/transformer/README.md +44 -0
- package/src/transformer/index.ts +112 -0
- package/src/transformer/preserveDirectives.ts +100 -0
- package/src/transformer/preserver.ts +47 -0
- package/src/transformer/transformer.ts +123 -0
- package/src/transformer/types.ts +15 -0
- package/src/types.ts +245 -0
- package/src/worker/createHtmlStream.ts +76 -0
- package/src/worker/createWorker.ts +39 -0
- package/src/worker/loader.ts +16 -0
- package/src/worker/renderPages.ts +144 -0
- package/src/worker/types.ts +38 -0
- package/src/worker/worker.tsx +136 -0
- package/tsconfig.json +79 -0
package/dist/options.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
const DEFAULT_CONFIG = {
|
|
3
|
+
FILE_REGEX: /\.(m|c)?(j|t)sx?$/,
|
|
4
|
+
CLIENT_ASSETS_DIR: "assets",
|
|
5
|
+
RSC_DIR: "rsc",
|
|
6
|
+
MODULE_BASE: "src",
|
|
7
|
+
MODULE_BASE_PATH: "/src",
|
|
8
|
+
MODULE_BASE_URL: "/src",
|
|
9
|
+
PAGE: "/src/page/page.tsx",
|
|
10
|
+
PROPS: "/src/page/props.ts",
|
|
11
|
+
CLIENT_ENTRY: "/src/client.tsx",
|
|
12
|
+
PAGE_EXPORT: "Page",
|
|
13
|
+
PROPS_EXPORT: "props",
|
|
14
|
+
// relative from plugin root
|
|
15
|
+
WORKER_PATH: "worker/worker.tsx",
|
|
16
|
+
LOADER_PATH: "worker/loader.ts",
|
|
17
|
+
RSC_EXTENSION: ".rsc",
|
|
18
|
+
HTML: ({ children }) => children,
|
|
19
|
+
COLLECT_CSS: true,
|
|
20
|
+
COLLECT_ASSETS: true,
|
|
21
|
+
PAGE_PATTERN: "/src/page/**/*.page.tsx",
|
|
22
|
+
PROPS_PATTERN: "/src/page/**/*.props.ts",
|
|
23
|
+
DEV_PORT: 5173,
|
|
24
|
+
PREVIEW_PORT: 4173,
|
|
25
|
+
DEV_HOST: "localhost",
|
|
26
|
+
PREVIEW_HOST: "localhost",
|
|
27
|
+
ENV_PREFIX: "VITE_",
|
|
28
|
+
BUILD: {
|
|
29
|
+
pages: () => ["/"],
|
|
30
|
+
client: "dist/client",
|
|
31
|
+
server: "dist/server"
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const resolveUserConfig = (condition, input, config, configEnv, userOptions) => {
|
|
35
|
+
const isReactServer = condition === "react-server";
|
|
36
|
+
const isViteServer = configEnv.command === "serve";
|
|
37
|
+
const isVitePreview = configEnv.isPreview;
|
|
38
|
+
if (isReactServer && configEnv.command === "build") {
|
|
39
|
+
if (!config.build?.rollupOptions?.input) {
|
|
40
|
+
config = {
|
|
41
|
+
...config,
|
|
42
|
+
build: {
|
|
43
|
+
...config.build,
|
|
44
|
+
rollupOptions: {
|
|
45
|
+
...config.build?.rollupOptions,
|
|
46
|
+
input
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (typeof config.build?.assetsDir === "string" && userOptions.assetsDir !== config.build?.assetsDir) {
|
|
53
|
+
return {
|
|
54
|
+
type: "error",
|
|
55
|
+
error: new Error(
|
|
56
|
+
`assetsDir cannot be changed after the config has been resolved, before: ${userOptions.assetsDir}, after: ${config.build?.assetsDir}`
|
|
57
|
+
)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (isReactServer) {
|
|
61
|
+
if (configEnv.command === "build") {
|
|
62
|
+
if (!configEnv.isSsrBuild) {
|
|
63
|
+
return {
|
|
64
|
+
type: "error",
|
|
65
|
+
error: new Error(
|
|
66
|
+
"ssr must be true when using the server plugin, NODE_OPTIONS='--conditions react-server' vite build --ssr"
|
|
67
|
+
)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
} else if (!isViteServer) {
|
|
71
|
+
return {
|
|
72
|
+
type: "error",
|
|
73
|
+
error: new Error(
|
|
74
|
+
isViteServer ? `react-server condition was not set. Please use \`NODE_OPTIONS='--conditions react-server' vite${isVitePreview ? " preview" : ""}\`` : "react-server condition was not set. Please use `NODE_OPTIONS='--conditions react-server' vite build --ssr`"
|
|
75
|
+
)
|
|
76
|
+
};
|
|
77
|
+
} else if (!configEnv.isSsrBuild && configEnv.command !== "serve") {
|
|
78
|
+
return {
|
|
79
|
+
type: "error",
|
|
80
|
+
error: new Error(
|
|
81
|
+
"Vite was run with the react-server condition, but is making a client build."
|
|
82
|
+
)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const { root: configRoot, mode: configMode, ...configRest } = config;
|
|
87
|
+
const { outDir: configOutDir, assetsDir: configAssetsDir, ssr: configSsr, manifest: configManifest, ssrManifest: configSsrManifest, target: configTarget, ...configBuildRest } = config.build ?? {};
|
|
88
|
+
return {
|
|
89
|
+
type: "success",
|
|
90
|
+
userConfig: {
|
|
91
|
+
...configRest,
|
|
92
|
+
root: configRoot ?? userOptions.projectRoot ?? process.cwd(),
|
|
93
|
+
mode: configMode ?? process.env["NODE_ENV"] ?? "production",
|
|
94
|
+
build: {
|
|
95
|
+
...configBuildRest,
|
|
96
|
+
ssr: configSsr ?? isReactServer,
|
|
97
|
+
manifest: configManifest ?? true,
|
|
98
|
+
ssrManifest: configSsrManifest ?? true,
|
|
99
|
+
target: configTarget ?? "es2020",
|
|
100
|
+
outDir: typeof configOutDir === "string" ? configOutDir : isReactServer ? userOptions.build.server : userOptions.build.client,
|
|
101
|
+
assetsDir: typeof configAssetsDir === "string" ? configAssetsDir : isReactServer ? "" : DEFAULT_CONFIG.CLIENT_ASSETS_DIR
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
const resolveOptions = (options) => {
|
|
107
|
+
const projectRoot = options.projectRoot ?? process.cwd();
|
|
108
|
+
const moduleBase = typeof options.moduleBase === "string" ? options.moduleBase.startsWith(path.sep) ? options.moduleBase.slice(path.sep.length) : options.moduleBase : DEFAULT_CONFIG.MODULE_BASE;
|
|
109
|
+
if (typeof options.moduleBase === "string" && options.moduleBase !== moduleBase) {
|
|
110
|
+
return {
|
|
111
|
+
type: "error",
|
|
112
|
+
error: new Error(
|
|
113
|
+
`moduleBase ${options.moduleBase} is invalid, should be like ${moduleBase}`
|
|
114
|
+
)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const moduleBasePath = typeof options.moduleBasePath === "string" ? !options.moduleBasePath.startsWith(path.sep) ? `${path.sep}${options.moduleBasePath}` : options.moduleBasePath : `${path.sep}${moduleBase}`;
|
|
118
|
+
if (!moduleBasePath.includes(moduleBase)) {
|
|
119
|
+
return {
|
|
120
|
+
type: "error",
|
|
121
|
+
error: new Error(
|
|
122
|
+
`moduleBasePath ${moduleBasePath} is invalid, should include moduleBase ${moduleBase}`
|
|
123
|
+
)
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const moduleBaseURL = typeof options.moduleBaseURL === "string" ? !options.moduleBaseURL.endsWith(moduleBasePath) ? path.join(options.moduleBaseURL, moduleBasePath) : options.moduleBaseURL : moduleBasePath;
|
|
127
|
+
if (!moduleBaseURL.includes(moduleBasePath)) {
|
|
128
|
+
return {
|
|
129
|
+
type: "error",
|
|
130
|
+
error: new Error(
|
|
131
|
+
`moduleBaseURL ${moduleBaseURL} is invalid, should include moduleBasePath ${moduleBasePath}`
|
|
132
|
+
)
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (typeof options.moduleBaseURL === "string" && options.moduleBaseURL !== moduleBaseURL) {
|
|
136
|
+
return {
|
|
137
|
+
type: "error",
|
|
138
|
+
error: new Error(
|
|
139
|
+
`moduleBaseURL ${options.moduleBaseURL} is invalid, should be like ${moduleBaseURL}`
|
|
140
|
+
)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const build = options.build ? {
|
|
144
|
+
client: options.build.client ?? DEFAULT_CONFIG.BUILD.client,
|
|
145
|
+
pages: options.build.pages ?? DEFAULT_CONFIG.BUILD.pages,
|
|
146
|
+
server: options.build.server ?? DEFAULT_CONFIG.BUILD.server
|
|
147
|
+
} : DEFAULT_CONFIG.BUILD;
|
|
148
|
+
return {
|
|
149
|
+
type: "success",
|
|
150
|
+
userOptions: {
|
|
151
|
+
moduleBase,
|
|
152
|
+
moduleBasePath,
|
|
153
|
+
moduleBaseURL,
|
|
154
|
+
build,
|
|
155
|
+
Page: options.Page ?? DEFAULT_CONFIG.PAGE,
|
|
156
|
+
props: options.props ?? DEFAULT_CONFIG.PROPS,
|
|
157
|
+
Html: options.Html ?? DEFAULT_CONFIG.HTML,
|
|
158
|
+
pageExportName: options.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT,
|
|
159
|
+
propsExportName: options.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT,
|
|
160
|
+
collectCss: options.collectCss ?? DEFAULT_CONFIG.COLLECT_CSS,
|
|
161
|
+
collectAssets: options.collectAssets ?? DEFAULT_CONFIG.COLLECT_ASSETS,
|
|
162
|
+
projectRoot,
|
|
163
|
+
assetsDir: options.assetsDir ?? DEFAULT_CONFIG.CLIENT_ASSETS_DIR
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
async function resolvePages(pages) {
|
|
168
|
+
if (!pages) {
|
|
169
|
+
return {
|
|
170
|
+
type: "success",
|
|
171
|
+
pages: []
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (typeof pages === "function") {
|
|
175
|
+
try {
|
|
176
|
+
return resolvePages(await Promise.resolve(pages()));
|
|
177
|
+
} catch (error) {
|
|
178
|
+
return {
|
|
179
|
+
type: "error",
|
|
180
|
+
error: error instanceof Error ? error : new Error(
|
|
181
|
+
`build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got "${JSON.stringify(
|
|
182
|
+
pages
|
|
183
|
+
)}"`,
|
|
184
|
+
{
|
|
185
|
+
cause: error
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
const result = pages;
|
|
193
|
+
const awaited = "then" in result ? await result : result;
|
|
194
|
+
if (typeof awaited === "string") {
|
|
195
|
+
return {
|
|
196
|
+
type: "success",
|
|
197
|
+
pages: [awaited]
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (Array.isArray(awaited)) {
|
|
201
|
+
if (awaited.every((page) => typeof page === "string")) {
|
|
202
|
+
return {
|
|
203
|
+
type: "success",
|
|
204
|
+
pages: awaited
|
|
205
|
+
};
|
|
206
|
+
} else {
|
|
207
|
+
return {
|
|
208
|
+
type: "error",
|
|
209
|
+
error: new Error(
|
|
210
|
+
`build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got "${JSON.stringify(
|
|
211
|
+
awaited.find((page) => typeof page !== "string")
|
|
212
|
+
)}"`,
|
|
213
|
+
{
|
|
214
|
+
cause: awaited
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
type: "error",
|
|
222
|
+
error: new Error(
|
|
223
|
+
`build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got "${JSON.stringify(
|
|
224
|
+
pages
|
|
225
|
+
)}"`,
|
|
226
|
+
{
|
|
227
|
+
cause: pages
|
|
228
|
+
}
|
|
229
|
+
)
|
|
230
|
+
};
|
|
231
|
+
} catch (error) {
|
|
232
|
+
return {
|
|
233
|
+
type: "error",
|
|
234
|
+
error: error instanceof Error ? error : new Error(
|
|
235
|
+
`build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got "${JSON.stringify(
|
|
236
|
+
error
|
|
237
|
+
)}"`,
|
|
238
|
+
{
|
|
239
|
+
cause: error
|
|
240
|
+
}
|
|
241
|
+
)
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
export {
|
|
246
|
+
DEFAULT_CONFIG,
|
|
247
|
+
resolveOptions,
|
|
248
|
+
resolvePages,
|
|
249
|
+
resolveUserConfig
|
|
250
|
+
};
|
|
251
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sources":["../src/options.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { ConfigEnv, ResolvedConfig, UserConfig } from \"vite\";\nimport type { ResolvedUserOptions, StreamPluginOptions } from \"./types.js\";\n// Default configuration values\nexport const DEFAULT_CONFIG = {\n FILE_REGEX: /\\.(m|c)?(j|t)sx?$/,\n CLIENT_ASSETS_DIR: \"assets\",\n RSC_DIR: \"rsc\",\n MODULE_BASE: \"src\",\n MODULE_BASE_PATH: \"/src\",\n MODULE_BASE_URL: \"/src\",\n PAGE: \"/src/page/page.tsx\",\n PROPS: \"/src/page/props.ts\",\n CLIENT_ENTRY: \"/src/client.tsx\",\n PAGE_EXPORT: \"Page\",\n PROPS_EXPORT: \"props\",\n // relative from plugin root\n WORKER_PATH: \"worker/worker.tsx\",\n LOADER_PATH: \"worker/loader.ts\",\n RSC_EXTENSION: \".rsc\",\n HTML: ({ children }: { children: any }) => children,\n COLLECT_CSS: true,\n COLLECT_ASSETS: true,\n PAGE_PATTERN: \"/src/page/**/*.page.tsx\",\n PROPS_PATTERN: \"/src/page/**/*.props.ts\",\n DEV_PORT: 5173,\n PREVIEW_PORT: 4173,\n DEV_HOST: \"localhost\",\n PREVIEW_HOST: \"localhost\",\n ENV_PREFIX: \"VITE_\",\n BUILD: {\n pages: () => [\"/\"],\n client: \"dist/client\",\n server: \"dist/server\",\n },\n} as const;\n\nexport const resolveConfig = <T extends ResolvedConfig>(\n config: T,\n resolvedUserConfig: UserConfig,\n userOptions: ResolvedUserOptions\n) => {\n return {\n ...config,\n build: {\n ...config.build,\n assetsDir: config.build?.assetsDir ?? DEFAULT_CONFIG.CLIENT_ASSETS_DIR,\n },\n };\n};\n\nexport const resolveUserConfig = (\n condition: \"react-client\" | \"react-server\",\n input: string[],\n config: UserConfig,\n configEnv: ConfigEnv,\n userOptions: ResolvedUserOptions\n):\n | { type: \"error\"; error: Error }\n | {\n type: \"success\";\n userConfig: Required<Pick<UserConfig, \"root\" | \"build\" | \"mode\">> &\n Omit<UserConfig, \"root\" | \"build\" | \"mode\">;\n } => {\n const isReactServer = condition === \"react-server\";\n const isViteServer = configEnv.command === \"serve\";\n const isVitePreview = configEnv.isPreview;\n\n if (isReactServer && configEnv.command === \"build\") {\n if (!config.build?.rollupOptions?.input) {\n config = {\n ...config,\n build: {\n ...config.build,\n rollupOptions: {\n ...config.build?.rollupOptions,\n input: input\n }\n }\n }\n }\n }\n\n if (typeof config.build?.assetsDir === 'string' && userOptions.assetsDir !== config.build?.assetsDir) {\n return {\n type: \"error\",\n error: new Error(\n `assetsDir cannot be changed after the config has been resolved, before: ${userOptions.assetsDir}, after: ${config.build?.assetsDir}`\n ),\n };\n }\n\n if (isReactServer) {\n if (configEnv.command === \"build\") {\n if (!configEnv.isSsrBuild) {\n return {\n type: \"error\",\n error: new Error(\n \"ssr must be true when using the server plugin, NODE_OPTIONS='--conditions react-server' vite build --ssr\"\n ),\n };\n }\n } else if (!isViteServer) {\n return {\n type: \"error\",\n error: new Error(\n isViteServer\n ? `react-server condition was not set. Please use \\`NODE_OPTIONS='--conditions react-server' vite${\n isVitePreview ? \" preview\" : \"\"\n }\\``\n : \"react-server condition was not set. Please use `NODE_OPTIONS='--conditions react-server' vite build --ssr`\"\n ),\n };\n } else if (!configEnv.isSsrBuild && configEnv.command !== 'serve') {\n return {\n type: \"error\",\n error: new Error(\n \"Vite was run with the react-server condition, but is making a client build.\"\n ),\n };\n }\n }\n\n const { root: configRoot, mode: configMode, ...configRest } = config;\n const { outDir: configOutDir, assetsDir: configAssetsDir, ssr: configSsr, manifest: configManifest, ssrManifest: configSsrManifest, target: configTarget, ...configBuildRest } = config.build ?? {};\n\n return {\n type: \"success\",\n userConfig: {\n ...configRest,\n root: configRoot ?? userOptions.projectRoot ?? process.cwd(),\n mode: configMode ?? process.env[\"NODE_ENV\"] ?? \"production\",\n build: {\n ...configBuildRest,\n ssr: configSsr ?? isReactServer,\n manifest: configManifest ?? true,\n ssrManifest: configSsrManifest ?? true,\n target: configTarget ?? \"es2020\",\n outDir:\n typeof configOutDir === \"string\"\n ? configOutDir\n : isReactServer\n ? userOptions.build.server\n : userOptions.build.client,\n assetsDir:\n typeof configAssetsDir === \"string\"\n ? configAssetsDir\n : isReactServer\n ? ''\n : DEFAULT_CONFIG.CLIENT_ASSETS_DIR,\n },\n },\n };\n};\n\nexport const resolveOptions = (\n options: StreamPluginOptions\n):\n | { type: \"error\"; error: Error }\n | {\n type: \"success\";\n userOptions: ResolvedUserOptions;\n } => {\n const projectRoot = options.projectRoot ?? process.cwd();\n /** the module base can be assumed to not have a leading slash */\n const moduleBase =\n typeof options.moduleBase === \"string\"\n ? options.moduleBase.startsWith(path.sep)\n ? options.moduleBase.slice(path.sep.length)\n : options.moduleBase\n : DEFAULT_CONFIG.MODULE_BASE;\n\n if (\n typeof options.moduleBase === \"string\" &&\n options.moduleBase !== moduleBase\n ) {\n return {\n type: \"error\",\n error: new Error(\n `moduleBase ${options.moduleBase} is invalid, should be like ${moduleBase}`\n ),\n };\n }\n\n const moduleBasePath =\n typeof options.moduleBasePath === \"string\"\n ? !options.moduleBasePath.startsWith(path.sep)\n ? `${path.sep}${options.moduleBasePath}`\n : options.moduleBasePath\n : `${path.sep}${moduleBase}`;\n\n if (!moduleBasePath.includes(moduleBase)) {\n return {\n type: \"error\",\n error: new Error(\n `moduleBasePath ${moduleBasePath} is invalid, should include moduleBase ${moduleBase}`\n ),\n };\n }\n\n const moduleBaseURL =\n typeof options.moduleBaseURL === \"string\"\n ? !options.moduleBaseURL.endsWith(moduleBasePath)\n ? path.join(options.moduleBaseURL, moduleBasePath)\n : options.moduleBaseURL\n : moduleBasePath;\n\n if (!moduleBaseURL.includes(moduleBasePath)) {\n return {\n type: \"error\",\n error: new Error(\n `moduleBaseURL ${moduleBaseURL} is invalid, should include moduleBasePath ${moduleBasePath}`\n ),\n };\n }\n\n if (\n typeof options.moduleBaseURL === \"string\" &&\n options.moduleBaseURL !== moduleBaseURL\n ) {\n return {\n type: \"error\",\n error: new Error(\n `moduleBaseURL ${options.moduleBaseURL} is invalid, should be like ${moduleBaseURL}`\n ),\n };\n }\n\n const build = options.build\n ? {\n client: options.build.client ?? DEFAULT_CONFIG.BUILD.client,\n pages: options.build.pages ?? DEFAULT_CONFIG.BUILD.pages,\n server: options.build.server ?? DEFAULT_CONFIG.BUILD.server,\n }\n : DEFAULT_CONFIG.BUILD;\n\n return {\n type: \"success\",\n userOptions: {\n moduleBase,\n moduleBasePath,\n moduleBaseURL,\n build,\n Page: options.Page ?? DEFAULT_CONFIG.PAGE,\n props: options.props ?? DEFAULT_CONFIG.PROPS,\n Html: options.Html ?? DEFAULT_CONFIG.HTML,\n pageExportName: options.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT,\n propsExportName: options.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT,\n collectCss: options.collectCss ?? DEFAULT_CONFIG.COLLECT_CSS,\n collectAssets: options.collectAssets ?? DEFAULT_CONFIG.COLLECT_ASSETS,\n projectRoot: projectRoot,\n assetsDir: options.assetsDir ?? DEFAULT_CONFIG.CLIENT_ASSETS_DIR,\n } satisfies ResolvedUserOptions,\n };\n};\n\nexport async function resolvePages(\n pages: ResolvedUserOptions[\"build\"][\"pages\"]\n): Promise<\n | {\n type: \"success\";\n pages: string[];\n }\n | {\n type: \"error\";\n error: Error;\n }\n> {\n if (!pages) {\n return {\n type: \"success\",\n pages: [],\n };\n }\n if (typeof pages === \"function\") {\n try {\n return resolvePages(await Promise.resolve(pages()));\n } catch (error) {\n return {\n type: \"error\",\n error:\n error instanceof Error\n ? error\n : new Error(\n `build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got \"${JSON.stringify(\n pages\n )}\"`,\n {\n cause: error,\n }\n ),\n };\n }\n }\n try {\n const result = pages;\n const awaited = \"then\" in result ? await result : result;\n if (typeof awaited === \"string\") {\n return {\n type: \"success\",\n pages: [awaited],\n };\n }\n if (Array.isArray(awaited)) {\n if (awaited.every((page) => typeof page === \"string\")) {\n return {\n type: \"success\",\n pages: awaited,\n };\n } else {\n return {\n type: \"error\",\n error: new Error(\n `build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got \"${JSON.stringify(\n awaited.find((page) => typeof page !== \"string\")\n )}\"`,\n {\n cause: awaited,\n }\n ),\n };\n }\n }\n return {\n type: \"error\",\n error: new Error(\n `build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got \"${JSON.stringify(\n pages\n )}\"`,\n {\n cause: pages,\n }\n ),\n };\n } catch (error) {\n return {\n type: \"error\",\n error:\n error instanceof Error\n ? error\n : new Error(\n `build.pages must be a array of strings, or a (async) function that returns a string or an array of strings. Got \"${JSON.stringify(\n error\n )}\"`,\n {\n cause: error,\n }\n ),\n };\n }\n}\n"],"names":[],"mappings":";AAIO,MAAM,iBAAiB;AAAA,EAC5B,YAAY;AAAA,EACZ,mBAAmB;AAAA,EACnB,SAAS;AAAA,EACT,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,MAAM;AAAA,EACN,OAAO;AAAA,EACP,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA;AAAA,EAEd,aAAa;AAAA,EACb,aAAa;AAAA,EACb,eAAe;AAAA,EACf,MAAM,CAAC,EAAE,SAAA,MAAkC;AAAA,EAC3C,aAA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AAO;AAAA,YAAA;AAAA,UACT;AAAA,QAEJ;AAAA,MAAA;AAAA,IACF;AAEK,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OAAO,IAAI;AAAA,QACT,oHAAoH,KAAK;AAAA,UACvH;AAAA,QACD,CAAA;AAAA,QACD;AAAA,UACE,OAAO;AAAA,QAAA;AAAA,MACT;AAAA,IAEJ;AAAA,WACO,OAAO;AACP,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OACE,iBAAiB,QACb,QACA,IAAI;AAAA,QACF,oHAAoH,KAAK;AAAA,UACvH;AAAA,QACD,CAAA;AAAA,QACD;AAAA,UACE,OAAO;AAAA,QAAA;AAAA,MACT;AAAA,IAEV;AAAA,EAAA;AAEJ;"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StreamPluginOptions } from "./types.js";
|
|
2
|
+
export declare const getCondition: (options?: {
|
|
3
|
+
env?: typeof process.env;
|
|
4
|
+
}) => "server" | "client";
|
|
5
|
+
export declare const reactStreamPlugin: (options: StreamPluginOptions) => Promise<(import("rollup").Plugin<any> | import("vite").Plugin<any> | Promise<import("vite").Plugin<any> & import("rollup").Plugin<any> & {
|
|
6
|
+
meta: import("./types.js").ReactStreamPluginMeta;
|
|
7
|
+
}>)[] | Promise<import("vite").Plugin<any>>[]>;
|
|
8
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,eAAO,MAAM,YAAY,aAAa;IAAE,GAAG,CAAC,EAAE,OAAO,OAAO,CAAC,GAAG,CAAA;CAAE,wBAGjE,CAAC;AAEF,eAAO,MAAM,iBAAiB,YAAmB,mBAAmB;;8CAoBnE,CAAC"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { resolveOptions } from "./options.js";
|
|
2
|
+
import { viteReactClientTransformPlugin } from "./transformer/index.js";
|
|
3
|
+
import { preserveDirectives } from "./transformer/preserveDirectives.js";
|
|
4
|
+
const getCondition = (options = {}) => {
|
|
5
|
+
const nodeOptions = options?.env?.["NODE_OPTIONS"] ?? process.env["NODE_OPTIONS"];
|
|
6
|
+
return nodeOptions?.match(/--conditions=react-server/) ? "server" : "client";
|
|
7
|
+
};
|
|
8
|
+
const reactStreamPlugin = async (options) => {
|
|
9
|
+
const condition = getCondition();
|
|
10
|
+
try {
|
|
11
|
+
const resolvedOptions = resolveOptions(options);
|
|
12
|
+
if (resolvedOptions.type === "error") {
|
|
13
|
+
throw resolvedOptions.error;
|
|
14
|
+
}
|
|
15
|
+
options = resolvedOptions.userOptions;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`[vite:react-stream:${condition}] ${error.message}`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return condition === "server" ? [
|
|
22
|
+
(await import("./react-server/plugin.js")).reactStreamPlugin(options),
|
|
23
|
+
viteReactClientTransformPlugin(),
|
|
24
|
+
preserveDirectives()
|
|
25
|
+
] : [(await import("./react-client/plugin.js")).reactStreamPlugin(options)];
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
getCondition,
|
|
29
|
+
reactStreamPlugin
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../src/plugin.ts"],"sourcesContent":["import { resolveOptions } from \"./options.js\";\nimport { viteReactClientTransformPlugin } from \"./transformer/index.js\";\nimport { preserveDirectives } from \"./transformer/preserveDirectives.js\";\nimport type { StreamPluginOptions } from \"./types.js\";\n\nexport const getCondition = (options: { env?: typeof process.env } = {}) => {\n const nodeOptions = options?.env?.['NODE_OPTIONS'] ?? process.env['NODE_OPTIONS'];\n return nodeOptions?.match(/--conditions=react-server/) ? \"server\" : \"client\";\n};\n\nexport const reactStreamPlugin = async (options: StreamPluginOptions) => {\n const condition = getCondition();\n try {\n const resolvedOptions = resolveOptions(options);\n if (resolvedOptions.type === \"error\") {\n throw resolvedOptions.error;\n }\n options = resolvedOptions.userOptions;\n } catch (error) {\n throw new Error(\n `[vite:react-stream:${condition}] ${(error as Error).message}`\n );\n }\n return condition === \"server\"\n ? [\n (await import(`./react-server/plugin.js`)).reactStreamPlugin(options),\n viteReactClientTransformPlugin(),\n preserveDirectives(),\n ]\n : [(await import(`./react-client/plugin.js`)).reactStreamPlugin(options)];\n};\n"],"names":[],"mappings":";;;AAKO,MAAM,eAAe,CAAC,UAAwC,OAAO;AAC1E,QAAM,cAAc,SAAS,MAAM,cAAc,KAAK,QAAQ,IAAI,cAAc;AAChF,SAAO,aAAa,MAAM,2BAA2B,IAAI,WAAW;AACtE;AAEa,MAAA,oBAAoB,OAAO,YAAiC;AACvE,QAAM,YAAY,aAAa;AAC3B,MAAA;AACI,UAAA,kBAAkB,eAAe,OAAO;AAC1C,QAAA,gBAAgB,SAAS,SAAS;AACpC,YAAM,gBAAgB;AAAA,IAAA;AAExB,cAAU,gBAAgB;AAAA,WACnB,OAAO;AACd,UAAM,IAAI;AAAA,MACR,sBAAsB,SAAS,KAAM,MAAgB,OAAO;AAAA,IAC9D;AAAA,EAAA;AAEF,SAAO,cAAc,WACjB;AAAA,KACG,MAAM,OAAO,0BAA0B,GAAG,kBAAkB,OAAO;AAAA,IACpE,+BAA+B;AAAA,IAC/B,mBAAmB;AAAA,EAAA,IAErB,EAAE,MAAM,OAAO,0BAA0B,GAAG,kBAAkB,OAAO,CAAC;AAC5E;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/react-client/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAMnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,MAAM,CAAC,CAuBjB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { resolveOptions, resolvePages, resolveUserConfig } from "../options.js";
|
|
2
|
+
async function reactStreamPlugin(options) {
|
|
3
|
+
const resolvedOptions = resolveOptions(options);
|
|
4
|
+
if (resolvedOptions.type === "error") {
|
|
5
|
+
throw resolvedOptions.error;
|
|
6
|
+
}
|
|
7
|
+
const { userOptions } = resolvedOptions;
|
|
8
|
+
const resolvedPages = await resolvePages(userOptions.build.pages);
|
|
9
|
+
if (resolvedPages.type === "error") {
|
|
10
|
+
throw resolvedPages.error;
|
|
11
|
+
}
|
|
12
|
+
const { pages } = resolvedPages;
|
|
13
|
+
return {
|
|
14
|
+
name: "vite:react-stream",
|
|
15
|
+
config(config, configEnv) {
|
|
16
|
+
const resolvedConfig = resolveUserConfig("react-client", pages, config, configEnv, userOptions);
|
|
17
|
+
if (resolvedConfig.type === "error") {
|
|
18
|
+
throw resolvedConfig.error;
|
|
19
|
+
}
|
|
20
|
+
const { userConfig } = resolvedConfig;
|
|
21
|
+
return userConfig;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
reactStreamPlugin
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../src/react-client/plugin.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport {\n resolveOptions,\n resolvePages,\n resolveUserConfig,\n} from \"../options.js\";\nimport type { StreamPluginOptions } from \"../types.js\";\n\nexport async function reactStreamPlugin(\n options: StreamPluginOptions\n): Promise<Plugin> {\n const resolvedOptions = resolveOptions(options);\n if (resolvedOptions.type === \"error\") {\n throw resolvedOptions.error;\n }\n const { userOptions } = resolvedOptions;\n\n const resolvedPages = await resolvePages(userOptions.build.pages)\n if(resolvedPages.type === \"error\") {\n throw resolvedPages.error\n }\n const { pages } = resolvedPages\n return {\n name: \"vite:react-stream\",\n config(config, configEnv) {\n const resolvedConfig = resolveUserConfig(\"react-client\", pages, config, configEnv, userOptions);\n if (resolvedConfig.type === \"error\") {\n throw resolvedConfig.error;\n }\n const { userConfig } = resolvedConfig;\n return userConfig\n },\n };\n}\n"],"names":[],"mappings":";AAQA,eAAsB,kBACpB,SACiB;AACX,QAAA,kBAAkB,eAAe,OAAO;AAC1C,MAAA,gBAAgB,SAAS,SAAS;AACpC,UAAM,gBAAgB;AAAA,EAAA;AAElB,QAAA,EAAE,gBAAgB;AAExB,QAAM,gBAAiB,MAAM,aAAa,YAAY,MAAM,KAAK;AAC9D,MAAA,cAAc,SAAS,SAAS;AACjC,UAAM,cAAc;AAAA,EAAA;AAEhB,QAAA,EAAE,UAAU;AACX,SAAA;AAAA,IACL,MAAM;AAAA,IACN,OAAO,QAAQ,WAAW;AACxB,YAAM,iBAAiB,kBAAkB,gBAAgB,OAAO,QAAQ,WAAW,WAAW;AAC1F,UAAA,eAAe,SAAS,SAAS;AACnC,cAAM,eAAe;AAAA,MAAA;AAEjB,YAAA,EAAE,eAAe;AAChB,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ViteDevServer } from "vite";
|
|
2
|
+
import { type RequestHandler, type StreamPluginOptions } from "../types.js";
|
|
3
|
+
export type DevMiddlewareOptions = Required<Pick<StreamPluginOptions, "moduleBase" | "moduleBasePath" | "moduleBaseURL" | "projectRoot">> & Pick<StreamPluginOptions, "Page" | "props" | "build" | "Html" | "pageExportName" | "propsExportName">;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a request handler for development
|
|
6
|
+
*/
|
|
7
|
+
export declare function createDevMiddleware(server: ViteDevServer, options: DevMiddlewareOptions): RequestHandler;
|
|
8
|
+
//# sourceMappingURL=createDevMiddleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDevMiddleware.d.ts","sourceRoot":"","sources":["../../src/react-server/createDevMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG5E,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CACzC,IAAI,CACF,mBAAmB,EACnB,YAAY,GAAG,gBAAgB,GAAG,eAAe,GAAG,aAAa,CAClE,CACF,GACC,IAAI,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,gBAAgB,GAAG,iBAAiB,CAAC,CAAC;AAExG;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,oBAAoB,GAC5B,cAAc,CAuDhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDevServer.d.ts","sourceRoot":"","sources":["../../src/react-server/createDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EAAuB,KAAK,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAE1F,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,oBAAoB,QAG9B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CreateHandlerOptions, StreamPluginOptions } from "../types.js";
|
|
2
|
+
export declare function createHandler<T>(url: string, pluginOptions: Pick<StreamPluginOptions, "Page" | "props" | "build" | "Html" | "pageExportName" | "propsExportName"> & Required<Pick<StreamPluginOptions, "moduleBase" | "moduleBasePath" | "projectRoot">>, streamOptions: CreateHandlerOptions<T>): Promise<{
|
|
3
|
+
type: any;
|
|
4
|
+
error: any;
|
|
5
|
+
controller?: undefined;
|
|
6
|
+
stream?: undefined;
|
|
7
|
+
assets?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
type: any;
|
|
10
|
+
error?: undefined;
|
|
11
|
+
controller?: undefined;
|
|
12
|
+
stream?: undefined;
|
|
13
|
+
assets?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
type: "success";
|
|
16
|
+
controller: AbortController;
|
|
17
|
+
stream: import("react-server-dom-esm/server.node").PipeableStream;
|
|
18
|
+
assets: {
|
|
19
|
+
css: string[] | undefined;
|
|
20
|
+
};
|
|
21
|
+
error?: undefined;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=createHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHandler.d.ts","sourceRoot":"","sources":["../../src/react-server/createHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG7E,wBAAsB,aAAa,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,IAAI,CACjB,mBAAmB,EACnB,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,gBAAgB,GAAG,iBAAiB,CAC3E,GACC,QAAQ,CACN,IAAI,CAAC,mBAAmB,EAAE,YAAY,GAAG,gBAAgB,GAAG,aAAa,CAAC,CAC3E,EACH,aAAa,EAAE,oBAAoB,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;GA2HvC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createLogger } from "vite";
|
|
2
|
+
import { collectManifestCss, collectModuleGraphCss } from "../collect-css-manifest.js";
|
|
3
|
+
import { DEFAULT_CONFIG } from "../options.js";
|
|
4
|
+
import { resolvePage } from "../resolvePage.js";
|
|
5
|
+
import { resolveProps } from "../resolveProps.js";
|
|
6
|
+
import { createRscStream } from "./createRscStream.js";
|
|
7
|
+
async function createHandler(url, pluginOptions, streamOptions) {
|
|
8
|
+
const root = pluginOptions.projectRoot ?? process.cwd();
|
|
9
|
+
const Html = pluginOptions.Html ?? DEFAULT_CONFIG.HTML;
|
|
10
|
+
const pageExportName = pluginOptions.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT;
|
|
11
|
+
const propsExportName = pluginOptions.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT;
|
|
12
|
+
const controller = new AbortController();
|
|
13
|
+
const cssFiles = streamOptions.cssFiles;
|
|
14
|
+
const propsPath = typeof pluginOptions.props === "function" ? pluginOptions.props(url) : pluginOptions.props;
|
|
15
|
+
const pagePath = typeof pluginOptions.Page === "function" ? pluginOptions.Page(url) : pluginOptions.Page;
|
|
16
|
+
const cssModules = /* @__PURE__ */ new Set();
|
|
17
|
+
if (!(streamOptions.manifest || streamOptions.moduleGraph))
|
|
18
|
+
throw new Error("Missing manifest or moduleGraph, pass it to options.");
|
|
19
|
+
const getCss = streamOptions.manifest ? (id) => collectManifestCss(
|
|
20
|
+
streamOptions.manifest,
|
|
21
|
+
root,
|
|
22
|
+
id,
|
|
23
|
+
streamOptions.onCssFile
|
|
24
|
+
) : (id) => collectModuleGraphCss(streamOptions.moduleGraph, id);
|
|
25
|
+
const loadWithCss = async (id) => {
|
|
26
|
+
if (!id) return {};
|
|
27
|
+
try {
|
|
28
|
+
const mod = await streamOptions.loader(id);
|
|
29
|
+
const pageCss = await Promise.resolve(getCss(id));
|
|
30
|
+
Array.from(pageCss.keys()).forEach((css) => cssModules.add(css));
|
|
31
|
+
return mod;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
if (e.message?.includes("module runner has been closed")) {
|
|
34
|
+
return { type: "skip" };
|
|
35
|
+
} else {
|
|
36
|
+
return { type: "error", error: e };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const PropsModule = await resolveProps({
|
|
41
|
+
propsModule: await loadWithCss(propsPath ?? pagePath),
|
|
42
|
+
path: String(propsPath ?? pagePath),
|
|
43
|
+
exportName: propsExportName,
|
|
44
|
+
url
|
|
45
|
+
});
|
|
46
|
+
if (PropsModule.type === "error")
|
|
47
|
+
return { type: PropsModule.type, error: PropsModule?.error };
|
|
48
|
+
if (PropsModule.type === "skip") return { type: PropsModule.type };
|
|
49
|
+
const props = PropsModule[propsExportName];
|
|
50
|
+
if (props?.type === "error") return { type: props.type, error: props.error };
|
|
51
|
+
if (props?.type === "skip") return { type: props.type };
|
|
52
|
+
const PageModule = await resolvePage({
|
|
53
|
+
pageModule: await loadWithCss(pagePath),
|
|
54
|
+
path: pagePath,
|
|
55
|
+
exportName: pageExportName,
|
|
56
|
+
url
|
|
57
|
+
});
|
|
58
|
+
if (PageModule.type === "error")
|
|
59
|
+
return { type: PageModule.type, error: PageModule.error };
|
|
60
|
+
if (PageModule.type === "skip") return { type: PageModule.type };
|
|
61
|
+
const Page = PageModule[pageExportName];
|
|
62
|
+
if (Page?.type === "error") return { type: Page.type, error: Page.error };
|
|
63
|
+
if (Page?.type === "skip") return { type: Page.type };
|
|
64
|
+
if (!(typeof Page === "function")) {
|
|
65
|
+
return {
|
|
66
|
+
type: "error",
|
|
67
|
+
error: new Error("Invalid Page component: " + pagePath, {
|
|
68
|
+
cause: Page
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (!(typeof props === "object")) {
|
|
73
|
+
return {
|
|
74
|
+
type: "error",
|
|
75
|
+
error: new Error("Invalid props: " + propsPath, {
|
|
76
|
+
cause: props
|
|
77
|
+
})
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (streamOptions.cssFiles) {
|
|
81
|
+
streamOptions.cssFiles.forEach((css) => cssModules.add(css));
|
|
82
|
+
}
|
|
83
|
+
const stream = createRscStream({
|
|
84
|
+
Html,
|
|
85
|
+
Page,
|
|
86
|
+
props,
|
|
87
|
+
moduleBasePath: pluginOptions.moduleBasePath,
|
|
88
|
+
// eg /src
|
|
89
|
+
logger: streamOptions.logger ?? createLogger(),
|
|
90
|
+
cssFiles: Array.from(cssModules),
|
|
91
|
+
route: url,
|
|
92
|
+
url,
|
|
93
|
+
pipableStreamOptions: streamOptions.pipableStreamOptions
|
|
94
|
+
});
|
|
95
|
+
if (!stream) {
|
|
96
|
+
return { type: "skip" };
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
type: "success",
|
|
100
|
+
controller,
|
|
101
|
+
stream,
|
|
102
|
+
assets: {
|
|
103
|
+
css: cssFiles
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
createHandler
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=createHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHandler.js","sources":["../../src/react-server/createHandler.ts"],"sourcesContent":["import { createLogger } from \"vite\";\nimport {\n collectManifestCss,\n collectModuleGraphCss,\n} from \"../collect-css-manifest.js\";\nimport { DEFAULT_CONFIG } from \"../options.js\";\nimport { resolvePage } from \"../resolvePage.js\";\nimport { resolveProps } from \"../resolveProps.js\";\nimport type { CreateHandlerOptions, StreamPluginOptions } from \"../types.js\";\nimport { createRscStream } from \"./createRscStream.js\";\n\nexport async function createHandler<T>(\n url: string,\n pluginOptions: Pick<\n StreamPluginOptions,\n \"Page\" | \"props\" | \"build\" | \"Html\" | \"pageExportName\" | \"propsExportName\"\n > &\n Required<\n Pick<StreamPluginOptions, \"moduleBase\" | \"moduleBasePath\" | \"projectRoot\">\n >,\n streamOptions: CreateHandlerOptions<T>\n) {\n const root = pluginOptions.projectRoot ?? process.cwd();\n\n const Html = pluginOptions.Html ?? DEFAULT_CONFIG.HTML;\n const pageExportName =\n pluginOptions.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT;\n const propsExportName =\n pluginOptions.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT;\n const controller = new AbortController();\n\n const cssFiles = streamOptions.cssFiles;\n const propsPath =\n typeof pluginOptions.props === \"function\"\n ? pluginOptions.props(url)\n : pluginOptions.props;\n const pagePath =\n typeof pluginOptions.Page === \"function\"\n ? pluginOptions.Page(url)\n : pluginOptions.Page;\n\n const cssModules = new Set<string>();\n\n if (!(streamOptions.manifest || streamOptions.moduleGraph))\n throw new Error(\"Missing manifest or moduleGraph, pass it to options.\");\n\n const getCss = streamOptions.manifest\n ? (id: string) =>\n collectManifestCss(\n streamOptions.manifest!,\n root,\n id,\n streamOptions.onCssFile\n )\n : (id: string) => collectModuleGraphCss(streamOptions.moduleGraph!, id);\n\n const loadWithCss = async (id: string) => {\n if (!id) return {};\n\n try {\n const mod = await streamOptions.loader(id);\n const pageCss = await Promise.resolve(getCss(id));\n Array.from(pageCss.keys()).forEach((css) => cssModules.add(css));\n return mod as Record<string, any>;\n } catch (e: any) {\n if (e.message?.includes(\"module runner has been closed\")) {\n return { type: \"skip\" } as Record<string, any>;\n } else {\n return { type: \"error\", error: e } as Record<string, any>;\n }\n }\n };\n\n const PropsModule = await resolveProps({\n propsModule: await loadWithCss(propsPath ?? pagePath),\n path: String(propsPath ?? pagePath),\n exportName: propsExportName,\n url,\n });\n if (PropsModule.type === \"error\")\n return { type: PropsModule.type, error: PropsModule?.error };\n if (PropsModule.type === \"skip\") return { type: PropsModule.type };\n const props = PropsModule[propsExportName as keyof typeof PropsModule] as any;\n if (props?.type === \"error\") return { type: props.type, error: props.error };\n if (props?.type === \"skip\") return { type: props.type };\n\n const PageModule = await resolvePage({\n pageModule: await loadWithCss(pagePath),\n path: pagePath,\n exportName: pageExportName,\n url,\n });\n if (PageModule.type === \"error\")\n return { type: PageModule.type, error: PageModule.error };\n if (PageModule.type === \"skip\") return { type: PageModule.type };\n const Page = PageModule[pageExportName as keyof typeof PageModule] as any;\n if (Page?.type === \"error\") return { type: Page.type, error: Page.error };\n if (Page?.type === \"skip\") return { type: Page.type };\n if (!(typeof Page === \"function\")) {\n return {\n type: \"error\",\n error: new Error(\"Invalid Page component: \" + pagePath, {\n cause: Page,\n }),\n };\n }\n if (!(typeof props === \"object\")) {\n return {\n type: \"error\",\n error: new Error(\"Invalid props: \" + propsPath, {\n cause: props,\n }),\n };\n }\n\n // Add any additional CSS files\n if (streamOptions.cssFiles) {\n streamOptions.cssFiles.forEach((css) => cssModules.add(css));\n }\n const stream = createRscStream({\n Html: Html,\n Page: Page,\n props: props,\n moduleBasePath: pluginOptions.moduleBasePath, // eg /src\n logger: streamOptions.logger ?? createLogger(),\n cssFiles: Array.from(cssModules),\n route: url,\n url,\n pipableStreamOptions: streamOptions.pipableStreamOptions,\n });\n\n if (!stream) {\n return { type: \"skip\" as const };\n }\n\n return {\n type: \"success\" as const,\n controller,\n stream,\n assets: {\n css: cssFiles,\n },\n };\n}\n"],"names":[],"mappings":";;;;;;AAWsB,eAAA,cACpB,KACA,eAOA,eACA;AACA,QAAM,OAAO,cAAc,eAAe,QAAQ,IAAI;AAEhD,QAAA,OAAO,cAAc,QAAQ,eAAe;AAC5C,QAAA,iBACJ,cAAc,kBAAkB,eAAe;AAC3C,QAAA,kBACJ,cAAc,mBAAmB,eAAe;AAC5C,QAAA,aAAa,IAAI,gBAAgB;AAEvC,QAAM,WAAW,cAAc;AACzB,QAAA,YACJ,OAAO,cAAc,UAAU,aAC3B,cAAc,MAAM,GAAG,IACvB,cAAc;AACd,QAAA,WACJ,OAAO,cAAc,SAAS,aAC1B,cAAc,KAAK,GAAG,IACtB,cAAc;AAEd,QAAA,iCAAiB,IAAY;AAE/B,MAAA,EAAE,cAAc,YAAY,cAAc;AACtC,UAAA,IAAI,MAAM,sDAAsD;AAExE,QAAM,SAAS,cAAc,WACzB,CAAC,OACC;AAAA,IACE,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA,cAAc;AAAA,MAElB,CAAC,OAAe,sBAAsB,cAAc,aAAc,EAAE;AAElE,QAAA,cAAc,OAAO,OAAe;AACpC,QAAA,CAAC,GAAI,QAAO,CAAC;AAEb,QAAA;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,SAAS,eAAe,EAAE,MAAM,KAAK,KAAK;AAChD,MAAA,EAAE,OAAO,SAAS,aAAa;AAC1B,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OAAO,IAAI,MAAM,6BAA6B,UAAU;AAAA,QACtD,OAAO;AAAA,MACR,CAAA;AAAA,IACH;AAAA,EAAA;AAEE,MAAA,EAAE,OAAO,UAAU,WAAW;AACzB,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OAAO,IAAI,MAAM,oBAAoB,WAAW;AAAA,QAC9C,OAAO;AAAA,MACR,CAAA;AAAA,IACH;AAAA,EAAA;AAIF,MAAI,cAAc,UAAU;AAC1B,kBAAc,SAAS,QAAQ,CAAC,QAAQ,WAAW,IAAI,GAAG,CAAC;AAAA,EAAA;AAE7D,QAAM,SAAS,gBAAgB;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,cAAc;AAAA;AAAA,IAC9B,QAAQ,cAAc,UAAU,aAAa;AAAA,IAC7C,UAAU,MAAM,KAAK,UAAU;AAAA,IAC/B,OAAO;AAAA,IACP;AAAA,IACA,sBAAsB,cAAc;AAAA,EAAA,CACrC;AAED,MAAI,CAAC,QAAQ;AACJ,WAAA,EAAE,MAAM,OAAgB;AAAA,EAAA;AAG1B,SAAA;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,MACN,KAAK;AAAA,IAAA;AAAA,EAET;AACF;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type CreateFromNodeStreamOptions } from "react-server-dom-esm/client.node";
|
|
3
|
+
import type { Readable } from "stream";
|
|
4
|
+
export declare function createReactNodeStreamer({ stream, moduleBasePath, moduleBaseURL, options, }: {
|
|
5
|
+
stream: Readable;
|
|
6
|
+
moduleBasePath: string;
|
|
7
|
+
moduleBaseURL: string;
|
|
8
|
+
options?: CreateFromNodeStreamOptions;
|
|
9
|
+
}): React.Usable<React.ReactNode>;
|
|
10
|
+
//# sourceMappingURL=createReactNodeStreamer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createReactNodeStreamer.d.ts","sourceRoot":"","sources":["../../src/react-server/createReactNodeStreamer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC,wBAAgB,uBAAuB,CAAC,EACtC,MAAM,EACN,cAAc,EACd,aAAa,EACb,OAAO,GACR,EAAE;IACD,MAAM,EAAE,QAAQ,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,2BAA2B,CAAC;CACvC,GAMM,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CACnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRscStream.d.ts","sourceRoot":"","sources":["../../src/react-server/createRscStream.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,wBAAgB,eAAe,CAC7B,aAAa,EAAE,gBAAgB,GAC9B,cAAc,CAyChB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { renderToPipeableStream } from "react-server-dom-esm/server.node";
|
|
3
|
+
import { CssCollector } from "../components.js";
|
|
4
|
+
function createRscStream(streamOptions) {
|
|
5
|
+
const {
|
|
6
|
+
Html,
|
|
7
|
+
Page,
|
|
8
|
+
props,
|
|
9
|
+
logger,
|
|
10
|
+
cssFiles,
|
|
11
|
+
route,
|
|
12
|
+
url,
|
|
13
|
+
moduleBasePath,
|
|
14
|
+
pipableStreamOptions
|
|
15
|
+
} = streamOptions;
|
|
16
|
+
const css = Array.isArray(cssFiles) ? cssFiles.map(
|
|
17
|
+
(css2, index) => React.createElement(CssCollector, {
|
|
18
|
+
key: `css-${index}`,
|
|
19
|
+
url: css2
|
|
20
|
+
})
|
|
21
|
+
) : [];
|
|
22
|
+
return renderToPipeableStream(
|
|
23
|
+
React.createElement(
|
|
24
|
+
Html,
|
|
25
|
+
{
|
|
26
|
+
key: "html",
|
|
27
|
+
pageProps: props,
|
|
28
|
+
moduleBasePath,
|
|
29
|
+
route,
|
|
30
|
+
url
|
|
31
|
+
},
|
|
32
|
+
React.createElement(Page, { key: "page", ...props }),
|
|
33
|
+
...css
|
|
34
|
+
),
|
|
35
|
+
moduleBasePath,
|
|
36
|
+
{
|
|
37
|
+
onError: logger?.error ?? console.error,
|
|
38
|
+
onPostpone: logger?.info ?? console.info,
|
|
39
|
+
environmentName: "Server",
|
|
40
|
+
...pipableStreamOptions
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
createRscStream
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=createRscStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRscStream.js","sources":["../../src/react-server/createRscStream.ts"],"sourcesContent":["import React from \"react\";\nimport {\n renderToPipeableStream,\n type PipeableStream,\n} from \"react-server-dom-esm/server.node\";\nimport { CssCollector } from \"../components.js\";\nimport type { RscStreamOptions } from \"../types.js\";\n\nexport function createRscStream(\n streamOptions: RscStreamOptions\n): PipeableStream {\n const {\n Html,\n Page,\n props,\n logger,\n cssFiles,\n route,\n url,\n moduleBasePath,\n pipableStreamOptions,\n } = streamOptions;\n const css = Array.isArray(cssFiles)\n ? cssFiles.map((css, index) =>\n React.createElement(CssCollector, {\n key: `css-${index}`,\n url: css,\n })\n )\n : [];\n return renderToPipeableStream(\n React.createElement(\n Html,\n {\n key: \"html\",\n pageProps: props,\n moduleBasePath: moduleBasePath,\n route,\n url,\n },\n React.createElement(Page, { key: \"page\", ...props }),\n ...css\n ),\n moduleBasePath,\n {\n onError: logger?.error ?? console.error,\n onPostpone: logger?.info ?? console.info,\n environmentName: \"Server\",\n ...pipableStreamOptions,\n }\n );\n}\n"],"names":["css"],"mappings":";;;AAQO,SAAS,gBACd,eACgB;AACV,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AACJ,QAAM,MAAM,MAAM,QAAQ,QAAQ,IAC9B,SAAS;AAAA,IAAI,CAACA,MAAK,UACjB,MAAM,cAAc,cAAc;AAAA,MAChC,KAAK,OAAO,KAAK;AAAA,MACjB,KAAKA;AAAAA,IACN,CAAA;AAAA,EAAA,IAEH,CAAC;AACE,SAAA;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA;AAAA,QACE,KAAK;AAAA,QACL,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,MAAM,cAAc,MAAM,EAAE,KAAK,QAAQ,GAAG,OAAO;AAAA,MACnD,GAAG;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,MACE,SAAS,QAAQ,SAAS,QAAQ;AAAA,MAClC,YAAY,QAAQ,QAAQ,QAAQ;AAAA,MACpC,iBAAiB;AAAA,MACjB,GAAG;AAAA,IAAA;AAAA,EAEP;AACF;"}
|