vite-plugin-react-server 0.3.0 → 0.3.3
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 +73 -40
- package/dist/assertServerCondition.d.ts +2 -0
- package/dist/assertServerCondition.d.ts.map +1 -0
- package/dist/bin/patch.js +51 -0
- package/dist/bin/patch.js.map +1 -0
- package/dist/build/createBuildConfig.d.ts +7 -6
- package/dist/build/createBuildConfig.d.ts.map +1 -1
- package/dist/build/mergeInputs.d.ts +5 -0
- package/dist/build/mergeInputs.d.ts.map +1 -0
- package/dist/helpers/inputNormalizer.d.ts +6 -0
- package/dist/helpers/inputNormalizer.d.ts.map +1 -0
- package/dist/helpers/normalizedRelativePath.d.ts +3 -1
- package/dist/helpers/normalizedRelativePath.d.ts.map +1 -1
- package/dist/helpers/tryManifest.d.ts +10 -3
- package/dist/helpers/tryManifest.d.ts.map +1 -1
- package/dist/html/createPageLoader.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/options.d.ts +13 -8
- package/dist/options.d.ts.map +1 -1
- package/dist/plugin.d.ts +2 -7
- package/dist/plugin.d.ts.map +1 -1
- package/dist/react-client/plugin.js +1 -1
- package/dist/react-server/plugin.d.ts.map +1 -1
- package/dist/react-server/plugin.js +108 -61
- package/dist/react-server/plugin.js.map +1 -1
- package/dist/src/build/createBuildConfig.js +44 -0
- package/dist/src/build/createBuildConfig.js.map +1 -0
- package/dist/src/build/mergeInputs.js +16 -0
- package/dist/src/build/mergeInputs.js.map +1 -0
- package/dist/src/checkFilesExist.js.map +1 -0
- package/dist/src/collect-css-manifest.js.map +1 -0
- package/dist/src/components.js.map +1 -0
- package/dist/src/getEnv.js.map +1 -0
- package/dist/src/helpers/inputNormalizer.js +11 -0
- package/dist/src/helpers/inputNormalizer.js.map +1 -0
- package/dist/src/helpers/normalizedRelativePath.js +34 -0
- package/dist/src/helpers/normalizedRelativePath.js.map +1 -0
- package/dist/src/helpers/tryManifest.js +27 -0
- package/dist/src/helpers/tryManifest.js.map +1 -0
- package/dist/{html → src/html}/createPageLoader.js +3 -1
- package/dist/src/html/createPageLoader.js.map +1 -0
- package/dist/{options.js → src/options.js} +80 -24
- package/dist/src/options.js.map +1 -0
- package/dist/src/react-server/createHandler.js.map +1 -0
- package/dist/src/react-server/createRscStream.js.map +1 -0
- package/dist/src/resolvePage.js.map +1 -0
- package/dist/src/resolveProps.js.map +1 -0
- package/dist/src/worker/createHtmlStream.js +62 -0
- package/dist/src/worker/createHtmlStream.js.map +1 -0
- package/dist/{worker → src/worker}/createWorker.js +9 -8
- package/dist/src/worker/createWorker.js.map +1 -0
- package/dist/src/worker/renderPages.js.map +1 -0
- package/dist/types.d.ts +7 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/worker/createWorker.d.ts +8 -1
- package/dist/worker/createWorker.d.ts.map +1 -1
- package/dist/worker/loader.js +7 -0
- package/dist/worker/loader.js.map +1 -0
- package/dist/worker/worker.js +112 -0
- package/dist/worker/worker.js.map +1 -0
- package/package.json +108 -111
- package/patches/react-server-dom-esm+0.0.1.patch +14519 -0
- package/src/assertServerCondition.ts +13 -0
- package/src/build/createBuildConfig.ts +27 -44
- package/src/build/mergeInputs.ts +42 -0
- package/src/helpers/inputNormalizer.ts +22 -0
- package/src/helpers/normalizedRelativePath.ts +25 -25
- package/src/helpers/tryManifest.ts +19 -5
- package/src/html/createPageLoader.ts +2 -0
- package/src/options.ts +119 -47
- package/src/plugin.ts +4 -30
- package/src/react-server/createSsrHandler.ts +1 -1
- package/src/react-server/plugin.ts +116 -56
- package/src/types.ts +19 -1
- package/src/worker/createWorker.ts +12 -7
- package/tsconfig.json +2 -0
- package/dist/build/createBuildConfig.js +0 -55
- package/dist/build/createBuildConfig.js.map +0 -1
- package/dist/checkFilesExist.js.map +0 -1
- package/dist/collect-css-manifest.js.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/getEnv.js.map +0 -1
- package/dist/helpers/normalizedRelativePath.js +0 -31
- package/dist/helpers/normalizedRelativePath.js.map +0 -1
- package/dist/html/createPageLoader.js.map +0 -1
- package/dist/options.js.map +0 -1
- package/dist/plugin.js +0 -31
- package/dist/plugin.js.map +0 -1
- package/dist/react-server/createHandler.js.map +0 -1
- package/dist/react-server/createRscStream.js.map +0 -1
- package/dist/resolvePage.js.map +0 -1
- package/dist/resolveProps.js.map +0 -1
- package/dist/transformer/index.js +0 -54
- package/dist/transformer/index.js.map +0 -1
- package/dist/transformer/preserveDirectives.js +0 -72
- package/dist/transformer/preserveDirectives.js.map +0 -1
- package/dist/transformer/transformer.js +0 -80
- package/dist/transformer/transformer.js.map +0 -1
- package/dist/worker/createWorker.js.map +0 -1
- package/dist/worker/renderPages.js.map +0 -1
- /package/dist/{checkFilesExist.js → src/checkFilesExist.js} +0 -0
- /package/dist/{collect-css-manifest.js → src/collect-css-manifest.js} +0 -0
- /package/dist/{components.js → src/components.js} +0 -0
- /package/dist/{getEnv.js → src/getEnv.js} +0 -0
- /package/dist/{react-server → src/react-server}/createHandler.js +0 -0
- /package/dist/{react-server → src/react-server}/createRscStream.js +0 -0
- /package/dist/{resolvePage.js → src/resolvePage.js} +0 -0
- /package/dist/{resolveProps.js → src/resolveProps.js} +0 -0
- /package/dist/{worker → src/worker}/renderPages.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import type { ServerResponse } from "node:http";
|
|
3
|
-
import { resolve as resolvePath } from "node:path";
|
|
3
|
+
import { join, relative, resolve, resolve as resolvePath } from "node:path";
|
|
4
4
|
import { performance } from "node:perf_hooks";
|
|
5
5
|
import { Worker } from "node:worker_threads";
|
|
6
6
|
import type { Plugin as RollupPlugin } from "rollup";
|
|
@@ -21,15 +21,18 @@ import type { BuildTiming, ReactStreamPluginMeta } from "../types.js";
|
|
|
21
21
|
import { type StreamPluginOptions } from "../types.js";
|
|
22
22
|
import { createWorker } from "../worker/createWorker.js";
|
|
23
23
|
import { createHandler } from "./createHandler.js";
|
|
24
|
+
import { tryManifest } from "../helpers/tryManifest.js";
|
|
25
|
+
import { createNormalizedRelativePath } from "../helpers/normalizedRelativePath.js";
|
|
24
26
|
|
|
25
|
-
let
|
|
26
|
-
let
|
|
27
|
+
let files: Awaited<ReturnType<typeof checkFilesExist>>;
|
|
28
|
+
let env: Awaited<ReturnType<typeof getEnv>>;
|
|
27
29
|
let worker: Worker;
|
|
28
30
|
let config: ResolvedConfig;
|
|
29
31
|
let cssModules = new Set<string>();
|
|
30
32
|
let clientComponents = new Map<string, string>();
|
|
31
33
|
let define: Record<string, string>;
|
|
32
34
|
let buildCssFiles = new Set<string>();
|
|
35
|
+
let root: string = process.cwd();
|
|
33
36
|
|
|
34
37
|
interface BuildStats {
|
|
35
38
|
htmlFiles: number;
|
|
@@ -127,7 +130,7 @@ export async function reactStreamPlugin(
|
|
|
127
130
|
propsExportName: userOptions.propsExportName,
|
|
128
131
|
moduleBase: userOptions.moduleBase,
|
|
129
132
|
moduleBasePath: userOptions.moduleBasePath,
|
|
130
|
-
projectRoot: server.config.root,
|
|
133
|
+
projectRoot: server.config.root ?? userOptions.projectRoot,
|
|
131
134
|
},
|
|
132
135
|
{
|
|
133
136
|
cssFiles: Array.from(cssModules),
|
|
@@ -148,39 +151,70 @@ export async function reactStreamPlugin(
|
|
|
148
151
|
|
|
149
152
|
async config(config, configEnv): Promise<UserConfig> {
|
|
150
153
|
const resolvedPages = await resolvePages(userOptions.build.pages);
|
|
151
|
-
if(resolvedPages.type ===
|
|
154
|
+
if (resolvedPages.type === "error") {
|
|
152
155
|
throw resolvedPages.error;
|
|
153
156
|
}
|
|
154
157
|
const { pages } = resolvedPages;
|
|
158
|
+
env = getEnv(config, configEnv);
|
|
159
|
+
define = env.define;
|
|
160
|
+
files = await checkFilesExist(
|
|
161
|
+
pages,
|
|
162
|
+
userOptions,
|
|
163
|
+
config.root ?? userOptions.projectRoot
|
|
164
|
+
);
|
|
165
|
+
root = config.root ?? userOptions.projectRoot;
|
|
155
166
|
const resolvedConfig = resolveUserConfig(
|
|
156
167
|
"react-server",
|
|
157
|
-
pages,
|
|
168
|
+
[...pages, userOptions.workerPath, userOptions.loaderPath],
|
|
158
169
|
config,
|
|
159
170
|
configEnv,
|
|
160
171
|
userOptions
|
|
161
172
|
);
|
|
162
|
-
if(resolvedConfig.type === "error") {
|
|
173
|
+
if (resolvedConfig.type === "error") {
|
|
163
174
|
throw resolvedConfig.error;
|
|
164
175
|
}
|
|
165
176
|
const { userConfig } = resolvedConfig;
|
|
177
|
+
console.log({
|
|
178
|
+
worker: userOptions.workerPath,
|
|
179
|
+
loader: userOptions.loaderPath,
|
|
180
|
+
});
|
|
181
|
+
const entriesClient = Object.fromEntries([
|
|
182
|
+
...Array.from(files.pageMap.entries()).map(([key, value]) => [
|
|
183
|
+
key,
|
|
184
|
+
relative(root, value),
|
|
185
|
+
]),
|
|
186
|
+
...Array.from(files.propsMap.entries()).map(([key, value]) => [
|
|
187
|
+
key,
|
|
188
|
+
relative(root, value),
|
|
189
|
+
]),
|
|
190
|
+
]);
|
|
191
|
+
const entriesResolved = Object.fromEntries(
|
|
192
|
+
(Object.entries(entriesClient) as [string, string][]).map(
|
|
193
|
+
([key, entry]) => {
|
|
194
|
+
if (typeof entry !== "string") {
|
|
195
|
+
return [key, entry];
|
|
196
|
+
}
|
|
166
197
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
pageMap = files.pageMap;
|
|
171
|
-
define = envResult.define;
|
|
172
|
-
const entries = Array.from(
|
|
173
|
-
new Set([
|
|
174
|
-
...Array.from(files.pageSet.values()),
|
|
175
|
-
...Array.from(files.propsSet.values()),
|
|
176
|
-
]).values()
|
|
198
|
+
return [key, entry];
|
|
199
|
+
}
|
|
200
|
+
)
|
|
177
201
|
);
|
|
202
|
+
const serverEntries = {
|
|
203
|
+
...entriesResolved,
|
|
204
|
+
["worker/worker"]: userOptions.workerPath,
|
|
205
|
+
["worker/loader"]: userOptions.loaderPath,
|
|
206
|
+
};
|
|
178
207
|
|
|
179
208
|
const buildConfig = createBuildConfig({
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
209
|
+
input: serverEntries,
|
|
210
|
+
userConfig: userConfig,
|
|
211
|
+
userOptions: userOptions,
|
|
212
|
+
root,
|
|
213
|
+
moduleBaseExceptions: [
|
|
214
|
+
userOptions.workerPath,
|
|
215
|
+
userOptions.loaderPath,
|
|
216
|
+
...userOptions.moduleBaseExceptions,
|
|
217
|
+
],
|
|
184
218
|
});
|
|
185
219
|
return {
|
|
186
220
|
...buildConfig,
|
|
@@ -192,44 +226,70 @@ export async function reactStreamPlugin(
|
|
|
192
226
|
timing.buildStart = performance.now();
|
|
193
227
|
},
|
|
194
228
|
async closeBundle() {
|
|
195
|
-
if(!config) return;
|
|
229
|
+
if (!config) return;
|
|
196
230
|
console.log("RSC CLOSE BUNDLE CALLED");
|
|
197
|
-
if (!pageSet
|
|
231
|
+
if (!files.pageSet.size) return;
|
|
198
232
|
timing.renderStart = performance.now();
|
|
199
233
|
|
|
200
234
|
try {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
235
|
+
const resolvedServerManifest = tryManifest({
|
|
236
|
+
root,
|
|
237
|
+
outDir: userOptions.build.server,
|
|
238
|
+
ssrManifest: false,
|
|
239
|
+
});
|
|
240
|
+
if (resolvedServerManifest.type === "error") {
|
|
241
|
+
console.error(
|
|
242
|
+
"[vite-react-stream] Server Build failed, can not build without a server manifest. Please set `manifest: true` in your vite config.",
|
|
243
|
+
resolvedServerManifest.error
|
|
244
|
+
);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const { manifest: serverManifest } = resolvedServerManifest;
|
|
248
|
+
|
|
249
|
+
// get worker path from server manifest
|
|
250
|
+
const workerPath =
|
|
251
|
+
serverManifest[userOptions.workerPath]?.file ??
|
|
252
|
+
serverManifest[relative(root, userOptions.workerPath)]?.file ??
|
|
253
|
+
serverManifest[
|
|
254
|
+
relative(
|
|
255
|
+
join(root, userOptions.build.server),
|
|
256
|
+
userOptions.workerPath
|
|
257
|
+
)
|
|
258
|
+
]?.file;
|
|
259
|
+
if (!workerPath) {
|
|
260
|
+
console.log(serverManifest, userOptions.build.server);
|
|
261
|
+
throw new Error(
|
|
262
|
+
`Worker path not found in server manifest, tried: ${userOptions.workerPath}, ${relative(root, userOptions.workerPath)}, ${join(root, userOptions.build.server, userOptions.workerPath)}`
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
console.log("workerPath", workerPath);
|
|
266
|
+
// client
|
|
267
|
+
const resolvedClientManifest = tryManifest({
|
|
268
|
+
root,
|
|
269
|
+
outDir: userOptions.build.client,
|
|
270
|
+
ssrManifest: false,
|
|
271
|
+
});
|
|
272
|
+
if (resolvedClientManifest.type === "error") {
|
|
273
|
+
console.error(
|
|
274
|
+
"[vite-react-stream] Server Build failed, can not build without a client manifest. Make sure to run the client build before the server build and set `manifest: true` in your vite config.",
|
|
275
|
+
resolvedClientManifest.error
|
|
276
|
+
);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const { manifest: clientManifest } = resolvedClientManifest;
|
|
280
|
+
|
|
223
281
|
// Create a single worker for all routes
|
|
224
282
|
if (!worker)
|
|
225
|
-
worker = await createWorker(
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
283
|
+
worker = await createWorker({
|
|
284
|
+
workerPath: join(root, userOptions.build.server, workerPath),
|
|
285
|
+
nodePath: process.env["NODE_PATH"] ?? resolve(root, "node_modules"),
|
|
286
|
+
mode:
|
|
287
|
+
process.env["NODE_ENV"] === "development"
|
|
288
|
+
? "development"
|
|
289
|
+
: "production",
|
|
290
|
+
});
|
|
231
291
|
// this is based on the user config - the routes should lead to a page and props but the rendering is agnostic of that
|
|
232
|
-
const routes = Array.from(pageMap.keys());
|
|
292
|
+
const routes = Array.from(files.pageMap.keys());
|
|
233
293
|
const indexEntry = clientManifest["index.html"];
|
|
234
294
|
if (!indexEntry) {
|
|
235
295
|
throw new Error("root /index.html not found");
|
|
@@ -250,19 +310,19 @@ export async function reactStreamPlugin(
|
|
|
250
310
|
moduleBase: userOptions.moduleBase,
|
|
251
311
|
moduleBasePath: userOptions.moduleBasePath,
|
|
252
312
|
moduleBaseURL: userOptions.moduleBaseURL,
|
|
253
|
-
projectRoot:
|
|
313
|
+
projectRoot: root,
|
|
254
314
|
},
|
|
255
315
|
worker: worker,
|
|
256
|
-
manifest: clientManifest
|
|
316
|
+
manifest: clientManifest,
|
|
257
317
|
loader: createPageLoader({
|
|
258
|
-
manifest,
|
|
318
|
+
manifest: clientManifest,
|
|
259
319
|
root: config.root,
|
|
260
320
|
outDir: config.build.outDir,
|
|
261
321
|
moduleBase: userOptions.moduleBase,
|
|
262
322
|
alwaysRegisterServer: false,
|
|
263
323
|
alwaysRegisterClient: false,
|
|
264
324
|
registerServer: [],
|
|
265
|
-
registerClient: Object.keys(
|
|
325
|
+
registerClient: Object.keys(resolvedClientManifest).filter(
|
|
266
326
|
(key) =>
|
|
267
327
|
key.endsWith(".client.tsx") && clientManifest[key].isEntry
|
|
268
328
|
),
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AliasOptions,
|
|
3
|
+
BuildOptions,
|
|
3
4
|
Connect,
|
|
4
5
|
Logger,
|
|
5
6
|
Manifest,
|
|
6
7
|
ModuleGraph,
|
|
8
|
+
UserConfig,
|
|
7
9
|
ViteDevServer,
|
|
8
10
|
} from "vite";
|
|
9
11
|
|
|
@@ -35,8 +37,23 @@ export type ResolvedUserOptions = Required<
|
|
|
35
37
|
| "collectCss"
|
|
36
38
|
| "collectAssets"
|
|
37
39
|
| "assetsDir"
|
|
40
|
+
| "workerPath"
|
|
41
|
+
| "loaderPath"
|
|
42
|
+
| "clientEntry"
|
|
43
|
+
| "serverOutDir"
|
|
44
|
+
| "clientOutDir"
|
|
45
|
+
| "moduleBaseExceptions"
|
|
38
46
|
>
|
|
39
|
-
> & {
|
|
47
|
+
> & {
|
|
48
|
+
build: NonNullable<Required<StreamPluginOptions["build"]>>;
|
|
49
|
+
autoDiscover: NonNullable<Required<StreamPluginOptions["autoDiscover"]>>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type ResolvedUserConfig = Required<Pick<UserConfig, "root" | "mode">> &
|
|
53
|
+
Omit<UserConfig, "root" | "mode" | "build"> & {
|
|
54
|
+
build: Required<Pick<BuildOptions, "target" | "outDir" | "assetsDir" | "ssr" | "ssrEmitAssets" | "ssrManifest" | "manifest">> &
|
|
55
|
+
Partial<Omit<BuildOptions, "target" | "outDir" | "assetsDir" | "ssr" | "ssrEmitAssets" | "ssrManifest" | "manifest">>;
|
|
56
|
+
};
|
|
40
57
|
|
|
41
58
|
export interface StreamPluginOptions {
|
|
42
59
|
projectRoot?: string;
|
|
@@ -70,6 +87,7 @@ export interface StreamPluginOptions {
|
|
|
70
87
|
collectCss?: boolean;
|
|
71
88
|
collectAssets?: boolean;
|
|
72
89
|
build?: BuildConfig;
|
|
90
|
+
moduleBaseExceptions?: string[];
|
|
73
91
|
}
|
|
74
92
|
|
|
75
93
|
export interface CreateHandlerOptions<T = any> {
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join } from "node:path";
|
|
2
2
|
import { Worker } from "node:worker_threads";
|
|
3
3
|
|
|
4
|
+
type CreateWorkerOptions = {
|
|
5
|
+
workerPath: string;
|
|
6
|
+
nodePath: string;
|
|
7
|
+
mode: "production" | "development";
|
|
8
|
+
workerOptions?: WorkerOptions;
|
|
9
|
+
};
|
|
10
|
+
|
|
4
11
|
export async function createWorker(
|
|
5
|
-
|
|
6
|
-
outDir: string,
|
|
7
|
-
fileName: string,
|
|
8
|
-
mode: "production" | "development"
|
|
12
|
+
options: CreateWorkerOptions
|
|
9
13
|
) {
|
|
14
|
+
const { workerPath, nodePath, mode, workerOptions } = options;
|
|
10
15
|
console.log("[Worker] Creating worker...");
|
|
11
|
-
const workerPath = resolve(projectRoot, outDir, fileName);
|
|
12
16
|
console.log("[Worker] Worker path:", workerPath);
|
|
13
17
|
|
|
14
18
|
try {
|
|
15
19
|
const worker = new Worker(workerPath, {
|
|
16
20
|
env: {
|
|
17
21
|
NODE_OPTIONS: "",
|
|
18
|
-
NODE_PATH: resolve(projectRoot, "node_modules"),
|
|
19
22
|
NODE_ENV: mode,
|
|
23
|
+
NODE_PATH: nodePath,
|
|
20
24
|
},
|
|
25
|
+
...workerOptions,
|
|
21
26
|
});
|
|
22
27
|
worker.setMaxListeners(1000);
|
|
23
28
|
|
package/tsconfig.json
CHANGED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { dirname, resolve } from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { DEFAULT_CONFIG } from "../options.js";
|
|
4
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
5
|
-
function createBuildConfig({
|
|
6
|
-
root,
|
|
7
|
-
base,
|
|
8
|
-
outDir,
|
|
9
|
-
entries,
|
|
10
|
-
options
|
|
11
|
-
}) {
|
|
12
|
-
const entryInputs = Object.fromEntries(
|
|
13
|
-
entries.map((entry) => {
|
|
14
|
-
const relativePath = entry.replace(root + "/", "");
|
|
15
|
-
const key = relativePath.replace(/\.[^/.]+$/, "");
|
|
16
|
-
return [key, entry];
|
|
17
|
-
})
|
|
18
|
-
);
|
|
19
|
-
const workerPath = options?.workerPath ? resolve(root, options.workerPath) : resolve(__dirname, "..", DEFAULT_CONFIG.WORKER_PATH);
|
|
20
|
-
const loaderPath = options?.loaderPath ? resolve(root, options.loaderPath) : resolve(__dirname, "..", DEFAULT_CONFIG.LOADER_PATH);
|
|
21
|
-
const config = {
|
|
22
|
-
configFile: false,
|
|
23
|
-
root,
|
|
24
|
-
base,
|
|
25
|
-
build: {
|
|
26
|
-
target: "node18",
|
|
27
|
-
ssr: true,
|
|
28
|
-
ssrEmitAssets: false,
|
|
29
|
-
manifest: true,
|
|
30
|
-
ssrManifest: true,
|
|
31
|
-
outDir,
|
|
32
|
-
rollupOptions: {
|
|
33
|
-
input: {
|
|
34
|
-
...entryInputs,
|
|
35
|
-
worker: workerPath,
|
|
36
|
-
loader: loaderPath
|
|
37
|
-
},
|
|
38
|
-
output: {
|
|
39
|
-
format: "esm",
|
|
40
|
-
preserveModules: true,
|
|
41
|
-
hoistTransitiveImports: false,
|
|
42
|
-
esModule: true,
|
|
43
|
-
entryFileNames: "[name].js",
|
|
44
|
-
chunkFileNames: "[name].js",
|
|
45
|
-
assetFileNames: "[name][extname]"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
return config;
|
|
51
|
-
}
|
|
52
|
-
export {
|
|
53
|
-
createBuildConfig
|
|
54
|
-
};
|
|
55
|
-
//# sourceMappingURL=createBuildConfig.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createBuildConfig.js","sources":["../../src/build/createBuildConfig.ts"],"sourcesContent":["import { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { InlineConfig } from \"vite\";\nimport { DEFAULT_CONFIG } from \"../options.js\";\nimport type { StreamPluginOptions } from \"../types.js\";\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\ntype CreateBuildConfigOptions = {\n root: string;\n base: string;\n outDir: string;\n entries: string[];\n options?: StreamPluginOptions;\n};\n\nexport function createBuildConfig({\n root,\n base,\n outDir,\n entries,\n options,\n}: CreateBuildConfigOptions) {\n // Transform entries into proper input format with unique keys\n const entryInputs = Object.fromEntries(\n entries.map((entry) => {\n // Get the path relative to root\n const relativePath = entry.replace(root + \"/\", \"\");\n // Create a unique key based on the full path\n const key = relativePath.replace(/\\.[^/.]+$/, \"\"); // Remove extension\n\n return [key, entry];\n })\n );\n\n const workerPath = options?.workerPath\n ? resolve(root, options.workerPath)\n : resolve(__dirname, \"..\", DEFAULT_CONFIG.WORKER_PATH);\n\n const loaderPath = options?.loaderPath\n ? resolve(root, options.loaderPath)\n : resolve(__dirname, \"..\", DEFAULT_CONFIG.LOADER_PATH);\n\n const config: InlineConfig = {\n configFile: false,\n root,\n base,\n build: {\n target: \"node18\",\n ssr: true,\n ssrEmitAssets: false,\n manifest: true,\n ssrManifest: true,\n outDir,\n rollupOptions: {\n input: {\n ...entryInputs,\n worker: workerPath,\n loader: loaderPath,\n },\n output: {\n format: \"esm\",\n preserveModules: true,\n hoistTransitiveImports: false,\n esModule: true,\n entryFileNames: \"[name].js\",\n chunkFileNames: \"[name].js\",\n assetFileNames: \"[name][extname]\",\n },\n },\n },\n };\n\n return config;\n}\n"],"names":[],"mappings":";;;AAKA,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAUjD,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA6B;AAE3B,QAAM,cAAc,OAAO;AAAA,IACzB,QAAQ,IAAI,CAAC,UAAU;AAErB,YAAM,eAAe,MAAM,QAAQ,OAAO,KAAK,EAAE;AAEjD,YAAM,MAAM,aAAa,QAAQ,aAAa,EAAE;AAEzC,aAAA,CAAC,KAAK,KAAK;AAAA,IACnB,CAAA;AAAA,EACH;AAEA,QAAM,aAAa,SAAS,aACxB,QAAQ,MAAM,QAAQ,UAAU,IAChC,QAAQ,WAAW,MAAM,eAAe,WAAW;AAEvD,QAAM,aAAa,SAAS,aACxB,QAAQ,MAAM,QAAQ,UAAU,IAChC,QAAQ,WAAW,MAAM,eAAe,WAAW;AAEvD,QAAM,SAAuB;AAAA,IAC3B,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,KAAK;AAAA,MACL,eAAe;AAAA,MACf,UAAU;AAAA,MACV,aAAa;AAAA,MACb;AAAA,MACA,eAAe;AAAA,QACb,OAAO;AAAA,UACL,GAAG;AAAA,UACH,QAAQ;AAAA,UACR,QAAQ;AAAA,QACV;AAAA,QACA,QAAQ;AAAA,UACN,QAAQ;AAAA,UACR,iBAAiB;AAAA,UACjB,wBAAwB;AAAA,UACxB,UAAU;AAAA,UACV,gBAAgB;AAAA,UAChB,gBAAgB;AAAA,UAChB,gBAAgB;AAAA,QAAA;AAAA,MAClB;AAAA,IACF;AAAA,EAEJ;AAEO,SAAA;AACT;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkFilesExist.js","sources":["../src/checkFilesExist.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { StreamPluginOptions } from \"./types.js\";\n\nexport async function checkFilesExist(\n pages: string[],\n options: Pick<StreamPluginOptions, \"Page\" | \"props\">,\n root: string\n) {\n const errors: string[] = [];\n const pageSet = new Set<string>();\n const pageMap = new Map<string, string>();\n // Check if files exist when string paths are provided\n if (typeof options.Page === \"string\") {\n const pagePath = resolve(root, options.Page);\n pageMap.set(options.Page, pagePath);\n if (!pageSet.has(pagePath)) {\n if (!existsSync(pagePath)) {\n errors.push(`Page file not found: ${pagePath}`);\n }\n pageSet.add(pagePath);\n }\n } else if (typeof options.Page === \"function\" && pages) {\n for (const page of pages) {\n const pagePath = options.Page(resolve(root, page));\n pageMap.set(page, pagePath);\n if (pageSet.has(pagePath)) {\n continue;\n }\n if (!existsSync(pagePath)) {\n errors.push(`Page file not found: ${pagePath}`);\n }\n pageSet.add(pagePath);\n }\n }\n\n const propsSet = new Set<string>();\n const propsMap = new Map<string, string>();\n if (typeof options.props === \"string\") {\n const propsPath = resolve(root, options.props);\n propsMap.set(options.props, propsPath);\n if (!propsSet.has(propsPath)) {\n if (!existsSync(propsPath)) {\n errors.push(`Props file not found: ${propsPath}`);\n }\n propsSet.add(propsPath);\n }\n } else if (typeof options.props === \"function\" && pages) {\n for (const page of pages) {\n const propsPath = options.props(resolve(root, page));\n propsMap.set(page, propsPath);\n if (propsSet.has(propsPath)) {\n continue;\n }\n if (!existsSync(propsPath)) {\n errors.push(`Props file not found: ${propsPath}`);\n }\n propsSet.add(propsPath);\n }\n }\n\n if (errors.length) {\n throw new Error(\"React Stream Plugin Validation:\\n\" + errors.join(\"\\n\"));\n }\n\n return { pageMap, pageSet, propsMap, propsSet };\n}\n"],"names":[],"mappings":";;AAIsB,eAAA,gBACpB,OACA,SACA,MACA;AACA,QAAM,SAAmB,CAAC;AACpB,QAAA,8BAAc,IAAY;AAC1B,QAAA,8BAAc,IAAoB;AAEpC,MAAA,OAAO,QAAQ,SAAS,UAAU;AACpC,UAAM,WAAW,QAAQ,MAAM,QAAQ,IAAI;AACnC,YAAA,IAAI,QAAQ,MAAM,QAAQ;AAClC,QAAI,CAAC,QAAQ,IAAI,QAAQ,GAAG;AACtB,UAAA,CAAC,WAAW,QAAQ,GAAG;AAClB,eAAA,KAAK,wBAAwB,QAAQ,EAAE;AAAA,MAAA;AAEhD,cAAQ,IAAI,QAAQ;AAAA,IAAA;AAAA,EAEb,WAAA,OAAO,QAAQ,SAAS,cAAc,OAAO;AACtD,eAAW,QAAQ,OAAO;AACxB,YAAM,WAAW,QAAQ,KAAK,QAAQ,MAAM,IAAI,CAAC;AACzC,cAAA,IAAI,MAAM,QAAQ;AACtB,UAAA,QAAQ,IAAI,QAAQ,GAAG;AACzB;AAAA,MAAA;AAEE,UAAA,CAAC,WAAW,QAAQ,GAAG;AAClB,eAAA,KAAK,wBAAwB,QAAQ,EAAE;AAAA,MAAA;AAEhD,cAAQ,IAAI,QAAQ;AAAA,IAAA;AAAA,EACtB;AAGI,QAAA,+BAAe,IAAY;AAC3B,QAAA,+BAAe,IAAoB;AACrC,MAAA,OAAO,QAAQ,UAAU,UAAU;AACrC,UAAM,YAAY,QAAQ,MAAM,QAAQ,KAAK;AACpC,aAAA,IAAI,QAAQ,OAAO,SAAS;AACrC,QAAI,CAAC,SAAS,IAAI,SAAS,GAAG;AACxB,UAAA,CAAC,WAAW,SAAS,GAAG;AACnB,eAAA,KAAK,yBAAyB,SAAS,EAAE;AAAA,MAAA;AAElD,eAAS,IAAI,SAAS;AAAA,IAAA;AAAA,EAEf,WAAA,OAAO,QAAQ,UAAU,cAAc,OAAO;AACvD,eAAW,QAAQ,OAAO;AACxB,YAAM,YAAY,QAAQ,MAAM,QAAQ,MAAM,IAAI,CAAC;AAC1C,eAAA,IAAI,MAAM,SAAS;AACxB,UAAA,SAAS,IAAI,SAAS,GAAG;AAC3B;AAAA,MAAA;AAEE,UAAA,CAAC,WAAW,SAAS,GAAG;AACnB,eAAA,KAAK,yBAAyB,SAAS,EAAE;AAAA,MAAA;AAElD,eAAS,IAAI,SAAS;AAAA,IAAA;AAAA,EACxB;AAGF,MAAI,OAAO,QAAQ;AACjB,UAAM,IAAI,MAAM,sCAAsC,OAAO,KAAK,IAAI,CAAC;AAAA,EAAA;AAGzE,SAAO,EAAE,SAAS,SAAS,UAAU,SAAS;AAChD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collect-css-manifest.js","sources":["../src/collect-css-manifest.ts"],"sourcesContent":["import type { Manifest, ModuleGraph } from \"vite\";\n\nexport async function collectModuleGraphCss(\n moduleGraph: ModuleGraph,\n pagePath: string\n) {\n if (!pagePath) return new Map<string, string>();\n\n const cssFiles = new Map<string, string>();\n const pageModule = await moduleGraph.getModuleByUrl(pagePath, true);\n if (!pageModule) {\n return new Map<string, string>();\n }\n const seen = new Set<string>();\n const walkModule = (mod: any) => {\n if (!mod?.id || seen.has(mod.id)) return;\n seen.add(mod.id);\n if (mod?.id?.endsWith(\".css\")) {\n cssFiles.set(mod?.url, mod?.id);\n }\n mod?.importedModules?.forEach((imp: any) => walkModule(imp));\n };\n walkModule(pageModule);\n return cssFiles;\n}\n\nexport function collectManifestCss(\n manifest: Manifest,\n root: string,\n pagePath: string,\n onCss?: (path: string) => void\n) {\n const relativePagePath = pagePath.startsWith(root + \"/\")\n ? pagePath.slice(root.length + 1)\n : pagePath;\n if (!relativePagePath) return new Map<string, string>();\n const cssFiles = new Map<string, string>();\n const seen = new Set<string>();\n\n const walkManifestEntry = (id: string) => {\n if (seen.has(id)) return;\n seen.add(id);\n if (id.endsWith(\".css\")) {\n cssFiles.set(id, id);\n onCss?.(id);\n return;\n }\n // Get the manifest entry\n const entry = manifest[id];\n if (!entry) return;\n\n // Add direct CSS\n if (entry.css) {\n entry.css.forEach((css: string) => {\n cssFiles.set(entry.file, css);\n onCss?.(css);\n });\n }\n\n // Walk imports recursively\n if (entry.imports) {\n entry.imports.forEach((imp: string) => walkManifestEntry(imp));\n }\n\n // Also check dynamicImports\n if (entry.dynamicImports) {\n entry.dynamicImports.forEach((imp: string) => walkManifestEntry(imp));\n }\n };\n\n if (manifest[relativePagePath]) {\n walkManifestEntry(relativePagePath);\n }\n\n return cssFiles;\n}\n"],"names":[],"mappings":"AAEsB,eAAA,sBACpB,aACA,UACA;AACA,MAAI,CAAC,SAAiB,QAAA,oBAAI,IAAoB;AAExC,QAAA,+BAAe,IAAoB;AACzC,QAAM,aAAa,MAAM,YAAY,eAAe,UAAU,IAAI;AAClE,MAAI,CAAC,YAAY;AACf,+BAAW,IAAoB;AAAA,EAAA;AAE3B,QAAA,2BAAW,IAAY;AACvB,QAAA,aAAa,CAAC,QAAa;AAC/B,QAAI,CAAC,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,EAAG;AAC7B,SAAA,IAAI,IAAI,EAAE;AACf,QAAI,KAAK,IAAI,SAAS,MAAM,GAAG;AAC7B,eAAS,IAAI,KAAK,KAAK,KAAK,EAAE;AAAA,IAAA;AAEhC,SAAK,iBAAiB,QAAQ,CAAC,QAAa,WAAW,GAAG,CAAC;AAAA,EAC7D;AACA,aAAW,UAAU;AACd,SAAA;AACT;AAEO,SAAS,mBACd,UACA,MACA,UACA,OACA;AACM,QAAA,mBAAmB,SAAS,WAAW,OAAO,GAAG,IACnD,SAAS,MAAM,KAAK,SAAS,CAAC,IAC9B;AACJ,MAAI,CAAC,iBAAyB,QAAA,oBAAI,IAAoB;AAChD,QAAA,+BAAe,IAAoB;AACnC,QAAA,2BAAW,IAAY;AAEvB,QAAA,oBAAoB,CAAC,OAAe;AACpC,QAAA,KAAK,IAAI,EAAE,EAAG;AAClB,SAAK,IAAI,EAAE;AACP,QAAA,GAAG,SAAS,MAAM,GAAG;AACd,eAAA,IAAI,IAAI,EAAE;AACnB,cAAQ,EAAE;AACV;AAAA,IAAA;AAGI,UAAA,QAAQ,SAAS,EAAE;AACzB,QAAI,CAAC,MAAO;AAGZ,QAAI,MAAM,KAAK;AACP,YAAA,IAAI,QAAQ,CAAC,QAAgB;AACxB,iBAAA,IAAI,MAAM,MAAM,GAAG;AAC5B,gBAAQ,GAAG;AAAA,MAAA,CACZ;AAAA,IAAA;AAIH,QAAI,MAAM,SAAS;AACjB,YAAM,QAAQ,QAAQ,CAAC,QAAgB,kBAAkB,GAAG,CAAC;AAAA,IAAA;AAI/D,QAAI,MAAM,gBAAgB;AACxB,YAAM,eAAe,QAAQ,CAAC,QAAgB,kBAAkB,GAAG,CAAC;AAAA,IAAA;AAAA,EAExE;AAEI,MAAA,SAAS,gBAAgB,GAAG;AAC9B,sBAAkB,gBAAgB;AAAA,EAAA;AAG7B,SAAA;AACT;"}
|
package/dist/components.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../src/components.tsx"],"sourcesContent":["import { createElement } from 'react';\n\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({ url }: { url: string }) {\n return createElement('link', {\n key: url,\n rel: 'stylesheet',\n href: url,\n precedence: 'high'\n });\n} "],"names":[],"mappings":";AAMgB,SAAA,aAAa,EAAE,OAAwB;AACrD,SAAO,cAAc,QAAQ;AAAA,IAC3B,KAAK;AAAA,IACL,KAAK;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,EAAA,CACb;AACH;"}
|
package/dist/getEnv.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getEnv.js","sources":["../src/getEnv.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { ConfigEnv, UserConfig } from \"vite\";\nimport { loadEnv } from \"vite\";\nimport { DEFAULT_CONFIG } from \"./options.js\";\n\n/**\n * Get environment variables for Vite, sets defaults to ensure the server can start with BASE_URL and PUBLIC_URL\n *\n * @param config - Vite configuration object\n * @param { isPreview: boolean } - Object containing a boolean indicating if the environment is for preview\n * @returns An object containing the environment variables\n */\nexport function getEnv(config: UserConfig, configEnv: ConfigEnv) {\n const isLocal =\n config.mode === \"development\"\n\n const envName = isLocal\n ? `${config.mode}.local`\n : config.mode\n ? config.mode\n : \"production\";\n const environmentName = config.mode ?? envName ?? \"production\";\n\n const env = loadEnv(\n environmentName,\n config.envDir ?? config.root ?? process.cwd(),\n config.envPrefix ?? DEFAULT_CONFIG.ENV_PREFIX ?? \"VITE_\"\n );\n\n // Get server config\n const serverConfig = config.server || {};\n const previewConfig = config.preview || {};\n const host = configEnv.isPreview\n ? previewConfig.host ?? DEFAULT_CONFIG.PREVIEW_HOST\n : serverConfig.host ?? DEFAULT_CONFIG.DEV_HOST;\n let previewPort = previewConfig.port ?? DEFAULT_CONFIG.PREVIEW_PORT;\n let devPort = serverConfig.port ?? DEFAULT_CONFIG.DEV_PORT;\n\n let homepage = env[\"VITE_BASE_URL\"]\n if (configEnv.command === \"build\" && (!homepage || homepage === \"\")) {\n try {\n const packageJson = JSON.parse(\n readFileSync(resolve(config.root ?? \"\", \"package.json\"), \"utf-8\")\n );\n homepage = packageJson.homepage ?? \"\";\n if (!homepage || homepage === \"\") {\n console.warn(\n \"[RSC] 🔧 For production builds, please set 'homepage' in package.json, or set VITE_BASE_URL in your environment\"\n );\n }\n } catch (e) {\n console.error(e);\n }\n }\n\n let baseUrl =\n env[\"VITE_BASE_URL\"] && env[\"VITE_PUBLIC_URL\"] !== \"\"\n ? env[\"VITE_BASE_URL\"]\n : configEnv.isPreview\n ? `http://${host}:${previewPort}`\n : configEnv.command === \"serve\"\n ? `http://${host}:${devPort}`\n : homepage;\n\n let publicUrl =\n env[\"VITE_PUBLIC_URL\"] && env[\"VITE_PUBLIC_URL\"] !== \"\"\n ? env[\"VITE_PUBLIC_URL\"]\n : \"\";\n\n // Determine port and host based on mode\n const port = configEnv.isPreview\n ? previewConfig.port || DEFAULT_CONFIG.PREVIEW_PORT // Preview server\n : serverConfig.port || DEFAULT_CONFIG.DEV_PORT; // Dev server\n\n // Build base URL\n if (configEnv.isPreview && `http://${host}:${port}` !== baseUrl) {\n console.log(\n `VITE_BASE_URL: \\\"${baseUrl}\\\" wasn't configured correctly for this server, overriding to: \\\"http://${host}:${port}\\\"`\n );\n baseUrl = `http://${host}:${port}`;\n }\n\n const envPrefix =\n typeof config.envPrefix === \"string\"\n ? config.envPrefix\n : Array.isArray(config.envPrefix)\n ? config.envPrefix[0]\n : DEFAULT_CONFIG.ENV_PREFIX;\n\n const nodeProcessEnv = {\n NODE_ENV: configEnv.command === \"build\" ? \"production\" : \"development\",\n };\n const defineProcess = Object.entries(nodeProcessEnv)\n .map(([key, value]) => {\n switch (key) {\n case \"NODE_ENV\":\n const isDev =\n value === \"\"\n ? configEnv.command === \"build\"\n ? false\n : true\n : value === \"development\";\n return [`import.meta.env.DEV`, JSON.stringify(isDev)];\n default:\n return null;\n }\n })\n .filter(Array.isArray);\n\n const defineImportMeta = Object.entries(env).map(([key, value]) => [\n `import.meta.env.${key}`,\n key === \"VITE_BASE_URL\"\n ? value\n ? JSON.stringify(value)\n : JSON.stringify(baseUrl)\n : key === \"VITE_PUBLIC_URL\"\n ? value\n ? JSON.stringify(value)\n : JSON.stringify(publicUrl)\n : JSON.stringify(value),\n ]);\n const define = Object.fromEntries([...defineProcess, ...defineImportMeta]);\n\n return {\n baseUrl,\n publicUrl,\n port,\n host,\n envPrefix,\n environmentName,\n env,\n define,\n };\n}\n"],"names":[],"mappings":";;;;AAagB,SAAA,OAAO,QAAoB,WAAsB;AACzD,QAAA,UACJ,OAAO,SAAS;AAEZ,QAAA,UAAU,UACZ,GAAG,OAAO,IAAI,WACd,OAAO,OACP,OAAO,OACP;AACE,QAAA,kBAAkB,OAAO,QAAQ,WAAW;AAElD,QAAM,MAAM;AAAA,IACV;AAAA,IACA,OAAO,UAAU,OAAO,QAAQ,QAAQ,IAAI;AAAA,IAC5C,OAAO,aAAa,eAAe,cAAc;AAAA,EACnD;AAGM,QAAA,eAAe,OAAO,UAAU,CAAC;AACjC,QAAA,gBAAgB,OAAO,WAAW,CAAC;AACnC,QAAA,OAAO,UAAU,YACnB,cAAc,QAAQ,eAAe,eACrC,aAAa,QAAQ,eAAe;AACpC,MAAA,cAAc,cAAc,QAAQ,eAAe;AACnD,MAAA,UAAU,aAAa,QAAQ,eAAe;AAE9C,MAAA,WAAW,IAAI,eAAe;AAClC,MAAI,UAAU,YAAY,YAAY,CAAC,YAAY,aAAa,KAAK;AAC/D,QAAA;AACF,YAAM,cAAc,KAAK;AAAA,QACvB,aAAa,QAAQ,OAAO,QAAQ,IAAI,cAAc,GAAG,OAAO;AAAA,MAClE;AACA,iBAAW,YAAY,YAAY;AAC/B,UAAA,CAAC,YAAY,aAAa,IAAI;AACxB,gBAAA;AAAA,UACN;AAAA,QACF;AAAA,MAAA;AAAA,aAEK,GAAG;AACV,cAAQ,MAAM,CAAC;AAAA,IAAA;AAAA,EACjB;AAGE,MAAA,UACF,IAAI,eAAe,KAAK,IAAI,iBAAiB,MAAM,KAC/C,IAAI,eAAe,IACnB,UAAU,YACV,UAAU,IAAI,IAAI,WAAW,KA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AG,gBAAgB,CAAC;AAElE,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { normalizePath } from "vite";
|
|
2
|
-
const createNormalizedRelativePath = (options = {
|
|
3
|
-
root: process.cwd(),
|
|
4
|
-
outDir: ["dist", "build"],
|
|
5
|
-
moduleBase: "src",
|
|
6
|
-
noLeadingSlash: false
|
|
7
|
-
}) => {
|
|
8
|
-
const base = options.noLeadingSlash && options.moduleBase.startsWith("/") ? options.moduleBase.slice(1) : options.moduleBase;
|
|
9
|
-
const removeOutDir = Array.isArray(options.outDir) ? (path) => options.outDir.map((dir) => path.startsWith(dir)).some((v) => v) ? path.slice(options.outDir[0].length) : path : (path) => options.outDir === path ? path.slice(options.outDir.length) : path;
|
|
10
|
-
const removeRoot = (path) => {
|
|
11
|
-
const normalized = normalizePath(path);
|
|
12
|
-
const relative = normalized.startsWith(options.root) ? normalized.slice(options.root.length) : normalized;
|
|
13
|
-
return relative;
|
|
14
|
-
};
|
|
15
|
-
const ensureModuleBase = (path) => {
|
|
16
|
-
if (options.noLeadingSlash && path.startsWith("/")) {
|
|
17
|
-
return path.slice(1);
|
|
18
|
-
}
|
|
19
|
-
if (!path.startsWith(base)) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
`Path ${path} does not start with module base ${base}, this will not work down the line.`
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
return path;
|
|
25
|
-
};
|
|
26
|
-
return (path) => ensureModuleBase(removeOutDir(removeRoot(path)));
|
|
27
|
-
};
|
|
28
|
-
export {
|
|
29
|
-
createNormalizedRelativePath
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=normalizedRelativePath.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normalizedRelativePath.js","sources":["../../src/helpers/normalizedRelativePath.ts"],"sourcesContent":["import { normalizePath } from \"vite\";\n\ntype NormalizedRelativePathOptions = {\n // will automatically remove this part\n root: string;\n // will automatically see this as a optional extra part of the rootDir that will be removed\n outDir: string | string[];\n // will ensure it always starts with this path, if it does not it will be added\n moduleBase: string;\n // will ensure it never starts with a leading /, which in some cases is needed (vite entry), other cases it is not for example from project root /\n noLeadingSlash: boolean;\n};\n\nexport const createNormalizedRelativePath = (\n options: NormalizedRelativePathOptions = {\n root: process.cwd(),\n outDir: [\"dist\", \"build\"],\n moduleBase: \"src\",\n noLeadingSlash: false,\n }\n) => {\n const base =\n options.noLeadingSlash && options.moduleBase.startsWith(\"/\")\n ? options.moduleBase.slice(1)\n : options.moduleBase;\n const removeOutDir = Array.isArray(options.outDir)\n ? (path: string) =>\n (options.outDir as string[])\n .map((dir) => path.startsWith(dir))\n .some((v) => v)\n ? path.slice(options.outDir[0].length)\n : path\n : (path: string) =>\n (options.outDir as string) === path\n ? path.slice(options.outDir.length)\n : path;\n\n const removeRoot = (path: string) => {\n const normalized = normalizePath(path);\n const relative = normalized.startsWith(options.root)\n ? normalized.slice(options.root.length)\n : normalized;\n return relative;\n };\n\n const ensureModuleBase = (path: string) => {\n if (options.noLeadingSlash && path.startsWith(\"/\")) {\n return path.slice(1);\n }\n if (!path.startsWith(base)) {\n throw new Error(\n `Path ${path} does not start with module base ${base}, this will not work down the line.`\n );\n }\n return path;\n };\n\n return (path: string) => ensureModuleBase(removeOutDir(removeRoot(path)));\n};\n"],"names":[],"mappings":";AAaa,MAAA,+BAA+B,CAC1C,UAAyC;AAAA,EACvC,MAAM,QAAQ,IAAI;AAAA,EAClB,QAAQ,CAAC,QAAQ,OAAO;AAAA,EACxB,YAAY;AAAA,EACZ,gBAAgB;AAClB,MACG;AACH,QAAM,OACJ,QAAQ,kBAAkB,QAAQ,WAAW,WAAW,GAAG,IACvD,QAAQ,WAAW,MAAM,CAAC,IAC1B,QAAQ;AACd,QAAM,eAAe,MAAM,QAAQ,QAAQ,MAAM,IAC7C,CAAC,SACE,QAAQ,OACN,IAAI,CAAC,QAAQ,KAAK,WAAW,GAAG,CAAC,EACjC,KAAK,CAAC,MAAM,CAAC,IACZ,KAAK,MAAM,QAAQ,OAAO,CAAC,EAAE,MAAM,IACnC,OACN,CAAC,SACE,QAAQ,WAAsB,OAC3B,KAAK,MAAM,QAAQ,OAAO,MAAM,IAChC;AAEJ,QAAA,aAAa,CAAC,SAAiB;AAC7B,UAAA,aAAa,cAAc,IAAI;AAC/B,UAAA,WAAW,WAAW,WAAW,QAAQ,IAAI,IAC/C,WAAW,MAAM,QAAQ,KAAK,MAAM,IACpC;AACG,WAAA;AAAA,EACT;AAEM,QAAA,mBAAmB,CAAC,SAAiB;AACzC,QAAI,QAAQ,kBAAkB,KAAK,WAAW,GAAG,GAAG;AAC3C,aAAA,KAAK,MAAM,CAAC;AAAA,IAAA;AAErB,QAAI,CAAC,KAAK,WAAW,IAAI,GAAG;AAC1B,YAAM,IAAI;AAAA,QACR,QAAQ,IAAI,oCAAoC,IAAI;AAAA,MACtD;AAAA,IAAA;AAEK,WAAA;AAAA,EACT;AAEA,SAAO,CAAC,SAAiB,iBAAiB,aAAa,WAAW,IAAI,CAAC,CAAC;AAC1E;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createPageLoader.js","sources":["../../src/html/createPageLoader.ts"],"sourcesContent":["import { resolve as resolvePath } from \"node:path\";\nimport { load } from \"react-server-dom-esm/node-loader\";\nimport {\n registerClientReference,\n registerServerReference,\n} from \"react-server-dom-esm/server.node\";\nimport { createNormalizedRelativePath } from \"../helpers/normalizedRelativePath.js\";\n\ntype CreatePageLoaderOptions = {\n manifest: Record<string, { file: string }>;\n root: string;\n outDir: string;\n moduleBase: string;\n registerServer?: string[];\n registerClient?: string[];\n alwaysRegisterServer?: boolean;\n alwaysRegisterClient?: boolean;\n};\n\ntype CreateDefaultLoaderOptions = {\n id: string;\n registerServer?: string[];\n registerClient?: string[];\n alwaysRegisterServer?: boolean;\n alwaysRegisterClient?: boolean;\n};\n\nexport const createDefaultLoader = ({\n id,\n registerServer,\n registerClient,\n alwaysRegisterServer = false,\n alwaysRegisterClient = false,\n}: CreateDefaultLoaderOptions) => {\n const mapper = ([key, value]: [string, any]) => {\n try {\n if (\n registerClient?.includes(key) ||\n (alwaysRegisterClient && typeof value === \"function\")\n ) {\n return [key, registerClientReference(value, id, key)];\n }\n if (\n registerServer?.includes(key) ||\n (alwaysRegisterServer && typeof value === \"function\")\n ) {\n return [key, registerServerReference(value, id, key)];\n }\n return [key, value];\n } catch (e) {\n console.error(\"[RSC] Error registering reference:\", key, value, e);\n return [key, value];\n }\n };\n return async (url: string) =>\n Object.fromEntries(Object.entries(await import(url)).map(mapper));\n};\n\nexport const createPageLoader = ({\n manifest,\n root,\n outDir,\n moduleBase,\n registerServer,\n registerClient,\n alwaysRegisterServer,\n alwaysRegisterClient,\n}: CreatePageLoaderOptions) => {\n const pathNormalizer = createNormalizedRelativePath({\n root,\n outDir,\n moduleBase,\n noLeadingSlash: true,\n });\n return async (id: string) => {\n const normalizedId = pathNormalizer(id);\n const entry =\n normalizedId in manifest\n ? manifest[normalizedId]\n : Object.values(manifest).find((entry) => entry.file === normalizedId);\n if (!entry) {\n throw new Error(\n `Could not find manifest entry for ${id}, ${normalizedId} from ${root}`\n );\n }\n const loaderResult = await load(\n resolvePath(root, outDir, entry.file),\n { format: \"module\" },\n createDefaultLoader({\n id,\n registerServer,\n registerClient,\n alwaysRegisterServer,\n alwaysRegisterClient,\n })\n );\n return loaderResult;\n };\n};\n"],"names":["entry","resolvePath"],"mappings":";;;;AA2BO,MAAM,sBAAsB,CAAC;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA,uBAAuB;AAAA,EACvB,uBAAuB;AACzB,MAAkC;AAChC,QAAM,SAAS,CAAC,CAAC,KAAK,KAAK,MAAqB;AAC1C,QAAA;AACF,UACE,gBAAgB,SAAS,GAAG,KAC3B,wBAAwB,OAAO,UAAU,Y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 @@
|
|
|
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,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,UAAU;AAAA,EACV,cAAc;AAAA,EACd,UAAU;AAAA,EACV,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,OAAO;AAAA,IACL,OAAO,MAAM,CAAC,GAAG;AAAA,IACjB,QAAQ;AAAA,IACR,QAAQ;AAAA,EAAA;AAEZ;AAgBO,MAAM,oBAAoB,CAC/B,WACA,OACA,QACA,WACA,gBAOO;AACP,QAAM,gBAAgB,cAAc;AAC9B,QAAA,eAAe,UAAU,YAAY;AAC3C,QAAM,gBAAgB,UAAU;AAE5B,M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;AAAA,QAAA;AAAA,MACT;AAAA,IAEV;AAAA,EAAA;AAEJ;"}
|
package/dist/plugin.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
package/dist/plugin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;"}
|
|
@@ -1 +0,0 @@
|
|
|
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":";;;;;;AAWs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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;"}
|
|
@@ -1 +0,0 @@
|
|
|
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;"}
|
package/dist/resolvePage.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolvePage.js","sources":["../src/resolvePage.ts"],"sourcesContent":["type ResolvePageOptions = {\n pageModule: Record<string, any>;\n path: string;\n url: string;\n exportName: string;\n};\n\ntype ResolvePageResult =\n | { type: \"success\"; key: string; Page: any }\n | { type: \"error\"; error: Error }\n | { type: \"skip\" };\n\nexport async function resolvePage({\n pageModule,\n path,\n url,\n exportName,\n}: ResolvePageOptions): Promise<ResolvePageResult> {\n if (!pageModule) {\n return {\n type: \"error\",\n error: new Error(`pageModule is ${typeof pageModule}`),\n };\n }\n const keys =\n typeof pageModule === \"object\" && pageModule != null\n ? Object.keys(pageModule)\n : [];\n const found = keys.find((v) => v === exportName || v === url || v === path);\n if (found) {\n if (typeof pageModule[found] === \"function\") {\n return {\n type: \"success\",\n key: found,\n Page: pageModule[found],\n };\n } else {\n if (\n typeof pageModule === \"object\" &&\n pageModule != null &&\n Object.keys(pageModule).includes(\"type\")\n )\n return pageModule as ResolvePageResult;\n return {\n type: \"error\",\n [exportName]: () => found,\n error: pageModule[found][\"error\"],\n };\n }\n }\n if (keys.includes(\"type\")) return pageModule as ResolvePageResult;\n return {\n type: \"error\",\n error: new Error(\n `Could not find Page export \"${exportName}\" in \"${path}\". ${\n typeof pageModule === \"object\" && pageModule != null\n ? keys.length\n ? \"Available exports: \" + keys.join(\", \")\n : \"The object was defined but has no properties.\"\n : \"typeof pageModule =\" + typeof pageModule\n }`,\n { cause: pageModule }\n ),\n };\n}\n"],"names":[],"mappings":"AAYA,eAAsB,YAAY;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAmD;AACjD,MAAI,CAAC,YAAY;AACR,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OAAO,IAAI,MAAM,iBAAiB,OAAO,UAAU,EAAE;AAAA,IACvD;AAAA,EAAA;AAEI,QAAA,OACJ,OAAO,eAAe,YAAY,cAAc,OAC5C,OAAO,KAAK,UAAU,IACtB,CAAC;AACD,QAAA,QAAQ,KAAK,KAAK,CAAC,MAAM,MAAM,cAAc,MAAM,OAAO,MAAM,IAAI;AAC1E,MAAI,OAAO;AACT,QAAI,OAAO,WAAW,KAAK,MAAM,YAAY;AACpC,aAAA;AAAA,QACL,MAAM;AAAA,QACN,KAAK;AAAA,QACL,MAAM,WAAW,KAAK;AAAA,MACxB;AAAA,IAAA,OACK;AAEH,UAAA,OAAO,eAAe,YACtB,cAAc,QACd,OAAO,KAAK,UAAU,EAAE,SAAS,MAAM;AAEhC,eAAA;AACF,aAAA;AAAA,QACL,MAAM;AAAA,QACN,CAAC,UAAU,GAAG,MAAM;AAAA,QACpB,OAAO,WAAW,KAAK,EAAE,OAAO;AAAA,MAClC;AAAA,IAAA;AAAA,EACF;AAEF,MAAI,KAAK,SAAS,MAAM,EAAU,QAAA;AAC3B,SAAA;AAAA,IACL,MAAM;AAAA,IACN,OAAO,IAAI;AAAA,MACT,+BAA+B,UAAU,SAAS,IAAI,MACpD,OAAO,eAAe,YAAY,cAAc,OAC5C,KAAK,SACH,wBAAwB,KAAK,KAAK,IAAI,IACtC,kDACF,wBAAwB,OAAO,UACrC;AAAA,MACA,EAAE,OAAO,WAAW;AAAA,IAAA;AAAA,EAExB;AACF;"}
|
package/dist/resolveProps.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolveProps.js","sources":["../src/resolveProps.ts"],"sourcesContent":["type ResolvePropsOptions = {\n propsModule: Record<string, any>;\n path: string;\n exportName: string;\n url: string;\n};\n\ntype ResolvePropsResult =\n | { type: \"success\"; key: string; props: any }\n | { type: \"error\"; error: Error }\n | { type: \"skip\" };\n\nfunction isFunction(value: any) {\n return typeof value === \"function\";\n}\n\nexport async function resolveProps({\n propsModule,\n path,\n exportName,\n url,\n}: ResolvePropsOptions): Promise<ResolvePropsResult> {\n if (!propsModule) {\n return {\n type: \"error\",\n error: new Error(`propsModule is ${typeof propsModule}`),\n };\n }\n\n if (typeof propsModule !== \"object\") {\n return {\n type: \"error\",\n error: new Error(\n `propsModule must be an object, got ${typeof propsModule}`\n ),\n };\n }\n\n const keys = Object.keys(propsModule);\n const found = keys.find((v) => v === exportName || v === url || v === path);\n if (found) {\n const value = propsModule[found];\n\n try {\n // If it's a function, call it with the URL\n if (isFunction(value)) {\n const props = await value(url);\n return {\n type: \"success\",\n key: found,\n props,\n };\n }\n\n // If it's a promise, await it\n if (value && typeof value.then === \"function\") {\n const props = await value;\n return {\n type: \"success\",\n key: found,\n props,\n };\n }\n\n // If it's a plain object, use it directly\n if (typeof value === \"object\" && value !== null) {\n return {\n type: \"success\",\n key: found,\n props: value,\n };\n }\n\n console.warn(found, \"error in resolveProps\", propsModule, url, path);\n return {\n type: \"error\",\n error: new Error(\n `Expected props export \"${exportName}\" in \"${path}\" to be a function, promise, or object that resolves to props, instead got typeof ${typeof value}.`\n ),\n };\n } catch (error) {\n console.warn(found, \"error in resolveProps\", propsModule, url, path);\n return {\n type: \"error\",\n error: error as Error,\n };\n }\n }\n const commonjs = keys.find((v) => v === \"exports\");\n\n if (!!commonjs) {\n const exportKeys = (commonjs as unknown as { exports: any })[\"exports\"]\n ? Object.keys((commonjs as unknown as { exports: any })[\"exports\"])\n : [];\n const foundCommonJS = exportKeys.find(\n (v) => v === exportName || v === url || v === path\n );\n return {\n type: \"error\",\n error: new Error(\n `Expected props export \"${exportName}\" in \"${path}\", but instead got \"exports\" with ${\n !!foundCommonJS\n ? foundCommonJS.toString()\n : exportKeys.length\n ? exportKeys.join(\", \")\n : \"no keys\"\n }, this will not work. Make sure to set esModule: true in rollupOptions.output`\n ),\n };\n }\n\n return {\n type: \"error\",\n error: new Error(\n `Could not find props export \"${exportName}\" in \"${path}\". ${\n keys.length\n ? \"Available exports: \" + keys.join(\", \")\n : \"The object was defined but has no properties.\"\n }`\n ),\n };\n}\n"],"names":[],"mappings":"AAYA,SAAS,WAAW,OAAY;AAC9B,SAAO,OAAO,UAAU;AAC1B;AAEA,eAAsB,aAAa;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAqD;AACnD,MAAI,CAAC,aAAa;AACT,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OAAO,IAAI,MAAM,kBAAkB,OAAO,WAAW,EAAE;AAAA,IACzD;AAAA,EAAA;AAGE,MAAA,OAAO,gBAAgB,UAAU;AAC5B,WAAA;AAAA,MACL,MAAM;AAAA,MACN,OAAO,IAAI;AAAA,QACT,sCAAsC,OAAO,WAAW;AAAA,MAAA;AAAA,IAE5D;AAAA,EAAA;AAGI,QAAA,OAAO,OAAO,KAAK,WAAW;AAC9B,QAAA,QAAQ,KAAK,KAAK,CAAC,MAAM,MAAM,cAAc,MAAM,OAAO,MAAM,IAAI;AAC1E,MAAI,OAAO;AACH,UAAA,QAAQ,YAAY,KAAK;AAE3B,QAAA;AAEE,UAAA,WAAW,KAAK,GAAG;AACf,cAAA,QAAQ,MAAM,MAAM,GAAG;AACtB,eAAA;AAAA,UACL,MAAM;AAAA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