@vitejs/plugin-rsc 0.4.28 → 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-BFcMxUSS.d.ts → plugin-BDdwA9-Y.d.ts} +1 -9
  22. package/dist/{plugin-iKgvucKS.js → plugin-DB5WEabT.js} +29 -339
  23. package/dist/plugin.d.ts +2 -1
  24. package/dist/plugin.js +4 -3
  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
@@ -1,8 +1,9 @@
1
- import { createDebug, tinyassert } from "./dist-DiJnRA1C.js";
1
+ import { createDebug } from "./dist-DiJnRA1C.js";
2
2
  import { vitePluginRscCore } from "./plugin-CZbI4rhS.js";
3
+ import { hasDirective, transformDirectiveProxyExport, transformServerActionServer, transformWrapExport } from "./transforms-D1-2JfCh.js";
3
4
  import { generateEncryptionKey, toBase64 } from "./encryption-utils-BDwwcMVT.js";
4
- import { createRpcServer } from "./rpc-tGuLT8PD.js";
5
- import { parseCssVirtual, parseIdQuery, toCssVirtual } from "./shared-BWHxNw3Q.js";
5
+ import { createRpcServer } from "./rpc-CUvSZurk.js";
6
+ import { parseCssVirtual, parseIdQuery, toCssVirtual } from "./shared-Cwk6fxfN.js";
6
7
  import { createRequire } from "node:module";
7
8
  import assert from "node:assert";
8
9
  import fs from "node:fs";
@@ -15,298 +16,10 @@ import * as vite from "vite";
15
16
  import { defaultServerConditions, isCSSRequest, normalizePath, parseAstAsync } from "vite";
16
17
  import { crawlFrameworkPkgs, findClosestPkgJsonPath } from "vitefu";
17
18
  import { walk } from "estree-walker";
18
- import { analyze, extract_names } from "periscopic";
19
+ import { analyze } from "periscopic";
19
20
  import { stripVTControlCharacters } from "node:util";
20
21
  import { createHash } from "node:crypto";
21
22
 
22
- //#region src/transforms/hoist.ts
23
- function transformHoistInlineDirective(input, ast, { runtime, rejectNonAsyncFunction,...options }) {
24
- const output = new MagicString(input);
25
- const directive = typeof options.directive === "string" ? exactRegex(options.directive) : options.directive;
26
- walk(ast, { enter(node) {
27
- if (node.type === "ExportAllDeclaration") this.remove();
28
- if (node.type === "ExportNamedDeclaration" && !node.declaration) this.remove();
29
- } });
30
- const analyzed = analyze(ast);
31
- const names = [];
32
- walk(ast, { enter(node, parent) {
33
- if ((node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") && node.body.type === "BlockStatement") {
34
- const match = matchDirective(node.body.body, directive);
35
- if (!match) return;
36
- if (!node.async && rejectNonAsyncFunction) throw Object.assign(/* @__PURE__ */ new Error(`"${directive}" doesn't allow non async function`), { pos: node.start });
37
- const scope = analyzed.map.get(node);
38
- tinyassert(scope);
39
- const declName = node.type === "FunctionDeclaration" && node.id.name;
40
- const originalName = declName || parent?.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.id.name || "anonymous_server_function";
41
- const bindVars = [...scope.references].filter((ref) => {
42
- if (ref === declName) return false;
43
- const owner = scope.find_owner(ref);
44
- return owner && owner !== scope && owner !== analyzed.scope;
45
- });
46
- let newParams = [...bindVars, ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
47
- if (bindVars.length > 0 && options.decode) {
48
- newParams = ["$$hoist_encoded", ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
49
- output.appendLeft(node.body.body[0].start, `const [${bindVars.join(",")}] = ${options.decode("$$hoist_encoded")};\n`);
50
- }
51
- const newName = `$$hoist_${names.length}` + (originalName ? `_${originalName}` : "");
52
- names.push(newName);
53
- output.update(node.start, node.body.start, `\n;${options.noExport ? "" : "export "}${node.async ? "async " : ""}function ${newName}(${newParams}) `);
54
- output.appendLeft(node.end, `;\n/* #__PURE__ */ Object.defineProperty(${newName}, "name", { value: ${JSON.stringify(originalName)} });\n`);
55
- output.move(node.start, node.end, input.length);
56
- let newCode = `/* #__PURE__ */ ${runtime(newName, newName, { directiveMatch: match })}`;
57
- if (bindVars.length > 0) {
58
- const bindArgs = options.encode ? options.encode("[" + bindVars.join(", ") + "]") : bindVars.join(", ");
59
- newCode = `${newCode}.bind(null, ${bindArgs})`;
60
- }
61
- if (declName) {
62
- newCode = `const ${declName} = ${newCode};`;
63
- if (parent?.type === "ExportDefaultDeclaration") {
64
- output.remove(parent.start, node.start);
65
- newCode = `${newCode}\nexport default ${declName};`;
66
- }
67
- }
68
- output.appendLeft(node.start, newCode);
69
- }
70
- } });
71
- return {
72
- output,
73
- names
74
- };
75
- }
76
- const exactRegex = (s) => /* @__PURE__ */ new RegExp("^" + s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + "$");
77
- function matchDirective(body, directive) {
78
- for (const stable of body) if (stable.type === "ExpressionStatement" && stable.expression.type === "Literal" && typeof stable.expression.value === "string") {
79
- const match = stable.expression.value.match(directive);
80
- if (match) return match;
81
- }
82
- }
83
-
84
- //#endregion
85
- //#region src/transforms/wrap-export.ts
86
- function transformWrapExport(input, ast, options) {
87
- const output = new MagicString(input);
88
- const exportNames = [];
89
- const toAppend = [];
90
- const filter = options.filter ?? (() => true);
91
- function wrapSimple(start, end, exports) {
92
- exportNames.push(...exports.map((e) => e.name));
93
- 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("");
94
- output.update(start, end, newCode);
95
- output.move(start, end, input.length);
96
- }
97
- function wrapExport(name, exportName, meta = {}) {
98
- exportNames.push(exportName);
99
- if (!filter(exportName, meta)) {
100
- toAppend.push(`export { ${name} as ${exportName} }`);
101
- return;
102
- }
103
- toAppend.push(`const $$wrap_${name} = /* #__PURE__ */ ${options.runtime(name, exportName, meta)}`, `export { $$wrap_${name} as ${exportName} }`);
104
- }
105
- function validateNonAsyncFunction(node) {
106
- if (!options.rejectNonAsyncFunction) return;
107
- 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 });
108
- }
109
- for (const node of ast.body) {
110
- if (node.type === "ExportNamedDeclaration") if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
111
- /**
112
- * export function foo() {}
113
- */
114
- validateNonAsyncFunction(node.declaration);
115
- const name = node.declaration.id.name;
116
- wrapSimple(node.start, node.declaration.start, [{
117
- name,
118
- meta: {
119
- isFunction: true,
120
- declName: name
121
- }
122
- }]);
123
- } else if (node.declaration.type === "VariableDeclaration") {
124
- /**
125
- * export const foo = 1, bar = 2
126
- */
127
- for (const decl of node.declaration.declarations) if (decl.init) validateNonAsyncFunction(decl.init);
128
- if (node.declaration.kind === "const") output.update(node.declaration.start, node.declaration.start + 5, "let");
129
- const names = node.declaration.declarations.flatMap((decl) => extract_names(decl.id));
130
- let isFunction = false;
131
- if (node.declaration.declarations.length === 1) {
132
- const decl = node.declaration.declarations[0];
133
- isFunction = decl.id.type === "Identifier" && (decl.init?.type === "ArrowFunctionExpression" || decl.init?.type === "FunctionExpression");
134
- }
135
- wrapSimple(node.start, node.declaration.start, names.map((name) => ({
136
- name,
137
- meta: {
138
- isFunction,
139
- declName: name
140
- }
141
- })));
142
- } else node.declaration;
143
- else if (node.source) {
144
- /**
145
- * export { foo, bar as car } from './foo'
146
- */
147
- output.remove(node.start, node.end);
148
- for (const spec of node.specifiers) {
149
- tinyassert(spec.local.type === "Identifier");
150
- tinyassert(spec.exported.type === "Identifier");
151
- const name = spec.local.name;
152
- toAppend.push(`import { ${name} as $$import_${name} } from ${node.source.raw}`);
153
- wrapExport(`$$import_${name}`, spec.exported.name);
154
- }
155
- } else {
156
- /**
157
- * export { foo, bar as car }
158
- */
159
- output.remove(node.start, node.end);
160
- for (const spec of node.specifiers) {
161
- tinyassert(spec.local.type === "Identifier");
162
- tinyassert(spec.exported.type === "Identifier");
163
- wrapExport(spec.local.name, spec.exported.name);
164
- }
165
- }
166
- /**
167
- * export * from './foo'
168
- */
169
- if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw Object.assign(/* @__PURE__ */ new Error("unsupported ExportAllDeclaration"), { pos: node.start });
170
- /**
171
- * export default function foo() {}
172
- * export default class Foo {}
173
- * export default () => {}
174
- */
175
- if (node.type === "ExportDefaultDeclaration") {
176
- validateNonAsyncFunction(node.declaration);
177
- let localName;
178
- let isFunction = false;
179
- let declName;
180
- let defaultExportIdentifierName;
181
- if ((node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") && node.declaration.id) {
182
- localName = node.declaration.id.name;
183
- output.remove(node.start, node.declaration.start);
184
- isFunction = node.declaration.type === "FunctionDeclaration";
185
- declName = node.declaration.id.name;
186
- } else {
187
- localName = "$$default";
188
- output.update(node.start, node.declaration.start, "const $$default = ");
189
- if (node.declaration.type === "Identifier") defaultExportIdentifierName = node.declaration.name;
190
- }
191
- wrapExport(localName, "default", {
192
- isFunction,
193
- declName,
194
- defaultExportIdentifierName
195
- });
196
- }
197
- }
198
- if (toAppend.length > 0) output.append([
199
- "",
200
- ...toAppend,
201
- ""
202
- ].join(";\n"));
203
- return {
204
- exportNames,
205
- output
206
- };
207
- }
208
-
209
- //#endregion
210
- //#region src/transforms/utils.ts
211
- function hasDirective(body, directive) {
212
- return !!body.find((stmt) => stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && stmt.expression.value === directive);
213
- }
214
-
215
- //#endregion
216
- //#region src/transforms/proxy-export.ts
217
- function transformDirectiveProxyExport(ast, options) {
218
- if (!hasDirective(ast.body, options.directive)) return;
219
- return transformProxyExport(ast, options);
220
- }
221
- function transformProxyExport(ast, options) {
222
- if (options.keep && typeof options.code !== "string") throw new Error("`keep` option requires `code`");
223
- const output = new MagicString(options.code ?? " ".repeat(ast.end));
224
- const exportNames = [];
225
- function createExport(node, names) {
226
- exportNames.push(...names);
227
- const newCode = names.map((name) => (name === "default" ? `export default` : `export const ${name} =`) + ` /* #__PURE__ */ ${options.runtime(name)};\n`).join("");
228
- output.update(node.start, node.end, newCode);
229
- }
230
- function validateNonAsyncFunction(node, ok) {
231
- if (options.rejectNonAsyncFunction && !ok) throw Object.assign(/* @__PURE__ */ new Error(`unsupported non async function`), { pos: node.start });
232
- }
233
- for (const node of ast.body) {
234
- if (node.type === "ExportNamedDeclaration") {
235
- if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
236
- /**
237
- * export function foo() {}
238
- */
239
- validateNonAsyncFunction(node, node.declaration.type === "FunctionDeclaration" && node.declaration.async);
240
- createExport(node, [node.declaration.id.name]);
241
- } else if (node.declaration.type === "VariableDeclaration") {
242
- /**
243
- * export const foo = 1, bar = 2
244
- */
245
- validateNonAsyncFunction(node, node.declaration.declarations.every((decl) => decl.init?.type === "ArrowFunctionExpression" && decl.init.async));
246
- if (options.keep && options.code) {
247
- if (node.declaration.declarations.length === 1) {
248
- const decl = node.declaration.declarations[0];
249
- if (decl.id.type === "Identifier" && decl.init) {
250
- const name = decl.id.name;
251
- const value = options.code.slice(decl.init.start, decl.init.end);
252
- const newCode = `export const ${name} = /* #__PURE__ */ ${options.runtime(name, { value })};`;
253
- output.update(node.start, node.end, newCode);
254
- exportNames.push(name);
255
- continue;
256
- }
257
- }
258
- }
259
- const names = node.declaration.declarations.flatMap((decl) => extract_names(decl.id));
260
- createExport(node, names);
261
- } else node.declaration;
262
- else {
263
- /**
264
- * export { foo, bar as car } from './foo'
265
- * export { foo, bar as car }
266
- */
267
- const names = [];
268
- for (const spec of node.specifiers) {
269
- tinyassert(spec.exported.type === "Identifier");
270
- names.push(spec.exported.name);
271
- }
272
- createExport(node, names);
273
- }
274
- continue;
275
- }
276
- /**
277
- * export * from './foo'
278
- */
279
- if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw new Error("unsupported ExportAllDeclaration");
280
- /**
281
- * export default function foo() {}
282
- * export default class Foo {}
283
- * export default () => {}
284
- */
285
- if (node.type === "ExportDefaultDeclaration") {
286
- validateNonAsyncFunction(node, node.declaration.type === "Identifier" || node.declaration.type === "FunctionDeclaration" && node.declaration.async);
287
- createExport(node, ["default"]);
288
- continue;
289
- }
290
- if (options.keep) continue;
291
- output.remove(node.start, node.end);
292
- }
293
- return {
294
- exportNames,
295
- output
296
- };
297
- }
298
-
299
- //#endregion
300
- //#region src/transforms/server-action.ts
301
- function transformServerActionServer(input, ast, options) {
302
- if (hasDirective(ast.body, "use server")) return transformWrapExport(input, ast, options);
303
- return transformHoistInlineDirective(input, ast, {
304
- ...options,
305
- directive: "use server"
306
- });
307
- }
308
-
309
- //#endregion
310
23
  //#region src/plugins/vite-utils.ts
311
24
  const VALID_ID_PREFIX = `/@id/`;
312
25
  const NULL_BYTE_PLACEHOLDER = `__x00__`;
@@ -336,8 +49,7 @@ function slash(p) {
336
49
  const isWindows = typeof process !== "undefined" && process.platform === "win32";
337
50
  function injectQuery(url, queryToInject) {
338
51
  const { file, postfix } = splitFileAndPostfix(url);
339
- const normalizedFile = isWindows ? slash(file) : file;
340
- return `${normalizedFile}?${queryToInject}${postfix[0] === "?" ? `&${postfix.slice(1)}` : postfix}`;
52
+ return `${isWindows ? slash(file) : file}?${queryToInject}${postfix[0] === "?" ? `&${postfix.slice(1)}` : postfix}`;
341
53
  }
342
54
  function normalizeResolvedIdToUrl(environment, url, resolved) {
343
55
  const root = environment.config.root;
@@ -371,11 +83,10 @@ function cleanStack(stack) {
371
83
  return stack.split(/\n/).filter((l) => /^\s*at/.test(l)).join("\n");
372
84
  }
373
85
  function evalValue(rawValue) {
374
- const fn = new Function(`
86
+ return new Function(`
375
87
  var console, exports, global, module, process, require
376
88
  return (\n${rawValue}\n)
377
- `);
378
- return fn();
89
+ `)();
379
90
  }
380
91
 
381
92
  //#endregion
@@ -434,8 +145,7 @@ function cjsModuleRunnerPlugin() {
434
145
  if (id.endsWith(".js")) {
435
146
  const pkgJsonPath = await findClosestPkgJsonPath(path.dirname(id));
436
147
  if (pkgJsonPath) {
437
- const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
438
- if (pkgJson.type === "module") return;
148
+ if (JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")).type === "module") return;
439
149
  }
440
150
  }
441
151
  const [, , , hasModuleSyntax] = esModuleLexer.parse(code);
@@ -446,8 +156,7 @@ function cjsModuleRunnerPlugin() {
446
156
  warnedPackages.add(packageKey);
447
157
  }
448
158
  const ast = await parseAstAsync(code);
449
- const result = transformCjsToEsm(code, ast);
450
- const output = result.output;
159
+ const output = transformCjsToEsm(code, ast).output;
451
160
  output.append(`
452
161
  ;__vite_ssr_exportAll__(module.exports);
453
162
  export default module.exports;
@@ -526,9 +235,8 @@ function scanBuildStripPlugin({ manager }) {
526
235
  enforce: "post",
527
236
  async transform(code, _id, _options) {
528
237
  if (!manager.isScanBuild) return;
529
- const output = await transformScanBuildStrip(code);
530
238
  return {
531
- code: output,
239
+ code: await transformScanBuildStrip(code),
532
240
  map: { mappings: "" }
533
241
  };
534
242
  }
@@ -676,8 +384,7 @@ var RscPluginManager = class {
676
384
  };
677
385
  /** @experimental */
678
386
  function getPluginApi(config) {
679
- const plugin = config.plugins.find((p) => p.name === "rsc:minimal");
680
- return plugin?.api;
387
+ return config.plugins.find((p) => p.name === "rsc:minimal")?.api;
681
388
  }
682
389
  /** @experimental */
683
390
  function vitePluginRscMinimal(rscPluginOptions = {}, manager = new RscPluginManager()) {
@@ -891,11 +598,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
891
598
  entryName: "index"
892
599
  };
893
600
  const entryFile = path.join(manager.config.environments[options.environmentName].build.outDir, `${options.entryName}.js`);
894
- const entry = pathToFileURL(entryFile).href;
895
- const mod = await import(
896
- /* @vite-ignore */
897
- entry
898
- );
601
+ const mod = await import(pathToFileURL(entryFile).href);
899
602
  const handler = createRequestListener(mod.default);
900
603
  server.middlewares.use((req, _res, next) => {
901
604
  delete req.headers["accept-encoding"];
@@ -916,8 +619,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
916
619
  if (isCSSRequest(ctx.file)) {
917
620
  if (this.environment.name === "client") return ctx.modules.filter((m) => !(m.id?.includes("?direct") && !m.isSelfAccepting));
918
621
  }
919
- const ids = ctx.modules.map((mod) => mod.id).filter((v) => v !== null);
920
- if (ids.length === 0) return;
622
+ if (ctx.modules.map((mod) => mod.id).filter((v) => v !== null).length === 0) return;
921
623
  if (this.environment.name === "rsc") {
922
624
  for (const mod of ctx.modules) if (mod.type === "js" && mod.id && mod.id in manager.clientReferenceMetaMap) try {
923
625
  await this.environment.transformRequest(mod.url);
@@ -957,9 +659,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
957
659
  });
958
660
  }
959
661
  if (this.environment.name === "client") {
960
- const env = ctx.server.environments.rsc;
961
- const mod = env.moduleGraph.getModuleById(ctx.file);
962
- if (mod) {
662
+ if (ctx.server.environments.rsc.moduleGraph.getModuleById(ctx.file)) {
963
663
  for (const clientMod of ctx.modules) for (const importer of clientMod.importers) if (importer.id && isCSSRequest(importer.id)) await this.environment.reloadModule(importer);
964
664
  return [];
965
665
  }
@@ -1039,8 +739,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
1039
739
  const runnerProxy = new Proxy({}, { get(_target, p, _receiver) {
1040
740
  if (typeof p !== "string" || p === "then") return;
1041
741
  return async (...args) => {
1042
- const mod = await environment.runner.import(resolvedEntry.id);
1043
- return mod[p](...args);
742
+ return (await environment.runner.import(resolvedEntry.id))[p](...args);
1044
743
  };
1045
744
  } });
1046
745
  return createRpcServer(runnerProxy);
@@ -1167,8 +866,7 @@ export default assetsManifest.bootstrapScriptContent;
1167
866
  createVirtualPlugin(VIRTUAL_ENTRIES.browser.slice(8), async function() {
1168
867
  assert(this.environment.mode === "dev");
1169
868
  let code = "";
1170
- const resolved = await this.resolve("/@react-refresh");
1171
- if (resolved) code += `
869
+ if (await this.resolve("/@react-refresh")) code += `
1172
870
  import RefreshRuntime from "/@react-refresh";
1173
871
  RefreshRuntime.injectIntoGlobalHook(window);
1174
872
  window.$RefreshReg$ = () => {};
@@ -1264,8 +962,7 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
1264
962
  importId = id;
1265
963
  referenceKey = hashString(manager.toRelativeId(id));
1266
964
  }
1267
- const transformDirectiveProxyExport_ = withRollupError(this, transformDirectiveProxyExport);
1268
- const result = transformDirectiveProxyExport_(ast, {
965
+ const result = withRollupError(this, transformDirectiveProxyExport)(ast, {
1269
966
  directive: "use client",
1270
967
  code,
1271
968
  keep: !!useClientPluginOptions.keepUseCientProxy,
@@ -1314,14 +1011,14 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
1314
1011
  let code = "";
1315
1012
  manager.clientReferenceGroups = {};
1316
1013
  for (const meta of Object.values(manager.clientReferenceMetaMap)) {
1014
+ if (!meta.serverChunk) continue;
1317
1015
  let name = useClientPluginOptions.clientChunks?.({
1318
1016
  id: meta.importId,
1319
1017
  normalizedId: manager.toRelativeId(meta.importId),
1320
1018
  serverChunk: meta.serverChunk
1321
1019
  }) ?? meta.serverChunk;
1322
1020
  name = cleanUrl(name.replaceAll("..", "__"));
1323
- const group = manager.clientReferenceGroups[name] ??= [];
1324
- group.push(meta);
1021
+ (manager.clientReferenceGroups[name] ??= []).push(meta);
1325
1022
  meta.groupChunkId = `\0virtual:vite-rsc/client-references/group/${name}`;
1326
1023
  }
1327
1024
  debug$1("client-reference-groups", manager.clientReferenceGroups);
@@ -1392,12 +1089,11 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
1392
1089
  if (id.startsWith("\0virtual:vite-rsc/client-package-proxy/")) {
1393
1090
  assert(this.environment.mode === "dev");
1394
1091
  const source = id.slice(39);
1395
- const meta = Object.values(manager.clientReferenceMetaMap).find((v) => v.packageSource === source);
1396
- const exportNames = meta.exportNames;
1397
- return `export {${exportNames.join(",")}} from ${JSON.stringify(source)};\n`;
1092
+ return `export {${Object.values(manager.clientReferenceMetaMap).find((v) => v.packageSource === source).exportNames.join(",")}} from ${JSON.stringify(source)};\n`;
1398
1093
  }
1399
1094
  },
1400
1095
  generateBundle(_options, bundle) {
1096
+ if (manager.isScanBuild) return;
1401
1097
  if (this.environment.name !== serverEnvironmentName) return;
1402
1098
  for (const chunk of Object.values(bundle)) if (chunk.type === "chunk") {
1403
1099
  const metas = [];
@@ -1432,8 +1128,7 @@ function customOptimizerMetadataPlugin({ setMetadata }) {
1432
1128
  setup(build) {
1433
1129
  build.onEnd((result) => {
1434
1130
  if (!result.metafile?.inputs || !build.initialOptions.outdir) return;
1435
- const ids = Object.keys(result.metafile.inputs);
1436
- const metadata = { ids };
1131
+ const metadata = { ids: Object.keys(result.metafile.inputs) };
1437
1132
  setMetadata(metadata);
1438
1133
  fs.writeFileSync(path.join(build.initialOptions.outdir, MEATADATA_FILE), JSON.stringify(metadata, null, 2));
1439
1134
  });
@@ -1445,8 +1140,7 @@ function customOptimizerMetadataPlugin({ setMetadata }) {
1445
1140
  name: "vite-rsc-metafile",
1446
1141
  writeBundle(options) {
1447
1142
  assert(options.dir);
1448
- const ids = [...this.getModuleIds()].map((id) => path.relative(process.cwd(), id));
1449
- const metadata = { ids };
1143
+ const metadata = { ids: [...this.getModuleIds()].map((id) => path.relative(process.cwd(), id)) };
1450
1144
  setMetadata(metadata);
1451
1145
  fs.writeFileSync(path.join(options.dir, MEATADATA_FILE), JSON.stringify(metadata, null, 2));
1452
1146
  }
@@ -1565,8 +1259,7 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
1565
1259
  delete manager.serverReferenceMetaMap[id];
1566
1260
  return;
1567
1261
  }
1568
- const transformDirectiveProxyExport_ = withRollupError(this, transformDirectiveProxyExport);
1569
- const result = transformDirectiveProxyExport_(ast, {
1262
+ const result = withRollupError(this, transformDirectiveProxyExport)(ast, {
1570
1263
  code,
1571
1264
  runtime: (name$1) => `$$ReactClient.createServerReference(${JSON.stringify(getNormalizedId() + "#" + name$1)},$$ReactClient.callServer, undefined, ` + (this.environment.mode === "dev" ? `$$ReactClient.findSourceMapURL,` : "undefined,") + `${JSON.stringify(name$1)})`,
1572
1265
  directive: "use server",
@@ -1735,8 +1428,7 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
1735
1428
  if (options === false) return false;
1736
1429
  if (options?.filter && !options.filter(filename)) return false;
1737
1430
  if (!/\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)\b/.test(code) || !/\.[tj]sx?$/.test(filename)) return false;
1738
- const result = esModuleLexer.parse(code);
1739
- if (!result[0].some((i) => i.t === 1 && i.n && isCSSRequest(i.n))) return false;
1431
+ if (!esModuleLexer.parse(code)[0].some((i) => i.t === 1 && i.n && isCSSRequest(i.n))) return false;
1740
1432
  return (_name, meta) => !!(meta.isFunction && meta.declName && /^[A-Z]/.test(meta.declName) || meta.defaultExportIdentifierName && /^[A-Z]/.test(meta.defaultExportIdentifierName));
1741
1433
  }
1742
1434
  return [
@@ -1835,8 +1527,7 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
1835
1527
  assert(this.environment.name === "rsc");
1836
1528
  const importer = parsed.id;
1837
1529
  if (this.environment.mode === "dev") {
1838
- const result = collectCss(server.environments.rsc, importer);
1839
- const cssHrefs = result.hrefs.map((href) => href.slice(1));
1530
+ const cssHrefs = collectCss(server.environments.rsc, importer).hrefs.map((href) => href.slice(1));
1840
1531
  const jsHrefs = [`@id/__x00__${toCssVirtual({
1841
1532
  id: importer,
1842
1533
  type: "rsc-browser"
@@ -1859,8 +1550,7 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
1859
1550
  assert(this.environment.name === "client");
1860
1551
  assert(this.environment.mode === "dev");
1861
1552
  const importer = parsed.id;
1862
- const result = collectCss(server.environments.rsc, importer);
1863
- let code = result.ids.map((id$1) => id$1.replace(/^\0/, "")).map((id$1) => `import ${JSON.stringify(id$1)};\n`).join("");
1553
+ let code = collectCss(server.environments.rsc, importer).ids.map((id$1) => id$1.replace(/^\0/, "")).map((id$1) => `import ${JSON.stringify(id$1)};\n`).join("");
1864
1554
  code += `if (import.meta.hot) { import.meta.hot.accept() }\n`;
1865
1555
  return code;
1866
1556
  }
@@ -1979,4 +1669,4 @@ function __vite_rsc_wrap_css__(value, name) {
1979
1669
  }
1980
1670
 
1981
1671
  //#endregion
1982
- export { getPluginApi, transformHoistInlineDirective, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal };
1672
+ export { getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal };
package/dist/plugin.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- import { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-BFcMxUSS.js";
1
+ import "./index-BH1wcQPN.js";
2
+ import { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-BDdwA9-Y.js";
2
3
  export { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
package/dist/plugin.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import "./dist-DiJnRA1C.js";
2
2
  import "./plugin-CZbI4rhS.js";
3
- import { getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-iKgvucKS.js";
3
+ import "./transforms-D1-2JfCh.js";
4
4
  import "./encryption-utils-BDwwcMVT.js";
5
- import "./rpc-tGuLT8PD.js";
6
- import "./shared-BWHxNw3Q.js";
5
+ import "./rpc-CUvSZurk.js";
6
+ import { getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-DB5WEabT.js";
7
+ import "./shared-Cwk6fxfN.js";
7
8
 
8
9
  export { vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
@@ -1,4 +1,4 @@
1
- import { CallServerCallback } from "../index-QWzVHuya.js";
2
- import { setRequireModule } from "../browser-CuwQIlVY.js";
3
- import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "../browser-mbRygLxB.js";
1
+ import { CallServerCallback } from "../index-CrcbP1rd.js";
2
+ import { setRequireModule } from "../browser-CyGTajab.js";
3
+ import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "../browser-DUDACP5e.js";
4
4
  export { CallServerCallback, callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
@@ -1,6 +1,6 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import "../shared-CEyKoKAb.js";
3
- import { setRequireModule } from "../browser-BhJd-Orx.js";
2
+ import "../shared-CXg_u-4h.js";
3
+ import { setRequireModule } from "../browser-7NhxQxuk.js";
4
4
  import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "../browser-D8OPzpF5.js";
5
5
 
6
6
  export { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
@@ -1,4 +1,4 @@
1
- import "../index-QWzVHuya.js";
2
- import { loadServerAction, setRequireModule } from "../rsc-CxDPDiLz.js";
3
- import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "../rsc-CFtzqEG8.js";
1
+ import "../index-CrcbP1rd.js";
2
+ import { loadServerAction, setRequireModule } from "../rsc-BeJKxeMX.js";
3
+ import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "../rsc-CpPqIkYr.js";
4
4
  export { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
package/dist/react/rsc.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import "../shared-CEyKoKAb.js";
3
- import { loadServerAction, setRequireModule } from "../rsc-BfBPoIV8.js";
4
- import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "../rsc-VjVw_i-M.js";
2
+ import "../shared-CXg_u-4h.js";
3
+ import { loadServerAction, setRequireModule } from "../rsc-cp4EenMG.js";
4
+ import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "../rsc-DdBcg-Lb.js";
5
5
 
6
6
  export { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
@@ -1,4 +1,4 @@
1
- import "../index-QWzVHuya.js";
2
- import { setRequireModule } from "../ssr-BoNKka-5.js";
3
- import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "../ssr-D6GTzOzx.js";
1
+ import "../index-CrcbP1rd.js";
2
+ import { setRequireModule } from "../ssr-Bv84RACl.js";
3
+ import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "../ssr-CXrYz0RZ.js";
4
4
  export { callServer, createFromReadableStream, createServerReference, findSourceMapURL, setRequireModule };
package/dist/react/ssr.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "../dist-DiJnRA1C.js";
2
- import "../shared-CEyKoKAb.js";
3
- import { setRequireModule } from "../ssr--rFiBtws.js";
4
- import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "../ssr-BEKKb_cw.js";
2
+ import "../shared-CXg_u-4h.js";
3
+ import { setRequireModule } from "../ssr-CMFFChNQ.js";
4
+ import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "../ssr-D8iPOYvE.js";
5
5
 
6
6
  export { callServer, createFromReadableStream, createServerReference, findSourceMapURL, setRequireModule };
@@ -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