@vitejs/plugin-rsc 0.4.27 → 0.4.29

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.
Files changed (62) hide show
  1. package/dist/{browser-QU10IP0-.js → browser--ZREVnM9.js} +1 -1
  2. package/dist/{browser-BhJd-Orx.js → browser-7NhxQxuk.js} +1 -1
  3. package/dist/{browser-mbRygLxB.d.ts → browser-DUDACP5e.d.ts} +1 -1
  4. package/dist/browser.d.ts +3 -3
  5. package/dist/browser.js +3 -3
  6. package/dist/core/browser.d.ts +1 -1
  7. package/dist/core/browser.js +2 -2
  8. package/dist/core/rsc.d.ts +2 -2
  9. package/dist/core/rsc.js +2 -2
  10. package/dist/core/ssr.d.ts +2 -2
  11. package/dist/core/ssr.js +2 -2
  12. package/dist/{encryption-runtime-CJUalqt3.js → encryption-runtime-CAmm02Ms.js} +2 -3
  13. package/dist/extra/browser.d.ts +1 -1
  14. package/dist/extra/browser.js +5 -6
  15. package/dist/extra/rsc.d.ts +1 -1
  16. package/dist/extra/rsc.js +11 -17
  17. package/dist/extra/ssr.js +8 -10
  18. package/dist/index-BH1wcQPN.d.ts +89 -0
  19. package/dist/index.d.ts +3 -24
  20. package/dist/index.js +5 -4
  21. package/dist/{plugin-Be24jgQb.d.ts → plugin-BDdwA9-Y.d.ts} +7 -10
  22. package/dist/{plugin-CtdHIozK.js → plugin-DB5WEabT.js} +38 -341
  23. package/dist/plugin.d.ts +3 -2
  24. package/dist/plugin.js +5 -4
  25. package/dist/react/browser.d.ts +3 -3
  26. package/dist/react/browser.js +2 -2
  27. package/dist/react/rsc.d.ts +3 -3
  28. package/dist/react/rsc.js +3 -3
  29. package/dist/react/ssr.d.ts +3 -3
  30. package/dist/react/ssr.js +3 -3
  31. package/dist/{rpc-tGuLT8PD.js → rpc-CUvSZurk.js} +2 -3
  32. package/dist/{rsc-CxDPDiLz.d.ts → rsc-BeJKxeMX.d.ts} +1 -1
  33. package/dist/{rsc-BwEwbLG4.js → rsc-D_DDN0W1.js} +1 -1
  34. package/dist/{rsc-VjVw_i-M.js → rsc-DdBcg-Lb.js} +1 -1
  35. package/dist/{rsc-BfBPoIV8.js → rsc-cp4EenMG.js} +2 -3
  36. package/dist/rsc-html-stream/browser.js +1 -1
  37. package/dist/rsc-html-stream/ssr.js +1 -1
  38. package/dist/rsc.d.ts +4 -4
  39. package/dist/rsc.js +5 -5
  40. package/dist/{shared-CEyKoKAb.js → shared-CXg_u-4h.js} +1 -2
  41. package/dist/{ssr-BoNKka-5.d.ts → ssr-Bv84RACl.d.ts} +1 -1
  42. package/dist/{ssr--rFiBtws.js → ssr-CMFFChNQ.js} +1 -1
  43. package/dist/{ssr-BEKKb_cw.js → ssr-D8iPOYvE.js} +1 -1
  44. package/dist/{ssr-CWjOQSe3.js → ssr-Y4u1WaMw.js} +2 -2
  45. package/dist/ssr.d.ts +3 -3
  46. package/dist/ssr.js +5 -5
  47. package/dist/transforms/index.d.ts +2 -0
  48. package/dist/transforms/index.js +4 -0
  49. package/dist/transforms-D1-2JfCh.js +330 -0
  50. package/dist/utils/encryption-runtime.d.ts +1 -1
  51. package/dist/utils/encryption-runtime.js +4 -4
  52. package/dist/utils/rpc.js +1 -1
  53. package/package.json +3 -2
  54. /package/dist/{browser-CuwQIlVY.d.ts → browser-CyGTajab.d.ts} +0 -0
  55. /package/dist/{client-C1J4FCf5.js → client-BPIq1kGs.js} +0 -0
  56. /package/dist/{encryption-runtime-SgJRa9yj.d.ts → encryption-runtime-BwOew_5N.d.ts} +0 -0
  57. /package/dist/{index-QWzVHuya.d.ts → index-CrcbP1rd.d.ts} +0 -0
  58. /package/dist/{rsc-CFtzqEG8.d.ts → rsc-CpPqIkYr.d.ts} +0 -0
  59. /package/dist/{rsc-Cv3XEZqB.d.ts → rsc-D-lnfNSa.d.ts} +0 -0
  60. /package/dist/{server-D0-DavPP.js → server-DoWzqBNF.js} +0 -0
  61. /package/dist/{shared-BWHxNw3Q.js → shared-Cwk6fxfN.js} +0 -0
  62. /package/dist/{ssr-D6GTzOzx.d.ts → ssr-CXrYz0RZ.d.ts} +0 -0
@@ -22,11 +22,10 @@ function createRpcServer(handlers) {
22
22
  }
23
23
  function createRpcClient(options) {
24
24
  async function callRpc(method, args) {
25
- const reqPayload = {
25
+ const body = encode({
26
26
  method,
27
27
  args
28
- };
29
- const body = encode(reqPayload).pipeThrough(new TextEncoderStream());
28
+ }).pipeThrough(new TextEncoderStream());
30
29
  const res = await fetch(options.endpoint, {
31
30
  method: "POST",
32
31
  body,
@@ -1,4 +1,4 @@
1
- import { BundlerConfig, ModuleMap } from "./index-QWzVHuya.js";
1
+ import { BundlerConfig, ModuleMap } from "./index-CrcbP1rd.js";
2
2
 
3
3
  //#region src/core/rsc.d.ts
4
4
  declare function setRequireModule(options: {
@@ -1,4 +1,4 @@
1
- import { setRequireModule } from "./rsc-BfBPoIV8.js";
1
+ import { setRequireModule } from "./rsc-cp4EenMG.js";
2
2
  import serverReferences from "virtual:vite-rsc/server-references";
3
3
 
4
4
  //#region src/rsc.tsx
@@ -1,4 +1,4 @@
1
- import { createClientManifest, createServerDecodeClientManifest, createServerManifest } from "./rsc-BfBPoIV8.js";
1
+ import { createClientManifest, createServerDecodeClientManifest, createServerManifest } from "./rsc-cp4EenMG.js";
2
2
  import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
3
3
  import * as ReactClient from "@vitejs/plugin-rsc/vendor/react-server-dom/client.edge";
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { memoize, tinyassert } from "./dist-DiJnRA1C.js";
2
- import { SERVER_DECODE_CLIENT_PREFIX, SERVER_REFERENCE_PREFIX, createReferenceCacheTag, removeReferenceCacheTag, setInternalRequire } from "./shared-CEyKoKAb.js";
2
+ import { SERVER_DECODE_CLIENT_PREFIX, SERVER_REFERENCE_PREFIX, createReferenceCacheTag, removeReferenceCacheTag, setInternalRequire } from "./shared-CXg_u-4h.js";
3
3
  import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
4
4
 
5
5
  //#region src/core/rsc.ts
@@ -28,8 +28,7 @@ function setRequireModule(options) {
28
28
  }
29
29
  async function loadServerAction(id) {
30
30
  const [file, name] = id.split("#");
31
- const mod = await requireModule(file);
32
- return mod[name];
31
+ return (await requireModule(file))[name];
33
32
  }
34
33
  function createServerManifest() {
35
34
  const cacheTag = import.meta.env.DEV ? createReferenceCacheTag() : "";
@@ -1,4 +1,4 @@
1
- import { rscStream } from "../client-C1J4FCf5.js";
1
+ import { rscStream } from "../client-BPIq1kGs.js";
2
2
 
3
3
  //#region src/rsc-html-stream/browser.ts
4
4
  /** @deprecated use `rsc-html-stream/client` instead */
@@ -1,4 +1,4 @@
1
- import { injectRSCPayload } from "../server-D0-DavPP.js";
1
+ import { injectRSCPayload } from "../server-DoWzqBNF.js";
2
2
 
3
3
  //#region src/rsc-html-stream/ssr.ts
4
4
  /** @deprecated use `rsc-html-stream/server` instead */
package/dist/rsc.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import "./index-QWzVHuya.js";
2
- import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-CxDPDiLz.js";
3
- import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-CFtzqEG8.js";
4
- import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-SgJRa9yj.js";
1
+ import "./index-CrcbP1rd.js";
2
+ import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-BeJKxeMX.js";
3
+ import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-CpPqIkYr.js";
4
+ import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-BwOew_5N.js";
5
5
  export { createClientManifest, createClientTemporaryReferenceSet, createFromReadableStream, createServerManifest, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, decryptActionBoundArgs, encodeReply, encryptActionBoundArgs, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
package/dist/rsc.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import "./dist-DiJnRA1C.js";
2
- import "./shared-CEyKoKAb.js";
2
+ import "./shared-CXg_u-4h.js";
3
3
  import "./encryption-utils-BDwwcMVT.js";
4
- import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-BfBPoIV8.js";
5
- import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-VjVw_i-M.js";
6
- import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-CJUalqt3.js";
7
- import "./rsc-BwEwbLG4.js";
4
+ import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-cp4EenMG.js";
5
+ import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-DdBcg-Lb.js";
6
+ import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-CAmm02Ms.js";
7
+ import "./rsc-D_DDN0W1.js";
8
8
 
9
9
  export { createClientManifest, createClientTemporaryReferenceSet, createFromReadableStream, createServerManifest, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, decryptActionBoundArgs, encodeReply, encryptActionBoundArgs, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
@@ -2,8 +2,7 @@
2
2
  const SERVER_REFERENCE_PREFIX = "$$server:";
3
3
  const SERVER_DECODE_CLIENT_PREFIX = "$$decode-client:";
4
4
  function createReferenceCacheTag() {
5
- const cache = Math.random().toString(36).slice(2);
6
- return "$$cache=" + cache;
5
+ return "$$cache=" + Math.random().toString(36).slice(2);
7
6
  }
8
7
  function removeReferenceCacheTag(id) {
9
8
  return id.split("$$cache=")[0];
@@ -1,4 +1,4 @@
1
- import { ServerConsumerManifest } from "./index-QWzVHuya.js";
1
+ import { ServerConsumerManifest } from "./index-CrcbP1rd.js";
2
2
 
3
3
  //#region src/core/ssr.d.ts
4
4
  declare function setRequireModule(options: {
@@ -1,5 +1,5 @@
1
1
  import { memoize } from "./dist-DiJnRA1C.js";
2
- import { removeReferenceCacheTag, setInternalRequire } from "./shared-CEyKoKAb.js";
2
+ import { removeReferenceCacheTag, setInternalRequire } from "./shared-CXg_u-4h.js";
3
3
 
4
4
  //#region src/core/ssr.ts
5
5
  let init = false;
@@ -1,4 +1,4 @@
1
- import { createServerConsumerManifest } from "./ssr--rFiBtws.js";
1
+ import { createServerConsumerManifest } from "./ssr-CMFFChNQ.js";
2
2
  import * as ReactClient from "@vitejs/plugin-rsc/vendor/react-server-dom/client.edge";
3
3
 
4
4
  //#region src/react/ssr.ts
@@ -1,5 +1,5 @@
1
- import { toCssVirtual } from "./shared-BWHxNw3Q.js";
2
- import { setRequireModule } from "./ssr--rFiBtws.js";
1
+ import { toCssVirtual } from "./shared-Cwk6fxfN.js";
2
+ import { setRequireModule } from "./ssr-CMFFChNQ.js";
3
3
  import * as clientReferences from "virtual:vite-rsc/client-references";
4
4
  import assetsManifest from "virtual:vite-rsc/assets-manifest";
5
5
  import * as ReactDOM from "react-dom";
package/dist/ssr.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import "./index-QWzVHuya.js";
2
- import { createServerConsumerManifest, setRequireModule } from "./ssr-BoNKka-5.js";
3
- import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-D6GTzOzx.js";
1
+ import "./index-CrcbP1rd.js";
2
+ import { createServerConsumerManifest, setRequireModule } from "./ssr-Bv84RACl.js";
3
+ import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-CXrYz0RZ.js";
4
4
  export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, findSourceMapURL, setRequireModule };
package/dist/ssr.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import "./dist-DiJnRA1C.js";
2
- import "./shared-CEyKoKAb.js";
3
- import "./shared-BWHxNw3Q.js";
4
- import { createServerConsumerManifest, setRequireModule } from "./ssr--rFiBtws.js";
5
- import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-BEKKb_cw.js";
6
- import "./ssr-CWjOQSe3.js";
2
+ import "./shared-CXg_u-4h.js";
3
+ import "./shared-Cwk6fxfN.js";
4
+ import { createServerConsumerManifest, setRequireModule } from "./ssr-CMFFChNQ.js";
5
+ import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-D8iPOYvE.js";
6
+ import "./ssr-Y4u1WaMw.js";
7
7
 
8
8
  export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, findSourceMapURL, setRequireModule };
@@ -0,0 +1,2 @@
1
+ import { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport } from "../index-BH1wcQPN.js";
2
+ export { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
@@ -0,0 +1,4 @@
1
+ import "../dist-DiJnRA1C.js";
2
+ import { getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport } from "../transforms-D1-2JfCh.js";
3
+
4
+ export { getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
@@ -0,0 +1,330 @@
1
+ import { tinyassert } from "./dist-DiJnRA1C.js";
2
+ import MagicString from "magic-string";
3
+ import { walk } from "estree-walker";
4
+ import { analyze, extract_names } from "periscopic";
5
+
6
+ //#region src/transforms/hoist.ts
7
+ function transformHoistInlineDirective(input, ast, { runtime, rejectNonAsyncFunction,...options }) {
8
+ const output = new MagicString(input);
9
+ const directive = typeof options.directive === "string" ? exactRegex(options.directive) : options.directive;
10
+ walk(ast, { enter(node) {
11
+ if (node.type === "ExportAllDeclaration") this.remove();
12
+ if (node.type === "ExportNamedDeclaration" && !node.declaration) this.remove();
13
+ } });
14
+ const analyzed = analyze(ast);
15
+ const names = [];
16
+ walk(ast, { enter(node, parent) {
17
+ if ((node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") && node.body.type === "BlockStatement") {
18
+ const match = matchDirective(node.body.body, directive);
19
+ if (!match) return;
20
+ if (!node.async && rejectNonAsyncFunction) throw Object.assign(/* @__PURE__ */ new Error(`"${directive}" doesn't allow non async function`), { pos: node.start });
21
+ const scope = analyzed.map.get(node);
22
+ tinyassert(scope);
23
+ const declName = node.type === "FunctionDeclaration" && node.id.name;
24
+ const originalName = declName || parent?.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.id.name || "anonymous_server_function";
25
+ const bindVars = [...scope.references].filter((ref) => {
26
+ if (ref === declName) return false;
27
+ const owner = scope.find_owner(ref);
28
+ return owner && owner !== scope && owner !== analyzed.scope;
29
+ });
30
+ let newParams = [...bindVars, ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
31
+ if (bindVars.length > 0 && options.decode) {
32
+ newParams = ["$$hoist_encoded", ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
33
+ output.appendLeft(node.body.body[0].start, `const [${bindVars.join(",")}] = ${options.decode("$$hoist_encoded")};\n`);
34
+ }
35
+ const newName = `$$hoist_${names.length}` + (originalName ? `_${originalName}` : "");
36
+ names.push(newName);
37
+ output.update(node.start, node.body.start, `\n;${options.noExport ? "" : "export "}${node.async ? "async " : ""}function ${newName}(${newParams}) `);
38
+ output.appendLeft(node.end, `;\n/* #__PURE__ */ Object.defineProperty(${newName}, "name", { value: ${JSON.stringify(originalName)} });\n`);
39
+ output.move(node.start, node.end, input.length);
40
+ let newCode = `/* #__PURE__ */ ${runtime(newName, newName, { directiveMatch: match })}`;
41
+ if (bindVars.length > 0) {
42
+ const bindArgs = options.encode ? options.encode("[" + bindVars.join(", ") + "]") : bindVars.join(", ");
43
+ newCode = `${newCode}.bind(null, ${bindArgs})`;
44
+ }
45
+ if (declName) {
46
+ newCode = `const ${declName} = ${newCode};`;
47
+ if (parent?.type === "ExportDefaultDeclaration") {
48
+ output.remove(parent.start, node.start);
49
+ newCode = `${newCode}\nexport default ${declName};`;
50
+ }
51
+ }
52
+ output.appendLeft(node.start, newCode);
53
+ }
54
+ } });
55
+ return {
56
+ output,
57
+ names
58
+ };
59
+ }
60
+ const exactRegex = (s) => /* @__PURE__ */ new RegExp("^" + s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + "$");
61
+ function matchDirective(body, directive) {
62
+ for (const stable of body) if (stable.type === "ExpressionStatement" && stable.expression.type === "Literal" && typeof stable.expression.value === "string") {
63
+ const match = stable.expression.value.match(directive);
64
+ if (match) return match;
65
+ }
66
+ }
67
+
68
+ //#endregion
69
+ //#region src/transforms/wrap-export.ts
70
+ function transformWrapExport(input, ast, options) {
71
+ const output = new MagicString(input);
72
+ const exportNames = [];
73
+ const toAppend = [];
74
+ const filter = options.filter ?? (() => true);
75
+ function wrapSimple(start, end, exports) {
76
+ exportNames.push(...exports.map((e) => e.name));
77
+ const newCode = exports.map((e) => [filter(e.name, e.meta) && `${e.name} = /* #__PURE__ */ ${options.runtime(e.name, e.name, e.meta)};\n`, `export { ${e.name} };\n`]).flat().filter(Boolean).join("");
78
+ output.update(start, end, newCode);
79
+ output.move(start, end, input.length);
80
+ }
81
+ function wrapExport(name, exportName, meta = {}) {
82
+ exportNames.push(exportName);
83
+ if (!filter(exportName, meta)) {
84
+ toAppend.push(`export { ${name} as ${exportName} }`);
85
+ return;
86
+ }
87
+ toAppend.push(`const $$wrap_${name} = /* #__PURE__ */ ${options.runtime(name, exportName, meta)}`, `export { $$wrap_${name} as ${exportName} }`);
88
+ }
89
+ function validateNonAsyncFunction(node) {
90
+ if (!options.rejectNonAsyncFunction) return;
91
+ if (node.type === "ClassDeclaration" || (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && !node.async) throw Object.assign(/* @__PURE__ */ new Error(`unsupported non async function`), { pos: node.start });
92
+ }
93
+ for (const node of ast.body) {
94
+ if (node.type === "ExportNamedDeclaration") if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
95
+ /**
96
+ * export function foo() {}
97
+ */
98
+ validateNonAsyncFunction(node.declaration);
99
+ const name = node.declaration.id.name;
100
+ wrapSimple(node.start, node.declaration.start, [{
101
+ name,
102
+ meta: {
103
+ isFunction: true,
104
+ declName: name
105
+ }
106
+ }]);
107
+ } else if (node.declaration.type === "VariableDeclaration") {
108
+ /**
109
+ * export const foo = 1, bar = 2
110
+ */
111
+ for (const decl of node.declaration.declarations) if (decl.init) validateNonAsyncFunction(decl.init);
112
+ if (node.declaration.kind === "const") output.update(node.declaration.start, node.declaration.start + 5, "let");
113
+ const names = node.declaration.declarations.flatMap((decl) => extract_names(decl.id));
114
+ let isFunction = false;
115
+ if (node.declaration.declarations.length === 1) {
116
+ const decl = node.declaration.declarations[0];
117
+ isFunction = decl.id.type === "Identifier" && (decl.init?.type === "ArrowFunctionExpression" || decl.init?.type === "FunctionExpression");
118
+ }
119
+ wrapSimple(node.start, node.declaration.start, names.map((name) => ({
120
+ name,
121
+ meta: {
122
+ isFunction,
123
+ declName: name
124
+ }
125
+ })));
126
+ } else node.declaration;
127
+ else if (node.source) {
128
+ /**
129
+ * export { foo, bar as car } from './foo'
130
+ */
131
+ output.remove(node.start, node.end);
132
+ for (const spec of node.specifiers) {
133
+ tinyassert(spec.local.type === "Identifier");
134
+ tinyassert(spec.exported.type === "Identifier");
135
+ const name = spec.local.name;
136
+ toAppend.push(`import { ${name} as $$import_${name} } from ${node.source.raw}`);
137
+ wrapExport(`$$import_${name}`, spec.exported.name);
138
+ }
139
+ } else {
140
+ /**
141
+ * export { foo, bar as car }
142
+ */
143
+ output.remove(node.start, node.end);
144
+ for (const spec of node.specifiers) {
145
+ tinyassert(spec.local.type === "Identifier");
146
+ tinyassert(spec.exported.type === "Identifier");
147
+ wrapExport(spec.local.name, spec.exported.name);
148
+ }
149
+ }
150
+ /**
151
+ * export * from './foo'
152
+ */
153
+ if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw Object.assign(/* @__PURE__ */ new Error("unsupported ExportAllDeclaration"), { pos: node.start });
154
+ /**
155
+ * export default function foo() {}
156
+ * export default class Foo {}
157
+ * export default () => {}
158
+ */
159
+ if (node.type === "ExportDefaultDeclaration") {
160
+ validateNonAsyncFunction(node.declaration);
161
+ let localName;
162
+ let isFunction = false;
163
+ let declName;
164
+ let defaultExportIdentifierName;
165
+ if ((node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") && node.declaration.id) {
166
+ localName = node.declaration.id.name;
167
+ output.remove(node.start, node.declaration.start);
168
+ isFunction = node.declaration.type === "FunctionDeclaration";
169
+ declName = node.declaration.id.name;
170
+ } else {
171
+ localName = "$$default";
172
+ output.update(node.start, node.declaration.start, "const $$default = ");
173
+ if (node.declaration.type === "Identifier") defaultExportIdentifierName = node.declaration.name;
174
+ }
175
+ wrapExport(localName, "default", {
176
+ isFunction,
177
+ declName,
178
+ defaultExportIdentifierName
179
+ });
180
+ }
181
+ }
182
+ if (toAppend.length > 0) output.append([
183
+ "",
184
+ ...toAppend,
185
+ ""
186
+ ].join(";\n"));
187
+ return {
188
+ exportNames,
189
+ output
190
+ };
191
+ }
192
+
193
+ //#endregion
194
+ //#region src/transforms/utils.ts
195
+ function hasDirective(body, directive) {
196
+ return !!body.find((stmt) => stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && stmt.expression.value === directive);
197
+ }
198
+ function getExportNames(ast, options) {
199
+ const exportNames = [];
200
+ for (const node of ast.body) {
201
+ if (node.type === "ExportNamedDeclaration") if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration")
202
+ /**
203
+ * export function foo() {}
204
+ */
205
+ exportNames.push(node.declaration.id.name);
206
+ else if (node.declaration.type === "VariableDeclaration")
207
+ /**
208
+ * export const foo = 1, bar = 2
209
+ */
210
+ for (const decl of node.declaration.declarations) exportNames.push(...extract_names(decl.id));
211
+ else node.declaration;
212
+ else
213
+ /**
214
+ * export { foo, bar as car } from './foo'
215
+ * export { foo, bar as car }
216
+ */
217
+ for (const spec of node.specifiers) {
218
+ tinyassert(spec.exported.type === "Identifier");
219
+ exportNames.push(spec.exported.name);
220
+ }
221
+ /**
222
+ * export * from './foo'
223
+ */
224
+ if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw new Error("unsupported ExportAllDeclaration");
225
+ /**
226
+ * export default function foo() {}
227
+ * export default class Foo {}
228
+ * export default () => {}
229
+ */
230
+ if (node.type === "ExportDefaultDeclaration") exportNames.push("default");
231
+ }
232
+ return { exportNames };
233
+ }
234
+
235
+ //#endregion
236
+ //#region src/transforms/proxy-export.ts
237
+ function transformDirectiveProxyExport(ast, options) {
238
+ if (!hasDirective(ast.body, options.directive)) return;
239
+ return transformProxyExport(ast, options);
240
+ }
241
+ function transformProxyExport(ast, options) {
242
+ if (options.keep && typeof options.code !== "string") throw new Error("`keep` option requires `code`");
243
+ const output = new MagicString(options.code ?? " ".repeat(ast.end));
244
+ const exportNames = [];
245
+ function createExport(node, names) {
246
+ exportNames.push(...names);
247
+ const newCode = names.map((name) => (name === "default" ? `export default` : `export const ${name} =`) + ` /* #__PURE__ */ ${options.runtime(name)};\n`).join("");
248
+ output.update(node.start, node.end, newCode);
249
+ }
250
+ function validateNonAsyncFunction(node, ok) {
251
+ if (options.rejectNonAsyncFunction && !ok) throw Object.assign(/* @__PURE__ */ new Error(`unsupported non async function`), { pos: node.start });
252
+ }
253
+ for (const node of ast.body) {
254
+ if (node.type === "ExportNamedDeclaration") {
255
+ if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
256
+ /**
257
+ * export function foo() {}
258
+ */
259
+ validateNonAsyncFunction(node, node.declaration.type === "FunctionDeclaration" && node.declaration.async);
260
+ createExport(node, [node.declaration.id.name]);
261
+ } else if (node.declaration.type === "VariableDeclaration") {
262
+ /**
263
+ * export const foo = 1, bar = 2
264
+ */
265
+ validateNonAsyncFunction(node, node.declaration.declarations.every((decl) => decl.init?.type === "ArrowFunctionExpression" && decl.init.async));
266
+ if (options.keep && options.code) {
267
+ if (node.declaration.declarations.length === 1) {
268
+ const decl = node.declaration.declarations[0];
269
+ if (decl.id.type === "Identifier" && decl.init) {
270
+ const name = decl.id.name;
271
+ const value = options.code.slice(decl.init.start, decl.init.end);
272
+ const newCode = `export const ${name} = /* #__PURE__ */ ${options.runtime(name, { value })};`;
273
+ output.update(node.start, node.end, newCode);
274
+ exportNames.push(name);
275
+ continue;
276
+ }
277
+ }
278
+ }
279
+ const names = node.declaration.declarations.flatMap((decl) => extract_names(decl.id));
280
+ createExport(node, names);
281
+ } else node.declaration;
282
+ else {
283
+ /**
284
+ * export { foo, bar as car } from './foo'
285
+ * export { foo, bar as car }
286
+ */
287
+ const names = [];
288
+ for (const spec of node.specifiers) {
289
+ tinyassert(spec.exported.type === "Identifier");
290
+ names.push(spec.exported.name);
291
+ }
292
+ createExport(node, names);
293
+ }
294
+ continue;
295
+ }
296
+ /**
297
+ * export * from './foo'
298
+ */
299
+ if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw new Error("unsupported ExportAllDeclaration");
300
+ /**
301
+ * export default function foo() {}
302
+ * export default class Foo {}
303
+ * export default () => {}
304
+ */
305
+ if (node.type === "ExportDefaultDeclaration") {
306
+ validateNonAsyncFunction(node, node.declaration.type === "Identifier" || node.declaration.type === "FunctionDeclaration" && node.declaration.async);
307
+ createExport(node, ["default"]);
308
+ continue;
309
+ }
310
+ if (options.keep) continue;
311
+ output.remove(node.start, node.end);
312
+ }
313
+ return {
314
+ exportNames,
315
+ output
316
+ };
317
+ }
318
+
319
+ //#endregion
320
+ //#region src/transforms/server-action.ts
321
+ function transformServerActionServer(input, ast, options) {
322
+ if (hasDirective(ast.body, "use server")) return transformWrapExport(input, ast, options);
323
+ return transformHoistInlineDirective(input, ast, {
324
+ ...options,
325
+ directive: "use server"
326
+ });
327
+ }
328
+
329
+ //#endregion
330
+ export { getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
@@ -1,2 +1,2 @@
1
- import { decryptActionBoundArgs, encryptActionBoundArgs } from "../encryption-runtime-SgJRa9yj.js";
1
+ import { decryptActionBoundArgs, encryptActionBoundArgs } from "../encryption-runtime-BwOew_5N.js";
2
2
  export { decryptActionBoundArgs, encryptActionBoundArgs };
@@ -1,8 +1,8 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import "../shared-CEyKoKAb.js";
2
+ import "../shared-CXg_u-4h.js";
3
3
  import "../encryption-utils-BDwwcMVT.js";
4
- import "../rsc-BfBPoIV8.js";
5
- import "../rsc-VjVw_i-M.js";
6
- import { decryptActionBoundArgs, encryptActionBoundArgs } from "../encryption-runtime-CJUalqt3.js";
4
+ import "../rsc-cp4EenMG.js";
5
+ import "../rsc-DdBcg-Lb.js";
6
+ import { decryptActionBoundArgs, encryptActionBoundArgs } from "../encryption-runtime-CAmm02Ms.js";
7
7
 
8
8
  export { decryptActionBoundArgs, encryptActionBoundArgs };
package/dist/utils/rpc.js CHANGED
@@ -1,3 +1,3 @@
1
- import { createRpcClient, createRpcServer } from "../rpc-tGuLT8PD.js";
1
+ import { createRpcClient, createRpcServer } from "../rpc-CUvSZurk.js";
2
2
 
3
3
  export { createRpcClient, createRpcServer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-rsc",
3
- "version": "0.4.27",
3
+ "version": "0.4.29",
4
4
  "description": "React Server Components (RSC) support for Vite.",
5
5
  "keywords": [
6
6
  "vite",
@@ -21,6 +21,7 @@
21
21
  "./package.json": "./package.json",
22
22
  "./types": "./types/index.d.ts",
23
23
  ".": "./dist/index.js",
24
+ "./transforms": "./dist/transforms/index.js",
24
25
  "./*": "./dist/*.js"
25
26
  },
26
27
  "files": [
@@ -51,7 +52,7 @@
51
52
  "@playwright/test": "^1.55.0",
52
53
  "@tsconfig/strictest": "^2.0.5",
53
54
  "@types/estree": "^1.0.8",
54
- "@types/node": "^22.18.0",
55
+ "@types/node": "^22.18.1",
55
56
  "@types/react": "^19.1.12",
56
57
  "@types/react-dom": "^19.1.9",
57
58
  "@vitejs/plugin-react": "workspace:*",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes