@vitejs/plugin-rsc 0.5.21 → 0.5.23

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 (55) hide show
  1. package/dist/browser-CUMAmYC3.d.ts +6 -0
  2. package/dist/browser.d.ts +2 -2
  3. package/dist/browser.js +1 -3
  4. package/dist/{chunk-f2BShn47.js → chunk-BYIdrdsR.js} +8 -14
  5. package/dist/cjs-BdahOUyh.js +115 -0
  6. package/dist/core/browser.d.ts +1 -5
  7. package/dist/core/browser.js +3 -5
  8. package/dist/core/plugin.js +1 -2
  9. package/dist/core/rsc.d.ts +1 -1
  10. package/dist/core/rsc.js +4 -6
  11. package/dist/core/ssr.d.ts +1 -1
  12. package/dist/core/ssr.js +3 -5
  13. package/dist/{dist-yW9-EeG1.js → dist-rz-Bnebz.js} +1 -2
  14. package/dist/{encryption-utils-Bk5eKdu6.js → encryption-utils-BblioYEx.js} +1 -2
  15. package/dist/{server-action-B2zS9t-J.d.ts → index-2GoUFmVR.d.ts} +34 -1
  16. package/dist/index-D2a5dlVU.d.ts +70 -0
  17. package/dist/index.d.ts +1 -3
  18. package/dist/index.js +2 -6
  19. package/dist/{picocolors-B0A1T24z.js → picocolors-B6RAUUd2.js} +2 -5
  20. package/dist/plugin-DGxRH4Nv.d.ts +185 -0
  21. package/dist/plugin-DMfc_Eqq.js +1944 -0
  22. package/dist/plugin.d.ts +2 -179
  23. package/dist/plugin.js +2 -1468
  24. package/dist/plugins/cjs.js +2 -64
  25. package/dist/react/browser.d.ts +6 -6
  26. package/dist/react/browser.js +1 -3
  27. package/dist/react/rsc.d.ts +7 -6
  28. package/dist/react/rsc.js +2 -6
  29. package/dist/react/ssr.d.ts +2 -1
  30. package/dist/react/ssr.js +1 -3
  31. package/dist/rsc.d.ts +1 -3
  32. package/dist/rsc.js +2 -4
  33. package/dist/scope-DKCDtt0O.js +211 -0
  34. package/dist/{shared-Dhw3vs8e.js → shared-BViDMJTQ.js} +2 -3
  35. package/dist/{shared-d80_k_tn.js → shared-DeahDSXi.js} +1 -2
  36. package/dist/ssr.d.ts +1 -3
  37. package/dist/ssr.js +2 -4
  38. package/dist/transforms/index.d.ts +2 -2
  39. package/dist/transforms/index.js +367 -3
  40. package/dist/utils/encryption-runtime.js +3 -5
  41. package/dist/utils/rpc.js +1 -3
  42. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.browser.development.js +2 -2
  43. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.browser.development.js +3 -6
  44. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.browser.production.js +3 -6
  45. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.edge.development.js +3 -6
  46. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.edge.production.js +3 -6
  47. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.development.js +3 -6
  48. package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.production.js +3 -6
  49. package/dist/vendor/react-server-dom/package.json +3 -3
  50. package/package.json +12 -13
  51. package/dist/cjs-v2jRTNln.js +0 -59
  52. package/dist/import-environment-B994HXEc.d.ts +0 -11
  53. package/dist/index-BIbdRBfk.d.ts +0 -26
  54. package/dist/server-action-JkEy-6yW.js +0 -344
  55. package/dist/validate-import-DJumtHRw.js +0 -498
@@ -1,59 +0,0 @@
1
- import path from "node:path";
2
- import { fileURLToPath, pathToFileURL } from "node:url";
3
- import MagicString from "magic-string";
4
- import { walk } from "estree-walker";
5
- import { analyze } from "periscopic";
6
-
7
- //#region src/transforms/cjs.ts
8
- function __cjs_interop__(m) {
9
- return m.__cjs_module_runner_transform || "default" in m && Object.keys(m).every((k) => k === "default" || m[k] === m.default[k]) ? m.default : m;
10
- }
11
- const CJS_INTEROP_HELPER = __cjs_interop__.toString().replace(/\n\s*/g, "");
12
- function transformCjsToEsm(code, ast, options) {
13
- const output = new MagicString(code);
14
- const analyzed = analyze(ast);
15
- const parentNodes = [];
16
- const hoistedCodes = [];
17
- let hoistIndex = 0;
18
- walk(ast, {
19
- enter(node) {
20
- parentNodes.push(node);
21
- if (node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "require" && node.arguments.length === 1) {
22
- let isTopLevel = true;
23
- for (const parent of parentNodes) {
24
- if (parent.type === "FunctionExpression" || parent.type === "FunctionDeclaration" || parent.type === "ArrowFunctionExpression") isTopLevel = false;
25
- const scope = analyzed.map.get(parent);
26
- if (scope && scope.declarations.has("require")) return;
27
- }
28
- if (isTopLevel) {
29
- output.update(node.start, node.callee.end, "(__cjs_interop__(await import");
30
- output.appendRight(node.end, "))");
31
- } else {
32
- const hoisted = `__cjs_to_esm_hoist_${hoistIndex}`;
33
- const importee = code.slice(node.arguments[0].start, node.arguments[0].end);
34
- hoistedCodes.push(`const ${hoisted} = __cjs_interop__(await import(${importee}));\n`);
35
- output.update(node.start, node.end, hoisted);
36
- hoistIndex++;
37
- }
38
- }
39
- },
40
- leave() {
41
- parentNodes.pop();
42
- }
43
- });
44
- for (const hoisted of hoistedCodes.reverse()) output.prepend(hoisted);
45
- if (output.hasChanged()) output.prepend(`${CJS_INTEROP_HELPER}\n`);
46
- output.prepend(`let exports = {}; const module = { exports };\n`);
47
- const __filename = fileURLToPath(pathToFileURL(options.id).href);
48
- const __dirname = path.dirname(__filename);
49
- output.prepend(`let __filename = ${JSON.stringify(__filename)}; let __dirname = ${JSON.stringify(__dirname)};\n`);
50
- output.append(`
51
- ;__vite_ssr_exportAll__(module.exports);
52
- export default module.exports;
53
- export const __cjs_module_runner_transform = true;
54
- `);
55
- return { output };
56
- }
57
-
58
- //#endregion
59
- export { transformCjsToEsm as t };
@@ -1,11 +0,0 @@
1
- import { Plugin, ResolvedConfig } from "vite";
2
-
3
- //#region src/plugins/import-environment.d.ts
4
- type EnvironmentImportMeta = {
5
- resolvedId: string;
6
- targetEnv: string;
7
- sourceEnv: string;
8
- specifier: string;
9
- };
10
- //#endregion
11
- export { EnvironmentImportMeta as t };
@@ -1,26 +0,0 @@
1
- //#region src/types/index.d.ts
2
- interface ImportManifestEntry {
3
- id: string;
4
- name: string;
5
- chunks: string[];
6
- async?: boolean;
7
- }
8
- interface BundlerConfig {
9
- [bundlerId: string]: ImportManifestEntry;
10
- }
11
- type ModuleMap = {
12
- [id: string]: {
13
- [exportName: string]: ImportManifestEntry;
14
- };
15
- };
16
- interface ServerConsumerManifest {
17
- moduleMap?: ModuleMap;
18
- serverModuleMap?: BundlerConfig;
19
- moduleLoading?: {
20
- prefix: string;
21
- crossOriign?: string;
22
- };
23
- }
24
- type CallServerCallback = (id: string, args: unknown[]) => unknown;
25
- //#endregion
26
- export { ServerConsumerManifest as i, CallServerCallback as n, ModuleMap as r, BundlerConfig as t };
@@ -1,344 +0,0 @@
1
- import { i as tinyassert } from "./dist-yW9-EeG1.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
- if (!input.endsWith("\n")) input += "\n";
9
- const output = new MagicString(input);
10
- const directive = typeof options.directive === "string" ? exactRegex(options.directive) : options.directive;
11
- walk(ast, { enter(node) {
12
- if (node.type === "ExportAllDeclaration") this.remove();
13
- if (node.type === "ExportNamedDeclaration" && !node.declaration) this.remove();
14
- } });
15
- const analyzed = analyze(ast);
16
- const names = [];
17
- walk(ast, { enter(node, parent) {
18
- if ((node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") && node.body.type === "BlockStatement") {
19
- const match = matchDirective(node.body.body, directive)?.match;
20
- if (!match) return;
21
- if (!node.async && rejectNonAsyncFunction) throw Object.assign(/* @__PURE__ */ new Error(`"${directive}" doesn't allow non async function`), { pos: node.start });
22
- const scope = analyzed.map.get(node);
23
- tinyassert(scope);
24
- const declName = node.type === "FunctionDeclaration" && node.id.name;
25
- const originalName = declName || parent?.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.id.name || "anonymous_server_function";
26
- const bindVars = [...scope.references].filter((ref) => {
27
- if (ref === declName) return false;
28
- const owner = scope.find_owner(ref);
29
- return owner && owner !== scope && owner !== analyzed.scope;
30
- });
31
- let newParams = [...bindVars, ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
32
- if (bindVars.length > 0 && options.decode) {
33
- newParams = ["$$hoist_encoded", ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
34
- output.appendLeft(node.body.body[0].start, `const [${bindVars.join(",")}] = ${options.decode("$$hoist_encoded")};\n`);
35
- }
36
- const newName = `$$hoist_${names.length}` + (originalName ? `_${originalName}` : "");
37
- names.push(newName);
38
- output.update(node.start, node.body.start, `\n;${options.noExport ? "" : "export "}${node.async ? "async " : ""}function ${newName}(${newParams}) `);
39
- output.appendLeft(node.end, `;\n/* #__PURE__ */ Object.defineProperty(${newName}, "name", { value: ${JSON.stringify(originalName)} });\n`);
40
- output.move(node.start, node.end, input.length);
41
- let newCode = `/* #__PURE__ */ ${runtime(newName, newName, { directiveMatch: match })}`;
42
- if (bindVars.length > 0) {
43
- const bindArgs = options.encode ? options.encode("[" + bindVars.join(", ") + "]") : bindVars.join(", ");
44
- newCode = `${newCode}.bind(null, ${bindArgs})`;
45
- }
46
- if (declName) {
47
- newCode = `const ${declName} = ${newCode};`;
48
- if (parent?.type === "ExportDefaultDeclaration") {
49
- output.remove(parent.start, node.start);
50
- newCode = `${newCode}\nexport default ${declName};`;
51
- }
52
- }
53
- output.appendLeft(node.start, newCode);
54
- }
55
- } });
56
- return {
57
- output,
58
- names
59
- };
60
- }
61
- const exactRegex = (s) => new RegExp("^" + s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + "$");
62
- function matchDirective(body, directive) {
63
- for (const stmt of body) if (stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string") {
64
- const match = stmt.expression.value.match(directive);
65
- if (match) return {
66
- match,
67
- node: stmt.expression
68
- };
69
- }
70
- }
71
- function findDirectives(ast, directive) {
72
- const directiveRE = exactRegex(directive);
73
- const nodes = [];
74
- walk(ast, { enter(node) {
75
- if (node.type === "Program" || node.type === "BlockStatement") {
76
- const match = matchDirective(node.body, directiveRE);
77
- if (match) nodes.push(match.node);
78
- }
79
- } });
80
- return nodes;
81
- }
82
-
83
- //#endregion
84
- //#region src/transforms/wrap-export.ts
85
- function transformWrapExport(input, ast, options) {
86
- const output = new MagicString(input);
87
- const exportNames = [];
88
- const toAppend = [];
89
- const filter = options.filter ?? (() => true);
90
- function wrapSimple(start, end, exports) {
91
- exportNames.push(...exports.map((e) => e.name));
92
- 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("");
93
- output.update(start, end, newCode);
94
- output.move(start, end, input.length);
95
- }
96
- function wrapExport(name, exportName, meta = {}) {
97
- exportNames.push(exportName);
98
- if (!filter(exportName, meta)) {
99
- toAppend.push(`export { ${name} as ${exportName} }`);
100
- return;
101
- }
102
- toAppend.push(`const $$wrap_${name} = /* #__PURE__ */ ${options.runtime(name, exportName, meta)}`, `export { $$wrap_${name} as ${exportName} }`);
103
- }
104
- function validateNonAsyncFunction(node) {
105
- if (!options.rejectNonAsyncFunction) return;
106
- 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 });
107
- }
108
- for (const node of ast.body) {
109
- if (node.type === "ExportNamedDeclaration") if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
110
- /**
111
- * export function foo() {}
112
- */
113
- validateNonAsyncFunction(node.declaration);
114
- const name = node.declaration.id.name;
115
- wrapSimple(node.start, node.declaration.start, [{
116
- name,
117
- meta: {
118
- isFunction: true,
119
- declName: name
120
- }
121
- }]);
122
- } else if (node.declaration.type === "VariableDeclaration") {
123
- /**
124
- * export const foo = 1, bar = 2
125
- */
126
- for (const decl of node.declaration.declarations) if (decl.init) validateNonAsyncFunction(decl.init);
127
- if (node.declaration.kind === "const") output.update(node.declaration.start, node.declaration.start + 5, "let");
128
- const names = node.declaration.declarations.flatMap((decl) => extract_names(decl.id));
129
- let isFunction = false;
130
- if (node.declaration.declarations.length === 1) {
131
- const decl = node.declaration.declarations[0];
132
- isFunction = decl.id.type === "Identifier" && (decl.init?.type === "ArrowFunctionExpression" || decl.init?.type === "FunctionExpression");
133
- }
134
- wrapSimple(node.start, node.declaration.start, names.map((name) => ({
135
- name,
136
- meta: {
137
- isFunction,
138
- declName: name
139
- }
140
- })));
141
- } else node.declaration;
142
- else if (node.source) {
143
- /**
144
- * export { foo, bar as car } from './foo'
145
- */
146
- output.remove(node.start, node.end);
147
- for (const spec of node.specifiers) {
148
- tinyassert(spec.local.type === "Identifier");
149
- tinyassert(spec.exported.type === "Identifier");
150
- const name = spec.local.name;
151
- toAppend.push(`import { ${name} as $$import_${name} } from ${node.source.raw}`);
152
- wrapExport(`$$import_${name}`, spec.exported.name);
153
- }
154
- } else {
155
- /**
156
- * export { foo, bar as car }
157
- */
158
- output.remove(node.start, node.end);
159
- for (const spec of node.specifiers) {
160
- tinyassert(spec.local.type === "Identifier");
161
- tinyassert(spec.exported.type === "Identifier");
162
- wrapExport(spec.local.name, spec.exported.name);
163
- }
164
- }
165
- /**
166
- * export * from './foo'
167
- */
168
- if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw Object.assign(/* @__PURE__ */ new Error("unsupported ExportAllDeclaration"), { pos: node.start });
169
- /**
170
- * export default function foo() {}
171
- * export default class Foo {}
172
- * export default () => {}
173
- */
174
- if (node.type === "ExportDefaultDeclaration") {
175
- validateNonAsyncFunction(node.declaration);
176
- let localName;
177
- let isFunction = false;
178
- let declName;
179
- let defaultExportIdentifierName;
180
- if ((node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") && node.declaration.id) {
181
- localName = node.declaration.id.name;
182
- output.remove(node.start, node.declaration.start);
183
- isFunction = node.declaration.type === "FunctionDeclaration";
184
- declName = node.declaration.id.name;
185
- } else {
186
- localName = "$$default";
187
- output.update(node.start, node.declaration.start, "const $$default = ");
188
- if (node.declaration.type === "Identifier") defaultExportIdentifierName = node.declaration.name;
189
- }
190
- wrapExport(localName, "default", {
191
- isFunction,
192
- declName,
193
- defaultExportIdentifierName
194
- });
195
- }
196
- }
197
- if (toAppend.length > 0) output.append([
198
- "",
199
- ...toAppend,
200
- ""
201
- ].join(";\n"));
202
- return {
203
- exportNames,
204
- output
205
- };
206
- }
207
-
208
- //#endregion
209
- //#region src/transforms/utils.ts
210
- function hasDirective(body, directive) {
211
- return !!body.find((stmt) => stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && stmt.expression.value === directive);
212
- }
213
- function getExportNames(ast, options) {
214
- const exportNames = [];
215
- for (const node of ast.body) {
216
- if (node.type === "ExportNamedDeclaration") if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration")
217
- /**
218
- * export function foo() {}
219
- */
220
- exportNames.push(node.declaration.id.name);
221
- else if (node.declaration.type === "VariableDeclaration")
222
- /**
223
- * export const foo = 1, bar = 2
224
- */
225
- for (const decl of node.declaration.declarations) exportNames.push(...extract_names(decl.id));
226
- else node.declaration;
227
- else
228
- /**
229
- * export { foo, bar as car } from './foo'
230
- * export { foo, bar as car }
231
- */
232
- for (const spec of node.specifiers) {
233
- tinyassert(spec.exported.type === "Identifier");
234
- exportNames.push(spec.exported.name);
235
- }
236
- /**
237
- * export * from './foo'
238
- */
239
- if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw new Error("unsupported ExportAllDeclaration");
240
- /**
241
- * export default function foo() {}
242
- * export default class Foo {}
243
- * export default () => {}
244
- */
245
- if (node.type === "ExportDefaultDeclaration") exportNames.push("default");
246
- }
247
- return { exportNames };
248
- }
249
-
250
- //#endregion
251
- //#region src/transforms/proxy-export.ts
252
- function transformDirectiveProxyExport(ast, options) {
253
- if (!hasDirective(ast.body, options.directive)) return;
254
- return transformProxyExport(ast, options);
255
- }
256
- function transformProxyExport(ast, options) {
257
- if (options.keep && typeof options.code !== "string") throw new Error("`keep` option requires `code`");
258
- const output = new MagicString(options.code ?? " ".repeat(ast.end));
259
- const exportNames = [];
260
- function createExport(node, names) {
261
- exportNames.push(...names);
262
- const newCode = names.map((name) => (name === "default" ? `export default` : `export const ${name} =`) + ` /* #__PURE__ */ ${options.runtime(name)};\n`).join("");
263
- output.update(node.start, node.end, newCode);
264
- }
265
- function validateNonAsyncFunction(node, ok) {
266
- if (options.rejectNonAsyncFunction && !ok) throw Object.assign(/* @__PURE__ */ new Error(`unsupported non async function`), { pos: node.start });
267
- }
268
- for (const node of ast.body) {
269
- if (node.type === "ExportNamedDeclaration") {
270
- if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
271
- /**
272
- * export function foo() {}
273
- */
274
- validateNonAsyncFunction(node, node.declaration.type === "FunctionDeclaration" && node.declaration.async);
275
- createExport(node, [node.declaration.id.name]);
276
- } else if (node.declaration.type === "VariableDeclaration") {
277
- /**
278
- * export const foo = 1, bar = 2
279
- */
280
- validateNonAsyncFunction(node, node.declaration.declarations.every((decl) => decl.init?.type === "ArrowFunctionExpression" && decl.init.async));
281
- if (options.keep && options.code) {
282
- if (node.declaration.declarations.length === 1) {
283
- const decl = node.declaration.declarations[0];
284
- if (decl.id.type === "Identifier" && decl.init) {
285
- const name = decl.id.name;
286
- const value = options.code.slice(decl.init.start, decl.init.end);
287
- const newCode = `export const ${name} = /* #__PURE__ */ ${options.runtime(name, { value })};`;
288
- output.update(node.start, node.end, newCode);
289
- exportNames.push(name);
290
- continue;
291
- }
292
- }
293
- }
294
- createExport(node, node.declaration.declarations.flatMap((decl) => extract_names(decl.id)));
295
- } else node.declaration;
296
- else {
297
- /**
298
- * export { foo, bar as car } from './foo'
299
- * export { foo, bar as car }
300
- */
301
- const names = [];
302
- for (const spec of node.specifiers) {
303
- tinyassert(spec.exported.type === "Identifier");
304
- names.push(spec.exported.name);
305
- }
306
- createExport(node, names);
307
- }
308
- continue;
309
- }
310
- /**
311
- * export * from './foo'
312
- */
313
- if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw new Error("unsupported ExportAllDeclaration");
314
- /**
315
- * export default function foo() {}
316
- * export default class Foo {}
317
- * export default () => {}
318
- */
319
- if (node.type === "ExportDefaultDeclaration") {
320
- validateNonAsyncFunction(node, node.declaration.type === "Identifier" || node.declaration.type === "FunctionDeclaration" && node.declaration.async);
321
- createExport(node, ["default"]);
322
- continue;
323
- }
324
- if (options.keep) continue;
325
- output.remove(node.start, node.end);
326
- }
327
- return {
328
- exportNames,
329
- output
330
- };
331
- }
332
-
333
- //#endregion
334
- //#region src/transforms/server-action.ts
335
- function transformServerActionServer(input, ast, options) {
336
- if (hasDirective(ast.body, "use server")) return transformWrapExport(input, ast, options);
337
- return transformHoistInlineDirective(input, ast, {
338
- ...options,
339
- directive: "use server"
340
- });
341
- }
342
-
343
- //#endregion
344
- export { hasDirective as a, transformHoistInlineDirective as c, getExportNames as i, transformDirectiveProxyExport as n, transformWrapExport as o, transformProxyExport as r, findDirectives as s, transformServerActionServer as t };