@vitejs/plugin-rsc 0.4.31 → 0.4.33
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/{cjs-WQBk0zA_.js → cjs-BamOAUgw.js} +17 -11
- package/dist/{encryption-runtime-CugTJCLM.js → encryption-runtime-DT6dtlC5.js} +2 -5
- package/dist/extra/rsc.js +4 -6
- package/dist/extra/ssr.js +3 -3
- package/dist/{index-DWN3vCIQ.d.ts → index-B04iFwO5.d.ts} +3 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/{plugin-BI8kK-GE.js → plugin-BDLEZ1UW.js} +36 -54
- package/dist/{plugin-Cfy_9VpM.d.ts → plugin-DCLI7Wh8.d.ts} +1 -1
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.js +4 -4
- package/dist/plugins/cjs.js +2 -2
- package/dist/rsc-html-stream/ssr.js +1 -1
- package/dist/rsc.js +1 -1
- package/dist/{server-BTo03tXh.js → server-DMhFuTz_.js} +1 -2
- package/dist/{shared-AvKUASD5.js → shared-n-ykEs15.js} +1 -2
- package/dist/{ssr-8BA2nj0-.js → ssr-BQwZitKq.js} +11 -15
- package/dist/ssr.js +2 -2
- package/dist/transforms/index.d.ts +2 -2
- package/dist/transforms/index.js +2 -2
- package/dist/{transforms-D1-2JfCh.js → transforms-CpF3zNE0.js} +20 -7
- package/dist/utils/encryption-runtime.js +1 -1
- package/package.json +9 -8
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createDebug } from "./dist-DiJnRA1C.js";
|
|
2
|
-
import { parseIdQuery } from "./shared-
|
|
2
|
+
import { parseIdQuery } from "./shared-n-ykEs15.js";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
6
|
import * as esModuleLexer from "es-module-lexer";
|
|
6
7
|
import MagicString from "magic-string";
|
|
7
8
|
import { parseAstAsync } from "vite";
|
|
@@ -10,7 +11,8 @@ import { walk } from "estree-walker";
|
|
|
10
11
|
import { analyze } from "periscopic";
|
|
11
12
|
|
|
12
13
|
//#region src/transforms/cjs.ts
|
|
13
|
-
function
|
|
14
|
+
const CJS_INTEROP_HELPER = `function __cjs_interop__(m) { return m.__cjs_module_runner_transform ? m.default : m; }`;
|
|
15
|
+
function transformCjsToEsm(code, ast, options) {
|
|
14
16
|
const output = new MagicString(code);
|
|
15
17
|
const analyzed = analyze(ast);
|
|
16
18
|
const parentNodes = [];
|
|
@@ -27,12 +29,12 @@ function transformCjsToEsm(code, ast) {
|
|
|
27
29
|
if (scope && scope.declarations.has("require")) return;
|
|
28
30
|
}
|
|
29
31
|
if (isTopLevel) {
|
|
30
|
-
output.update(node.start, node.callee.end, "((await import");
|
|
31
|
-
output.appendRight(node.end, ")
|
|
32
|
+
output.update(node.start, node.callee.end, "(__cjs_interop__(await import");
|
|
33
|
+
output.appendRight(node.end, "))");
|
|
32
34
|
} else {
|
|
33
35
|
const hoisted = `__cjs_to_esm_hoist_${hoistIndex}`;
|
|
34
36
|
const importee = code.slice(node.arguments[0].start, node.arguments[0].end);
|
|
35
|
-
hoistedCodes.push(`const ${hoisted} = (await import(${importee}))
|
|
37
|
+
hoistedCodes.push(`const ${hoisted} = __cjs_interop__(await import(${importee}));\n`);
|
|
36
38
|
output.update(node.start, node.end, hoisted);
|
|
37
39
|
hoistIndex++;
|
|
38
40
|
}
|
|
@@ -43,7 +45,16 @@ function transformCjsToEsm(code, ast) {
|
|
|
43
45
|
}
|
|
44
46
|
});
|
|
45
47
|
for (const hoisted of hoistedCodes.reverse()) output.prepend(hoisted);
|
|
48
|
+
if (output.hasChanged()) output.prepend(`${CJS_INTEROP_HELPER}\n`);
|
|
46
49
|
output.prepend(`let exports = {}; const module = { exports };\n`);
|
|
50
|
+
const __filename = fileURLToPath(pathToFileURL(options.id).href);
|
|
51
|
+
const __dirname = path.dirname(__filename);
|
|
52
|
+
output.prepend(`let __filename = ${JSON.stringify(__filename)}; let __dirname = ${JSON.stringify(__dirname)};\n`);
|
|
53
|
+
output.append(`
|
|
54
|
+
;__vite_ssr_exportAll__(module.exports);
|
|
55
|
+
export default module.exports;
|
|
56
|
+
export const __cjs_module_runner_transform = true;
|
|
57
|
+
`);
|
|
47
58
|
return { output };
|
|
48
59
|
}
|
|
49
60
|
|
|
@@ -74,12 +85,7 @@ function cjsModuleRunnerPlugin() {
|
|
|
74
85
|
debug(`non-optimized CJS dependency in '${this.environment.name}' environment: ${id}`);
|
|
75
86
|
warnedPackages.add(packageKey);
|
|
76
87
|
}
|
|
77
|
-
const
|
|
78
|
-
const output = transformCjsToEsm(code, ast).output;
|
|
79
|
-
output.append(`
|
|
80
|
-
;__vite_ssr_exportAll__(module.exports);
|
|
81
|
-
export default module.exports;
|
|
82
|
-
`);
|
|
88
|
+
const output = transformCjsToEsm(code, await parseAstAsync(code), { id }).output;
|
|
83
89
|
return {
|
|
84
90
|
code: output.toString(),
|
|
85
91
|
map: output.generateMap({ hires: "boundary" })
|
|
@@ -5,14 +5,11 @@ import encryptionKeySource from "virtual:vite-rsc/encryption-key";
|
|
|
5
5
|
|
|
6
6
|
//#region src/utils/encryption-runtime.ts
|
|
7
7
|
async function encryptActionBoundArgs(originalValue) {
|
|
8
|
-
|
|
9
|
-
const serializedBuffer = await concatArrayStream(serialized);
|
|
10
|
-
return encryptBuffer(serializedBuffer, await getEncryptionKey());
|
|
8
|
+
return encryptBuffer(await concatArrayStream(renderToReadableStream(originalValue)), await getEncryptionKey());
|
|
11
9
|
}
|
|
12
10
|
async function decryptActionBoundArgs(encrypted) {
|
|
13
11
|
const serializedBuffer = await decryptBuffer(await encrypted, await getEncryptionKey());
|
|
14
|
-
|
|
15
|
-
return createFromReadableStream(serialized);
|
|
12
|
+
return createFromReadableStream(arrayToStream(new Uint8Array(serializedBuffer)));
|
|
16
13
|
}
|
|
17
14
|
const getEncryptionKey = /* @__PURE__ */ once(async () => {
|
|
18
15
|
const resolved = await encryptionKeySource();
|
package/dist/extra/rsc.js
CHANGED
|
@@ -3,7 +3,7 @@ import "../shared-CXg_u-4h.js";
|
|
|
3
3
|
import "../encryption-utils-BDwwcMVT.js";
|
|
4
4
|
import { loadServerAction } from "../rsc-GFzFWyhT.js";
|
|
5
5
|
import { createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, renderToReadableStream } from "../rsc-BdCB3621.js";
|
|
6
|
-
import "../encryption-runtime-
|
|
6
|
+
import "../encryption-runtime-DT6dtlC5.js";
|
|
7
7
|
import "../rsc-CiAoLCx8.js";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
|
|
@@ -13,11 +13,10 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
13
13
|
*/
|
|
14
14
|
async function renderRequest(request, root, options) {
|
|
15
15
|
function RscRoot() {
|
|
16
|
-
|
|
16
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [options?.nonce && /* @__PURE__ */ jsx("meta", {
|
|
17
17
|
property: "csp-nonce",
|
|
18
18
|
nonce: options.nonce
|
|
19
|
-
});
|
|
20
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [nonceMeta, root] });
|
|
19
|
+
}), root] });
|
|
21
20
|
}
|
|
22
21
|
const url = new URL(request.url);
|
|
23
22
|
const isAction = request.method === "POST";
|
|
@@ -34,8 +33,7 @@ async function renderRequest(request, root, options) {
|
|
|
34
33
|
returnValue = await (await loadServerAction(actionId)).apply(null, args);
|
|
35
34
|
} else {
|
|
36
35
|
const formData = await request.formData();
|
|
37
|
-
|
|
38
|
-
formState = await decodeFormState(result, formData);
|
|
36
|
+
formState = await decodeFormState(await (await decodeAction(formData))(), formData);
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
const rscStream = renderToReadableStream({
|
package/dist/extra/ssr.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "../dist-DiJnRA1C.js";
|
|
2
2
|
import "../shared-CXg_u-4h.js";
|
|
3
|
-
import "../shared-
|
|
3
|
+
import "../shared-n-ykEs15.js";
|
|
4
4
|
import "../ssr-Cm2FP2zD.js";
|
|
5
5
|
import { createFromReadableStream } from "../ssr-Cd4SbAaO.js";
|
|
6
|
-
import "../ssr-
|
|
7
|
-
import { injectRSCPayload } from "../server-
|
|
6
|
+
import "../ssr-BQwZitKq.js";
|
|
7
|
+
import { injectRSCPayload } from "../server-DMhFuTz_.js";
|
|
8
8
|
import React from "react";
|
|
9
9
|
import { jsx } from "react/jsx-runtime";
|
|
10
10
|
import ReactDomServer from "react-dom/server.edge";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import MagicString from "magic-string";
|
|
2
|
-
import { Program } from "estree";
|
|
2
|
+
import { Literal, Program } from "estree";
|
|
3
3
|
|
|
4
4
|
//#region src/transforms/hoist.d.ts
|
|
5
5
|
declare function transformHoistInlineDirective(input: string, ast: Program, {
|
|
@@ -19,6 +19,7 @@ declare function transformHoistInlineDirective(input: string, ast: Program, {
|
|
|
19
19
|
output: MagicString;
|
|
20
20
|
names: string[];
|
|
21
21
|
};
|
|
22
|
+
declare function findDirectives(ast: Program, directive: string): Literal[];
|
|
22
23
|
//#endregion
|
|
23
24
|
//#region src/transforms/wrap-export.d.ts
|
|
24
25
|
type ExportMeta = {
|
|
@@ -86,4 +87,4 @@ declare function transformServerActionServer(input: string, ast: Program, option
|
|
|
86
87
|
names: string[];
|
|
87
88
|
};
|
|
88
89
|
//#endregion
|
|
89
|
-
export { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
|
90
|
+
export { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { PluginApi, RscPluginOptions, getPluginApi, vitePluginRsc } from "./plugin-
|
|
1
|
+
import "./index-B04iFwO5.js";
|
|
2
|
+
import { PluginApi, RscPluginOptions, getPluginApi, vitePluginRsc } from "./plugin-DCLI7Wh8.js";
|
|
3
3
|
export { type PluginApi, type RscPluginOptions, vitePluginRsc as default, getPluginApi };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "./dist-DiJnRA1C.js";
|
|
2
2
|
import "./plugin-CZbI4rhS.js";
|
|
3
|
-
import "./transforms-
|
|
3
|
+
import "./transforms-CpF3zNE0.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import "./rpc-CUvSZurk.js";
|
|
6
|
-
import { getPluginApi, vitePluginRsc } from "./plugin-
|
|
7
|
-
import "./cjs-
|
|
8
|
-
import "./shared-
|
|
6
|
+
import { getPluginApi, vitePluginRsc } from "./plugin-BDLEZ1UW.js";
|
|
7
|
+
import "./cjs-BamOAUgw.js";
|
|
8
|
+
import "./shared-n-ykEs15.js";
|
|
9
9
|
|
|
10
10
|
export { vitePluginRsc as default, getPluginApi };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createDebug } from "./dist-DiJnRA1C.js";
|
|
2
2
|
import { vitePluginRscCore } from "./plugin-CZbI4rhS.js";
|
|
3
|
-
import { hasDirective, transformDirectiveProxyExport, transformServerActionServer, transformWrapExport } from "./transforms-
|
|
3
|
+
import { findDirectives, hasDirective, transformDirectiveProxyExport, transformServerActionServer, transformWrapExport } from "./transforms-CpF3zNE0.js";
|
|
4
4
|
import { generateEncryptionKey, toBase64 } from "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import { createRpcServer } from "./rpc-CUvSZurk.js";
|
|
6
|
-
import { cjsModuleRunnerPlugin } from "./cjs-
|
|
7
|
-
import { parseCssVirtual, parseIdQuery, toCssVirtual } from "./shared-
|
|
6
|
+
import { cjsModuleRunnerPlugin } from "./cjs-BamOAUgw.js";
|
|
7
|
+
import { parseCssVirtual, parseIdQuery, toCssVirtual } from "./shared-n-ykEs15.js";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
import assert from "node:assert";
|
|
10
10
|
import fs from "node:fs";
|
|
@@ -164,8 +164,7 @@ async function transformScanBuildStrip(code) {
|
|
|
164
164
|
const [imports] = esModuleLexer.parse(code);
|
|
165
165
|
let output = imports.map((e) => e.n && `import ${JSON.stringify(e.n)};\n`).filter(Boolean).join("");
|
|
166
166
|
if (importGlobRE.test(code)) {
|
|
167
|
-
|
|
168
|
-
walk(ast, { enter(node) {
|
|
167
|
+
walk(await parseAstAsync(code), { enter(node) {
|
|
169
168
|
if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.object.type === "MetaProperty" && node.callee.object.meta.type === "Identifier" && node.callee.object.meta.name === "import" && node.callee.object.property.type === "Identifier" && node.callee.object.property.name === "meta" && node.callee.property.type === "Identifier" && node.callee.property.name === "glob") {
|
|
170
169
|
const importMetaGlob = code.slice(node.start, node.end);
|
|
171
170
|
output += `console.log(${importMetaGlob});\n`;
|
|
@@ -205,19 +204,14 @@ function validateImportPlugin() {
|
|
|
205
204
|
order: "post",
|
|
206
205
|
async handler(_code, id) {
|
|
207
206
|
if (this.environment.mode === "dev") {
|
|
208
|
-
if (id.startsWith(`\0virtual:vite-rsc/validate-imports/invalid/`))
|
|
209
|
-
const chain = getImportChainDev(this.environment, id);
|
|
210
|
-
validateImportChain(chain, this.environment.name, this.environment.config.root);
|
|
211
|
-
}
|
|
207
|
+
if (id.startsWith(`\0virtual:vite-rsc/validate-imports/invalid/`)) validateImportChain(getImportChainDev(this.environment, id), this.environment.name, this.environment.config.root);
|
|
212
208
|
}
|
|
213
209
|
}
|
|
214
210
|
},
|
|
215
211
|
buildEnd() {
|
|
216
212
|
if (this.environment.mode === "build") {
|
|
217
|
-
|
|
218
|
-
validateImportChain(
|
|
219
|
-
const clientOnly = getImportChainBuild(this, "\0virtual:vite-rsc/validate-imports/invalid/client-only");
|
|
220
|
-
validateImportChain(clientOnly, this.environment.name, this.environment.config.root);
|
|
213
|
+
validateImportChain(getImportChainBuild(this, "\0virtual:vite-rsc/validate-imports/invalid/server-only"), this.environment.name, this.environment.config.root);
|
|
214
|
+
validateImportChain(getImportChainBuild(this, "\0virtual:vite-rsc/validate-imports/invalid/client-only"), this.environment.name, this.environment.config.root);
|
|
221
215
|
}
|
|
222
216
|
}
|
|
223
217
|
};
|
|
@@ -434,22 +428,21 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
434
428
|
name: "rsc",
|
|
435
429
|
async config(config, env) {
|
|
436
430
|
if (config.rsc) Object.assign(rscPluginOptions, vite.mergeConfig(config.rsc, rscPluginOptions));
|
|
437
|
-
const result = await crawlFrameworkPkgs({
|
|
438
|
-
root: process.cwd(),
|
|
439
|
-
isBuild: env.command === "build",
|
|
440
|
-
isFrameworkPkgByJson(pkgJson) {
|
|
441
|
-
if ([PKG_NAME, "react-dom"].includes(pkgJson.name)) return;
|
|
442
|
-
const deps = pkgJson["peerDependencies"];
|
|
443
|
-
return deps && "react" in deps;
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
431
|
const noExternal = [
|
|
447
432
|
"react",
|
|
448
433
|
"react-dom",
|
|
449
434
|
"server-only",
|
|
450
435
|
"client-only",
|
|
451
436
|
PKG_NAME,
|
|
452
|
-
...
|
|
437
|
+
...(await crawlFrameworkPkgs({
|
|
438
|
+
root: process.cwd(),
|
|
439
|
+
isBuild: env.command === "build",
|
|
440
|
+
isFrameworkPkgByJson(pkgJson) {
|
|
441
|
+
if ([PKG_NAME, "react-dom"].includes(pkgJson.name)) return;
|
|
442
|
+
const deps = pkgJson["peerDependencies"];
|
|
443
|
+
return deps && "react" in deps;
|
|
444
|
+
}
|
|
445
|
+
})).ssr.noExternal.sort()
|
|
453
446
|
];
|
|
454
447
|
return {
|
|
455
448
|
appType: config.appType ?? "custom",
|
|
@@ -553,8 +546,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
553
546
|
try {
|
|
554
547
|
const resolved = await environment.pluginContainer.resolveId(source);
|
|
555
548
|
assert(resolved, `[vite-rsc] failed to resolve server handler '${source}'`);
|
|
556
|
-
const
|
|
557
|
-
const fetchHandler = getFetchHandlerExport(mod);
|
|
549
|
+
const fetchHandler = getFetchHandlerExport(await environment.runner.import(resolved.id));
|
|
558
550
|
req.url = req.originalUrl ?? req.url;
|
|
559
551
|
await createRequestListener(fetchHandler)(req, res);
|
|
560
552
|
} catch (e) {
|
|
@@ -570,10 +562,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
570
562
|
environmentName: "rsc",
|
|
571
563
|
entryName: "index"
|
|
572
564
|
};
|
|
573
|
-
const
|
|
574
|
-
const mod = await import(pathToFileURL(entryFile).href);
|
|
575
|
-
const fetchHandler = getFetchHandlerExport(mod);
|
|
576
|
-
const handler = createRequestListener(fetchHandler);
|
|
565
|
+
const handler = createRequestListener(getFetchHandlerExport(await import(pathToFileURL(path.join(manager.config.environments[options.environmentName].build.outDir, `${options.entryName}.js`)).href)));
|
|
577
566
|
server.middlewares.use((req, _res, next) => {
|
|
578
567
|
delete req.headers["accept-encoding"];
|
|
579
568
|
next();
|
|
@@ -654,8 +643,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
654
643
|
const { server } = manager;
|
|
655
644
|
const s = new MagicString(code);
|
|
656
645
|
for (const match of code.matchAll(/import\.meta\.viteRsc\.loadModule\(([\s\S]*?)\)/dg)) {
|
|
657
|
-
const
|
|
658
|
-
const [environmentName, entryName] = evalValue(`[${argCode}]`);
|
|
646
|
+
const [environmentName, entryName] = evalValue(`[${match[1].trim()}]`);
|
|
659
647
|
let replacement;
|
|
660
648
|
if (this.environment.mode === "dev" && rscPluginOptions.loadModuleDevProxy) {
|
|
661
649
|
const origin = server.resolvedUrls?.local[0];
|
|
@@ -710,20 +698,18 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
710
698
|
const source = getEntrySource(environment.config, entryName);
|
|
711
699
|
const resolvedEntry = await environment.pluginContainer.resolveId(source);
|
|
712
700
|
assert(resolvedEntry, `[vite-rsc] failed to resolve entry '${source}'`);
|
|
713
|
-
|
|
701
|
+
return createRpcServer(new Proxy({}, { get(_target, p, _receiver) {
|
|
714
702
|
if (typeof p !== "string" || p === "then") return;
|
|
715
703
|
return async (...args) => {
|
|
716
704
|
return (await environment.runner.import(resolvedEntry.id))[p](...args);
|
|
717
705
|
};
|
|
718
|
-
} });
|
|
719
|
-
return createRpcServer(runnerProxy);
|
|
706
|
+
} }));
|
|
720
707
|
}
|
|
721
708
|
server.middlewares.use(async (req, res, next) => {
|
|
722
709
|
const url = new URL(req.url ?? "/", `http://localhost`);
|
|
723
710
|
if (url.pathname === "/__vite_rsc_load_module_dev_proxy") {
|
|
724
711
|
try {
|
|
725
|
-
|
|
726
|
-
createRequestListener(handler)(req, res);
|
|
712
|
+
createRequestListener(await createHandler(url))(req, res);
|
|
727
713
|
} catch (e) {
|
|
728
714
|
next(e);
|
|
729
715
|
}
|
|
@@ -748,9 +734,8 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
748
734
|
if (id === "\0virtual:vite-rsc/assets-manifest") {
|
|
749
735
|
assert(this.environment.name !== "client");
|
|
750
736
|
assert(this.environment.mode === "dev");
|
|
751
|
-
const entryUrl = assetsURL("@id/__x00__" + VIRTUAL_ENTRIES.browser, manager);
|
|
752
737
|
const manifest = {
|
|
753
|
-
bootstrapScriptContent: `import(${serializeValueWithRuntime(
|
|
738
|
+
bootstrapScriptContent: `import(${serializeValueWithRuntime(assetsURL("@id/__x00__" + VIRTUAL_ENTRIES.browser, manager))})`,
|
|
754
739
|
clientReferenceDeps: {}
|
|
755
740
|
};
|
|
756
741
|
return `export default ${JSON.stringify(manifest, null, 2)}`;
|
|
@@ -822,8 +807,7 @@ export default assetsManifest.bootstrapScriptContent;
|
|
|
822
807
|
const output = new MagicString(code);
|
|
823
808
|
for (const match of code.matchAll(/import\s*\.\s*meta\s*\.\s*viteRsc\s*\.\s*loadBootstrapScriptContent\(([\s\S]*?)\)/dg)) {
|
|
824
809
|
const argCode = match[1].trim();
|
|
825
|
-
|
|
826
|
-
assert(entryName, `[vite-rsc] expected 'loadBootstrapScriptContent("index")' but got ${argCode}`);
|
|
810
|
+
assert(evalValue(argCode), `[vite-rsc] expected 'loadBootstrapScriptContent("index")' but got ${argCode}`);
|
|
827
811
|
let replacement = `Promise.resolve(__vite_rsc_assets_manifest.bootstrapScriptContent)`;
|
|
828
812
|
const [start, end] = match.indices[0];
|
|
829
813
|
output.overwrite(start, end, replacement);
|
|
@@ -918,6 +902,10 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
|
|
|
918
902
|
delete manager.clientReferenceMetaMap[id];
|
|
919
903
|
return;
|
|
920
904
|
}
|
|
905
|
+
if (code.includes("use server")) {
|
|
906
|
+
const directives = findDirectives(ast, "use server");
|
|
907
|
+
if (directives.length > 0) this.error(`'use server' directive is not allowed inside 'use client'`, directives[0]?.start);
|
|
908
|
+
}
|
|
921
909
|
let importId;
|
|
922
910
|
let referenceKey;
|
|
923
911
|
const packageSource = packageSources.get(id);
|
|
@@ -1134,8 +1122,7 @@ function customOptimizerMetadataPlugin({ setMetadata }) {
|
|
|
1134
1122
|
configResolved(config) {
|
|
1135
1123
|
const file = path.join(config.cacheDir, "deps", MEATADATA_FILE);
|
|
1136
1124
|
if (fs.existsSync(file)) try {
|
|
1137
|
-
|
|
1138
|
-
setMetadata(metadata);
|
|
1125
|
+
setMetadata(JSON.parse(fs.readFileSync(file, "utf-8")));
|
|
1139
1126
|
} catch (e) {
|
|
1140
1127
|
this.warn(`failed to load '${file}'`);
|
|
1141
1128
|
}
|
|
@@ -1240,7 +1227,7 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
|
|
|
1240
1227
|
}
|
|
1241
1228
|
const result = withRollupError(this, transformDirectiveProxyExport)(ast, {
|
|
1242
1229
|
code,
|
|
1243
|
-
runtime: (name
|
|
1230
|
+
runtime: (name) => `$$ReactClient.createServerReference(${JSON.stringify(getNormalizedId() + "#" + name)},$$ReactClient.callServer, undefined, ` + (this.environment.mode === "dev" ? `$$ReactClient.findSourceMapURL,` : "undefined,") + `${JSON.stringify(name)})`,
|
|
1244
1231
|
directive: "use server",
|
|
1245
1232
|
rejectNonAsyncFunction: true
|
|
1246
1233
|
});
|
|
@@ -1252,8 +1239,7 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
|
|
|
1252
1239
|
referenceKey: getNormalizedId(),
|
|
1253
1240
|
exportNames: result.exportNames
|
|
1254
1241
|
};
|
|
1255
|
-
const
|
|
1256
|
-
const importSource = resolvePackage(`${PKG_NAME}/react/${name}`);
|
|
1242
|
+
const importSource = resolvePackage(`${PKG_NAME}/react/${this.environment.name === browserEnvironmentName ? "browser" : "ssr"}`);
|
|
1257
1243
|
output.prepend(`import * as $$ReactClient from "${importSource}";\n`);
|
|
1258
1244
|
return {
|
|
1259
1245
|
code: output.toString(),
|
|
@@ -1420,9 +1406,8 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
|
|
|
1420
1406
|
code
|
|
1421
1407
|
});
|
|
1422
1408
|
if (!filter) return;
|
|
1423
|
-
const ast = await parseAstAsync(code);
|
|
1424
1409
|
const result = await transformRscCssExport({
|
|
1425
|
-
ast,
|
|
1410
|
+
ast: await parseAstAsync(code),
|
|
1426
1411
|
code,
|
|
1427
1412
|
filter
|
|
1428
1413
|
});
|
|
@@ -1459,8 +1444,7 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
|
|
|
1459
1444
|
if (!mod?.id || !mod?.file) return `export default []`;
|
|
1460
1445
|
const result = collectCss(server.environments.ssr, mod.id);
|
|
1461
1446
|
for (const file of [mod.file, ...result.visitedFiles]) this.addWatchFile(file);
|
|
1462
|
-
|
|
1463
|
-
return `export default ${serializeValueWithRuntime(hrefs)}`;
|
|
1447
|
+
return `export default ${serializeValueWithRuntime(result.hrefs.map((href) => assetsURL(href.slice(1), manager)))}`;
|
|
1464
1448
|
}
|
|
1465
1449
|
}
|
|
1466
1450
|
},
|
|
@@ -1534,12 +1518,10 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
|
|
|
1534
1518
|
if (this.environment.mode === "dev") {
|
|
1535
1519
|
const result = collectCss(server.environments.rsc, importer);
|
|
1536
1520
|
for (const file of [importer, ...result.visitedFiles]) this.addWatchFile(file);
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
css: cssHrefs,
|
|
1521
|
+
return generateResourcesCode(serializeValueWithRuntime(assetsURLOfDeps({
|
|
1522
|
+
css: result.hrefs.map((href) => href.slice(1)),
|
|
1540
1523
|
js: []
|
|
1541
|
-
}, manager);
|
|
1542
|
-
return generateResourcesCode(serializeValueWithRuntime(deps), manager);
|
|
1524
|
+
}, manager)), manager);
|
|
1543
1525
|
} else {
|
|
1544
1526
|
const key = manager.toRelativeId(importer);
|
|
1545
1527
|
manager.serverResourcesMetaMap[importer] = { key };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-
|
|
1
|
+
import "./index-B04iFwO5.js";
|
|
2
|
+
import { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-DCLI7Wh8.js";
|
|
3
3
|
export { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
|
package/dist/plugin.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "./dist-DiJnRA1C.js";
|
|
2
2
|
import "./plugin-CZbI4rhS.js";
|
|
3
|
-
import "./transforms-
|
|
3
|
+
import "./transforms-CpF3zNE0.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import "./rpc-CUvSZurk.js";
|
|
6
|
-
import { getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-
|
|
7
|
-
import "./cjs-
|
|
8
|
-
import "./shared-
|
|
6
|
+
import { getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-BDLEZ1UW.js";
|
|
7
|
+
import "./cjs-BamOAUgw.js";
|
|
8
|
+
import "./shared-n-ykEs15.js";
|
|
9
9
|
|
|
10
10
|
export { vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
|
package/dist/plugins/cjs.js
CHANGED
package/dist/rsc.js
CHANGED
|
@@ -3,7 +3,7 @@ import "./shared-CXg_u-4h.js";
|
|
|
3
3
|
import "./encryption-utils-BDwwcMVT.js";
|
|
4
4
|
import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-GFzFWyhT.js";
|
|
5
5
|
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-BdCB3621.js";
|
|
6
|
-
import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-
|
|
6
|
+
import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-DT6dtlC5.js";
|
|
7
7
|
import "./rsc-CiAoLCx8.js";
|
|
8
8
|
|
|
9
9
|
export { createClientManifest, createClientTemporaryReferenceSet, createFromReadableStream, createServerManifest, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, decryptActionBoundArgs, encodeReply, encryptActionBoundArgs, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
|
|
@@ -56,8 +56,7 @@ async function writeRSCStream(rscStream, controller, nonce) {
|
|
|
56
56
|
for await (let chunk of rscStream) try {
|
|
57
57
|
writeChunk(JSON.stringify(decoder.decode(chunk, { stream: true })), controller, nonce);
|
|
58
58
|
} catch (err) {
|
|
59
|
-
|
|
60
|
-
writeChunk(`Uint8Array.from(atob(${base64}), m => m.codePointAt(0))`, controller, nonce);
|
|
59
|
+
writeChunk(`Uint8Array.from(atob(${JSON.stringify(btoa(String.fromCodePoint(...chunk)))}), m => m.codePointAt(0))`, controller, nonce);
|
|
61
60
|
}
|
|
62
61
|
let remaining = decoder.decode();
|
|
63
62
|
if (remaining.length) writeChunk(JSON.stringify(remaining), controller, nonce);
|
|
@@ -11,10 +11,9 @@ function parseIdQuery(id) {
|
|
|
11
11
|
query: {}
|
|
12
12
|
};
|
|
13
13
|
const [filename, rawQuery] = id.split(`?`, 2);
|
|
14
|
-
const query = Object.fromEntries(new URLSearchParams(rawQuery));
|
|
15
14
|
return {
|
|
16
15
|
filename,
|
|
17
|
-
query
|
|
16
|
+
query: Object.fromEntries(new URLSearchParams(rawQuery))
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
19
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toCssVirtual } from "./shared-
|
|
1
|
+
import { toCssVirtual } from "./shared-n-ykEs15.js";
|
|
2
2
|
import { setRequireModule } from "./ssr-Cm2FP2zD.js";
|
|
3
3
|
import * as clientReferences from "virtual:vite-rsc/client-references";
|
|
4
4
|
import assetsManifest from "virtual:vite-rsc/assets-manifest";
|
|
@@ -8,29 +8,25 @@ import * as ReactDOM from "react-dom";
|
|
|
8
8
|
initialize();
|
|
9
9
|
function initialize() {
|
|
10
10
|
setRequireModule({ load: async (id) => {
|
|
11
|
-
if (!import.meta.env.__vite_rsc_build__)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
if (!import.meta.env.__vite_rsc_build__) return wrapResourceProxy(await import(
|
|
12
|
+
/* @vite-ignore */
|
|
13
|
+
id
|
|
14
|
+
), {
|
|
15
|
+
js: [],
|
|
16
|
+
css: (await import(
|
|
17
17
|
/* @vite-ignore */
|
|
18
18
|
"/@id/__x00__" + toCssVirtual({
|
|
19
19
|
id,
|
|
20
20
|
type: "ssr"
|
|
21
21
|
})
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
css: modCss.default
|
|
26
|
-
});
|
|
27
|
-
} else {
|
|
22
|
+
)).default
|
|
23
|
+
});
|
|
24
|
+
else {
|
|
28
25
|
const import_ = clientReferences.default[id];
|
|
29
26
|
if (!import_) throw new Error(`client reference not found '${id}'`);
|
|
30
27
|
const deps = assetsManifest.clientReferenceDeps[id];
|
|
31
28
|
if (deps) preloadDeps(deps);
|
|
32
|
-
|
|
33
|
-
return wrapResourceProxy(mod, deps);
|
|
29
|
+
return wrapResourceProxy(await import_(), deps);
|
|
34
30
|
}
|
|
35
31
|
} });
|
|
36
32
|
}
|
package/dist/ssr.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./dist-DiJnRA1C.js";
|
|
2
2
|
import "./shared-CXg_u-4h.js";
|
|
3
|
-
import "./shared-
|
|
3
|
+
import "./shared-n-ykEs15.js";
|
|
4
4
|
import { createServerConsumerManifest, setRequireModule } from "./ssr-Cm2FP2zD.js";
|
|
5
5
|
import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-Cd4SbAaO.js";
|
|
6
|
-
import "./ssr-
|
|
6
|
+
import "./ssr-BQwZitKq.js";
|
|
7
7
|
|
|
8
8
|
export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, findSourceMapURL, setRequireModule };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport } from "../index-
|
|
2
|
-
export { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
|
1
|
+
import { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport } from "../index-B04iFwO5.js";
|
|
2
|
+
export { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
package/dist/transforms/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "../dist-DiJnRA1C.js";
|
|
2
|
-
import { getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport } from "../transforms-
|
|
2
|
+
import { findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport } from "../transforms-CpF3zNE0.js";
|
|
3
3
|
|
|
4
|
-
export { getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
|
4
|
+
export { findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
|
@@ -15,7 +15,7 @@ function transformHoistInlineDirective(input, ast, { runtime, rejectNonAsyncFunc
|
|
|
15
15
|
const names = [];
|
|
16
16
|
walk(ast, { enter(node, parent) {
|
|
17
17
|
if ((node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") && node.body.type === "BlockStatement") {
|
|
18
|
-
const match = matchDirective(node.body.body, directive);
|
|
18
|
+
const match = matchDirective(node.body.body, directive)?.match;
|
|
19
19
|
if (!match) return;
|
|
20
20
|
if (!node.async && rejectNonAsyncFunction) throw Object.assign(/* @__PURE__ */ new Error(`"${directive}" doesn't allow non async function`), { pos: node.start });
|
|
21
21
|
const scope = analyzed.map.get(node);
|
|
@@ -59,11 +59,25 @@ function transformHoistInlineDirective(input, ast, { runtime, rejectNonAsyncFunc
|
|
|
59
59
|
}
|
|
60
60
|
const exactRegex = (s) => /* @__PURE__ */ new RegExp("^" + s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + "$");
|
|
61
61
|
function matchDirective(body, directive) {
|
|
62
|
-
for (const
|
|
63
|
-
const match =
|
|
64
|
-
if (match) return
|
|
62
|
+
for (const stmt of body) if (stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string") {
|
|
63
|
+
const match = stmt.expression.value.match(directive);
|
|
64
|
+
if (match) return {
|
|
65
|
+
match,
|
|
66
|
+
node: stmt.expression
|
|
67
|
+
};
|
|
65
68
|
}
|
|
66
69
|
}
|
|
70
|
+
function findDirectives(ast, directive) {
|
|
71
|
+
const directiveRE = exactRegex(directive);
|
|
72
|
+
const nodes = [];
|
|
73
|
+
walk(ast, { enter(node) {
|
|
74
|
+
if (node.type === "Program" || node.type === "BlockStatement") {
|
|
75
|
+
const match = matchDirective(node.body, directiveRE);
|
|
76
|
+
if (match) nodes.push(match.node);
|
|
77
|
+
}
|
|
78
|
+
} });
|
|
79
|
+
return nodes;
|
|
80
|
+
}
|
|
67
81
|
|
|
68
82
|
//#endregion
|
|
69
83
|
//#region src/transforms/wrap-export.ts
|
|
@@ -276,8 +290,7 @@ function transformProxyExport(ast, options) {
|
|
|
276
290
|
}
|
|
277
291
|
}
|
|
278
292
|
}
|
|
279
|
-
|
|
280
|
-
createExport(node, names);
|
|
293
|
+
createExport(node, node.declaration.declarations.flatMap((decl) => extract_names(decl.id)));
|
|
281
294
|
} else node.declaration;
|
|
282
295
|
else {
|
|
283
296
|
/**
|
|
@@ -327,4 +340,4 @@ function transformServerActionServer(input, ast, options) {
|
|
|
327
340
|
}
|
|
328
341
|
|
|
329
342
|
//#endregion
|
|
330
|
-
export { getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
|
343
|
+
export { findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
|
@@ -3,6 +3,6 @@ import "../shared-CXg_u-4h.js";
|
|
|
3
3
|
import "../encryption-utils-BDwwcMVT.js";
|
|
4
4
|
import "../rsc-GFzFWyhT.js";
|
|
5
5
|
import "../rsc-BdCB3621.js";
|
|
6
|
-
import { decryptActionBoundArgs, encryptActionBoundArgs } from "../encryption-runtime-
|
|
6
|
+
import { decryptActionBoundArgs, encryptActionBoundArgs } from "../encryption-runtime-DT6dtlC5.js";
|
|
7
7
|
|
|
8
8
|
export { decryptActionBoundArgs, encryptActionBoundArgs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-rsc",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.33",
|
|
4
4
|
"description": "React Server Components (RSC) support for Vite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -39,29 +39,30 @@
|
|
|
39
39
|
"prepack": "tsdown"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@remix-run/node-fetch-server": "^0.
|
|
42
|
+
"@remix-run/node-fetch-server": "^0.10.0",
|
|
43
43
|
"es-module-lexer": "^1.7.0",
|
|
44
44
|
"estree-walker": "^3.0.3",
|
|
45
|
-
"magic-string": "^0.30.
|
|
45
|
+
"magic-string": "^0.30.19",
|
|
46
46
|
"periscopic": "^4.0.2",
|
|
47
47
|
"turbo-stream": "^3.1.0",
|
|
48
48
|
"vitefu": "^1.1.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@hiogawa/utils": "^1.7.0",
|
|
52
|
-
"@playwright/test": "^1.55.
|
|
53
|
-
"@tsconfig/strictest": "^2.0.
|
|
52
|
+
"@playwright/test": "^1.55.1",
|
|
53
|
+
"@tsconfig/strictest": "^2.0.6",
|
|
54
54
|
"@types/estree": "^1.0.8",
|
|
55
|
-
"@types/node": "^22.18.
|
|
56
|
-
"@types/react": "^19.1.
|
|
55
|
+
"@types/node": "^22.18.8",
|
|
56
|
+
"@types/react": "^19.1.16",
|
|
57
57
|
"@types/react-dom": "^19.1.9",
|
|
58
58
|
"@vitejs/plugin-react": "workspace:*",
|
|
59
|
+
"@vitejs/test-dep-cjs-and-esm": "./test-dep/cjs-and-esm",
|
|
59
60
|
"react": "^19.1.1",
|
|
60
61
|
"react-dom": "^19.1.1",
|
|
61
62
|
"react-server-dom-webpack": "^19.1.1",
|
|
62
63
|
"rsc-html-stream": "^0.0.7",
|
|
63
64
|
"tinyexec": "^1.0.1",
|
|
64
|
-
"tsdown": "^0.
|
|
65
|
+
"tsdown": "^0.15.6"
|
|
65
66
|
},
|
|
66
67
|
"peerDependencies": {
|
|
67
68
|
"react": "*",
|