@vitejs/plugin-rsc 0.5.32 → 0.5.34

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.
@@ -1,7 +1,7 @@
1
1
  import { t as createDebug } from "./dist-uqdtSkzK.js";
2
2
  import vitePluginRscCore from "./core/plugin.js";
3
- import { i as hasDirective } from "./scope-Do08R7C2.js";
4
- import { t as cjsModuleRunnerPlugin } from "./cjs-Cxg_7upE.js";
3
+ import { i as hasDirective } from "./scope-Bdx33sQv.js";
4
+ import { t as cjsModuleRunnerPlugin } from "./cjs-AWVWfddx.js";
5
5
  import { i as toCssVirtual, n as parseIdQuery, r as parseReferenceValidationVirtual, t as parseCssVirtual } from "./shared-B6H2TbnP.js";
6
6
  import { findDirectives, transformDirectiveProxyExport, transformExpandExportAll, transformServerActionServer, transformWrapExport } from "./transforms/index.js";
7
7
  import { o as generateEncryptionKey, s as toBase64 } from "./encryption-utils-BNbYHtC4.js";
@@ -489,11 +489,7 @@ function aggregateClaims(importId, claims) {
489
489
  exportNames: []
490
490
  };
491
491
  else if (aggregate.importId !== claim.importId || aggregate.referenceKey !== claim.referenceKey) throw new Error(`[vite-rsc] conflicting server reference identity for '${importId}'`);
492
- for (const name of claim.exportNames) {
493
- const existingOwner = exportOwners.get(name);
494
- if (existingOwner && existingOwner !== claimOwner) throw new Error(`[vite-rsc] server reference '${claim.referenceKey}#${name}' is claimed by both '${existingOwner}' and '${claimOwner}'`);
495
- exportOwners.set(name, claimOwner);
496
- }
492
+ for (const name of claim.exportNames) if (!exportOwners.get(name)) exportOwners.set(name, claimOwner);
497
493
  }
498
494
  assert(aggregate);
499
495
  aggregate.exportNames = [...exportOwners.keys()].sort();
@@ -714,7 +710,7 @@ function vitePluginRscMinimal(rscPluginOptions = {}, manager = new RscPluginMana
714
710
  function vitePluginRsc(rscPluginOptions = {}) {
715
711
  const manager = new RscPluginManager();
716
712
  const buildApp = async (builder) => {
717
- const colors = await import("./picocolors-CKiBgsDn.js").then((m) => /* @__PURE__ */ __toESM(m.default, 1));
713
+ const colors = await import("./picocolors-391UXIDd.js").then((m) => /* @__PURE__ */ __toESM(m.default, 1));
718
714
  const logStep = (msg) => {
719
715
  builder.config.logger.info(colors.blue(msg));
720
716
  };
@@ -1149,8 +1145,9 @@ export function createRpcClient(params) {
1149
1145
  if (id === "\0virtual:vite-rsc/assets-manifest") {
1150
1146
  assert(this.environment.name !== "client");
1151
1147
  assert(this.environment.mode === "dev");
1148
+ const entryUrl = assetsURL("@id/__x00__" + VIRTUAL_ENTRIES.browser, manager);
1152
1149
  const manifest = {
1153
- bootstrapScriptContent: `import(${serializeValueWithRuntime(assetsURL("@id/__x00__" + VIRTUAL_ENTRIES.browser, manager))})`,
1150
+ clientEntryUrl: rscPluginOptions.customClientEntry ? void 0 : entryUrl,
1154
1151
  clientReferenceDeps: {},
1155
1152
  cssLinkPrecedence: rscPluginOptions.cssLinkPrecedence
1156
1153
  };
@@ -1188,7 +1185,7 @@ export function createRpcClient(params) {
1188
1185
  css: rscAssetDeps[id]?.deps.css ?? []
1189
1186
  }, manager);
1190
1187
  const assetDeps = collectAssetDeps(bundle);
1191
- let bootstrapScriptContent = "";
1188
+ let clientEntryUrl;
1192
1189
  let clientEntryDeps;
1193
1190
  const clientReferenceDeps = {};
1194
1191
  for (const meta of Object.values(manager.clientReferenceMetaMap)) {
@@ -1203,12 +1200,10 @@ export function createRpcClient(params) {
1203
1200
  if (!entry) throw new Error(`[vite-rsc] Client build must have an entry chunk named "index". Use 'customClientEntry' option to disable this requirement.`);
1204
1201
  clientEntryDeps = assetsURLOfDeps(entry.deps, manager);
1205
1202
  for (const [key, deps] of Object.entries(clientReferenceDeps)) clientReferenceDeps[key] = mergeAssetDeps(deps, clientEntryDeps);
1206
- const entryUrl = assetsURL(entry.chunk.fileName, manager);
1207
- if (typeof entryUrl === "string") bootstrapScriptContent = `import(${JSON.stringify(entryUrl)})`;
1208
- else bootstrapScriptContent = new RuntimeAsset(`"import(" + JSON.stringify(${entryUrl.runtime}) + ")"`);
1203
+ clientEntryUrl = assetsURL(entry.chunk.fileName, manager);
1209
1204
  }
1210
1205
  manager.buildAssetsManifest = {
1211
- bootstrapScriptContent,
1206
+ clientEntryUrl,
1212
1207
  clientEntryDeps,
1213
1208
  clientReferenceDeps,
1214
1209
  serverResources,
@@ -1225,13 +1220,6 @@ export function createRpcClient(params) {
1225
1220
  }
1226
1221
  }
1227
1222
  },
1228
- createVirtualPlugin("vite-rsc/bootstrap-script-content", function() {
1229
- assert(this.environment.name !== "client");
1230
- return `\
1231
- import assetsManifest from "virtual:vite-rsc/assets-manifest";
1232
- export default assetsManifest.bootstrapScriptContent;
1233
- `;
1234
- }),
1235
1223
  {
1236
1224
  name: "rsc:bootstrap-script-content",
1237
1225
  transform: {
@@ -1245,7 +1233,7 @@ export default assetsManifest.bootstrapScriptContent;
1245
1233
  const [argStart, argEnd] = match.indices[1];
1246
1234
  const argCode = code.slice(argStart, argEnd).trim();
1247
1235
  assert(evalValue(argCode), `[vite-rsc] expected 'loadBootstrapScriptContent("index")' but got ${argCode}`);
1248
- let replacement = `Promise.resolve(__vite_rsc_assets_manifest.bootstrapScriptContent)`;
1236
+ let replacement = `Promise.resolve("import(" + JSON.stringify(__vite_rsc_assets_manifest.clientEntryUrl) + ")")`;
1249
1237
  const [start, end] = match.indices[0];
1250
1238
  output.overwrite(start, end, replacement);
1251
1239
  }
package/dist/plugin.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as ResolvedAssetsManifest, c as getPluginApi, d as vitePluginRscMinimal, i as ResolvedAssetDeps, l as transformRscCssExport, n as AssetsManifest, o as RscPluginManager, r as PluginApi, s as RscPluginOptions, t as AssetDeps, u as vitePluginRsc } from "./plugin-DqLpibhH.js";
1
+ import { a as ResolvedAssetsManifest, c as getPluginApi, d as vitePluginRscMinimal, i as ResolvedAssetDeps, l as transformRscCssExport, n as AssetsManifest, o as RscPluginManager, r as PluginApi, s as RscPluginOptions, t as AssetDeps, u as vitePluginRsc } from "./plugin-CKqXjp8D.js";
2
2
  export { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, type RscPluginManager, RscPluginOptions, vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
package/dist/plugin.js CHANGED
@@ -1,2 +1,2 @@
1
- import { i as vitePluginRscMinimal, n as transformRscCssExport, r as vitePluginRsc, t as getPluginApi } from "./plugin-C27mwbgw.js";
1
+ import { i as vitePluginRscMinimal, n as transformRscCssExport, r as vitePluginRsc, t as getPluginApi } from "./plugin-Cbs9j6lP.js";
2
2
  export { vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
@@ -1,2 +1,2 @@
1
- import { t as cjsModuleRunnerPlugin } from "../cjs-Cxg_7upE.js";
1
+ import { t as cjsModuleRunnerPlugin } from "../cjs-AWVWfddx.js";
2
2
  export { cjsModuleRunnerPlugin };
@@ -1,6 +1,6 @@
1
1
  import { a as createServerManifest, o as loadServerAction, r as createClientManifest, s as setRequireModule } from "../rsc-C3UdJLOW.js";
2
2
  import { a as registerClientReference, i as decodeReply, n as decodeAction, o as registerServerReference, r as decodeFormState, t as createTemporaryReferenceSet } from "../server-ZBjqNTqU.js";
3
- import { t as OnClientReference } from "../client-reference-Dy7j0iU8.js";
3
+ import { t as OnClientReference } from "../client-reference-DEZtXTv1.js";
4
4
  //#region src/rsc/server.d.ts
5
5
  declare function renderToReadableStream<T>(data: T, options?: object, extraOptions?: {
6
6
  /**
@@ -1,5 +1,5 @@
1
1
  import { d as RenderToReadableStreamOptions, u as PrerenderResult } from "../index-C5IY2S-e.js";
2
- import { t as OnClientReference } from "../client-reference-Dy7j0iU8.js";
2
+ import { t as OnClientReference } from "../client-reference-DEZtXTv1.js";
3
3
  //#region src/rsc/static.d.ts
4
4
  declare function prerender<T>(data: T, options?: RenderToReadableStreamOptions, extraOptions?: {
5
5
  /**
@@ -1,8 +1,11 @@
1
1
  import { i as tinyassert } from "./dist-uqdtSkzK.js";
2
2
  import { walk } from "estree-walker";
3
3
  //#region src/transforms/utils.ts
4
- function hasDirective(body, directive) {
5
- return !!body.find((stmt) => stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && stmt.expression.value === directive);
4
+ function isDirective(node) {
5
+ return node.type === "ExpressionStatement" && "directive" in node;
6
+ }
7
+ function hasDirective(viteBody, directive) {
8
+ return viteBody.some((stmt) => isDirective(stmt) && stmt.directive === directive);
6
9
  }
7
10
  function extractNames(param) {
8
11
  return extractIdentifiers(param).map((n) => n.name);
@@ -34,8 +37,10 @@ function extractIdentifiers(param, nodes = []) {
34
37
  return nodes;
35
38
  }
36
39
  function validateNonAsyncFunction(opts, node) {
37
- if (!opts.rejectNonAsyncFunction) return;
38
- if (node.type === "ClassDeclaration" || node.type === "ClassExpression" || (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && !node.async) throw Object.assign(/* @__PURE__ */ new Error(`unsupported non async function`), { pos: node.start });
40
+ if (node.type === "Literal" || node.type === "ObjectExpression" || node.type === "ArrayExpression" || node.type === "ClassDeclaration" || node.type === "ClassExpression" || (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && !node.async) rejectNonAsyncFunction(opts, node.start);
41
+ }
42
+ function rejectNonAsyncFunction(opts, pos) {
43
+ if (opts.rejectNonAsyncFunction) throw Object.assign(/* @__PURE__ */ new Error(`unsupported non async function`), { pos });
39
44
  }
40
45
  //#endregion
41
46
  //#region src/transforms/scope.ts
@@ -174,4 +179,4 @@ function getOutermostBindableReference(id, parentStack) {
174
179
  return current;
175
180
  }
176
181
  //#endregion
177
- export { validateNonAsyncFunction as a, hasDirective as i, extractIdentifiers as n, extractNames as r, buildScopeTree as t };
182
+ export { isDirective as a, hasDirective as i, extractIdentifiers as n, rejectNonAsyncFunction as o, extractNames as r, validateNonAsyncFunction as s, buildScopeTree as t };
package/dist/ssr.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { s as EncodeFormActionCallback } from "./index-C5IY2S-e.js";
2
2
  import { createServerConsumerManifest, setRequireModule } from "./core/ssr.js";
3
- import { i as ResolvedAssetDeps } from "./plugin-DqLpibhH.js";
3
+ import { i as ResolvedAssetDeps } from "./plugin-CKqXjp8D.js";
4
4
  import { callServer, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL } from "./react/ssr.js";
5
5
  //#region src/ssr.d.ts
6
+ declare function getClientEntryUrl(): string;
6
7
  /**
7
8
  * Callback type for client reference dependency notifications.
8
9
  * Called during SSR when a client component's dependencies are loaded.
@@ -19,4 +20,4 @@ type OnClientReference = (reference: {
19
20
  */
20
21
  declare function setOnClientReference(callback: OnClientReference | undefined): void;
21
22
  //#endregion
22
- export { type EncodeFormActionCallback, OnClientReference, callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setOnClientReference, setRequireModule };
23
+ export { type EncodeFormActionCallback, OnClientReference, callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, getClientEntryUrl, setOnClientReference, setRequireModule };
package/dist/ssr.js CHANGED
@@ -5,6 +5,11 @@ import * as clientReferences from "virtual:vite-rsc/client-references";
5
5
  import * as ReactDOM from "react-dom";
6
6
  import assetsManifest from "virtual:vite-rsc/assets-manifest";
7
7
  //#region src/ssr.tsx
8
+ function getClientEntryUrl() {
9
+ const url = assetsManifest.clientEntryUrl;
10
+ if (!url) throw new Error(`[vite-rsc] getClientEntryUrl() cannot be used with the 'customClientEntry' option`);
11
+ return url;
12
+ }
8
13
  let onClientReference;
9
14
  /**
10
15
  * Register a callback to be notified when client reference dependencies are loaded.
@@ -82,4 +87,4 @@ function preloadDeps(deps) {
82
87
  });
83
88
  }
84
89
  //#endregion
85
- export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setOnClientReference, setRequireModule };
90
+ export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, getClientEntryUrl, setOnClientReference, setRequireModule };
@@ -1,2 +1,2 @@
1
- import { a as extractIdentifiers, c as validateNonAsyncFunction, d as transformProxyExport, f as TransformWrapExportFilter, g as transformHoistInlineDirective, h as findDirectives, i as transformServerActionServer, l as TransformProxyExportOptions, m as transformWrapExport, n as TransformExpandExportAllOptions, o as extractNames, p as TransformWrapExportOptions, r as transformExpandExportAll, s as hasDirective, t as TransformExpandExportAllContext, u as transformDirectiveProxyExport } from "../index-COzKOTR1.js";
2
- export { TransformExpandExportAllContext, TransformExpandExportAllOptions, TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, extractIdentifiers, extractNames, findDirectives, hasDirective, transformDirectiveProxyExport, transformExpandExportAll, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport, validateNonAsyncFunction };
1
+ import { A as ModuleExportSpecifier, C as TransformModuleExportEffectFilter, D as ModuleExportEntry, E as transformModuleExportEffect, F as findDirectives, I as transformHoistInlineDirective, M as TransformHoistInlineDirectiveMeta, N as TransformHoistInlineDirectiveOptions, O as ModuleExportGroup, P as TransformHoistInlineDirectiveResult, S as TransformModuleExportEffectContext, T as TransformModuleExportEffectResult, _ as transformProxyExport, a as TransformServerActionServerResult, b as TransformWrapExportResult, c as extractNames, d as rejectNonAsyncFunction, f as validateNonAsyncFunction, g as transformDirectiveProxyExport, h as TransformProxyExportResult, i as TransformServerActionServerOptions, j as scanModuleExports, k as ModuleExportMeta, l as hasDirective, m as TransformProxyExportOptions, n as TransformExpandExportAllOptions, o as transformServerActionServer, p as TransformProxyExportFilter, r as transformExpandExportAll, s as extractIdentifiers, t as TransformExpandExportAllContext, u as isDirective, v as TransformWrapExportFilter, w as TransformModuleExportEffectOptions, x as transformWrapExport, y as TransformWrapExportOptions } from "../index-XXYjyFr6.js";
2
+ export { ModuleExportEntry, ModuleExportGroup, ModuleExportMeta, ModuleExportSpecifier, TransformExpandExportAllContext, TransformExpandExportAllOptions, TransformHoistInlineDirectiveMeta, TransformHoistInlineDirectiveOptions, TransformHoistInlineDirectiveResult, TransformModuleExportEffectContext, TransformModuleExportEffectFilter, TransformModuleExportEffectOptions, TransformModuleExportEffectResult, TransformProxyExportFilter, TransformProxyExportOptions, TransformProxyExportResult, TransformServerActionServerOptions, TransformServerActionServerResult, TransformWrapExportFilter, TransformWrapExportOptions, TransformWrapExportResult, extractIdentifiers, extractNames, findDirectives, hasDirective, isDirective, rejectNonAsyncFunction, scanModuleExports, transformDirectiveProxyExport, transformExpandExportAll, transformHoistInlineDirective, transformModuleExportEffect, transformProxyExport, transformServerActionServer, transformWrapExport, validateNonAsyncFunction };