@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,187 +0,0 @@
1
- import { s as TransformWrapExportFilter } from "./index-CLmWsR1c.js";
2
- import MagicString from "magic-string";
3
- import { Plugin, ResolvedConfig, Rollup, ViteDevServer, parseAstAsync } from "vite";
4
-
5
- //#region src/plugins/import-environment.d.ts
6
- type EnvironmentImportMeta = {
7
- resolvedId: string;
8
- targetEnv: string;
9
- sourceEnv: string;
10
- specifier: string;
11
- };
12
- //#endregion
13
- //#region src/plugin.d.ts
14
- type ClientReferenceMeta = {
15
- importId: string;
16
- referenceKey: string;
17
- packageSource?: string;
18
- exportNames: string[];
19
- renderedExports: string[];
20
- serverChunk?: string;
21
- groupChunkId?: string;
22
- };
23
- type ServerRerferenceMeta = {
24
- importId: string;
25
- referenceKey: string;
26
- exportNames: string[];
27
- };
28
- /**
29
- * @experimental
30
- */
31
- declare class RscPluginManager {
32
- server: ViteDevServer;
33
- config: ResolvedConfig;
34
- bundles: Record<string, Rollup.OutputBundle>;
35
- buildAssetsManifest: AssetsManifest | undefined;
36
- isScanBuild: boolean;
37
- clientReferenceMetaMap: Record<string, ClientReferenceMeta>;
38
- clientReferenceGroups: Record<string, ClientReferenceMeta[]>;
39
- serverReferenceMetaMap: Record<string, ServerRerferenceMeta>;
40
- serverResourcesMetaMap: Record<string, {
41
- key: string;
42
- }>;
43
- environmentImportMetaMap: Record<string, Record<string, Record<string, EnvironmentImportMeta>>>;
44
- stabilize(): void;
45
- toRelativeId(id: string): string;
46
- writeAssetsManifest(environmentNames: string[]): void;
47
- writeEnvironmentImportsManifest(): void;
48
- }
49
- type RscPluginOptions = {
50
- /**
51
- * shorthand for configuring `environments.(name).build.rollupOptions.input.index`
52
- */
53
- entries?: Partial<Record<"client" | "ssr" | "rsc", string>>; /** @default { enviornmentName: "rsc", entryName: "index" } */
54
- serverHandler?: {
55
- environmentName: string;
56
- entryName: string;
57
- } | false; /** @default false */
58
- loadModuleDevProxy?: boolean;
59
- rscCssTransform?: false | {
60
- filter?: (id: string) => boolean;
61
- };
62
- /**
63
- * This option allows customizing how client build copies assets from server build.
64
- * By default, all assets are copied, but frameworks can establish server asset convention
65
- * to tighten security using this option.
66
- */
67
- copyServerAssetsToClient?: (fileName: string) => boolean;
68
- /**
69
- * This option allows disabling action closure encryption for debugging purpose.
70
- * @default true
71
- */
72
- enableActionEncryption?: boolean;
73
- /**
74
- * By default, the plugin uses a build-time generated encryption key for
75
- * "use server" closure argument binding.
76
- * This can be overwritten by configuring `defineEncryptionKey` option,
77
- * for example, to obtain a key through environment variable during runtime.
78
- * cf. https://nextjs.org/docs/app/guides/data-security#overwriting-encryption-keys-advanced
79
- */
80
- defineEncryptionKey?: string; /** Escape hatch for Waku's `allowServer` */
81
- keepUseCientProxy?: boolean;
82
- /**
83
- * Enable build-time validation of 'client-only' and 'server-only' imports
84
- * @default true
85
- */
86
- validateImports?: boolean;
87
- /**
88
- * use `Plugin.buildApp` hook (introduced on Vite 7) instead of `builder.buildApp` configuration
89
- * for better composability with other plugins.
90
- * @default true since Vite 7
91
- */
92
- useBuildAppHook?: boolean;
93
- /**
94
- * Skip the default buildApp orchestration for downstream frameworks
95
- * to implement custom build pipelines using `getPluginApi()`.
96
- * @experimental
97
- * @default false
98
- */
99
- customBuildApp?: boolean;
100
- /**
101
- * Custom environment configuration
102
- * @experimental
103
- * @default { browser: 'client', ssr: 'ssr', rsc: 'rsc' }
104
- */
105
- environment?: {
106
- browser?: string;
107
- ssr?: string;
108
- rsc?: string;
109
- };
110
- /**
111
- * Custom chunking strategy for client reference modules.
112
- *
113
- * This function allows you to group multiple client components into
114
- * custom chunks instead of having each module in its own chunk.
115
- * By default, client chunks are grouped by `meta.serverChunk`.
116
- */
117
- clientChunks?: (meta: {
118
- /** client reference module id */id: string; /** normalized client reference module id */
119
- normalizedId: string; /** server chunk which includes a corresponding client reference proxy module */
120
- serverChunk: string;
121
- }) => string | undefined;
122
- /**
123
- * Controls whether CSS links use React's `precedence` attribute.
124
- * @experimental
125
- * @default true
126
- */
127
- cssLinkPrecedence?: boolean;
128
- /**
129
- * Opt out of the default "index" client entry convention.
130
- * When enabled, the plugin will not:
131
- * - Require an entry chunk named "index"
132
- * - Automatically include client entry deps in each client reference's dependencies
133
- *
134
- * Note: `import.meta.viteRsc.loadBootstrapScriptContent` cannot be used with this option.
135
- *
136
- * Use this when you manually handle client entry setup and preloading.
137
- *
138
- * @experimental
139
- * @default false
140
- */
141
- customClientEntry?: boolean;
142
- };
143
- type PluginApi = {
144
- manager: RscPluginManager;
145
- };
146
- /** @experimental */
147
- declare function getPluginApi(config: Pick<ResolvedConfig, "plugins">): PluginApi | undefined;
148
- /** @experimental */
149
- declare function vitePluginRscMinimal(rscPluginOptions?: RscPluginOptions, manager?: RscPluginManager): Plugin[];
150
- declare global {
151
- function __VITE_ENVIRONMENT_RUNNER_IMPORT__(environmentName: string, id: string): Promise<any>;
152
- }
153
- declare function vitePluginRsc(rscPluginOptions?: RscPluginOptions): Plugin[];
154
- declare class RuntimeAsset {
155
- runtime: string;
156
- constructor(value: string);
157
- }
158
- type AssetsManifest = {
159
- bootstrapScriptContent: string | RuntimeAsset;
160
- clientReferenceDeps: Record<string, AssetDeps>;
161
- serverResources?: Record<string, Pick<AssetDeps, "css">>;
162
- cssLinkPrecedence?: boolean;
163
- };
164
- type AssetDeps = {
165
- js: (string | RuntimeAsset)[];
166
- css: (string | RuntimeAsset)[];
167
- };
168
- type ResolvedAssetsManifest = {
169
- bootstrapScriptContent: string;
170
- clientReferenceDeps: Record<string, ResolvedAssetDeps>;
171
- serverResources?: Record<string, Pick<ResolvedAssetDeps, "css">>;
172
- cssLinkPrecedence?: boolean;
173
- };
174
- type ResolvedAssetDeps = {
175
- js: string[];
176
- css: string[];
177
- };
178
- declare function transformRscCssExport(options: {
179
- ast: Awaited<ReturnType<typeof parseAstAsync>>;
180
- code: string;
181
- id?: string;
182
- filter: TransformWrapExportFilter;
183
- }): Promise<{
184
- output: MagicString;
185
- } | undefined>;
186
- //#endregion
187
- export { ResolvedAssetsManifest as a, getPluginApi as c, vitePluginRscMinimal as d, ResolvedAssetDeps as i, transformRscCssExport as l, AssetsManifest as n, RscPluginManager as o, PluginApi as r, RscPluginOptions as s, AssetDeps as t, vitePluginRsc as u };
@@ -1,91 +0,0 @@
1
- import { decode, encode } from "turbo-stream";
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
91
- export { createRpcServer as n, createRpcClient as t };
@@ -1,86 +0,0 @@
1
- import { i as tinyassert, n as memoize } from "./dist-yW9-EeG1.js";
2
- import { a as setInternalRequire, i as removeReferenceCacheTag, n as SERVER_REFERENCE_PREFIX, r as createReferenceCacheTag, t as SERVER_DECODE_CLIENT_PREFIX } from "./shared-rtJPs0Yj.js";
3
- import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
4
-
5
- //#region src/core/rsc.ts
6
- let init = false;
7
- let requireModule;
8
- function setRequireModule(options) {
9
- if (init) return;
10
- init = true;
11
- requireModule = (id) => {
12
- return options.load(removeReferenceCacheTag(id));
13
- };
14
- globalThis.__vite_rsc_server_require__ = memoize(async (id) => {
15
- if (id.startsWith(SERVER_DECODE_CLIENT_PREFIX)) {
16
- id = id.slice(SERVER_DECODE_CLIENT_PREFIX.length);
17
- id = removeReferenceCacheTag(id);
18
- const target = {};
19
- const getOrCreateClientReference = (name) => {
20
- return target[name] ??= ReactServer.registerClientReference(() => {
21
- throw new Error(`Unexpectedly client reference export '${name}' is called on server`);
22
- }, id, name);
23
- };
24
- return new Proxy(target, { getOwnPropertyDescriptor(_target, name) {
25
- if (typeof name !== "string" || name === "then") return Reflect.getOwnPropertyDescriptor(target, name);
26
- getOrCreateClientReference(name);
27
- return Reflect.getOwnPropertyDescriptor(target, name);
28
- } });
29
- }
30
- return requireModule(id);
31
- });
32
- setInternalRequire();
33
- }
34
- async function loadServerAction(id) {
35
- const [file, name] = id.split("#");
36
- return (await requireModule(file))[name];
37
- }
38
- function createServerManifest() {
39
- const cacheTag = import.meta.env.DEV ? createReferenceCacheTag() : "";
40
- return new Proxy({}, { get(_target, $$id, _receiver) {
41
- tinyassert(typeof $$id === "string");
42
- let [id, name] = $$id.split("#");
43
- tinyassert(id);
44
- tinyassert(name);
45
- return {
46
- id: SERVER_REFERENCE_PREFIX + id + cacheTag,
47
- name,
48
- chunks: [],
49
- async: true
50
- };
51
- } });
52
- }
53
- function createServerDecodeClientManifest() {
54
- return new Proxy({}, { get(_target, id) {
55
- return new Proxy({}, { get(_target, name) {
56
- return {
57
- id: SERVER_REFERENCE_PREFIX + SERVER_DECODE_CLIENT_PREFIX + id,
58
- name,
59
- chunks: [],
60
- async: true
61
- };
62
- } });
63
- } });
64
- }
65
- function createClientManifest(options) {
66
- const cacheTag = import.meta.env.DEV ? createReferenceCacheTag() : "";
67
- return new Proxy({}, { get(_target, $$id, _receiver) {
68
- tinyassert(typeof $$id === "string");
69
- let [id, name] = $$id.split("#");
70
- tinyassert(id);
71
- tinyassert(name);
72
- options?.onClientReference?.({
73
- id,
74
- name
75
- });
76
- return {
77
- id: id + cacheTag,
78
- name,
79
- chunks: [],
80
- async: true
81
- };
82
- } });
83
- }
84
-
85
- //#endregion
86
- export { setRequireModule as a, loadServerAction as i, createServerDecodeClientManifest as n, createServerManifest as r, createClientManifest as t };
File without changes
File without changes