vite-plugin-react-server 0.3.19 → 1.0.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/README.md +219 -141
- package/dist/package.json +13 -6
- package/dist/plugin/collect-manifest-client-files.d.ts.map +1 -1
- package/dist/plugin/collect-manifest-client-files.js +25 -11
- package/dist/plugin/collect-manifest-client-files.js.map +1 -1
- package/dist/plugin/components.d.ts +3 -13
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +3 -54
- package/dist/plugin/config/defaults.d.ts +9 -2
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +3 -2
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/resolveOptions.d.ts +2 -2
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +6 -0
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +178 -149
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/css-collector-inline.d.ts +10 -0
- package/dist/plugin/css-collector-inline.d.ts.map +1 -0
- package/dist/plugin/css-collector-inline.js +55 -0
- package/dist/plugin/css-collector-inline.js.map +1 -0
- package/dist/plugin/css-collector.d.ts +14 -0
- package/dist/plugin/css-collector.d.ts.map +1 -0
- package/dist/plugin/css-collector.js +49 -0
- package/dist/plugin/css-collector.js.map +1 -0
- package/dist/plugin/helpers/createHandler.d.ts +3 -8
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createHandler.js +52 -55
- package/dist/plugin/helpers/createHandler.js.map +1 -1
- package/dist/plugin/helpers/createRscStream.d.ts +14 -4
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
- package/dist/plugin/helpers/createRscStream.js +25 -16
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/html.d.ts +5 -0
- package/dist/plugin/html.d.ts.map +1 -0
- package/dist/plugin/html.js +11 -0
- package/dist/plugin/html.js.map +1 -0
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +3 -2
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +47 -16
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +20 -12
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/types.d.ts +2 -0
- package/dist/plugin/react-static/types.d.ts.map +1 -0
- package/dist/plugin/react-static/types.js +1 -0
- package/dist/plugin/types.d.ts +48 -11
- 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 +4 -1
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/renderPages.d.ts +8 -25
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +61 -44
- 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 +37 -22
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/types.d.ts +3 -0
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -4
- package/plugin/collect-manifest-client-files.ts +25 -10
- package/plugin/components.ts +3 -0
- package/plugin/config/defaults.tsx +10 -9
- package/plugin/config/resolveOptions.ts +10 -5
- package/plugin/config/resolveUserConfig.ts +218 -177
- package/plugin/css-collector-inline.tsx +60 -0
- package/plugin/css-collector.tsx +62 -0
- package/plugin/helpers/createHandler.ts +73 -83
- package/plugin/helpers/createRscStream.ts +49 -21
- package/plugin/html.tsx +9 -0
- package/plugin/react-client/plugin.ts +3 -2
- package/plugin/react-server/plugin.ts +58 -22
- package/plugin/react-static/plugin.ts +20 -11
- package/plugin/react-static/types.ts +3 -0
- package/plugin/types.ts +53 -11
- package/plugin/worker/html/messageHandler.ts +5 -2
- package/plugin/worker/html/renderPages.ts +82 -78
- package/plugin/worker/rsc/messageHandler.tsx +41 -26
- package/plugin/worker/types.ts +3 -0
- package/dist/plugin/components.js.map +0 -1
- package/dist/plugin/getEnv.d.ts +0 -19
- package/dist/plugin/getEnv.d.ts.map +0 -1
- package/dist/plugin/getEnv.js +0 -107
- package/dist/plugin/module-graph.d.ts +0 -10
- package/dist/plugin/module-graph.d.ts.map +0 -1
- package/dist/plugin/module-graph.js +0 -35
- package/dist/plugin/worker/html/plugin.d.ts +0 -4
- package/dist/plugin/worker/html/plugin.d.ts.map +0 -1
- package/dist/plugin/worker/html/plugin.js +0 -93
- package/dist/plugin/worker/plugin.d.ts +0 -19
- package/dist/plugin/worker/plugin.d.ts.map +0 -1
- package/dist/plugin/worker/plugin.js +0 -23
- package/dist/plugin/worker/rsc/plugin.d.ts +0 -4
- package/dist/plugin/worker/rsc/plugin.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/plugin.js +0 -75
- package/plugin/components.tsx +0 -59
- package/plugin/getEnv.ts +0 -135
- package/plugin/module-graph.ts +0 -48
- package/plugin/worker/html/plugin.ts +0 -100
- package/plugin/worker/plugin.ts +0 -26
- package/plugin/worker/rsc/plugin.ts +0 -83
|
@@ -60,7 +60,7 @@ export const messageHandler = async (message: HtmlWorkerMessage) => {
|
|
|
60
60
|
const reactElements = await createFromNodeStream(
|
|
61
61
|
rscStream,
|
|
62
62
|
render.moduleRootPath,
|
|
63
|
-
|
|
63
|
+
render.moduleBaseURL
|
|
64
64
|
);
|
|
65
65
|
|
|
66
66
|
// Create a promise that resolves when HTML is complete
|
|
@@ -90,7 +90,10 @@ export const messageHandler = async (message: HtmlWorkerMessage) => {
|
|
|
90
90
|
// Calculate relative paths based on route depth
|
|
91
91
|
bootstrapModules: render.pipableStreamOptions?.bootstrapModules?.map(path => {
|
|
92
92
|
if (!path) return path;
|
|
93
|
-
|
|
93
|
+
if(render.moduleBaseURL && render.moduleBaseURL !== '') {
|
|
94
|
+
return new URL(path, render.moduleBaseURL).toString();
|
|
95
|
+
}
|
|
96
|
+
const depth = id.split('/').filter(Boolean).length;
|
|
94
97
|
const prefix = depth > 0 ? '../'.repeat(depth) : '/';
|
|
95
98
|
return path.startsWith('/') ? prefix + path.slice(1) : prefix + path;
|
|
96
99
|
}),
|
|
@@ -5,60 +5,46 @@ import type { Worker } from "node:worker_threads";
|
|
|
5
5
|
import { createHandler } from "../../helpers/createHandler.js";
|
|
6
6
|
import type {
|
|
7
7
|
CheckFilesExistReturn,
|
|
8
|
+
CreateHandlerOptions,
|
|
8
9
|
PageData,
|
|
9
|
-
ResolvedUserConfig,
|
|
10
|
-
ResolvedUserOptions,
|
|
11
10
|
} from "../../types.js";
|
|
12
11
|
import type { HtmlWorkerResponse } from "../types.js";
|
|
13
|
-
import type
|
|
12
|
+
import { type Manifest, type IndexHtmlTransformHook, createLogger } from "vite";
|
|
14
13
|
import React from "react";
|
|
14
|
+
import { collectManifestClientFiles } from "../../collect-manifest-client-files.js";
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
bootstrapModules?: string[];
|
|
18
|
-
bootstrapScripts?: string[];
|
|
19
|
-
bootstrapScriptContent?: string;
|
|
20
|
-
signal?: AbortSignal;
|
|
21
|
-
identifierPrefix?: string;
|
|
22
|
-
namespaceURI?: string;
|
|
23
|
-
nonce?: string;
|
|
24
|
-
progressiveChunkSize?: number;
|
|
25
|
-
onShellReady?: () => void;
|
|
26
|
-
onAllReady?: () => void;
|
|
27
|
-
onError?: (error: unknown) => void;
|
|
28
|
-
importMap?: {
|
|
29
|
-
imports?: Record<string, string>;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type RenderPagesOptions = {
|
|
34
|
-
pluginOptions: ResolvedUserOptions;
|
|
35
|
-
userConfig: ResolvedUserConfig;
|
|
16
|
+
type RenderPagesOptions<T = any> = Omit<CreateHandlerOptions<T>, "url" | "route" | "getCss" | "propsPath" | "pagePath"> & {
|
|
36
17
|
clientManifest: Manifest;
|
|
37
18
|
serverManifest: Manifest;
|
|
38
19
|
worker: Worker;
|
|
39
|
-
pipableStreamOptions?: PipeableStreamOptions;
|
|
40
20
|
loader: (id: string) => Promise<Record<string, any>>;
|
|
41
21
|
onCssFile?: (url: string, parentUrl: string) => void;
|
|
42
22
|
onClientJSFile?: (url: string, parentUrl: string) => void;
|
|
43
23
|
onPage?: (pageData: PageData) => Promise<void>;
|
|
44
24
|
clientCss?: string[];
|
|
45
|
-
moduleBasePath: string;
|
|
46
|
-
moduleBaseURL: string;
|
|
47
25
|
transformIndexHtml: IndexHtmlTransformHook;
|
|
48
26
|
outDir: string;
|
|
49
27
|
htmlOutputPath: string;
|
|
28
|
+
server?: any;
|
|
29
|
+
bundle?: any;
|
|
30
|
+
chunk?: any;
|
|
31
|
+
originalUrl?: string;
|
|
50
32
|
};
|
|
51
33
|
|
|
52
|
-
export async function renderPages(
|
|
34
|
+
export async function renderPages<T = any>(
|
|
53
35
|
routes: string[],
|
|
54
36
|
files: CheckFilesExistReturn,
|
|
55
|
-
options: RenderPagesOptions
|
|
37
|
+
options: RenderPagesOptions<T>
|
|
56
38
|
) {
|
|
57
39
|
const failedRoutes = new Map<string, Error>();
|
|
58
40
|
const completedRoutes = new Set<string>();
|
|
59
41
|
const clientCss = options.clientCss ?? [];
|
|
60
42
|
const partialPageData = new Map<string, Partial<PageData>>();
|
|
61
|
-
|
|
43
|
+
const moduleRootPath =
|
|
44
|
+
options.moduleBasePath !== "" &&
|
|
45
|
+
!options.moduleRootPath.endsWith(options.moduleBasePath)
|
|
46
|
+
? join(options.moduleRootPath, options.moduleBasePath)
|
|
47
|
+
: options.moduleRootPath;
|
|
62
48
|
const mergeAndSendPageData = async (route: string, resolve: () => void) => {
|
|
63
49
|
const partial = partialPageData.get(route);
|
|
64
50
|
if (!partial?.html || !partial.rsc) {
|
|
@@ -71,16 +57,20 @@ export async function renderPages(
|
|
|
71
57
|
rsc: partial.rsc,
|
|
72
58
|
};
|
|
73
59
|
|
|
74
|
-
// Write RSC file
|
|
75
|
-
console.log('route', route)
|
|
76
60
|
// Write HTML file
|
|
77
|
-
let routeHtmlPath =
|
|
78
|
-
|
|
61
|
+
let routeHtmlPath =
|
|
62
|
+
route === "/"
|
|
63
|
+
? options.htmlOutputPath
|
|
64
|
+
: options.htmlOutputPath.replace(
|
|
65
|
+
"index.html",
|
|
66
|
+
join(route, "index.html")
|
|
67
|
+
);
|
|
68
|
+
if (routeHtmlPath.startsWith("/")) {
|
|
79
69
|
routeHtmlPath = routeHtmlPath.slice(1);
|
|
80
70
|
}
|
|
81
|
-
const routeRscPath = routeHtmlPath.slice(0, -5) +
|
|
71
|
+
const routeRscPath = routeHtmlPath.slice(0, -5) + ".rsc";
|
|
82
72
|
await mkdir(dirname(routeHtmlPath), { recursive: true });
|
|
83
|
-
await writeFile(routeRscPath, partial.rsc.content);
|
|
73
|
+
await writeFile(routeRscPath, partial.rsc.content);
|
|
84
74
|
await writeFile(routeHtmlPath, partial.html.raw);
|
|
85
75
|
|
|
86
76
|
await options.onPage?.(pageData);
|
|
@@ -102,7 +92,13 @@ export async function renderPages(
|
|
|
102
92
|
|
|
103
93
|
partial.html = {
|
|
104
94
|
raw: html,
|
|
105
|
-
transformed:
|
|
95
|
+
transformed:
|
|
96
|
+
typeof options.transformIndexHtml === "function"
|
|
97
|
+
? String(await options.transformIndexHtml(id, {
|
|
98
|
+
path: id,
|
|
99
|
+
filename: join(id, "index.html"),
|
|
100
|
+
}) || "")
|
|
101
|
+
: "", // Will be set by main thread transform
|
|
106
102
|
assets: [],
|
|
107
103
|
};
|
|
108
104
|
partialPageData.set(id, partial);
|
|
@@ -139,54 +135,62 @@ export async function renderPages(
|
|
|
139
135
|
options.onClientJSFile?.(value, route);
|
|
140
136
|
}
|
|
141
137
|
}
|
|
142
|
-
|
|
138
|
+
const getCss = async (id: string) => {
|
|
139
|
+
const cssFiles = collectManifestClientFiles({
|
|
140
|
+
manifest: options.serverManifest,
|
|
141
|
+
root: options.root,
|
|
142
|
+
pagePath: id,
|
|
143
|
+
}).cssFiles;
|
|
144
|
+
return cssFiles;
|
|
145
|
+
}
|
|
146
|
+
const pagePath = files.urlMap.get(route)?.page;
|
|
147
|
+
const propsPath = files.urlMap.get(route)?.props;
|
|
148
|
+
if(!pagePath){
|
|
149
|
+
throw new Error(`No page path found for ${route}`);
|
|
150
|
+
}
|
|
143
151
|
// Create handler for pure RSC output
|
|
144
152
|
const rscResult = await createHandler({
|
|
153
|
+
root: options.root,
|
|
145
154
|
url: route,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
},
|
|
155
|
+
route: route,
|
|
156
|
+
getCss: getCss,
|
|
157
|
+
loader: options.loader,
|
|
158
|
+
cssFiles: clientCss,
|
|
159
|
+
moduleBase: options.moduleBase,
|
|
160
|
+
moduleBasePath: options.moduleBasePath,
|
|
161
|
+
moduleRootPath: moduleRootPath,
|
|
162
|
+
moduleBaseURL: options.moduleBaseURL,
|
|
163
|
+
pipableStreamOptions: options.pipableStreamOptions ?? {},
|
|
164
|
+
inlineCss: options.inlineCss,
|
|
165
|
+
Html: React.Fragment,
|
|
166
|
+
CssCollector: options.CssCollector,
|
|
167
|
+
pagePath: pagePath,
|
|
168
|
+
propsPath: propsPath,
|
|
169
|
+
pageExportName: options.pageExportName,
|
|
170
|
+
propsExportName: options.propsExportName,
|
|
171
|
+
logger: createLogger(),
|
|
167
172
|
});
|
|
168
|
-
|
|
169
173
|
// Create handler for HTML output
|
|
170
174
|
const htmlResult = await createHandler({
|
|
175
|
+
root: options.root,
|
|
171
176
|
url: route,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
},
|
|
177
|
+
route: route,
|
|
178
|
+
getCss: getCss,
|
|
179
|
+
loader: options.loader,
|
|
180
|
+
cssFiles: clientCss,
|
|
181
|
+
moduleBase: options.moduleBase,
|
|
182
|
+
moduleBasePath: options.moduleBasePath,
|
|
183
|
+
moduleRootPath: moduleRootPath,
|
|
184
|
+
moduleBaseURL: options.moduleBaseURL,
|
|
185
|
+
pipableStreamOptions: options.pipableStreamOptions,
|
|
186
|
+
inlineCss: options.inlineCss,
|
|
187
|
+
Html: options.Html,
|
|
188
|
+
CssCollector: options.CssCollector,
|
|
189
|
+
pagePath: pagePath,
|
|
190
|
+
propsPath: propsPath,
|
|
191
|
+
pageExportName: options.pageExportName,
|
|
192
|
+
propsExportName: options.propsExportName,
|
|
193
|
+
logger: createLogger(),
|
|
190
194
|
});
|
|
191
195
|
|
|
192
196
|
if (rscResult.type !== "success" || htmlResult.type !== "success") {
|
|
@@ -254,7 +258,7 @@ export async function renderPages(
|
|
|
254
258
|
type: "RSC_CHUNK",
|
|
255
259
|
id: route,
|
|
256
260
|
chunk: chunk.toString(),
|
|
257
|
-
moduleRootPath:
|
|
261
|
+
moduleRootPath: moduleRootPath,
|
|
258
262
|
moduleBaseURL: options.moduleBaseURL,
|
|
259
263
|
htmlOutputPath: options.htmlOutputPath,
|
|
260
264
|
pipableStreamOptions: options.pipableStreamOptions,
|
|
@@ -2,17 +2,15 @@ import { join } from "node:path";
|
|
|
2
2
|
import { PassThrough } from "node:stream";
|
|
3
3
|
import { parentPort } from "node:worker_threads";
|
|
4
4
|
import React from "react";
|
|
5
|
-
import {
|
|
6
|
-
renderToPipeableStream,
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
} from "react-server-dom-esm/server.node";
|
|
9
5
|
import type {
|
|
10
6
|
RscChunkMessage,
|
|
11
7
|
RscEndMessage,
|
|
12
8
|
RscWorkerMessage,
|
|
13
9
|
} from "../types.js";
|
|
14
10
|
import { addCssFile, cssFiles } from "./state.js";
|
|
15
|
-
import {
|
|
11
|
+
import { InlineCssCollector } from "../../css-collector-inline.js";
|
|
12
|
+
import { createRscStream } from "../../helpers/createRscStream.js";
|
|
13
|
+
import { createLogger } from "vite";
|
|
16
14
|
|
|
17
15
|
export async function messageHandler(message: RscWorkerMessage) {
|
|
18
16
|
switch (message.type) {
|
|
@@ -26,8 +24,10 @@ export async function messageHandler(message: RscWorkerMessage) {
|
|
|
26
24
|
url,
|
|
27
25
|
outDir,
|
|
28
26
|
projectRoot,
|
|
27
|
+
moduleRootPath,
|
|
29
28
|
moduleBaseURL,
|
|
30
29
|
moduleBasePath,
|
|
30
|
+
moduleBase,
|
|
31
31
|
pipableStreamOptions,
|
|
32
32
|
} = message;
|
|
33
33
|
|
|
@@ -46,17 +46,34 @@ export async function messageHandler(message: RscWorkerMessage) {
|
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
const PageComponent = Component[pageExportName];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
|
|
50
|
+
// Create stream using the helper
|
|
51
|
+
const stream = createRscStream({
|
|
52
|
+
Html: React.Fragment,
|
|
53
|
+
Page: PageComponent,
|
|
54
|
+
CssCollector: InlineCssCollector,
|
|
55
|
+
loader: (id: string) => import(id).then((m) => m.default),
|
|
56
|
+
props,
|
|
57
|
+
moduleBase,
|
|
58
|
+
moduleRootPath,
|
|
59
|
+
moduleBasePath,
|
|
57
60
|
moduleBaseURL,
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
logger: createLogger(),
|
|
62
|
+
inlineCss: true,
|
|
63
|
+
cssFiles: Array.from(cssFiles.values()).map((css) => ({
|
|
64
|
+
type: "text/css",
|
|
65
|
+
content: css,
|
|
66
|
+
path: css,
|
|
67
|
+
})),
|
|
68
|
+
route: url,
|
|
69
|
+
url: typeof moduleBaseURL === "string" && moduleBaseURL !== "" ? new URL(url, moduleBaseURL).toString() : url,
|
|
70
|
+
root: projectRoot,
|
|
71
|
+
pipableStreamOptions: {
|
|
72
|
+
...pipableStreamOptions,
|
|
73
|
+
onError: (error: unknown) => {
|
|
74
|
+
if (typeof pipableStreamOptions.onError === "function") {
|
|
75
|
+
pipableStreamOptions.onError(error);
|
|
76
|
+
}
|
|
60
77
|
parentPort?.postMessage({
|
|
61
78
|
type: "ERROR",
|
|
62
79
|
id,
|
|
@@ -64,26 +81,24 @@ export async function messageHandler(message: RscWorkerMessage) {
|
|
|
64
81
|
});
|
|
65
82
|
},
|
|
66
83
|
onPostpone: (reason: string) => {
|
|
84
|
+
if (typeof pipableStreamOptions.onPostpone === "function") {
|
|
85
|
+
pipableStreamOptions.onPostpone(reason);
|
|
86
|
+
}
|
|
67
87
|
parentPort?.postMessage({
|
|
68
88
|
type: "POSTPONE",
|
|
69
89
|
id,
|
|
70
90
|
reason,
|
|
71
91
|
});
|
|
72
92
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
...pipableStreamOptions,
|
|
81
|
-
}
|
|
82
|
-
);
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (!stream) {
|
|
97
|
+
throw new Error("Failed to create stream");
|
|
98
|
+
}
|
|
83
99
|
|
|
84
100
|
// Listen for data and end events
|
|
85
101
|
const passThrough = new PassThrough();
|
|
86
|
-
|
|
87
102
|
stream.pipe(passThrough);
|
|
88
103
|
|
|
89
104
|
passThrough.on("data", (chunk) => {
|
package/plugin/worker/types.ts
CHANGED
|
@@ -18,6 +18,8 @@ export interface PipeableStreamOptions {
|
|
|
18
18
|
onShellReady?: () => void;
|
|
19
19
|
onAllReady?: () => void;
|
|
20
20
|
onError?: (error: unknown) => void;
|
|
21
|
+
onPostpone?: (reason: string) => void;
|
|
22
|
+
environmentName?: string;
|
|
21
23
|
importMap?: {
|
|
22
24
|
imports?: Record<string, string>;
|
|
23
25
|
};
|
|
@@ -65,6 +67,7 @@ export interface RscRenderMessage extends WorkerMessage {
|
|
|
65
67
|
moduleRootPath: string;
|
|
66
68
|
moduleBaseURL: string;
|
|
67
69
|
moduleBasePath: string;
|
|
70
|
+
moduleBase: string;
|
|
68
71
|
pipableStreamOptions: PipeableStreamOptions;
|
|
69
72
|
cssFiles: string[];
|
|
70
73
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../plugin/components.tsx"],"sourcesContent":["import React from \"react\";\n/**\n * A component that emits <link> tags for CSS files during streaming.\n * The high precedence ensures they bubble up to the document head.\n */\nexport function CssCollector({\n children,\n cssFiles,\n moduleBaseUrl,\n route = \"/\"\n}: {\n children?: React.ReactNode;\n cssFiles: string[];\n moduleBaseUrl?: string;\n route?: string;\n}) {\n // Calculate depth and prefix based on route\n const depth = route.split('/').filter(Boolean).length ;\n const prefix = depth > 0 ? '../'.repeat(depth) : './';\n const base = typeof moduleBaseUrl === 'string' && moduleBaseUrl !== '' ? moduleBaseUrl : prefix;\n\n return React.createElement(\n React.Fragment,\n null,\n ...cssFiles.map((css) => {\n try {\n if(moduleBaseUrl) {\n new URL(css, moduleBaseUrl);\n } else {\n new URL(`file://${base}${css}`);\n }\n } catch (error) {\n return React.createElement('style', {type: 'text/css'}, \n css\n );\n }\n // Handle different types of paths\n let url = css;\n if (css.startsWith('http') || css.startsWith('data:')) {\n // Keep absolute URLs as is\n url = css;\n } else if (css.startsWith('/')) {\n // Convert absolute paths to relative\n url = base + css.slice(1);\n } else if (!css.startsWith('./') && !css.startsWith('../')) {\n // Add prefix to relative paths that don't start with ./ or ../\n url = base + css;\n }\n \n return React.createElement(\"link\", {\n key: css,\n rel: \"stylesheet\",\n href: url,\n precedence: \"high\",\n });\n }),\n children\n );\n}\n"],"names":["React"],"mappings":";;;;;;;AAKO,SAAS,YAAa,CAAA;AAAA,EAC3B,QAAA;AAAA,EACA,QAAA;AAAA,EACA,aAAA;AAAA,EACA,KAAQ,GAAA;AACV,CAKG,EAAA;AAED,EAAA,MAAM,QAAQ,KAAM,CAAA,KAAA,CAAM,GAAG,CAAE,CAAA,MAAA,CAAO,OAAO,CAAE,CAAA,MAAA;AAC/C,EAAA,MAAM,SAAS,KAAQ,GAAA,CAAA,GAAI,KAAM,CAAA,MAAA,CAAO,KAAK,CAAI,GAAA,IAAA;AACjD,EAAA,MAAM,OAAO,OAAO,aAAA,KAAkB,QAAY,IAAA,aAAA,KAAkB,KAAK,aAAgB,GAAA,MAAA;AAEzF,EAAA,OAAOA,cAAM,CAAA,aAAA;AAAA,IACXA,cAAM,CAAA,QAAA;AAAA,IACN,IAAA;AAAA,IACA,GAAG,QAAA,CAAS,GAAI,CAAA,CAAC,GAAQ,KAAA;AACvB,MAAI,IAAA;AACF,QAAA,IAAG,aAAe,EAAA;AAChB,UAAI,IAAA,GAAA,CAAI,KAAK,aAAa,CAAA;AAAA,SACrB,MAAA;AACL,UAAA,IAAI,GAAI,CAAA,CAAA,OAAA,EAAU,IAAI,CAAA,EAAG,GAAG,CAAE,CAAA,CAAA;AAAA;AAChC,eACO,KAAO,EAAA;AACd,QAAA,OAAOA,cAAM,CAAA,aAAA;AAAA,UAAc,OAAA;AAAA,UAAS,EAAC,MAAM,UAAU,EAAA;AAAA,UACnD;AAAA,SACF;AAAA;AAGF,MAAA,IAAI,GAAM,GAAA,GAAA;AACV,MAAA,IAAI,IAAI,UAAW,CAAA,MAAM,KAAK,GAAI,CAAA,UAAA,CAAW,OAAO,CAAG,EAAA;AAErD,QAAM,GAAA,GAAA,GAAA;AAAA,OACG,MAAA,IAAA,GAAA,CAAI,UAAW,CAAA,GAAG,CAAG,EAAA;AAE9B,QAAM,GAAA,GAAA,IAAA,GAAO,GAAI,CAAA,KAAA,CAAM,CAAC,CAAA;AAAA,OAC1B,MAAA,IAAW,CAAC,GAAA,CAAI,UAAW,CAAA,IAAI,KAAK,CAAC,GAAA,CAAI,UAAW,CAAA,KAAK,CAAG,EAAA;AAE1D,QAAA,GAAA,GAAM,IAAO,GAAA,GAAA;AAAA;AAGf,MAAO,OAAAA,cAAA,CAAM,cAAc,MAAQ,EAAA;AAAA,QACjC,GAAK,EAAA,GAAA;AAAA,QACL,GAAK,EAAA,YAAA;AAAA,QACL,IAAM,EAAA,GAAA;AAAA,QACN,UAAY,EAAA;AAAA,OACb,CAAA;AAAA,KACF,CAAA;AAAA,IACD;AAAA,GACF;AACF;;;;"}
|
package/dist/plugin/getEnv.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ConfigEnv, UserConfig } from "vite";
|
|
2
|
-
/**
|
|
3
|
-
* Get environment variables for Vite, sets defaults to ensure the server can start with BASE_URL and PUBLIC_URL
|
|
4
|
-
*
|
|
5
|
-
* @param config - Vite configuration object
|
|
6
|
-
* @param { isPreview: boolean } - Object containing a boolean indicating if the environment is for preview
|
|
7
|
-
* @returns An object containing the environment variables
|
|
8
|
-
*/
|
|
9
|
-
export declare function getEnv(config: UserConfig, configEnv: ConfigEnv): {
|
|
10
|
-
baseUrl: string;
|
|
11
|
-
publicUrl: string;
|
|
12
|
-
port: number;
|
|
13
|
-
host: string | boolean;
|
|
14
|
-
envPrefix: string;
|
|
15
|
-
environmentName: string;
|
|
16
|
-
env: Record<string, string>;
|
|
17
|
-
define: any;
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=getEnv.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getEnv.d.ts","sourceRoot":"","sources":["../../plugin/getEnv.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIlD;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS;;;;;;;;;EAyH9D"}
|
package/dist/plugin/getEnv.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
|
-
import { loadEnv } from "vite";
|
|
4
|
-
import { DEFAULT_CONFIG } from "./config/defaults.js";
|
|
5
|
-
/**
|
|
6
|
-
* Get environment variables for Vite, sets defaults to ensure the server can start with BASE_URL and PUBLIC_URL
|
|
7
|
-
*
|
|
8
|
-
* @param config - Vite configuration object
|
|
9
|
-
* @param { isPreview: boolean } - Object containing a boolean indicating if the environment is for preview
|
|
10
|
-
* @returns An object containing the environment variables
|
|
11
|
-
*/
|
|
12
|
-
export function getEnv(config, configEnv) {
|
|
13
|
-
const isLocal = config.mode === "development";
|
|
14
|
-
const envName = isLocal
|
|
15
|
-
? `${config.mode}.local`
|
|
16
|
-
: config.mode
|
|
17
|
-
? config.mode
|
|
18
|
-
: "production";
|
|
19
|
-
const environmentName = config.mode ?? envName ?? "production";
|
|
20
|
-
const env = loadEnv(environmentName, config.envDir ?? config.root ?? process.cwd(), config.envPrefix ?? DEFAULT_CONFIG.ENV_PREFIX ?? "VITE_");
|
|
21
|
-
// Get server config
|
|
22
|
-
const serverConfig = config.server || {};
|
|
23
|
-
const previewConfig = config.preview || {};
|
|
24
|
-
const host = configEnv.isPreview
|
|
25
|
-
? previewConfig.host ?? DEFAULT_CONFIG.PREVIEW_HOST
|
|
26
|
-
: serverConfig.host ?? DEFAULT_CONFIG.DEV_HOST;
|
|
27
|
-
let previewPort = previewConfig.port ?? DEFAULT_CONFIG.PREVIEW_PORT;
|
|
28
|
-
let devPort = serverConfig.port ?? DEFAULT_CONFIG.DEV_PORT;
|
|
29
|
-
let homepage = env["VITE_BASE_URL"];
|
|
30
|
-
if (configEnv.command === "build" && (!homepage || homepage === "")) {
|
|
31
|
-
try {
|
|
32
|
-
const packageJson = JSON.parse(readFileSync(resolve(config.root ?? "", "package.json"), "utf-8"));
|
|
33
|
-
homepage = packageJson.homepage ?? "";
|
|
34
|
-
if (!homepage || homepage === "") {
|
|
35
|
-
console.warn("[RSC] 🔧 For production builds, please set 'homepage' in package.json, or set VITE_BASE_URL in your environment");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
console.error(e);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
let baseUrl = env["VITE_BASE_URL"] && env["VITE_PUBLIC_URL"] !== ""
|
|
43
|
-
? env["VITE_BASE_URL"]
|
|
44
|
-
: configEnv.isPreview
|
|
45
|
-
? `http://${host}:${previewPort}`
|
|
46
|
-
: configEnv.command === "serve"
|
|
47
|
-
? `http://${host}:${devPort}`
|
|
48
|
-
: homepage;
|
|
49
|
-
let publicUrl = env["VITE_PUBLIC_URL"] && env["VITE_PUBLIC_URL"] !== ""
|
|
50
|
-
? env["VITE_PUBLIC_URL"]
|
|
51
|
-
: "";
|
|
52
|
-
// Determine port and host based on mode
|
|
53
|
-
const port = configEnv.isPreview
|
|
54
|
-
? previewConfig.port || DEFAULT_CONFIG.PREVIEW_PORT // Preview server
|
|
55
|
-
: serverConfig.port || DEFAULT_CONFIG.DEV_PORT; // Dev server
|
|
56
|
-
// Build base URL
|
|
57
|
-
if (configEnv.isPreview && `http://${host}:${port}` !== baseUrl) {
|
|
58
|
-
console.log(`VITE_BASE_URL: \"${baseUrl}\" wasn't configured correctly for this server, overriding to: \"http://${host}:${port}\"`);
|
|
59
|
-
baseUrl = `http://${host}:${port}`;
|
|
60
|
-
}
|
|
61
|
-
const envPrefix = typeof config.envPrefix === "string"
|
|
62
|
-
? config.envPrefix
|
|
63
|
-
: Array.isArray(config.envPrefix)
|
|
64
|
-
? config.envPrefix[0]
|
|
65
|
-
: DEFAULT_CONFIG.ENV_PREFIX;
|
|
66
|
-
const nodeProcessEnv = {
|
|
67
|
-
NODE_ENV: configEnv.command === "build" ? "production" : "development",
|
|
68
|
-
};
|
|
69
|
-
const defineProcess = Object.entries(nodeProcessEnv)
|
|
70
|
-
.map(([key, value]) => {
|
|
71
|
-
switch (key) {
|
|
72
|
-
case "NODE_ENV":
|
|
73
|
-
const isDev = value === ""
|
|
74
|
-
? configEnv.command === "build"
|
|
75
|
-
? false
|
|
76
|
-
: true
|
|
77
|
-
: value === "development";
|
|
78
|
-
return [`import.meta.env.DEV`, JSON.stringify(isDev)];
|
|
79
|
-
default:
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
.filter(Array.isArray);
|
|
84
|
-
const defineImportMeta = Object.entries(env).map(([key, value]) => [
|
|
85
|
-
`import.meta.env.${key}`,
|
|
86
|
-
key === "VITE_BASE_URL"
|
|
87
|
-
? value
|
|
88
|
-
? JSON.stringify(value)
|
|
89
|
-
: JSON.stringify(baseUrl)
|
|
90
|
-
: key === "VITE_PUBLIC_URL"
|
|
91
|
-
? value
|
|
92
|
-
? JSON.stringify(value)
|
|
93
|
-
: JSON.stringify(publicUrl)
|
|
94
|
-
: JSON.stringify(value),
|
|
95
|
-
]);
|
|
96
|
-
const define = Object.fromEntries([...defineProcess, ...defineImportMeta]);
|
|
97
|
-
return {
|
|
98
|
-
baseUrl,
|
|
99
|
-
publicUrl,
|
|
100
|
-
port,
|
|
101
|
-
host,
|
|
102
|
-
envPrefix,
|
|
103
|
-
environmentName,
|
|
104
|
-
env,
|
|
105
|
-
define,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ViteDevServer } from "vite";
|
|
2
|
-
export interface ModuleWithDeps {
|
|
3
|
-
id: string;
|
|
4
|
-
deps: Set<string>;
|
|
5
|
-
css: Set<string>;
|
|
6
|
-
}
|
|
7
|
-
export declare function getModuleGraph(server: ViteDevServer): {
|
|
8
|
-
getModuleWithDeps(id: string): Promise<ModuleWithDeps>;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=module-graph.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module-graph.d.ts","sourceRoot":"","sources":["../../plugin/module-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,aAAa,EAAE,MAAM,MAAM,CAAC;AAEtD,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClB,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAClB;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa;0BAEpB,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;EAqC/D"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export function getModuleGraph(server) {
|
|
2
|
-
return {
|
|
3
|
-
async getModuleWithDeps(id) {
|
|
4
|
-
// Load module first to ensure it's in the module graph
|
|
5
|
-
await server.ssrLoadModule(id);
|
|
6
|
-
const resolvedId = await server.pluginContainer.resolveId(id, undefined, {
|
|
7
|
-
// Add ssr and react-server conditions
|
|
8
|
-
ssr: true,
|
|
9
|
-
});
|
|
10
|
-
if (!resolvedId)
|
|
11
|
-
throw new Error(`Module not found: ${id}`);
|
|
12
|
-
const moduleNode = server.moduleGraph.getModuleById(resolvedId.id);
|
|
13
|
-
if (!moduleNode)
|
|
14
|
-
throw new Error(`Module node not found: ${id}`);
|
|
15
|
-
const deps = new Set();
|
|
16
|
-
const css = new Set();
|
|
17
|
-
// Recursively collect dependencies
|
|
18
|
-
const collectDeps = (node) => {
|
|
19
|
-
// Track CSS imports
|
|
20
|
-
if (node.id?.endsWith(".css") && node.id) {
|
|
21
|
-
css.add(node.id);
|
|
22
|
-
}
|
|
23
|
-
// Track all dependencies
|
|
24
|
-
for (const dep of node.importedModules) {
|
|
25
|
-
if (dep.id && !deps.has(dep.id)) {
|
|
26
|
-
deps.add(dep.id);
|
|
27
|
-
collectDeps(dep);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
collectDeps(moduleNode);
|
|
32
|
-
return { id: moduleNode.id ?? "", deps, css };
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/html/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAG/C,OAAO,KAAK,EAAuB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAM/E,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CA0F1E"}
|