vite-plugin-react-server 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -2
- package/dist/plugin/vendor/register-vendor.d.ts +2 -0
- package/dist/plugin/vendor/register-vendor.d.ts.map +1 -0
- package/dist/plugin/vendor/register-vendor.js +50 -0
- package/dist/plugin/vendor/vendor-alias.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor-alias.js +18 -8
- package/dist/plugin/vendor/vendor.client.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.client.js +2 -2
- package/dist/plugin/vendor/vendor.server.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.server.js +2 -2
- package/dist/plugin/vendor/vendor.static.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.static.js +2 -2
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +5 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-server.js +13 -0
- package/oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-server.node.js +13 -0
- package/package.json +1 -2
- package/plugin/vendor/register-vendor.ts +51 -0
- package/plugin/vendor/vendor-alias.ts +19 -9
- package/plugin/vendor/vendor.client.ts +2 -2
- package/plugin/vendor/vendor.server.ts +3 -2
- package/plugin/vendor/vendor.static.ts +2 -2
- package/plugin/worker/createWorker.ts +4 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import mod from "../server.node.js";
|
|
2
|
+
export const {
|
|
3
|
+
createTemporaryReferenceSet,
|
|
4
|
+
decodeAction,
|
|
5
|
+
decodeFormState,
|
|
6
|
+
decodeReply,
|
|
7
|
+
decodeReplyFromBusboy,
|
|
8
|
+
registerClientReference,
|
|
9
|
+
registerServerReference,
|
|
10
|
+
renderToPipeableStream,
|
|
11
|
+
unstable_prerenderToNodeStream,
|
|
12
|
+
} = mod;
|
|
13
|
+
export default mod;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import mod from "../server.node.js";
|
|
2
|
+
export const {
|
|
3
|
+
createTemporaryReferenceSet,
|
|
4
|
+
decodeAction,
|
|
5
|
+
decodeFormState,
|
|
6
|
+
decodeReply,
|
|
7
|
+
decodeReplyFromBusboy,
|
|
8
|
+
registerClientReference,
|
|
9
|
+
registerServerReference,
|
|
10
|
+
renderToPipeableStream,
|
|
11
|
+
unstable_prerenderToNodeStream,
|
|
12
|
+
} = mod;
|
|
13
|
+
export default mod;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-react-server",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Vite plugin for React Server Components (RSC)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/plugin/index.js",
|
|
@@ -223,7 +223,6 @@
|
|
|
223
223
|
"experimental:build-oss-full": "bash scripts/build-oss-experimental.sh --full",
|
|
224
224
|
"experimental:setup": "rm -rf patches/* && npm run experimental:clean-install && npm run experimental:copy && npm run experimental:patch && npm run experimental:move-patches",
|
|
225
225
|
"experimental:patch-react": "npm run experimental:clean-install && node scripts/check-react-version.mjs && node bin/patch.mjs",
|
|
226
|
-
"postinstall": "patch-package",
|
|
227
226
|
"test-parse": "node -e \"const acorn = require('acorn'); const ast = acorn.parse('export async function test() {}', { sourceType: 'module', ecmaVersion: 'latest' }); console.log(JSON.stringify(ast, null, 2));\"",
|
|
228
227
|
"precoverage": "npm run build",
|
|
229
228
|
"coverage": "npm run test:coverage"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js module resolution hook that redirects `react-server-dom-esm/*`
|
|
3
|
+
* to the vendored copy at runtime. Used by the RSC worker via --import.
|
|
4
|
+
*
|
|
5
|
+
* Server entries use ESM wrappers (in esm/) that re-export from CJS
|
|
6
|
+
* so Node's ESM loader can provide named exports.
|
|
7
|
+
*/
|
|
8
|
+
import { register } from "node:module";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { existsSync } from "node:fs";
|
|
12
|
+
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
function findPkgRoot(): string {
|
|
15
|
+
let dir = __dirname;
|
|
16
|
+
for (let i = 0; i < 5; i++) {
|
|
17
|
+
if (existsSync(join(dir, "oss-experimental", "react-server-dom-esm"))) return dir;
|
|
18
|
+
dir = dirname(dir);
|
|
19
|
+
}
|
|
20
|
+
return dirname(dirname(__dirname));
|
|
21
|
+
}
|
|
22
|
+
const ossDir = join(findPkgRoot(), "oss-experimental", "react-server-dom-esm");
|
|
23
|
+
|
|
24
|
+
register("data:text/javascript," + encodeURIComponent(`
|
|
25
|
+
const ossDir = ${JSON.stringify(ossDir)};
|
|
26
|
+
const { join } = await import("node:path");
|
|
27
|
+
const { pathToFileURL } = await import("node:url");
|
|
28
|
+
|
|
29
|
+
// Map bare specifiers to vendored files. Server entries use ESM wrappers
|
|
30
|
+
// that re-export from CJS for proper named export support.
|
|
31
|
+
const subpathMap = {
|
|
32
|
+
"react-server-dom-esm": join(ossDir, "index.js"),
|
|
33
|
+
"react-server-dom-esm/client": join(ossDir, "client.js"),
|
|
34
|
+
"react-server-dom-esm/client.browser": join(ossDir, "esm", "react-server-dom-esm-client.browser.production.js"),
|
|
35
|
+
"react-server-dom-esm/client.node": join(ossDir, "client.node.js"),
|
|
36
|
+
"react-server-dom-esm/server": join(ossDir, "esm", "react-server-dom-esm-server.node.js"),
|
|
37
|
+
"react-server-dom-esm/server.node": join(ossDir, "esm", "react-server-dom-esm-server.node.js"),
|
|
38
|
+
"react-server-dom-esm/static": join(ossDir, "static.js"),
|
|
39
|
+
"react-server-dom-esm/static.node": join(ossDir, "static.node.js"),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
43
|
+
if (specifier in subpathMap) {
|
|
44
|
+
return {
|
|
45
|
+
shortCircuit: true,
|
|
46
|
+
url: pathToFileURL(subpathMap[specifier]).href,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return nextResolve(specifier, context);
|
|
50
|
+
}
|
|
51
|
+
`), import.meta.url);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
2
|
import { dirname, join } from "node:path";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
5
4
|
import { existsSync } from "node:fs";
|
|
@@ -89,14 +88,25 @@ function isServerEntry(source: string): boolean {
|
|
|
89
88
|
);
|
|
90
89
|
}
|
|
91
90
|
|
|
91
|
+
// Explicit subpath → file mapping. Server entries always resolve to .node
|
|
92
|
+
// variants to bypass the react-server condition guard in server.js.
|
|
93
|
+
const subpathMap: Record<string, string> = {
|
|
94
|
+
"react-server-dom-esm": "index.js",
|
|
95
|
+
"react-server-dom-esm/client": "client.js",
|
|
96
|
+
"react-server-dom-esm/client.browser": "client.browser.js",
|
|
97
|
+
"react-server-dom-esm/client.node": "client.node.js",
|
|
98
|
+
"react-server-dom-esm/server": "server.node.js",
|
|
99
|
+
"react-server-dom-esm/server.node": "server.node.js",
|
|
100
|
+
"react-server-dom-esm/static": "static.node.js",
|
|
101
|
+
"react-server-dom-esm/static.node": "static.node.js",
|
|
102
|
+
};
|
|
103
|
+
|
|
92
104
|
function resolveVendored(source: string): string {
|
|
93
|
-
const
|
|
94
|
-
|
|
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");
|
|
105
|
+
const file = subpathMap[source];
|
|
106
|
+
if (file) {
|
|
107
|
+
return join(ossDir, "react-server-dom-esm", file);
|
|
101
108
|
}
|
|
109
|
+
// Fallback for unknown subpaths
|
|
110
|
+
const subpath = source.replace("react-server-dom-esm", "");
|
|
111
|
+
return join(ossDir, "react-server-dom-esm", subpath || "index.js");
|
|
102
112
|
}
|
|
@@ -17,9 +17,9 @@ function findPkgRoot(): string {
|
|
|
17
17
|
}
|
|
18
18
|
const ossDir = join(findPkgRoot(), "oss-experimental");
|
|
19
19
|
|
|
20
|
-
//
|
|
20
|
+
// Load react-server-dom-esm/client.node directly from vendored copy
|
|
21
21
|
const vendorRequire = createRequire(join(ossDir, "react-server-dom-esm", "package.json"));
|
|
22
|
-
const ReactDOMClient = vendorRequire("react-server-dom-esm
|
|
22
|
+
const ReactDOMClient = vendorRequire(join(ossDir, "react-server-dom-esm", "client.node.js")) as typeof import("react-server-dom-esm/client.node");
|
|
23
23
|
|
|
24
24
|
// React and react-dom still come from the consumer's project
|
|
25
25
|
const projectRoot = process.env["npm_config_local_prefix"] || process.cwd();
|
|
@@ -14,9 +14,10 @@ function findPkgRoot(): string {
|
|
|
14
14
|
}
|
|
15
15
|
const ossDir = join(findPkgRoot(), "oss-experimental");
|
|
16
16
|
|
|
17
|
-
//
|
|
17
|
+
// Load react-server-dom-esm/server.node directly from vendored copy
|
|
18
|
+
// Use server.node.js (not server.js which is a react-server condition guard)
|
|
18
19
|
const vendorRequire = createRequire(join(ossDir, "react-server-dom-esm", "package.json"));
|
|
19
|
-
const ReactDOMServer = vendorRequire("react-server-dom-esm
|
|
20
|
+
const ReactDOMServer = vendorRequire(join(ossDir, "react-server-dom-esm", "server.node.js")) as typeof import("react-server-dom-esm/server.node");
|
|
20
21
|
|
|
21
22
|
// React still comes from the consumer's project
|
|
22
23
|
const projectRoot = process.env["npm_config_local_prefix"] || process.cwd();
|
|
@@ -14,9 +14,9 @@ function findPkgRoot(): string {
|
|
|
14
14
|
}
|
|
15
15
|
const ossDir = join(findPkgRoot(), "oss-experimental");
|
|
16
16
|
|
|
17
|
-
//
|
|
17
|
+
// Load react-server-dom-esm/static.node directly from vendored copy
|
|
18
18
|
const vendorRequire = createRequire(join(ossDir, "react-server-dom-esm", "package.json"));
|
|
19
|
-
const ReactDOMServer = vendorRequire("react-server-dom-esm
|
|
19
|
+
const ReactDOMServer = vendorRequire(join(ossDir, "react-server-dom-esm", "static.node.js")) as typeof import("react-server-dom-esm/static.node");
|
|
20
20
|
|
|
21
21
|
// React still comes from the consumer's project
|
|
22
22
|
const projectRoot = process.env["npm_config_local_prefix"] || process.cwd();
|
|
@@ -255,10 +255,14 @@ Current condition: ${currentCondition}, Reverse condition: ${reverseCondition}`
|
|
|
255
255
|
}
|
|
256
256
|
return out;
|
|
257
257
|
};
|
|
258
|
+
// Register vendor resolution hook so the worker can find react-server-dom-esm
|
|
259
|
+
const vendorRegisterPath = new URL("../vendor/register-vendor.js", import.meta.url).href;
|
|
258
260
|
const computedExecArgv = [
|
|
259
261
|
...stripConditionsFromArgv(process.execArgv || []),
|
|
260
262
|
"--conditions",
|
|
261
263
|
reverseCondition,
|
|
264
|
+
"--import",
|
|
265
|
+
vendorRegisterPath,
|
|
262
266
|
];
|
|
263
267
|
|
|
264
268
|
// Always log the condition setup for debugging
|