@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
@@ -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
  }
@@ -675,11 +383,16 @@ var RscPluginManager = class {
675
383
  }
676
384
  };
677
385
  /** @experimental */
386
+ function getPluginApi(config) {
387
+ return config.plugins.find((p) => p.name === "rsc:minimal")?.api;
388
+ }
389
+ /** @experimental */
678
390
  function vitePluginRscMinimal(rscPluginOptions = {}, manager = new RscPluginManager()) {
679
391
  return [
680
392
  {
681
393
  name: "rsc:minimal",
682
394
  enforce: "pre",
395
+ api: { manager },
683
396
  async config() {
684
397
  await esModuleLexer.init;
685
398
  },
@@ -703,7 +416,8 @@ function vitePluginRscMinimal(rscPluginOptions = {}, manager = new RscPluginMana
703
416
  ...vitePluginRscCore(),
704
417
  ...vitePluginUseClient(rscPluginOptions, manager),
705
418
  ...vitePluginUseServer(rscPluginOptions, manager),
706
- ...vitePluginDefineEncryptionKey(rscPluginOptions)
419
+ ...vitePluginDefineEncryptionKey(rscPluginOptions),
420
+ scanBuildStripPlugin({ manager })
707
421
  ];
708
422
  }
709
423
  function vitePluginRsc(rscPluginOptions = {}) {
@@ -884,11 +598,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
884
598
  entryName: "index"
885
599
  };
886
600
  const entryFile = path.join(manager.config.environments[options.environmentName].build.outDir, `${options.entryName}.js`);
887
- const entry = pathToFileURL(entryFile).href;
888
- const mod = await import(
889
- /* @vite-ignore */
890
- entry
891
- );
601
+ const mod = await import(pathToFileURL(entryFile).href);
892
602
  const handler = createRequestListener(mod.default);
893
603
  server.middlewares.use((req, _res, next) => {
894
604
  delete req.headers["accept-encoding"];
@@ -909,8 +619,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
909
619
  if (isCSSRequest(ctx.file)) {
910
620
  if (this.environment.name === "client") return ctx.modules.filter((m) => !(m.id?.includes("?direct") && !m.isSelfAccepting));
911
621
  }
912
- const ids = ctx.modules.map((mod) => mod.id).filter((v) => v !== null);
913
- if (ids.length === 0) return;
622
+ if (ctx.modules.map((mod) => mod.id).filter((v) => v !== null).length === 0) return;
914
623
  if (this.environment.name === "rsc") {
915
624
  for (const mod of ctx.modules) if (mod.type === "js" && mod.id && mod.id in manager.clientReferenceMetaMap) try {
916
625
  await this.environment.transformRequest(mod.url);
@@ -950,9 +659,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
950
659
  });
951
660
  }
952
661
  if (this.environment.name === "client") {
953
- const env = ctx.server.environments.rsc;
954
- const mod = env.moduleGraph.getModuleById(ctx.file);
955
- if (mod) {
662
+ if (ctx.server.environments.rsc.moduleGraph.getModuleById(ctx.file)) {
956
663
  for (const clientMod of ctx.modules) for (const importer of clientMod.importers) if (importer.id && isCSSRequest(importer.id)) await this.environment.reloadModule(importer);
957
664
  return [];
958
665
  }
@@ -1019,8 +726,8 @@ function vitePluginRsc(rscPluginOptions = {}) {
1019
726
  },
1020
727
  {
1021
728
  name: "vite-rsc-load-module-dev-proxy",
1022
- apply: () => !!rscPluginOptions.loadModuleDevProxy,
1023
729
  configureServer(server) {
730
+ if (!rscPluginOptions.loadModuleDevProxy) return;
1024
731
  async function createHandler(url) {
1025
732
  const { environmentName, entryName } = Object.fromEntries(url.searchParams);
1026
733
  assert(environmentName);
@@ -1032,8 +739,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
1032
739
  const runnerProxy = new Proxy({}, { get(_target, p, _receiver) {
1033
740
  if (typeof p !== "string" || p === "then") return;
1034
741
  return async (...args) => {
1035
- const mod = await environment.runner.import(resolvedEntry.id);
1036
- return mod[p](...args);
742
+ return (await environment.runner.import(resolvedEntry.id))[p](...args);
1037
743
  };
1038
744
  } });
1039
745
  return createRpcServer(runnerProxy);
@@ -1160,8 +866,7 @@ export default assetsManifest.bootstrapScriptContent;
1160
866
  createVirtualPlugin(VIRTUAL_ENTRIES.browser.slice(8), async function() {
1161
867
  assert(this.environment.mode === "dev");
1162
868
  let code = "";
1163
- const resolved = await this.resolve("/@react-refresh");
1164
- if (resolved) code += `
869
+ if (await this.resolve("/@react-refresh")) code += `
1165
870
  import RefreshRuntime from "/@react-refresh";
1166
871
  RefreshRuntime.injectIntoGlobalHook(window);
1167
872
  window.$RefreshReg$ = () => {};
@@ -1257,8 +962,7 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
1257
962
  importId = id;
1258
963
  referenceKey = hashString(manager.toRelativeId(id));
1259
964
  }
1260
- const transformDirectiveProxyExport_ = withRollupError(this, transformDirectiveProxyExport);
1261
- const result = transformDirectiveProxyExport_(ast, {
965
+ const result = withRollupError(this, transformDirectiveProxyExport)(ast, {
1262
966
  directive: "use client",
1263
967
  code,
1264
968
  keep: !!useClientPluginOptions.keepUseCientProxy,
@@ -1307,14 +1011,14 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
1307
1011
  let code = "";
1308
1012
  manager.clientReferenceGroups = {};
1309
1013
  for (const meta of Object.values(manager.clientReferenceMetaMap)) {
1014
+ if (!meta.serverChunk) continue;
1310
1015
  let name = useClientPluginOptions.clientChunks?.({
1311
1016
  id: meta.importId,
1312
1017
  normalizedId: manager.toRelativeId(meta.importId),
1313
1018
  serverChunk: meta.serverChunk
1314
1019
  }) ?? meta.serverChunk;
1315
1020
  name = cleanUrl(name.replaceAll("..", "__"));
1316
- const group = manager.clientReferenceGroups[name] ??= [];
1317
- group.push(meta);
1021
+ (manager.clientReferenceGroups[name] ??= []).push(meta);
1318
1022
  meta.groupChunkId = `\0virtual:vite-rsc/client-references/group/${name}`;
1319
1023
  }
1320
1024
  debug$1("client-reference-groups", manager.clientReferenceGroups);
@@ -1385,12 +1089,11 @@ function vitePluginUseClient(useClientPluginOptions, manager) {
1385
1089
  if (id.startsWith("\0virtual:vite-rsc/client-package-proxy/")) {
1386
1090
  assert(this.environment.mode === "dev");
1387
1091
  const source = id.slice(39);
1388
- const meta = Object.values(manager.clientReferenceMetaMap).find((v) => v.packageSource === source);
1389
- const exportNames = meta.exportNames;
1390
- 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`;
1391
1093
  }
1392
1094
  },
1393
1095
  generateBundle(_options, bundle) {
1096
+ if (manager.isScanBuild) return;
1394
1097
  if (this.environment.name !== serverEnvironmentName) return;
1395
1098
  for (const chunk of Object.values(bundle)) if (chunk.type === "chunk") {
1396
1099
  const metas = [];
@@ -1425,8 +1128,7 @@ function customOptimizerMetadataPlugin({ setMetadata }) {
1425
1128
  setup(build) {
1426
1129
  build.onEnd((result) => {
1427
1130
  if (!result.metafile?.inputs || !build.initialOptions.outdir) return;
1428
- const ids = Object.keys(result.metafile.inputs);
1429
- const metadata = { ids };
1131
+ const metadata = { ids: Object.keys(result.metafile.inputs) };
1430
1132
  setMetadata(metadata);
1431
1133
  fs.writeFileSync(path.join(build.initialOptions.outdir, MEATADATA_FILE), JSON.stringify(metadata, null, 2));
1432
1134
  });
@@ -1438,8 +1140,7 @@ function customOptimizerMetadataPlugin({ setMetadata }) {
1438
1140
  name: "vite-rsc-metafile",
1439
1141
  writeBundle(options) {
1440
1142
  assert(options.dir);
1441
- const ids = [...this.getModuleIds()].map((id) => path.relative(process.cwd(), id));
1442
- const metadata = { ids };
1143
+ const metadata = { ids: [...this.getModuleIds()].map((id) => path.relative(process.cwd(), id)) };
1443
1144
  setMetadata(metadata);
1444
1145
  fs.writeFileSync(path.join(options.dir, MEATADATA_FILE), JSON.stringify(metadata, null, 2));
1445
1146
  }
@@ -1487,7 +1188,7 @@ function vitePluginDefineEncryptionKey(useServerPluginOptions) {
1487
1188
  },
1488
1189
  renderChunk(code, chunk) {
1489
1190
  if (code.includes(KEY_PLACEHOLDER)) {
1490
- assert.equal(this.environment.name, "rsc");
1191
+ assert.equal(this.environment.name, serverEnvironmentName);
1491
1192
  emitEncryptionKey = true;
1492
1193
  const normalizedPath = normalizeRelativePath(path.relative(path.join(chunk.fileName, ".."), KEY_FILE));
1493
1194
  const replacement = `import(${JSON.stringify(normalizedPath)}).then(__m => __m.default)`;
@@ -1496,7 +1197,7 @@ function vitePluginDefineEncryptionKey(useServerPluginOptions) {
1496
1197
  }
1497
1198
  },
1498
1199
  writeBundle() {
1499
- if (this.environment.name === "rsc" && emitEncryptionKey) fs.writeFileSync(path.join(this.environment.config.build.outDir, KEY_FILE), `export default ${defineEncryptionKey};\n`);
1200
+ if (this.environment.name === serverEnvironmentName && emitEncryptionKey) fs.writeFileSync(path.join(this.environment.config.build.outDir, KEY_FILE), `export default ${defineEncryptionKey};\n`);
1500
1201
  }
1501
1202
  }];
1502
1203
  }
@@ -1558,8 +1259,7 @@ function vitePluginUseServer(useServerPluginOptions, manager) {
1558
1259
  delete manager.serverReferenceMetaMap[id];
1559
1260
  return;
1560
1261
  }
1561
- const transformDirectiveProxyExport_ = withRollupError(this, transformDirectiveProxyExport);
1562
- const result = transformDirectiveProxyExport_(ast, {
1262
+ const result = withRollupError(this, transformDirectiveProxyExport)(ast, {
1563
1263
  code,
1564
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)})`,
1565
1265
  directive: "use server",
@@ -1728,8 +1428,7 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
1728
1428
  if (options === false) return false;
1729
1429
  if (options?.filter && !options.filter(filename)) return false;
1730
1430
  if (!/\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)\b/.test(code) || !/\.[tj]sx?$/.test(filename)) return false;
1731
- const result = esModuleLexer.parse(code);
1732
- 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;
1733
1432
  return (_name, meta) => !!(meta.isFunction && meta.declName && /^[A-Z]/.test(meta.declName) || meta.defaultExportIdentifierName && /^[A-Z]/.test(meta.defaultExportIdentifierName));
1734
1433
  }
1735
1434
  return [
@@ -1828,8 +1527,7 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
1828
1527
  assert(this.environment.name === "rsc");
1829
1528
  const importer = parsed.id;
1830
1529
  if (this.environment.mode === "dev") {
1831
- const result = collectCss(server.environments.rsc, importer);
1832
- const cssHrefs = result.hrefs.map((href) => href.slice(1));
1530
+ const cssHrefs = collectCss(server.environments.rsc, importer).hrefs.map((href) => href.slice(1));
1833
1531
  const jsHrefs = [`@id/__x00__${toCssVirtual({
1834
1532
  id: importer,
1835
1533
  type: "rsc-browser"
@@ -1852,8 +1550,7 @@ function vitePluginRscCss(rscCssOptions = {}, manager) {
1852
1550
  assert(this.environment.name === "client");
1853
1551
  assert(this.environment.mode === "dev");
1854
1552
  const importer = parsed.id;
1855
- const result = collectCss(server.environments.rsc, importer);
1856
- 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("");
1857
1554
  code += `if (import.meta.hot) { import.meta.hot.accept() }\n`;
1858
1555
  return code;
1859
1556
  }
@@ -1972,4 +1669,4 @@ function __vite_rsc_wrap_css__(value, name) {
1972
1669
  }
1973
1670
 
1974
1671
  //#endregion
1975
- export { transformHoistInlineDirective, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal };
1672
+ export { getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal };
package/dist/plugin.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- import { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-Be24jgQb.js";
2
- export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, vitePluginRsc as default, transformRscCssExport, vitePluginRscMinimal };
1
+ import "./index-BH1wcQPN.js";
2
+ import { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-BDdwA9-Y.js";
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 { transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-CtdHIozK.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
- export { vitePluginRsc as default, transformRscCssExport, vitePluginRscMinimal };
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 };