@vitejs/plugin-rsc 0.5.18 → 0.5.20

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 (41) hide show
  1. package/dist/browser.d.ts +2 -2
  2. package/dist/{chunk-Dj_d7TT4.js → chunk-f2BShn47.js} +1 -1
  3. package/dist/{cjs-D2v1gYgq.js → cjs-v2jRTNln.js} +1 -61
  4. package/dist/core/browser.d.ts +5 -1
  5. package/dist/core/browser.js +1 -1
  6. package/dist/core/plugin.js +25 -1
  7. package/dist/core/rsc.d.ts +1 -1
  8. package/dist/core/rsc.js +84 -1
  9. package/dist/core/ssr.d.ts +1 -1
  10. package/dist/core/ssr.js +1 -1
  11. package/dist/import-environment-B994HXEc.d.ts +11 -0
  12. package/dist/index.d.ts +3 -2
  13. package/dist/index.js +4 -4
  14. package/dist/{picocolors-BRyoHAlU.js → picocolors-B0A1T24z.js} +1 -1
  15. package/dist/plugin.d.ts +179 -3
  16. package/dist/plugin.js +1461 -4
  17. package/dist/plugins/cjs.js +62 -1
  18. package/dist/react/browser.d.ts +2 -2
  19. package/dist/react/rsc.js +1 -1
  20. package/dist/rsc.d.ts +3 -2
  21. package/dist/rsc.js +2 -2
  22. package/dist/ssr.d.ts +3 -2
  23. package/dist/ssr.js +1 -1
  24. package/dist/transforms/index.d.ts +1 -1
  25. package/dist/transforms/index.js +1 -1
  26. package/dist/utils/encryption-runtime.js +1 -2
  27. package/dist/utils/rpc.js +89 -1
  28. package/dist/validate-import-DJumtHRw.js +498 -0
  29. package/package.json +7 -7
  30. package/dist/browser-s-WcB8A7.d.ts +0 -6
  31. package/dist/plugin-BGmSmdwL.js +0 -27
  32. package/dist/plugin-Cp12dr0Z.js +0 -1944
  33. package/dist/plugin-K7i9F4Fd.d.ts +0 -187
  34. package/dist/rpc-EIuXyQpO.js +0 -91
  35. package/dist/rsc-Bhp6O2qz.js +0 -86
  36. /package/dist/{encryption-utils-DdqSKS_O.js → encryption-utils-Bk5eKdu6.js} +0 -0
  37. /package/dist/{index-now_lP2V.d.ts → index-BIbdRBfk.d.ts} +0 -0
  38. /package/dist/{index-CLmWsR1c.d.ts → server-action-B2zS9t-J.d.ts} +0 -0
  39. /package/dist/{transforms-B2EJTNXG.js → server-action-JkEy-6yW.js} +0 -0
  40. /package/dist/{shared-rtJPs0Yj.js → shared-Dhw3vs8e.js} +0 -0
  41. /package/dist/{shared-CGK4coF3.js → shared-d80_k_tn.js} +0 -0
@@ -1,3 +1,64 @@
1
- import { t as cjsModuleRunnerPlugin } from "../cjs-D2v1gYgq.js";
1
+ import { t as createDebug } from "../dist-yW9-EeG1.js";
2
+ import { t as transformCjsToEsm } from "../cjs-v2jRTNln.js";
3
+ import { n as parseIdQuery } from "../shared-d80_k_tn.js";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import * as esModuleLexer from "es-module-lexer";
7
+ import { parseAstAsync } from "vite";
8
+ import { findClosestPkgJsonPath } from "vitefu";
2
9
 
10
+ //#region src/plugins/cjs.ts
11
+ const debug = createDebug("vite-rsc:cjs");
12
+ function cjsModuleRunnerPlugin() {
13
+ const warnedPackages = /* @__PURE__ */ new Set();
14
+ return [{
15
+ name: "cjs-module-runner-transform",
16
+ apply: "serve",
17
+ applyToEnvironment: (env) => env.config.dev.moduleRunnerTransform,
18
+ transform: {
19
+ filter: {
20
+ id: /\/node_modules\//,
21
+ code: /\b(require|exports)\b/
22
+ },
23
+ async handler(code, id) {
24
+ if (id.includes("/node_modules/") && !id.startsWith(this.environment.config.cacheDir) && /\b(require|exports)\b/.test(code)) {
25
+ id = parseIdQuery(id).filename;
26
+ if (!/\.[cm]?js$/.test(id)) return;
27
+ if (id.endsWith(".mjs")) return;
28
+ if (id.endsWith(".js")) {
29
+ const pkgJsonPath = await findClosestPkgJsonPath(path.dirname(id));
30
+ if (pkgJsonPath) {
31
+ if (JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")).type === "module") return;
32
+ }
33
+ }
34
+ const [, , , hasModuleSyntax] = esModuleLexer.parse(code);
35
+ if (hasModuleSyntax) return;
36
+ const packageKey = extractPackageKey(id);
37
+ if (!warnedPackages.has(packageKey)) {
38
+ debug(`non-optimized CJS dependency in '${this.environment.name}' environment: ${id}`);
39
+ warnedPackages.add(packageKey);
40
+ }
41
+ const output = transformCjsToEsm(code, await parseAstAsync(code), { id }).output;
42
+ return {
43
+ code: output.toString(),
44
+ map: output.generateMap({ hires: "boundary" })
45
+ };
46
+ }
47
+ }
48
+ }
49
+ }];
50
+ }
51
+ function extractPackageKey(id) {
52
+ const yarnMatch = id.match(/\/.yarn\/cache\/([^/]+)/);
53
+ if (yarnMatch) return yarnMatch[1];
54
+ if (id.includes("/node_modules")) {
55
+ id = id.split("/node_modules/").at(-1);
56
+ let [x, y] = id.split("/");
57
+ if (x.startsWith("@")) return `${x}/${y}`;
58
+ return x;
59
+ }
60
+ return id;
61
+ }
62
+
63
+ //#endregion
3
64
  export { cjsModuleRunnerPlugin };
@@ -1,5 +1,5 @@
1
- import { n as CallServerCallback } from "../index-now_lP2V.js";
2
- import { t as setRequireModule } from "../browser-s-WcB8A7.js";
1
+ import { n as CallServerCallback } from "../index-BIbdRBfk.js";
2
+ import { setRequireModule } from "../core/browser.js";
3
3
 
4
4
  //#region src/react/browser.d.ts
5
5
  declare function createFromReadableStream<T>(stream: ReadableStream<Uint8Array>, options?: object): Promise<T>;
package/dist/react/rsc.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as setRequireModule, i as loadServerAction, n as createServerDecodeClientManifest, r as createServerManifest, t as createClientManifest } from "../rsc-Bhp6O2qz.js";
1
+ import { createClientManifest, createServerDecodeClientManifest, createServerManifest, loadServerAction, setRequireModule } from "../core/rsc.js";
2
2
  import * as ReactClient from "@vitejs/plugin-rsc/vendor/react-server-dom/client.edge";
3
3
  import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
4
4
 
package/dist/rsc.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./core/rsc.js";
2
- import { i as ResolvedAssetDeps } from "./plugin-K7i9F4Fd.js";
3
- import "./index-CLmWsR1c.js";
2
+ import "./import-environment-B994HXEc.js";
3
+ import "./server-action-B2zS9t-J.js";
4
+ import { ResolvedAssetDeps } from "./plugin.js";
4
5
  import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference } from "./react/rsc.js";
5
6
  import { decryptActionBoundArgs, encryptActionBoundArgs } from "./utils/encryption-runtime.js";
6
7
 
package/dist/rsc.js CHANGED
@@ -1,5 +1,5 @@
1
- import { a as toReferenceValidationVirtual } from "./shared-CGK4coF3.js";
2
- import { a as setRequireModule, i as loadServerAction, r as createServerManifest, t as createClientManifest } from "./rsc-Bhp6O2qz.js";
1
+ import { a as toReferenceValidationVirtual } from "./shared-d80_k_tn.js";
2
+ import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./core/rsc.js";
3
3
  import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream as renderToReadableStream$1 } from "./react/rsc.js";
4
4
  import { decryptActionBoundArgs, encryptActionBoundArgs } from "./utils/encryption-runtime.js";
5
5
  import assetsManifest from "virtual:vite-rsc/assets-manifest";
package/dist/ssr.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createServerConsumerManifest, setRequireModule } from "./core/ssr.js";
2
- import { i as ResolvedAssetDeps } from "./plugin-K7i9F4Fd.js";
3
- import "./index-CLmWsR1c.js";
2
+ import "./import-environment-B994HXEc.js";
3
+ import "./server-action-B2zS9t-J.js";
4
+ import { ResolvedAssetDeps } from "./plugin.js";
4
5
  import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./react/ssr.js";
5
6
 
6
7
  //#region src/ssr.d.ts
package/dist/ssr.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as toReferenceValidationVirtual, i as toCssVirtual } from "./shared-CGK4coF3.js";
1
+ import { a as toReferenceValidationVirtual, i as toCssVirtual } from "./shared-d80_k_tn.js";
2
2
  import { createServerConsumerManifest, setRequireModule } from "./core/ssr.js";
3
3
  import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./react/ssr.js";
4
4
  import * as clientReferences from "virtual:vite-rsc/client-references";
@@ -1,2 +1,2 @@
1
- import { a as transformDirectiveProxyExport, c as TransformWrapExportOptions, d as transformHoistInlineDirective, i as TransformProxyExportOptions, l as transformWrapExport, n as getExportNames, o as transformProxyExport, r as hasDirective, s as TransformWrapExportFilter, t as transformServerActionServer, u as findDirectives } from "../index-CLmWsR1c.js";
1
+ import { a as transformDirectiveProxyExport, c as TransformWrapExportOptions, d as transformHoistInlineDirective, i as TransformProxyExportOptions, l as transformWrapExport, n as getExportNames, o as transformProxyExport, r as hasDirective, s as TransformWrapExportFilter, t as transformServerActionServer, u as findDirectives } from "../server-action-B2zS9t-J.js";
2
2
  export { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
@@ -1,3 +1,3 @@
1
- import { a as hasDirective, c as transformHoistInlineDirective, i as getExportNames, n as transformDirectiveProxyExport, o as transformWrapExport, r as transformProxyExport, s as findDirectives, t as transformServerActionServer } from "../transforms-B2EJTNXG.js";
1
+ import { a as hasDirective, c as transformHoistInlineDirective, i as getExportNames, n as transformDirectiveProxyExport, o as transformWrapExport, r as transformProxyExport, s as findDirectives, t as transformServerActionServer } from "../server-action-JkEy-6yW.js";
2
2
 
3
3
  export { findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
@@ -1,6 +1,5 @@
1
1
  import { r as once } from "../dist-yW9-EeG1.js";
2
- import { a as fromBase64, i as encryptBuffer, n as concatArrayStream, r as decryptBuffer, t as arrayToStream } from "../encryption-utils-DdqSKS_O.js";
3
- import "../rsc-Bhp6O2qz.js";
2
+ import { a as fromBase64, i as encryptBuffer, n as concatArrayStream, r as decryptBuffer, t as arrayToStream } from "../encryption-utils-Bk5eKdu6.js";
4
3
  import { createFromReadableStream, renderToReadableStream } from "../react/rsc.js";
5
4
  import encryptionKeySource from "virtual:vite-rsc/encryption-key";
6
5
 
package/dist/utils/rpc.js CHANGED
@@ -1,3 +1,91 @@
1
- import { n as createRpcServer, t as createRpcClient } from "../rpc-EIuXyQpO.js";
1
+ import { decode, encode } from "turbo-stream";
2
2
 
3
+ //#region src/utils/rpc.ts
4
+ const decodePlugins = [(type, ...rest) => {
5
+ switch (type) {
6
+ case "Request": {
7
+ const [method, url, headers, body] = rest;
8
+ return { value: new Request(url, {
9
+ body,
10
+ headers,
11
+ method,
12
+ duplex: body ? "half" : void 0
13
+ }) };
14
+ }
15
+ case "Response": {
16
+ const [status, statusText, headers, body] = rest;
17
+ return { value: new Response(body, {
18
+ headers,
19
+ status,
20
+ statusText
21
+ }) };
22
+ }
23
+ }
24
+ return false;
25
+ }];
26
+ const encodePlugins = [(obj) => {
27
+ if (obj instanceof Request) return [
28
+ "Request",
29
+ obj.method,
30
+ obj.url,
31
+ Array.from(obj.headers),
32
+ obj.body
33
+ ];
34
+ if (obj instanceof Response) return [
35
+ "Response",
36
+ obj.status,
37
+ obj.statusText,
38
+ Array.from(obj.headers),
39
+ obj.body
40
+ ];
41
+ return false;
42
+ }];
43
+ function createRpcServer(handlers) {
44
+ return async (request) => {
45
+ if (!request.body) throw new Error(`loadModuleDevProxy error: missing request body`);
46
+ const reqPayload = await decode(request.body.pipeThrough(new TextDecoderStream()), { plugins: decodePlugins });
47
+ const handler = handlers[reqPayload.method];
48
+ if (!handler) throw new Error(`loadModuleDevProxy error: unknown method ${reqPayload.method}`);
49
+ const resPayload = {
50
+ ok: true,
51
+ data: void 0
52
+ };
53
+ try {
54
+ resPayload.data = await handler(...reqPayload.args);
55
+ } catch (e) {
56
+ resPayload.ok = false;
57
+ resPayload.data = e;
58
+ }
59
+ return new Response(encode(resPayload, {
60
+ plugins: encodePlugins,
61
+ redactErrors: false
62
+ }));
63
+ };
64
+ }
65
+ function createRpcClient(options) {
66
+ async function callRpc(method, args) {
67
+ const body = encode({
68
+ method,
69
+ args
70
+ }, {
71
+ plugins: encodePlugins,
72
+ redactErrors: false
73
+ }).pipeThrough(new TextEncoderStream());
74
+ const res = await fetch(options.endpoint, {
75
+ method: "POST",
76
+ body,
77
+ duplex: "half"
78
+ });
79
+ if (!res.ok || !res.body) throw new Error(`loadModuleDevProxy error: ${res.status} ${res.statusText}`);
80
+ const resPayload = await decode(res.body.pipeThrough(new TextDecoderStream()), { plugins: decodePlugins });
81
+ if (!resPayload.ok) throw resPayload.data;
82
+ return resPayload.data;
83
+ }
84
+ return new Proxy({}, { get(_target, p, _receiver) {
85
+ if (typeof p !== "string" || p === "then") return;
86
+ return (...args) => callRpc(p, args);
87
+ } });
88
+ }
89
+
90
+ //#endregion
3
91
  export { createRpcClient, createRpcServer };