vite-plugin-react-server 1.2.4 → 1.3.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 +18 -0
- package/dist/package.json +15 -3
- package/dist/plugin/orchestrator/createPluginOrchestrator.client.d.ts.map +1 -1
- package/dist/plugin/orchestrator/createPluginOrchestrator.client.js +3 -0
- package/dist/plugin/orchestrator/createPluginOrchestrator.server.d.ts.map +1 -1
- package/dist/plugin/orchestrator/createPluginOrchestrator.server.js +3 -0
- package/dist/plugin/utils/callServer.d.ts +1 -1
- package/dist/plugin/utils/callServer.d.ts.map +1 -1
- package/dist/plugin/utils/createCallServer.d.ts +1 -1
- package/dist/plugin/utils/createCallServer.d.ts.map +1 -1
- package/dist/plugin/utils/createReactFetcher.d.ts +2 -1
- package/dist/plugin/utils/createReactFetcher.d.ts.map +1 -1
- package/dist/plugin/utils/createReactFetcher.js +1 -1
- package/dist/plugin/vendor/vendor-alias.d.ts +12 -0
- package/dist/plugin/vendor/vendor-alias.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor-alias.js +87 -0
- package/dist/plugin/vendor/vendor.client.d.ts +1 -1
- package/dist/plugin/vendor/vendor.client.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.client.js +19 -6
- package/dist/plugin/vendor/vendor.server.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.server.js +18 -5
- package/dist/plugin/vendor/vendor.static.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.static.js +18 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/oss-experimental/react-server-dom-esm/LICENSE +21 -0
- package/oss-experimental/react-server-dom-esm/README.md +5 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2996 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.production.js +1612 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +3124 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.js +1752 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +4213 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.js +2857 -0
- package/oss-experimental/react-server-dom-esm/client.browser.js +7 -0
- package/oss-experimental/react-server-dom-esm/client.js +3 -0
- package/oss-experimental/react-server-dom-esm/client.node.js +7 -0
- package/oss-experimental/react-server-dom-esm/esm/package.json +3 -0
- package/oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +3969 -0
- package/oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.production.js +2347 -0
- package/oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-node-loader.production.js +515 -0
- package/oss-experimental/react-server-dom-esm/index.js +12 -0
- package/oss-experimental/react-server-dom-esm/package.json +63 -0
- package/oss-experimental/react-server-dom-esm/server.js +6 -0
- package/oss-experimental/react-server-dom-esm/server.node.js +17 -0
- package/oss-experimental/react-server-dom-esm/static.js +6 -0
- package/oss-experimental/react-server-dom-esm/static.node.js +12 -0
- package/package.json +15 -3
- package/plugin/orchestrator/createPluginOrchestrator.client.ts +4 -0
- package/plugin/orchestrator/createPluginOrchestrator.server.ts +4 -0
- package/plugin/types/react-server-dom-esm.d.ts +7 -2
- package/plugin/types/virtual-rsc-hmr.d.ts +14 -1
- package/plugin/utils/createReactFetcher.ts +2 -1
- package/plugin/vendor/vendor-alias.ts +102 -0
- package/plugin/vendor/vendor.client.ts +24 -9
- package/plugin/vendor/vendor.server.ts +22 -7
- package/plugin/vendor/vendor.static.ts +21 -7
- package/scripts/build-oss-experimental.sh +161 -0
- package/virtual.d.ts +20 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-react-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Vite plugin for React Server Components (RSC)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/plugin/index.js",
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"plugin",
|
|
12
12
|
"bin",
|
|
13
13
|
"scripts",
|
|
14
|
+
"virtual.d.ts",
|
|
14
15
|
"README.md",
|
|
15
16
|
"LICENSE",
|
|
16
|
-
"tsconfig.json"
|
|
17
|
+
"tsconfig.json",
|
|
18
|
+
"oss-experimental/react-server-dom-esm"
|
|
17
19
|
],
|
|
18
20
|
"exports": {
|
|
19
21
|
".": "./dist/plugin/index.js",
|
|
@@ -25,6 +27,9 @@
|
|
|
25
27
|
"./worker": "./dist/plugin/worker/index.js",
|
|
26
28
|
"./package.json": "./package.json",
|
|
27
29
|
"./patch": "./bin/patch.mjs",
|
|
30
|
+
"./virtual": {
|
|
31
|
+
"types": "./virtual.d.ts"
|
|
32
|
+
},
|
|
28
33
|
"./check-react-version": "./scripts/check-react-version.mjs",
|
|
29
34
|
"./components": "./dist/plugin/components/index.js",
|
|
30
35
|
"./types": "./dist/plugin/types.js",
|
|
@@ -149,6 +154,9 @@
|
|
|
149
154
|
],
|
|
150
155
|
"helpers/resolveStreamElements": [
|
|
151
156
|
"./dist/plugin/helpers/resolveStreamElements.d.ts"
|
|
157
|
+
],
|
|
158
|
+
"virtual": [
|
|
159
|
+
"./virtual.d.ts"
|
|
152
160
|
]
|
|
153
161
|
}
|
|
154
162
|
},
|
|
@@ -211,6 +219,8 @@
|
|
|
211
219
|
"experimental:copy": "cp -r ./oss-experimental/* ./node_modules/",
|
|
212
220
|
"experimental:patch": "npx patch-package react-server-dom-esm react react-dom --exclude 'nothing'",
|
|
213
221
|
"experimental:move-patches": "mv patches/* ./scripts/",
|
|
222
|
+
"experimental:build-oss": "bash scripts/build-oss-experimental.sh",
|
|
223
|
+
"experimental:build-oss-full": "bash scripts/build-oss-experimental.sh --full",
|
|
214
224
|
"experimental:setup": "rm -rf patches/* && npm run experimental:clean-install && npm run experimental:copy && npm run experimental:patch && npm run experimental:move-patches",
|
|
215
225
|
"experimental:patch-react": "npm run experimental:clean-install && node scripts/check-react-version.mjs && node bin/patch.mjs",
|
|
216
226
|
"postinstall": "patch-package",
|
|
@@ -241,7 +251,6 @@
|
|
|
241
251
|
"peerDependencies": {
|
|
242
252
|
"react": ">=0.0.0-experimental-0",
|
|
243
253
|
"react-dom": ">=0.0.0-experimental-0",
|
|
244
|
-
"react-server-dom-esm": "^0.0.1",
|
|
245
254
|
"vite": "*"
|
|
246
255
|
},
|
|
247
256
|
"peerDependenciesMeta": {
|
|
@@ -253,6 +262,9 @@
|
|
|
253
262
|
},
|
|
254
263
|
"vite": {
|
|
255
264
|
"optional": false
|
|
265
|
+
},
|
|
266
|
+
"react-server-dom-esm": {
|
|
267
|
+
"optional": true
|
|
256
268
|
}
|
|
257
269
|
},
|
|
258
270
|
"devDependencies": {
|
|
@@ -5,6 +5,7 @@ import { vitePluginReactDevServer } from "../dev-server/plugin.client.js";
|
|
|
5
5
|
import { reactStaticPlugin } from "../react-static/plugin.client.js";
|
|
6
6
|
import { createTransformerPlugin } from "../transformer/createTransformerPlugin.js";
|
|
7
7
|
import { virtualRscHmrPlugin } from "../dev-server/virtualRscHmrPlugin.js";
|
|
8
|
+
import { vitePluginVendorAlias } from "../vendor/vendor-alias.js";
|
|
8
9
|
|
|
9
10
|
// Client-first orchestrator - includes client SSG plugin for reverse paradigm
|
|
10
11
|
export const createPluginOrchestrator = (
|
|
@@ -15,6 +16,9 @@ export const createPluginOrchestrator = (
|
|
|
15
16
|
|
|
16
17
|
const plugins: Plugin[] = [];
|
|
17
18
|
|
|
19
|
+
// Alias react-server-dom-esm to our vendored copy
|
|
20
|
+
plugins.push(vitePluginVendorAlias());
|
|
21
|
+
|
|
18
22
|
// Virtual module for RSC HMR utilities (works in both dev and build)
|
|
19
23
|
plugins.push(virtualRscHmrPlugin());
|
|
20
24
|
|
|
@@ -5,6 +5,7 @@ import { vitePluginReactDevServer } from "../dev-server/plugin.server.js";
|
|
|
5
5
|
import { reactStaticPlugin } from "../react-static/plugin.server.js";
|
|
6
6
|
import { createTransformerPlugin } from "../transformer/createTransformerPlugin.js";
|
|
7
7
|
import { virtualRscHmrPlugin } from "../dev-server/virtualRscHmrPlugin.js";
|
|
8
|
+
import { vitePluginVendorAlias } from "../vendor/vendor-alias.js";
|
|
8
9
|
|
|
9
10
|
// Server-first orchestrator - only imports server plugins
|
|
10
11
|
export const createPluginOrchestrator = (
|
|
@@ -21,6 +22,9 @@ export const createPluginOrchestrator = (
|
|
|
21
22
|
|
|
22
23
|
const plugins: Plugin[] = [];
|
|
23
24
|
|
|
25
|
+
// Alias react-server-dom-esm to our vendored copy
|
|
26
|
+
plugins.push(vitePluginVendorAlias());
|
|
27
|
+
|
|
24
28
|
// Virtual module for RSC HMR utilities (works in both dev and build)
|
|
25
29
|
plugins.push(virtualRscHmrPlugin());
|
|
26
30
|
|
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
|
|
19
19
|
// Client-side modules (browser environment)
|
|
20
20
|
declare module 'react-server-dom-esm/client' {
|
|
21
|
-
import type { ReactNode
|
|
21
|
+
import type { ReactNode } from 'react';
|
|
22
|
+
// Usable was added in React 19 experimental — define locally to avoid
|
|
23
|
+
// type errors for consumers without react/experimental types
|
|
24
|
+
type Usable<T> = PromiseLike<T>;
|
|
22
25
|
|
|
23
26
|
export type CreateFromFetchOptions = {
|
|
24
27
|
moduleBaseURL?: string;
|
|
@@ -69,6 +72,7 @@ declare module 'react-server-dom-esm/client' {
|
|
|
69
72
|
|
|
70
73
|
declare module 'react-server-dom-esm/client.browser' {
|
|
71
74
|
import type { ReactNode } from 'react';
|
|
75
|
+
type Usable<T> = PromiseLike<T>;
|
|
72
76
|
|
|
73
77
|
// ReactDOM renderToPipeableStream options (for HTML rendering)
|
|
74
78
|
export type RenderToPipeableStreamOptions = {
|
|
@@ -352,6 +356,7 @@ declare module 'react-server-dom-esm/server.node' {
|
|
|
352
356
|
*/
|
|
353
357
|
declare module 'react-server-dom-esm/static.node' {
|
|
354
358
|
import type { ReactElement, ReactNode } from 'react';
|
|
359
|
+
type Usable<T> = PromiseLike<T>;
|
|
355
360
|
|
|
356
361
|
export type PrerenderToNodeStreamOptions = {
|
|
357
362
|
onError?: (error: unknown) => void;
|
|
@@ -367,5 +372,5 @@ declare module 'react-server-dom-esm/static.node' {
|
|
|
367
372
|
model: ReactNode,
|
|
368
373
|
moduleBasePath: string,
|
|
369
374
|
options?: PrerenderToNodeStreamOptions
|
|
370
|
-
):
|
|
375
|
+
): Usable<ReactNode>;
|
|
371
376
|
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
+
interface RscHmrData {
|
|
2
|
+
file: string;
|
|
3
|
+
path: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Augment Vite's CustomEventMap so hot.on()/hot.send() are typed
|
|
7
|
+
// See: https://vite.dev/guide/api-plugin#typescript-for-custom-events
|
|
8
|
+
declare module 'vite/types/customEvent' {
|
|
9
|
+
interface CustomEventMap {
|
|
10
|
+
'vite-plugin-react-server:server-component-update': RscHmrData;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
1
14
|
declare module 'virtual:react-server/hmr' {
|
|
2
|
-
export const RSC_HMR_EVENT:
|
|
15
|
+
export const RSC_HMR_EVENT: 'vite-plugin-react-server:server-component-update';
|
|
3
16
|
|
|
4
17
|
export interface RscHmrData {
|
|
5
18
|
file: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type React from "react";
|
|
1
2
|
import { createFromFetch } from "react-server-dom-esm/client.browser";
|
|
2
3
|
import { createCallServer } from "./createCallServer.js";
|
|
3
4
|
import { env } from "./env.js";
|
|
@@ -17,7 +18,7 @@ export function createReactFetcher({
|
|
|
17
18
|
publicOrigin?: string;
|
|
18
19
|
indexRSC?: string;
|
|
19
20
|
headers?: HeadersInit;
|
|
20
|
-
} = {}) {
|
|
21
|
+
} = {}): PromiseLike<React.ReactNode> {
|
|
21
22
|
const parsedURL = createPageURL(
|
|
22
23
|
moduleBaseURL,
|
|
23
24
|
publicOrigin,
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
|
|
7
|
+
// Find package root by walking up from current file until we find oss-experimental/
|
|
8
|
+
// Works from both plugin/vendor/ (source) and dist/plugin/vendor/ (built)
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
function findPkgRoot(): string {
|
|
11
|
+
let dir = __dirname;
|
|
12
|
+
for (let i = 0; i < 5; i++) {
|
|
13
|
+
if (existsSync(join(dir, "oss-experimental", "react-server-dom-esm"))) return dir;
|
|
14
|
+
dir = dirname(dir);
|
|
15
|
+
}
|
|
16
|
+
return dirname(dirname(__dirname)); // fallback
|
|
17
|
+
}
|
|
18
|
+
const pkgRoot = findPkgRoot();
|
|
19
|
+
const ossDir = join(pkgRoot, "oss-experimental");
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Vite plugin that aliases `react-server-dom-esm/*` imports to the vendored
|
|
23
|
+
* copy shipped with this plugin. This eliminates the need for consumers to
|
|
24
|
+
* install `react-server-dom-esm` separately or use patch-package.
|
|
25
|
+
*
|
|
26
|
+
* Browser client entries use true ESM files for Rollup tree-shaking.
|
|
27
|
+
* Server/static entries are marked external during builds — they're CJS
|
|
28
|
+
* modules loaded at runtime via createRequire in vendor.*.ts files.
|
|
29
|
+
*/
|
|
30
|
+
export function vitePluginVendorAlias(): Plugin {
|
|
31
|
+
let isBuild = false;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
name: "vite-plugin-react-server:vendor-alias",
|
|
35
|
+
enforce: "pre",
|
|
36
|
+
|
|
37
|
+
config(_config, env) {
|
|
38
|
+
const pkg = join(ossDir, "react-server-dom-esm");
|
|
39
|
+
const isProd = env.mode === "production";
|
|
40
|
+
|
|
41
|
+
// Only alias browser client to ESM for Rollup tree-shaking.
|
|
42
|
+
// Server/static are handled by resolveId with external:true.
|
|
43
|
+
return {
|
|
44
|
+
resolve: {
|
|
45
|
+
alias: [
|
|
46
|
+
{
|
|
47
|
+
find: "react-server-dom-esm/client.browser",
|
|
48
|
+
replacement: join(pkg, "esm", isProd
|
|
49
|
+
? "react-server-dom-esm-client.browser.production.js"
|
|
50
|
+
: "react-server-dom-esm-client.browser.development.js")
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
configResolved(config) {
|
|
58
|
+
isBuild = config.command === "build";
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
resolveId(source) {
|
|
62
|
+
// Only handle react-server-dom-esm specifiers (not already aliased paths)
|
|
63
|
+
if (!source.startsWith("react-server-dom-esm")) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Skip client.browser — handled by config alias above
|
|
68
|
+
if (source === "react-server-dom-esm/client.browser") {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// For server/static entries during build: mark external with resolved path.
|
|
73
|
+
// At runtime, vendor.*.ts uses createRequire to load from this path.
|
|
74
|
+
if (isBuild && isServerEntry(source)) {
|
|
75
|
+
const resolved = resolveVendored(source);
|
|
76
|
+
return { id: resolved, external: true };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// For all other entries (client.node, client, index), resolve to vendored path
|
|
80
|
+
return resolveVendored(source);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function isServerEntry(source: string): boolean {
|
|
86
|
+
return (
|
|
87
|
+
source.includes("/server") ||
|
|
88
|
+
source.includes("/static")
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function resolveVendored(source: string): string {
|
|
93
|
+
const vendorRequire = createRequire(
|
|
94
|
+
join(ossDir, "react-server-dom-esm", "package.json")
|
|
95
|
+
);
|
|
96
|
+
try {
|
|
97
|
+
return vendorRequire.resolve(source);
|
|
98
|
+
} catch {
|
|
99
|
+
const subpath = source.replace("react-server-dom-esm", "");
|
|
100
|
+
return join(ossDir, "react-server-dom-esm", subpath || "index.js");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { join } from "node:path";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
3
5
|
import { assertNonReactServer } from "../config/getCondition.js";
|
|
4
6
|
|
|
5
7
|
assertNonReactServer();
|
|
6
8
|
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
function findPkgRoot(): string {
|
|
11
|
+
let dir = __dirname;
|
|
12
|
+
for (let i = 0; i < 5; i++) {
|
|
13
|
+
if (existsSync(join(dir, "oss-experimental", "react-server-dom-esm"))) return dir;
|
|
14
|
+
dir = dirname(dir);
|
|
15
|
+
}
|
|
16
|
+
return dirname(dirname(__dirname));
|
|
17
|
+
}
|
|
18
|
+
const ossDir = join(findPkgRoot(), "oss-experimental");
|
|
19
|
+
|
|
20
|
+
// Resolve react-server-dom-esm from our vendored copy
|
|
21
|
+
const vendorRequire = createRequire(join(ossDir, "react-server-dom-esm", "package.json"));
|
|
22
|
+
const ReactDOMClient = vendorRequire("react-server-dom-esm/client.node") as typeof import("react-server-dom-esm/client.node");
|
|
23
|
+
|
|
24
|
+
// React and react-dom still come from the consumer's project
|
|
7
25
|
const projectRoot = process.env["npm_config_local_prefix"] || process.cwd();
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const React = nodeRequire("react") as typeof import("react");
|
|
14
|
-
|
|
15
|
-
export { ReactDOMServer, React, ReactDOMClient };
|
|
26
|
+
const projectRequire = createRequire(join(projectRoot, "package.json"));
|
|
27
|
+
const ReactDOMServer = projectRequire("react-dom/server") as typeof import("react-dom/server");
|
|
28
|
+
const React = projectRequire("react") as typeof import("react");
|
|
29
|
+
|
|
30
|
+
export { ReactDOMServer, React, ReactDOMClient };
|
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { join } from "node:path";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
3
5
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
function findPkgRoot(): string {
|
|
8
|
+
let dir = __dirname;
|
|
9
|
+
for (let i = 0; i < 5; i++) {
|
|
10
|
+
if (existsSync(join(dir, "oss-experimental", "react-server-dom-esm"))) return dir;
|
|
11
|
+
dir = dirname(dir);
|
|
12
|
+
}
|
|
13
|
+
return dirname(dirname(__dirname));
|
|
14
|
+
}
|
|
15
|
+
const ossDir = join(findPkgRoot(), "oss-experimental");
|
|
16
|
+
|
|
17
|
+
// Resolve react-server-dom-esm from our vendored copy
|
|
18
|
+
const vendorRequire = createRequire(join(ossDir, "react-server-dom-esm", "package.json"));
|
|
19
|
+
const ReactDOMServer = vendorRequire("react-server-dom-esm/server.node") as typeof import("react-server-dom-esm/server.node");
|
|
6
20
|
|
|
7
|
-
//
|
|
8
|
-
const
|
|
9
|
-
const
|
|
21
|
+
// React still comes from the consumer's project
|
|
22
|
+
const projectRoot = process.env["npm_config_local_prefix"] || process.cwd();
|
|
23
|
+
const projectRequire = createRequire(join(projectRoot, "package.json"));
|
|
24
|
+
const React = projectRequire("react") as typeof import("react");
|
|
10
25
|
|
|
11
26
|
export { ReactDOMServer, React };
|
|
12
27
|
export type * from "react-server-dom-esm/server.node";
|
|
13
|
-
export type React = typeof import("react");
|
|
28
|
+
export type React = typeof import("react");
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { join } from "node:path";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
3
5
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
function findPkgRoot(): string {
|
|
8
|
+
let dir = __dirname;
|
|
9
|
+
for (let i = 0; i < 5; i++) {
|
|
10
|
+
if (existsSync(join(dir, "oss-experimental", "react-server-dom-esm"))) return dir;
|
|
11
|
+
dir = dirname(dir);
|
|
12
|
+
}
|
|
13
|
+
return dirname(dirname(__dirname));
|
|
14
|
+
}
|
|
15
|
+
const ossDir = join(findPkgRoot(), "oss-experimental");
|
|
16
|
+
|
|
17
|
+
// Resolve react-server-dom-esm from our vendored copy
|
|
18
|
+
const vendorRequire = createRequire(join(ossDir, "react-server-dom-esm", "package.json"));
|
|
19
|
+
const ReactDOMServer = vendorRequire("react-server-dom-esm/static.node") as typeof import("react-server-dom-esm/static.node");
|
|
6
20
|
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const React =
|
|
21
|
+
// React still comes from the consumer's project
|
|
22
|
+
const projectRoot = process.env["npm_config_local_prefix"] || process.cwd();
|
|
23
|
+
const projectRequire = createRequire(join(projectRoot, "package.json"));
|
|
24
|
+
const React = projectRequire("react") as typeof import("react");
|
|
11
25
|
|
|
12
26
|
export { ReactDOMServer, React };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
# Build react-server-dom-esm from React source for the oss-experimental/ folder.
|
|
5
|
+
#
|
|
6
|
+
# Usage:
|
|
7
|
+
# ./scripts/build-oss-experimental.sh [--react-dir PATH] [--full]
|
|
8
|
+
#
|
|
9
|
+
# Prerequisites:
|
|
10
|
+
# - yarn (React repo uses yarn workspaces)
|
|
11
|
+
# - Node.js 18+
|
|
12
|
+
# - java (for Google Closure Compiler, used by React's build)
|
|
13
|
+
#
|
|
14
|
+
# This script:
|
|
15
|
+
# 1. Clones facebook/react into ../react (or uses existing checkout)
|
|
16
|
+
# 2. Installs dependencies with yarn
|
|
17
|
+
# 3. Builds react-server-dom-esm (targeted) or full experimental channel
|
|
18
|
+
# 4. Runs packaging to create the publishable output
|
|
19
|
+
# 5. Copies results into oss-experimental/
|
|
20
|
+
|
|
21
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
22
|
+
PLUGIN_DIR="$(dirname "$SCRIPT_DIR")"
|
|
23
|
+
REACT_DIR="${REACT_DIR:-$(dirname "$PLUGIN_DIR")/react}"
|
|
24
|
+
OSS_DIR="$PLUGIN_DIR/oss-experimental"
|
|
25
|
+
FULL_BUILD=false
|
|
26
|
+
|
|
27
|
+
# Parse args
|
|
28
|
+
while [[ $# -gt 0 ]]; do
|
|
29
|
+
case "$1" in
|
|
30
|
+
--react-dir) REACT_DIR="$2"; shift 2 ;;
|
|
31
|
+
--full) FULL_BUILD=true; shift ;;
|
|
32
|
+
--help|-h)
|
|
33
|
+
echo "Usage: $0 [--react-dir PATH] [--full]"
|
|
34
|
+
echo ""
|
|
35
|
+
echo "Build react-server-dom-esm from React source."
|
|
36
|
+
echo ""
|
|
37
|
+
echo "Options:"
|
|
38
|
+
echo " --react-dir PATH Path to React checkout (default: ../react)"
|
|
39
|
+
echo " --full Build ALL packages (slow, ~15 min)"
|
|
40
|
+
echo " Default: targeted build of react-server-dom-esm only (~2 min)"
|
|
41
|
+
exit 0
|
|
42
|
+
;;
|
|
43
|
+
*) echo "Unknown option: $1"; exit 1 ;;
|
|
44
|
+
esac
|
|
45
|
+
done
|
|
46
|
+
|
|
47
|
+
echo "Plugin dir: $PLUGIN_DIR"
|
|
48
|
+
echo "React dir: $REACT_DIR"
|
|
49
|
+
echo "Output dir: $OSS_DIR"
|
|
50
|
+
echo "Full build: $FULL_BUILD"
|
|
51
|
+
echo ""
|
|
52
|
+
|
|
53
|
+
# Step 1: Clone or update React
|
|
54
|
+
if [ ! -d "$REACT_DIR" ]; then
|
|
55
|
+
echo "==> Cloning facebook/react (shallow)..."
|
|
56
|
+
git clone --depth 1 https://github.com/facebook/react.git "$REACT_DIR"
|
|
57
|
+
else
|
|
58
|
+
echo "==> Using existing React checkout at $REACT_DIR"
|
|
59
|
+
echo " Branch: $(cd "$REACT_DIR" && git branch --show-current 2>/dev/null || echo 'detached')"
|
|
60
|
+
echo " Commit: $(cd "$REACT_DIR" && git rev-parse --short HEAD)"
|
|
61
|
+
echo ""
|
|
62
|
+
read -p " Pull latest? [y/N] " -n 1 -r
|
|
63
|
+
echo
|
|
64
|
+
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
65
|
+
(cd "$REACT_DIR" && git pull)
|
|
66
|
+
fi
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
# Step 2: Install dependencies
|
|
70
|
+
echo ""
|
|
71
|
+
echo "==> Installing React dependencies (yarn)..."
|
|
72
|
+
cd "$REACT_DIR"
|
|
73
|
+
|
|
74
|
+
if ! command -v yarn &>/dev/null; then
|
|
75
|
+
echo "ERROR: yarn is required but not installed."
|
|
76
|
+
echo "Install with: npm install -g yarn"
|
|
77
|
+
exit 1
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
yarn install --frozen-lockfile 2>&1 | tail -5
|
|
81
|
+
|
|
82
|
+
# Step 3: Build
|
|
83
|
+
echo ""
|
|
84
|
+
if [ "$FULL_BUILD" = true ]; then
|
|
85
|
+
echo "==> Building full React experimental channel (this takes ~15 min)..."
|
|
86
|
+
RELEASE_CHANNEL=experimental node scripts/rollup/build-all-release-channels.js \
|
|
87
|
+
--releaseChannel experimental 2>&1 | tail -20
|
|
88
|
+
else
|
|
89
|
+
echo "==> Building react-server-dom-esm (targeted, ~2 min)..."
|
|
90
|
+
echo " (Use --full to build all packages)"
|
|
91
|
+
echo ""
|
|
92
|
+
|
|
93
|
+
# React's build.js accepts bundle names as positional args to filter.
|
|
94
|
+
# We need react-server-dom-esm but it imports from shared React internals,
|
|
95
|
+
# so we also need to build the core 'react' package first.
|
|
96
|
+
#
|
|
97
|
+
# RELEASE_CHANNEL=experimental ensures __EXPERIMENTAL__ is true.
|
|
98
|
+
RELEASE_CHANNEL=experimental node scripts/rollup/build.js \
|
|
99
|
+
react react-server-dom-esm 2>&1 | tail -30
|
|
100
|
+
|
|
101
|
+
# Run packaging step to create the final publishable package structure
|
|
102
|
+
# (copies files into build/oss-experimental/)
|
|
103
|
+
echo ""
|
|
104
|
+
echo "==> Running packaging..."
|
|
105
|
+
RELEASE_CHANNEL=experimental node scripts/rollup/build-all-release-channels.js \
|
|
106
|
+
--releaseChannel experimental --unsafe-partial 2>&1 | tail -20
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
# Step 4: Copy to oss-experimental/
|
|
110
|
+
echo ""
|
|
111
|
+
echo "==> Copying packages to oss-experimental/..."
|
|
112
|
+
|
|
113
|
+
BUILD_BASE="$REACT_DIR/build/oss-experimental"
|
|
114
|
+
|
|
115
|
+
if [ ! -d "$BUILD_BASE" ]; then
|
|
116
|
+
echo "ERROR: Build output not found at $BUILD_BASE"
|
|
117
|
+
echo ""
|
|
118
|
+
echo "If the targeted build didn't create the packaging output,"
|
|
119
|
+
echo "try running with --full flag."
|
|
120
|
+
exit 1
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
mkdir -p "$OSS_DIR"
|
|
124
|
+
|
|
125
|
+
# Always copy react-server-dom-esm (the one we need)
|
|
126
|
+
for pkg in react-server-dom-esm react react-dom; do
|
|
127
|
+
BUILD_PKG="$BUILD_BASE/$pkg"
|
|
128
|
+
if [ -d "$BUILD_PKG" ]; then
|
|
129
|
+
rm -rf "$OSS_DIR/$pkg"
|
|
130
|
+
cp -r "$BUILD_PKG" "$OSS_DIR/$pkg"
|
|
131
|
+
echo " ✓ $pkg"
|
|
132
|
+
else
|
|
133
|
+
echo " ✗ $pkg (not found in build output)"
|
|
134
|
+
fi
|
|
135
|
+
done
|
|
136
|
+
|
|
137
|
+
# If full build, copy everything
|
|
138
|
+
if [ "$FULL_BUILD" = true ]; then
|
|
139
|
+
for pkg in "$BUILD_BASE"/*/; do
|
|
140
|
+
pkg_name=$(basename "$pkg")
|
|
141
|
+
if [[ "$pkg_name" != "react" && "$pkg_name" != "react-dom" && "$pkg_name" != "react-server-dom-esm" ]]; then
|
|
142
|
+
rm -rf "$OSS_DIR/$pkg_name"
|
|
143
|
+
cp -r "$pkg" "$OSS_DIR/$pkg_name"
|
|
144
|
+
echo " ✓ $pkg_name"
|
|
145
|
+
fi
|
|
146
|
+
done
|
|
147
|
+
fi
|
|
148
|
+
|
|
149
|
+
# Report version
|
|
150
|
+
VERSION=$(python3 -c "import json; print(json.load(open('$OSS_DIR/react-server-dom-esm/package.json'))['version'])" 2>/dev/null || echo "unknown")
|
|
151
|
+
echo ""
|
|
152
|
+
echo "==> Done! react-server-dom-esm version: $VERSION"
|
|
153
|
+
echo " Output: $OSS_DIR/"
|
|
154
|
+
echo ""
|
|
155
|
+
echo "Next steps:"
|
|
156
|
+
echo " 1. Update TEMPLATE_VERSION in bin/patch.mjs to:"
|
|
157
|
+
echo " $VERSION"
|
|
158
|
+
echo " 2. Regenerate patches:"
|
|
159
|
+
echo " npm run experimental:setup"
|
|
160
|
+
echo " 3. Test:"
|
|
161
|
+
echo " npm run experimental:patch-react"
|
package/virtual.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference path="./plugin/types/virtual-rsc-hmr.d.ts" />
|
|
2
|
+
|
|
3
|
+
// Type declarations for virtual modules and custom events provided by vite-plugin-react-server.
|
|
4
|
+
//
|
|
5
|
+
// To enable, add to your tsconfig.json:
|
|
6
|
+
// "types": ["vite/client", "vite-plugin-react-server/virtual"]
|
|
7
|
+
//
|
|
8
|
+
// This provides:
|
|
9
|
+
// - Type support for `virtual:react-server/hmr` (useRscHmr, setupRscHmr)
|
|
10
|
+
// - Typed custom HMR event: `vite-plugin-react-server:server-component-update`
|
|
11
|
+
// (augments Vite's CustomEventMap for import.meta.hot.on() / hot.send())
|
|
12
|
+
// - ImportMetaEnv augmentation for PUBLIC_ORIGIN
|
|
13
|
+
|
|
14
|
+
declare global {
|
|
15
|
+
interface ImportMetaEnv {
|
|
16
|
+
readonly PUBLIC_ORIGIN: string;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export {};
|