@vitejs/plugin-rsc 0.5.33 → 0.5.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -2
- package/dist/browser.d.ts +1 -1
- package/dist/{cjs-AWVWfddx.js → cjs-DhDj_zQT.js} +2 -2
- package/dist/client-Dq3oGLRS.d.ts +8 -0
- package/dist/{client-reference-DEZtXTv1.d.ts → client-reference-Bk5pzNGN.d.ts} +1 -1
- package/dist/client.node-BEQT2PT-.d.ts +9 -0
- package/dist/client.shared-D1HxyClg.js +10 -0
- package/dist/client.shared-VT232QCM.d.ts +16 -0
- package/dist/core/browser.js +1 -1
- package/dist/core/plugin.d.ts +2 -3
- package/dist/core/rsc.d.ts +1 -1
- package/dist/core/rsc.js +1 -1
- package/dist/core/ssr.d.ts +1 -7
- package/dist/core/ssr.js +1 -1
- package/dist/{index-C5IY2S-e.d.ts → index-CROaL0MT.d.ts} +34 -8
- package/dist/index.js +1 -1
- package/dist/{picocolors-D28_L_A0.js → picocolors-DCTC64Zv.js} +1 -1
- package/dist/{plugin-DarRieDr.js → plugin-CLvIS10V.js} +38 -32
- package/dist/plugin.js +1 -1
- package/dist/plugins/cjs.d.ts +2 -3
- package/dist/plugins/cjs.js +1 -1
- package/dist/react/browser.d.ts +10 -10
- package/dist/react/rsc/client.d.ts +1 -1
- package/dist/react/rsc/client.js +2 -5
- package/dist/react/rsc/client.node.d.ts +2 -0
- package/dist/react/rsc/client.node.js +16 -0
- package/dist/react/rsc/server.d.ts +2 -2
- package/dist/react/rsc/server.node.d.ts +3 -0
- package/dist/react/rsc/server.node.js +24 -0
- package/dist/react/rsc/static.d.ts +4 -5
- package/dist/react/rsc/static.node.d.ts +6 -0
- package/dist/react/rsc/static.node.js +11 -0
- package/dist/react/rsc.d.ts +3 -3
- package/dist/react/ssr.d.ts +9 -9
- package/dist/react/ssr.node.d.ts +12 -0
- package/dist/react/ssr.node.js +21 -0
- package/dist/rsc/client.d.ts +1 -1
- package/dist/rsc/client.node.d.ts +2 -0
- package/dist/rsc/client.node.js +3 -0
- package/dist/rsc/server.d.ts +5 -5
- package/dist/rsc/server.node.d.ts +19 -0
- package/dist/rsc/server.node.js +13 -0
- package/dist/rsc/static.d.ts +4 -5
- package/dist/rsc/static.node.d.ts +16 -0
- package/dist/rsc/static.node.js +12 -0
- package/dist/{rsc-C3UdJLOW.d.ts → rsc-D8UlANI2.d.ts} +1 -1
- package/dist/rsc.d.ts +3 -3
- package/dist/rsc.node.d.ts +6 -0
- package/dist/rsc.node.js +7 -0
- package/dist/{scope-Bdx33sQv.js → scope-Ck0n25my.js} +2 -4
- package/dist/{server-ZBjqNTqU.d.ts → server-YwgjVtsE.d.ts} +2 -2
- package/dist/server.node-DU77AeKU.d.ts +15 -0
- package/dist/shared-BWJvctW6.js +34 -0
- package/dist/shared-CXQb6hk9.js +89 -0
- package/dist/shared-DJBuYpZL.d.ts +20 -0
- package/dist/ssr-C-U7jY5S.d.ts +8 -0
- package/dist/ssr.d.ts +3 -21
- package/dist/ssr.js +1 -87
- package/dist/ssr.node.d.ts +5 -0
- package/dist/ssr.node.js +4 -0
- package/dist/transforms/index.js +91 -62
- package/dist/utils/encryption-runtime.d.ts +3 -4
- package/dist/utils/encryption-runtime.js +4 -2
- package/dist/utils/rpc.d.ts +3 -4
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.browser.development.js +909 -495
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.browser.production.js +399 -265
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.edge.development.js +901 -477
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.edge.production.js +380 -219
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.node.development.js +925 -484
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-client.node.production.js +385 -221
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.browser.development.js +726 -388
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.browser.production.js +566 -397
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.edge.development.js +734 -397
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.edge.production.js +477 -238
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.development.js +1029 -620
- package/dist/vendor/react-server-dom/cjs/react-server-dom-webpack-server.node.production.js +481 -261
- package/dist/vendor/react-server-dom/esm/react-server-dom-webpack-node-loader.production.js +2 -2
- package/dist/vendor/react-server-dom/package.json +3 -3
- package/package.json +15 -15
- package/dist/client-Bhch3O41.d.ts +0 -19
- package/dist/dist-uqdtSkzK.js +0 -64
package/dist/transforms/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as isDirective, i as hasDirective, n as extractIdentifiers, o as rejectNonAsyncFunction, r as extractNames, s as validateNonAsyncFunction, t as buildScopeTree } from "../scope-
|
|
1
|
+
import { r as tinyassert } from "../shared-BWJvctW6.js";
|
|
2
|
+
import { a as isDirective, i as hasDirective, n as extractIdentifiers, o as rejectNonAsyncFunction, r as extractNames, s as validateNonAsyncFunction, t as buildScopeTree } from "../scope-Ck0n25my.js";
|
|
3
3
|
import MagicString from "magic-string";
|
|
4
4
|
import { walk } from "estree-walker";
|
|
5
5
|
//#region src/transforms/hoist.ts
|
|
@@ -86,9 +86,10 @@ function transformHoistInlineDirective(input, viteAst, { runtime, rejectNonAsync
|
|
|
86
86
|
if ((node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") && node.body.type === "BlockStatement") {
|
|
87
87
|
const match = matchDirective(node.body.body, directive)?.match;
|
|
88
88
|
if (!match) return;
|
|
89
|
+
const methodInfo = getMethodInfo(node, parent, match[0]);
|
|
89
90
|
if (!node.async && rejectNonAsyncFunction) throw Object.assign(/* @__PURE__ */ new Error(`"${directive}" doesn't allow non async function`), { pos: node.start });
|
|
90
91
|
const declName = node.type === "FunctionDeclaration" && node.id.name;
|
|
91
|
-
const originalName = declName || parent?.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.id.name || "anonymous_server_function";
|
|
92
|
+
const originalName = declName || methodInfo?.name || parent?.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.id.name || "anonymous_server_function";
|
|
92
93
|
const bindVars = getBindVars(node, scopeTree);
|
|
93
94
|
let newParams = [...bindVars.map((b) => b.root), ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
|
|
94
95
|
if (bindVars.length > 0 && options.decode) {
|
|
@@ -111,7 +112,13 @@ function transformHoistInlineDirective(input, viteAst, { runtime, rejectNonAsync
|
|
|
111
112
|
const bindArgs = options.encode ? options.encode("[" + bindVars.map((b) => b.expr).join(", ") + "]") : bindVars.map((b) => b.expr).join(", ");
|
|
112
113
|
newCode = `${newCode}.bind(null, ${bindArgs})`;
|
|
113
114
|
}
|
|
114
|
-
if (
|
|
115
|
+
if (methodInfo) {
|
|
116
|
+
const isStatic = methodInfo.node.type === "MethodDefinition";
|
|
117
|
+
const key = input.slice(methodInfo.node.key.start, methodInfo.node.key.end);
|
|
118
|
+
const propertyKey = !methodInfo.node.computed && methodInfo.node.key.type === "Identifier" ? `["${key}"]` : `[${key}]`;
|
|
119
|
+
output.update(methodInfo.node.start, node.start, `${isStatic ? "static " : ""}${propertyKey}${isStatic ? " = " : ": "}`);
|
|
120
|
+
if (isStatic) newCode += ";";
|
|
121
|
+
} else if (declName) {
|
|
115
122
|
newCode = `const ${declName} = ${newCode};`;
|
|
116
123
|
if (parent?.type === "ExportDefaultDeclaration") {
|
|
117
124
|
output.remove(parent.start, node.start);
|
|
@@ -127,6 +134,21 @@ function transformHoistInlineDirective(input, viteAst, { runtime, rejectNonAsync
|
|
|
127
134
|
names
|
|
128
135
|
};
|
|
129
136
|
}
|
|
137
|
+
function getMethodInfo(node, parent, directive) {
|
|
138
|
+
if (node.type !== "FunctionExpression") return;
|
|
139
|
+
let method;
|
|
140
|
+
if (parent?.type === "Property" && parent.value === node && (parent.method || parent.kind !== "init")) method = parent;
|
|
141
|
+
else if (parent?.type === "MethodDefinition") method = parent;
|
|
142
|
+
else return;
|
|
143
|
+
if (method.type === "MethodDefinition" && !method.static) throw Object.assign(/* @__PURE__ */ new Error(`It is not allowed to define inline ${JSON.stringify(directive)} class instance methods.`), { pos: method.start });
|
|
144
|
+
if (method.type === "MethodDefinition" && method.key.type === "PrivateIdentifier") throw Object.assign(/* @__PURE__ */ new Error(`It is not allowed to define inline ${JSON.stringify(directive)} private class methods.`), { pos: method.start });
|
|
145
|
+
if (method.type === "Property" && method.kind !== "init" || method.type === "MethodDefinition" && method.kind !== "method") throw Object.assign(/* @__PURE__ */ new Error(`It is not allowed to define inline ${JSON.stringify(directive)} getters or setters.`), { pos: method.start });
|
|
146
|
+
const keyName = !method.computed && method.key.type === "Identifier" ? method.key.name : void 0;
|
|
147
|
+
return {
|
|
148
|
+
node: method,
|
|
149
|
+
name: keyName
|
|
150
|
+
};
|
|
151
|
+
}
|
|
130
152
|
function getRuntimeHoistPosition(ast) {
|
|
131
153
|
for (const statement of ast.body) if (!isDirective(statement)) return statement.start;
|
|
132
154
|
return 0;
|
|
@@ -246,59 +268,61 @@ function dedupeByPrefix(paths) {
|
|
|
246
268
|
function scanModuleExports(viteAst) {
|
|
247
269
|
const ast = viteAst;
|
|
248
270
|
const groups = [];
|
|
249
|
-
for (const node of ast.body) if (node.type === "ExportNamedDeclaration")
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
271
|
+
for (const node of ast.body) if (node.type === "ExportNamedDeclaration") {
|
|
272
|
+
if (node.declaration) {
|
|
273
|
+
if (node.declaration.type === "VariableDeclaration") {
|
|
274
|
+
const declaration = node.declaration;
|
|
275
|
+
groups.push({
|
|
276
|
+
type: "variable-declaration",
|
|
277
|
+
node,
|
|
278
|
+
declaration,
|
|
279
|
+
declarators: declaration.declarations.map((declarator) => {
|
|
280
|
+
const isFunction = declarator.id.type === "Identifier" && declarator.init ? getIsFunction(declarator.init) : void 0;
|
|
281
|
+
return {
|
|
282
|
+
node: declarator,
|
|
283
|
+
exports: extractNames(declarator.id).map((name) => ({
|
|
284
|
+
localName: name,
|
|
285
|
+
exportName: name,
|
|
286
|
+
meta: {
|
|
287
|
+
declName: name,
|
|
288
|
+
isFunction,
|
|
289
|
+
valueNode: declarator.init ?? void 0
|
|
290
|
+
}
|
|
291
|
+
}))
|
|
292
|
+
};
|
|
293
|
+
})
|
|
294
|
+
});
|
|
295
|
+
} else {
|
|
296
|
+
tinyassert(node.declaration.id);
|
|
297
|
+
const name = node.declaration.id.name;
|
|
298
|
+
groups.push({
|
|
299
|
+
type: "declaration",
|
|
300
|
+
node,
|
|
301
|
+
declaration: node.declaration,
|
|
302
|
+
export: {
|
|
260
303
|
localName: name,
|
|
261
304
|
exportName: name,
|
|
262
305
|
meta: {
|
|
263
306
|
declName: name,
|
|
264
|
-
isFunction,
|
|
265
|
-
valueNode:
|
|
307
|
+
isFunction: getIsFunction(node.declaration),
|
|
308
|
+
valueNode: node.declaration
|
|
266
309
|
}
|
|
267
|
-
}
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
} else groups.push({
|
|
314
|
+
type: "specifiers",
|
|
315
|
+
node,
|
|
316
|
+
exports: node.specifiers.map((specifier) => {
|
|
317
|
+
return {
|
|
318
|
+
node: specifier,
|
|
319
|
+
localName: specifier.local.type === "Identifier" ? specifier.local.name : "__unsupported_string_export__",
|
|
320
|
+
exportName: specifier.exported.type === "Identifier" ? specifier.exported.name : "__unsupported_string_export__",
|
|
321
|
+
meta: {}
|
|
268
322
|
};
|
|
269
323
|
})
|
|
270
324
|
});
|
|
271
|
-
} else {
|
|
272
|
-
tinyassert(node.declaration.id);
|
|
273
|
-
const name = node.declaration.id.name;
|
|
274
|
-
groups.push({
|
|
275
|
-
type: "declaration",
|
|
276
|
-
node,
|
|
277
|
-
declaration: node.declaration,
|
|
278
|
-
export: {
|
|
279
|
-
localName: name,
|
|
280
|
-
exportName: name,
|
|
281
|
-
meta: {
|
|
282
|
-
declName: name,
|
|
283
|
-
isFunction: getIsFunction(node.declaration),
|
|
284
|
-
valueNode: node.declaration
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
else groups.push({
|
|
290
|
-
type: "specifiers",
|
|
291
|
-
node,
|
|
292
|
-
exports: node.specifiers.map((specifier) => {
|
|
293
|
-
return {
|
|
294
|
-
node: specifier,
|
|
295
|
-
localName: specifier.local.type === "Identifier" ? specifier.local.name : "__unsupported_string_export__",
|
|
296
|
-
exportName: specifier.exported.type === "Identifier" ? specifier.exported.name : "__unsupported_string_export__",
|
|
297
|
-
meta: {}
|
|
298
|
-
};
|
|
299
|
-
})
|
|
300
|
-
});
|
|
301
|
-
else if (node.type === "ExportAllDeclaration") groups.push({
|
|
325
|
+
} else if (node.type === "ExportAllDeclaration") groups.push({
|
|
302
326
|
type: "export-all",
|
|
303
327
|
node
|
|
304
328
|
});
|
|
@@ -567,8 +591,10 @@ function transformWrapExport(input, viteAst, options) {
|
|
|
567
591
|
const selectedExportNames = new Set(exports.filter((entry) => filter(entry.exportName, entry.meta)).map((entry) => entry.exportName));
|
|
568
592
|
if (selectedExportNames.size === 0) continue;
|
|
569
593
|
if (group.declaration.kind === "const") output.update(group.declaration.start, group.declaration.start + 5, "let");
|
|
570
|
-
for (const declarator of group.declarators) if (declarator.exports.some(({ exportName }) => selectedExportNames.has(exportName)))
|
|
571
|
-
|
|
594
|
+
for (const declarator of group.declarators) if (declarator.exports.some(({ exportName }) => selectedExportNames.has(exportName))) {
|
|
595
|
+
if (declarator.node.init) validateNonAsyncFunction(options, declarator.node.init);
|
|
596
|
+
else rejectNonAsyncFunction(options, declarator.node.start);
|
|
597
|
+
}
|
|
572
598
|
emitWrappedAssignments(group.node.start, group.declaration.start, exports, selectedExportNames);
|
|
573
599
|
} else if (group.type === "specifiers") {
|
|
574
600
|
const skippedExports = [];
|
|
@@ -707,10 +733,12 @@ function transformProxyExport(viteAst, options) {
|
|
|
707
733
|
else removeNode(node);
|
|
708
734
|
} else if (!options.ignoreExportAllDeclaration) throw new Error("unsupported ExportAllDeclaration");
|
|
709
735
|
else if (!options.keep) removeNode(node);
|
|
710
|
-
} else if (group.type === "default")
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
736
|
+
} else if (group.type === "default") {
|
|
737
|
+
if (filter("default", group.meta)) {
|
|
738
|
+
validateNonAsyncFunction(options, group.node.declaration);
|
|
739
|
+
createExport(node, ["default"]);
|
|
740
|
+
} else removeNode(node);
|
|
741
|
+
}
|
|
714
742
|
}
|
|
715
743
|
if (!options.keep) {
|
|
716
744
|
for (const node of ast.body) if (!exportNodes.has(node)) removeNode(node);
|
|
@@ -788,13 +816,14 @@ async function collectExportScan(resolvedId, context, seen) {
|
|
|
788
816
|
}
|
|
789
817
|
function collectExplicitExportNames(ast) {
|
|
790
818
|
const names = /* @__PURE__ */ new Set();
|
|
791
|
-
for (const node of ast.body) if (node.type === "ExportNamedDeclaration")
|
|
792
|
-
if (node.declaration
|
|
793
|
-
if (node.declaration.
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
819
|
+
for (const node of ast.body) if (node.type === "ExportNamedDeclaration") {
|
|
820
|
+
if (node.declaration) {
|
|
821
|
+
if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
|
|
822
|
+
if (node.declaration.id) names.add(node.declaration.id.name);
|
|
823
|
+
} else if (node.declaration.type === "VariableDeclaration") for (const decl of node.declaration.declarations) for (const name of extractNames(decl.id)) names.add(name);
|
|
824
|
+
} else for (const spec of node.specifiers) if (spec.exported.type === "Identifier") names.add(spec.exported.name);
|
|
825
|
+
else throw Object.assign(/* @__PURE__ */ new Error("unsupported string literal export name"), { pos: spec.exported.start });
|
|
826
|
+
} else if (node.type === "ExportDefaultDeclaration") names.add("default");
|
|
798
827
|
else if (node.type === "ExportAllDeclaration") {
|
|
799
828
|
if (node.exported?.type === "Identifier") names.add(node.exported.name);
|
|
800
829
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/utils/encryption-runtime.d.ts
|
|
2
|
-
declare function encryptActionBoundArgs(originalValue: unknown): Promise<string>;
|
|
3
|
-
declare function decryptActionBoundArgs(encrypted: ReturnType<typeof encryptActionBoundArgs>): Promise<unknown>;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { decryptActionBoundArgs, encryptActionBoundArgs };
|
|
2
|
+
export declare function encryptActionBoundArgs(originalValue: unknown): Promise<string>;
|
|
3
|
+
export declare function decryptActionBoundArgs(encrypted: ReturnType<typeof encryptActionBoundArgs>): Promise<unknown>;
|
|
4
|
+
//#endregion
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as once } from "../shared-BWJvctW6.js";
|
|
2
2
|
import { a as fromBase64, i as encryptBuffer, n as concatArrayStream, r as decryptBuffer, t as arrayToStream } from "../encryption-utils-BNbYHtC4.js";
|
|
3
3
|
import { renderToReadableStream } from "../react/rsc/server.js";
|
|
4
4
|
import encryptionKeySource from "virtual:vite-rsc/encryption-key";
|
|
5
5
|
//#region src/utils/encryption-runtime.ts
|
|
6
6
|
async function encryptActionBoundArgs(originalValue) {
|
|
7
|
-
|
|
7
|
+
const serialized = renderToReadableStream(originalValue);
|
|
8
|
+
const serializedBuffer = await concatArrayStream(serialized);
|
|
9
|
+
return encryptBuffer(serializedBuffer, await getEncryptionKey());
|
|
8
10
|
}
|
|
9
11
|
async function decryptActionBoundArgs(encrypted) {
|
|
10
12
|
const [{ createFromReadableStream }, serializedBuffer] = await Promise.all([import("../react/rsc/client.js"), decryptBuffer(await encrypted, await getEncryptionKey())]);
|
package/dist/utils/rpc.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
//#region src/utils/rpc.d.ts
|
|
2
|
-
declare function createRpcServer<T extends object>(handlers: T): (request: Request) => Promise<Response>;
|
|
3
|
-
declare function createRpcClient<T>(options: {
|
|
2
|
+
export declare function createRpcServer<T extends object>(handlers: T): (request: Request) => Promise<Response>;
|
|
3
|
+
export declare function createRpcClient<T>(options: {
|
|
4
4
|
endpoint: string;
|
|
5
5
|
}): T;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { createRpcClient, createRpcServer };
|
|
6
|
+
//#endregion
|