@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.
- package/README.md +20 -19
- package/dist/{cjs-Cxg_7upE.js → cjs-AWVWfddx.js} +3 -2
- package/dist/{client-reference-Dy7j0iU8.d.ts → client-reference-DEZtXTv1.d.ts} +1 -1
- package/dist/{index-COzKOTR1.d.ts → index-XXYjyFr6.d.ts} +291 -37
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{picocolors-CKiBgsDn.js → picocolors-391UXIDd.js} +1 -1
- package/dist/{plugin-DqLpibhH.d.ts → plugin-CKqXjp8D.d.ts} +5 -4
- package/dist/{plugin-C27mwbgw.js → plugin-Cbs9j6lP.js} +10 -22
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugins/cjs.js +1 -1
- package/dist/rsc/server.d.ts +1 -1
- package/dist/rsc/static.d.ts +1 -1
- package/dist/{scope-Do08R7C2.js → scope-Bdx33sQv.js} +10 -5
- package/dist/ssr.d.ts +3 -2
- package/dist/ssr.js +6 -1
- package/dist/transforms/index.d.ts +2 -2
- package/dist/transforms/index.js +508 -189
- package/package.json +16 -15
- package/types/index.d.ts +1 -0
package/README.md
CHANGED
|
@@ -26,12 +26,15 @@ npm create vite@latest -- --template rsc
|
|
|
26
26
|
**Integration examples:**
|
|
27
27
|
|
|
28
28
|
- [`./examples/basic`](./examples/basic) - Comprehensive showcase of standard RSC features and the primary E2E test fixture.
|
|
29
|
-
- [`./examples/use-cache`](./examples/use-cache) -
|
|
29
|
+
- [`./examples/use-cache`](./examples/use-cache) - Local cached functions and components demonstrating argument keys, Flight replay, dynamic children, captured values, and invalidation.
|
|
30
|
+
- [`./examples/use-cache-callable`](./examples/use-cache-callable) - Cached server references demonstrating inline and file directives, client invocation, argument admission, and encrypted closure captures.
|
|
31
|
+
- [`./examples/use-cache-persistent`](./examples/use-cache-persistent) - Persistent callable cache entries demonstrating Flight value replay and dependency-aware development invalidation.
|
|
30
32
|
- [`./examples/custom-server-function`](./examples/custom-server-function) - Third-party Server Function directive integration using server reference claims.
|
|
31
33
|
- [`./examples/ssg`](./examples/ssg) - Static site generation with MDX and client components for interactivity.
|
|
32
34
|
- [`./examples/ppr`](./examples/ppr) - Partial prerendering with a reusable static HTML shell and request-time RSC content.
|
|
33
35
|
- [`./examples/no-ssr`](./examples/no-ssr) - RSC application without an SSR environment.
|
|
34
36
|
- [`./examples/client-first`](./examples/client-first) - Experimental client-owned page that consumes RSC function results.
|
|
37
|
+
- [`./examples/action-reachability`](./examples/action-reachability) - Route-aware dispatch for a retained server action.
|
|
35
38
|
- [`./examples/browser-mode`](./examples/browser-mode) - Advanced setup that runs both RSC and React client environments in the browser with custom module loading.
|
|
36
39
|
- [`./examples/performance-track`](./examples/performance-track) - Minimal React Server Components performance track probe.
|
|
37
40
|
- [`./examples/react-router`](./examples/react-router) - React Router RSC integration
|
|
@@ -47,7 +50,7 @@ This is the diagram to show the basic flow of RSC rendering process. See also ht
|
|
|
47
50
|
graph TD
|
|
48
51
|
|
|
49
52
|
subgraph "<strong>rsc environment</strong>"
|
|
50
|
-
A["React virtual dom tree"] --> |"[@vitejs/plugin-rsc/rsc]<br /><code>renderToReadableStream</code>"| B1["RSC Stream"];
|
|
53
|
+
A["React virtual dom tree"] --> |"[@vitejs/plugin-rsc/rsc/server]<br /><code>renderToReadableStream</code>"| B1["RSC Stream"];
|
|
51
54
|
end
|
|
52
55
|
|
|
53
56
|
B1 --> B2
|
|
@@ -137,7 +140,7 @@ export default defineConfig({
|
|
|
137
140
|
- [`entry.rsc.tsx`](./examples/starter/src/framework/entry.rsc.tsx)
|
|
138
141
|
|
|
139
142
|
```tsx
|
|
140
|
-
import { renderToReadableStream } from '@vitejs/plugin-rsc/rsc'
|
|
143
|
+
import { renderToReadableStream } from '@vitejs/plugin-rsc/rsc/server'
|
|
141
144
|
|
|
142
145
|
// the plugin assumes `rsc` entry having default export of request handler
|
|
143
146
|
export default async function handler(request: Request): Promise<Response> {
|
|
@@ -184,20 +187,19 @@ if (import.meta.hot) {
|
|
|
184
187
|
- [`entry.ssr.tsx`](./examples/starter/src/framework/entry.ssr.tsx)
|
|
185
188
|
|
|
186
189
|
```tsx
|
|
187
|
-
import {
|
|
190
|
+
import {
|
|
191
|
+
createFromReadableStream,
|
|
192
|
+
getClientEntryUrl,
|
|
193
|
+
} from '@vitejs/plugin-rsc/ssr'
|
|
188
194
|
import { renderToReadableStream } from 'react-dom/server.edge'
|
|
189
195
|
|
|
190
196
|
export async function handleSsr(rscStream: ReadableStream) {
|
|
191
197
|
// deserialize RSC stream back to React VDOM
|
|
192
198
|
const root = await createFromReadableStream(rscStream)
|
|
193
199
|
|
|
194
|
-
// helper API to allow referencing browser entry content from SSR environment
|
|
195
|
-
const bootstrapScriptContent =
|
|
196
|
-
await import.meta.viteRsc.loadBootstrapScriptContent('index')
|
|
197
|
-
|
|
198
200
|
// render html (traditional SSR)
|
|
199
201
|
const htmlStream = renderToReadableStream(root, {
|
|
200
|
-
|
|
202
|
+
bootstrapModules: [getClientEntryUrl()],
|
|
201
203
|
})
|
|
202
204
|
|
|
203
205
|
return htmlStream
|
|
@@ -332,20 +334,21 @@ export function UserApp() {
|
|
|
332
334
|
|
|
333
335
|
### Available on `ssr` environment
|
|
334
336
|
|
|
335
|
-
#### `
|
|
337
|
+
#### `getClientEntryUrl()`
|
|
336
338
|
|
|
337
|
-
This
|
|
339
|
+
This returns the URL used to load the client entry specified by `environments.client.build.rollupOptions.input.index`. This can be used with React DOM SSR APIs such as [`renderToReadableStream`](https://react.dev/reference/react-dom/server/renderToReadableStream).
|
|
338
340
|
|
|
339
341
|
```js
|
|
342
|
+
import { getClientEntryUrl } from '@vitejs/plugin-rsc/ssr'
|
|
340
343
|
import { renderToReadableStream } from 'react-dom/server.edge'
|
|
341
344
|
|
|
342
|
-
const bootstrapScriptContent =
|
|
343
|
-
await import.meta.viteRsc.loadBootstrapScriptContent('index')
|
|
344
345
|
const htmlStream = await renderToReadableStream(reactNode, {
|
|
345
|
-
|
|
346
|
+
bootstrapModules: [getClientEntryUrl()],
|
|
346
347
|
})
|
|
347
348
|
```
|
|
348
349
|
|
|
350
|
+
`getClientEntryUrl()` cannot be used when the `customClientEntry` plugin option is enabled.
|
|
351
|
+
|
|
349
352
|
### Available on `client` environment
|
|
350
353
|
|
|
351
354
|
#### `rsc:update` event
|
|
@@ -486,6 +489,8 @@ Together, these APIs allow a React VDOM to be serialized, saved as an RSC stream
|
|
|
486
489
|
This module re-exports `@vitejs/plugin-rsc/rsc/server` and
|
|
487
490
|
`@vitejs/plugin-rsc/rsc/client`.
|
|
488
491
|
|
|
492
|
+
Prefer the explicit `/rsc/server` and `/rsc/client` entry points when only one protocol side is needed. Besides making API ownership explicit, this allows Vite to avoid loading and bundling the unused `react-server-dom` runtime. Use `/rsc` when both sides are intentionally needed.
|
|
493
|
+
|
|
489
494
|
#### Vite-specific extension: `renderToReadableStream` (experimental)
|
|
490
495
|
|
|
491
496
|
> [!NOTE]
|
|
@@ -534,11 +539,7 @@ This module provides Vite-integrated RSC runtime APIs based on
|
|
|
534
539
|
|
|
535
540
|
The runtime APIs are exposed through two layers:
|
|
536
541
|
|
|
537
|
-
- `@vitejs/plugin-rsc/rsc`, `@vitejs/plugin-rsc/ssr`, and
|
|
538
|
-
`@vitejs/plugin-rsc/browser` are the recommended entry points for application
|
|
539
|
-
and framework runtime code. They initialize the plugin's built-in module
|
|
540
|
-
loading using the manifests generated by Vite and re-export the corresponding
|
|
541
|
-
React runtime APIs described above.
|
|
542
|
+
- `@vitejs/plugin-rsc/rsc/server`, `@vitejs/plugin-rsc/rsc/client`, `@vitejs/plugin-rsc/rsc/static`, `@vitejs/plugin-rsc/ssr`, and `@vitejs/plugin-rsc/browser` are the recommended entry points for application and framework runtime code. They initialize the plugin's built-in module loading using the manifests generated by Vite and re-export the corresponding React runtime APIs described above.
|
|
542
543
|
- `@vitejs/plugin-rsc/react/rsc`, `@vitejs/plugin-rsc/react/ssr`, and
|
|
543
544
|
`@vitejs/plugin-rsc/react/browser` are low-level runtime adapters. They are
|
|
544
545
|
used by code generated for `"use client"` and `"use server"`, and by custom
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as createDebug } from "./dist-uqdtSkzK.js";
|
|
2
|
-
import { t as buildScopeTree } from "./scope-
|
|
2
|
+
import { t as buildScopeTree } from "./scope-Bdx33sQv.js";
|
|
3
3
|
import { n as parseIdQuery } from "./shared-B6H2TbnP.js";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
@@ -14,7 +14,8 @@ function __cjs_interop__(m) {
|
|
|
14
14
|
return m.__cjs_module_runner_transform || "default" in m && Object.keys(m).every((k) => k === "default" || m[k] === m.default[k]) ? m.default : m;
|
|
15
15
|
}
|
|
16
16
|
const CJS_INTEROP_HELPER = __cjs_interop__.toString().replace(/\n\s*/g, "");
|
|
17
|
-
function transformCjsToEsm(code,
|
|
17
|
+
function transformCjsToEsm(code, viteAst, options) {
|
|
18
|
+
const ast = viteAst;
|
|
18
19
|
const output = new MagicString(code);
|
|
19
20
|
const scopeTree = buildScopeTree(ast);
|
|
20
21
|
const parentNodes = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as ClientReferenceMetadata } from "./rsc-C3UdJLOW.js";
|
|
2
|
-
import { i as ResolvedAssetDeps } from "./plugin-
|
|
2
|
+
import { i as ResolvedAssetDeps } from "./plugin-CKqXjp8D.js";
|
|
3
3
|
//#region src/rsc/client-reference.d.ts
|
|
4
4
|
type OnClientReference = (metadata: ClientReferenceMetadata & {
|
|
5
5
|
deps: ResolvedAssetDeps;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import MagicString from "magic-string";
|
|
2
|
+
import { ESTree } from "vite";
|
|
2
3
|
//#region ../../node_modules/.pnpm/@types+estree@1.0.9/node_modules/@types/estree/index.d.ts
|
|
3
4
|
// This definition file follows a somewhat unusual format. ESTree allows
|
|
4
5
|
// runtime type checks based on the `type` parameter. In order to explain this
|
|
@@ -526,6 +527,31 @@ interface AwaitExpression extends BaseExpression {
|
|
|
526
527
|
}
|
|
527
528
|
//#endregion
|
|
528
529
|
//#region src/transforms/hoist.d.ts
|
|
530
|
+
type TransformHoistInlineDirectiveOptions = {
|
|
531
|
+
runtime: (value: string, name: string, meta: TransformHoistInlineDirectiveMeta) => string;
|
|
532
|
+
directive: string | RegExp;
|
|
533
|
+
rejectNonAsyncFunction?: boolean;
|
|
534
|
+
encode?: (value: string) => string;
|
|
535
|
+
decode?: (value: string) => string;
|
|
536
|
+
/** Keep generated hoisted declarations module-local instead of exporting them. */
|
|
537
|
+
noExport?: boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Evaluate the runtime expression once during module initialization.
|
|
540
|
+
* The expression can reference imports and the hoisted implementation, but
|
|
541
|
+
* must not depend on other module-local initialization.
|
|
542
|
+
*/
|
|
543
|
+
hoistRuntime?: boolean;
|
|
544
|
+
};
|
|
545
|
+
type TransformHoistInlineDirectiveMeta = {
|
|
546
|
+
/** Match result for the source function directive. */
|
|
547
|
+
directiveMatch: RegExpMatchArray;
|
|
548
|
+
/** Original source function before closure captures are added as parameters. */
|
|
549
|
+
valueNode: ArrowFunctionExpression | FunctionDeclaration | FunctionExpression;
|
|
550
|
+
};
|
|
551
|
+
type TransformHoistInlineDirectiveResult = {
|
|
552
|
+
output: MagicString;
|
|
553
|
+
names: string[];
|
|
554
|
+
};
|
|
529
555
|
/**
|
|
530
556
|
* Turns an inline directive function into a module-level registered function.
|
|
531
557
|
* Conceptually:
|
|
@@ -578,25 +604,40 @@ interface AwaitExpression extends BaseExpression {
|
|
|
578
604
|
*
|
|
579
605
|
* In this second sketch, `__ENCODE__(...)` and `__DECODE__(...)` likewise
|
|
580
606
|
* represent the expressions returned by those code-generation callbacks.
|
|
607
|
+
*
|
|
608
|
+
* With `hoistRuntime`, the runtime result becomes the module-level binding and
|
|
609
|
+
* the moved function becomes its private implementation:
|
|
610
|
+
*
|
|
611
|
+
* ```js
|
|
612
|
+
* function Component() {
|
|
613
|
+
* const x = 1
|
|
614
|
+
* const action = $$hoist_0_action.bind(null, x)
|
|
615
|
+
* }
|
|
616
|
+
* export const $$hoist_0_action = __RUNTIME__($$hoist_0_action$$impl)
|
|
617
|
+
* async function $$hoist_0_action$$impl(x, y) {
|
|
618
|
+
* "use server"
|
|
619
|
+
* return x + y
|
|
620
|
+
* }
|
|
621
|
+
* ```
|
|
622
|
+
*
|
|
623
|
+
* `noExport` independently keeps `$$hoist_0_action` module-local when an
|
|
624
|
+
* integration needs module-scope runtime initialization without an export.
|
|
581
625
|
*/
|
|
582
|
-
declare function transformHoistInlineDirective(input: string,
|
|
583
|
-
|
|
584
|
-
directiveMatch: RegExpMatchArray;
|
|
585
|
-
}) => string;
|
|
586
|
-
directive: string | RegExp;
|
|
587
|
-
rejectNonAsyncFunction?: boolean;
|
|
588
|
-
encode?: (value: string) => string;
|
|
589
|
-
decode?: (value: string) => string;
|
|
590
|
-
/** Keep generated hoisted declarations module-local instead of exporting them. */
|
|
591
|
-
noExport?: boolean;
|
|
592
|
-
}): {
|
|
593
|
-
output: MagicString;
|
|
594
|
-
names: string[];
|
|
595
|
-
};
|
|
596
|
-
declare function findDirectives(ast: Program, directive: string): Literal[];
|
|
626
|
+
declare function transformHoistInlineDirective(input: string, viteAst: ESTree.Program, { runtime, rejectNonAsyncFunction, ...options }: TransformHoistInlineDirectiveOptions): TransformHoistInlineDirectiveResult;
|
|
627
|
+
declare function findDirectives(viteAst: ESTree.Program, directive: string): Literal[];
|
|
597
628
|
//#endregion
|
|
598
|
-
//#region src/transforms/
|
|
599
|
-
type
|
|
629
|
+
//#region src/transforms/module-export-scan.d.ts
|
|
630
|
+
type ModuleExportMeta = {
|
|
631
|
+
/**
|
|
632
|
+
* The source node that evaluates to the exported value when directly
|
|
633
|
+
* available.
|
|
634
|
+
*
|
|
635
|
+
* - The declaration for a function or class export.
|
|
636
|
+
* - The initializer for a variable export.
|
|
637
|
+
* - The declaration expression for a default export.
|
|
638
|
+
* - `undefined` for export specifiers and re-exports.
|
|
639
|
+
*/
|
|
640
|
+
valueNode?: Node | ExportDefaultDeclaration["declaration"];
|
|
600
641
|
/**
|
|
601
642
|
* The local declaration name when statically available.
|
|
602
643
|
*
|
|
@@ -617,8 +658,6 @@ type ExportMeta = {
|
|
|
617
658
|
isFunction?: boolean;
|
|
618
659
|
/**
|
|
619
660
|
* The local identifier referenced by a default export.
|
|
620
|
-
* The RSC CSS transform uses this to detect a component by its capitalized
|
|
621
|
-
* local name and preserve that name on the generated wrapper.
|
|
622
661
|
*
|
|
623
662
|
* - `"Page"` for `const Page = () => {}; export default Page`
|
|
624
663
|
* - `undefined` for `export default function Page() {}`
|
|
@@ -626,59 +665,273 @@ type ExportMeta = {
|
|
|
626
665
|
*/
|
|
627
666
|
defaultExportIdentifierName?: string;
|
|
628
667
|
};
|
|
629
|
-
type
|
|
668
|
+
type ModuleExportEntry = {
|
|
669
|
+
localName: string;
|
|
670
|
+
exportName: string;
|
|
671
|
+
meta: ModuleExportMeta;
|
|
672
|
+
};
|
|
673
|
+
type ModuleExportSpecifier = {
|
|
674
|
+
node: ExportSpecifier;
|
|
675
|
+
localName: string;
|
|
676
|
+
exportName: string;
|
|
677
|
+
meta: ModuleExportMeta;
|
|
678
|
+
};
|
|
679
|
+
type ModuleExportDefaultKind = "named-declaration" | "identifier" | "other";
|
|
680
|
+
type ModuleExportGroup = {
|
|
681
|
+
/**
|
|
682
|
+
* export function foo() {}
|
|
683
|
+
* export class Foo {}
|
|
684
|
+
*/
|
|
685
|
+
type: "declaration";
|
|
686
|
+
node: ExportNamedDeclaration;
|
|
687
|
+
declaration: FunctionDeclaration | ClassDeclaration;
|
|
688
|
+
export: ModuleExportEntry;
|
|
689
|
+
} | {
|
|
690
|
+
/**
|
|
691
|
+
* export const foo = 1, bar = 2
|
|
692
|
+
*/
|
|
693
|
+
type: "variable-declaration";
|
|
694
|
+
node: ExportNamedDeclaration;
|
|
695
|
+
declaration: VariableDeclaration;
|
|
696
|
+
declarators: {
|
|
697
|
+
node: VariableDeclarator;
|
|
698
|
+
exports: ModuleExportEntry[];
|
|
699
|
+
}[];
|
|
700
|
+
} | {
|
|
701
|
+
/**
|
|
702
|
+
* export { foo as bar }
|
|
703
|
+
* export { foo as bar } from './dep'
|
|
704
|
+
*/
|
|
705
|
+
type: "specifiers";
|
|
706
|
+
node: ExportNamedDeclaration;
|
|
707
|
+
exports: ModuleExportSpecifier[];
|
|
708
|
+
} | {
|
|
709
|
+
/**
|
|
710
|
+
* export * from './dep'
|
|
711
|
+
* export * as ns from './dep'
|
|
712
|
+
*/
|
|
713
|
+
type: "export-all";
|
|
714
|
+
node: ExportAllDeclaration;
|
|
715
|
+
} | {
|
|
716
|
+
/**
|
|
717
|
+
* `named-declaration`: export default function foo() {}
|
|
718
|
+
* `identifier`: export default value
|
|
719
|
+
* `other`: export default function () {}
|
|
720
|
+
* `other`: export default () => {}
|
|
721
|
+
*/
|
|
722
|
+
type: "default";
|
|
723
|
+
kind: ModuleExportDefaultKind;
|
|
724
|
+
node: ExportDefaultDeclaration;
|
|
725
|
+
localName?: string;
|
|
726
|
+
meta: ModuleExportMeta;
|
|
727
|
+
};
|
|
728
|
+
declare function scanModuleExports(viteAst: ESTree.Program): ModuleExportGroup[];
|
|
729
|
+
//#endregion
|
|
730
|
+
//#region src/transforms/module-export-effect.d.ts
|
|
731
|
+
type TransformModuleExportEffectFilter = (name: string, meta: ModuleExportMeta) => boolean;
|
|
732
|
+
type TransformModuleExportEffectContext = {
|
|
733
|
+
binding: string;
|
|
734
|
+
exportName: string;
|
|
735
|
+
meta: ModuleExportMeta;
|
|
736
|
+
};
|
|
737
|
+
type TransformModuleExportEffectOptions = {
|
|
738
|
+
generate: (context: TransformModuleExportEffectContext) => string;
|
|
739
|
+
filter?: TransformModuleExportEffectFilter;
|
|
740
|
+
rejectNonAsyncFunction?: boolean;
|
|
741
|
+
exportAll?: "error" | "preserve";
|
|
742
|
+
};
|
|
743
|
+
type TransformModuleExportEffectResult = {
|
|
744
|
+
output: MagicString;
|
|
745
|
+
references: TransformModuleExportEffectContext[];
|
|
746
|
+
referenceNames: string[];
|
|
747
|
+
};
|
|
748
|
+
/**
|
|
749
|
+
* Preserves source bindings and emits registration effects at module end.
|
|
750
|
+
*
|
|
751
|
+
* Conceptually:
|
|
752
|
+
*
|
|
753
|
+
* ```js
|
|
754
|
+
* export async function action() {}
|
|
755
|
+
* export default async () => {}
|
|
756
|
+
* ```
|
|
757
|
+
*
|
|
758
|
+
* becomes:
|
|
759
|
+
*
|
|
760
|
+
* ```js
|
|
761
|
+
* async function action() {}
|
|
762
|
+
* const $$effect_default = async () => {}
|
|
763
|
+
*
|
|
764
|
+
* __GENERATE__(action, 'action')
|
|
765
|
+
* export { action }
|
|
766
|
+
* __GENERATE__($$effect_default, 'default')
|
|
767
|
+
* export default $$effect_default
|
|
768
|
+
* ```
|
|
769
|
+
*
|
|
770
|
+
* Here, `__GENERATE__(...)` represents the expression returned by the
|
|
771
|
+
* `generate` callback for each `{ binding, exportName, meta }` context.
|
|
772
|
+
* `references` returns those contexts in generation order, while
|
|
773
|
+
* `referenceNames` returns only their export names.
|
|
774
|
+
*
|
|
775
|
+
* Effects emitted through declaration and default-export rewrites remain mapped
|
|
776
|
+
* to their original export sites. Export-specifier effects are appended without
|
|
777
|
+
* explicit mappings and rely on adjacent-source fallback. React captures the
|
|
778
|
+
* `registerServerReference` caller as the reference source location.
|
|
779
|
+
*
|
|
780
|
+
* Generated bindings such as `$$effect_default` and `$$effect_import_*` are not
|
|
781
|
+
* deconflicted from user bindings, consistent with the other transform helpers.
|
|
782
|
+
*/
|
|
783
|
+
declare function transformModuleExportEffect(input: string, viteAst: ESTree.Program, options: TransformModuleExportEffectOptions): TransformModuleExportEffectResult;
|
|
784
|
+
//#endregion
|
|
785
|
+
//#region src/transforms/wrap-export.d.ts
|
|
786
|
+
type TransformWrapExportFilter = (name: string, meta: ModuleExportMeta) => boolean;
|
|
630
787
|
type TransformWrapExportOptions = {
|
|
631
|
-
runtime: (value: string, name: string, meta:
|
|
788
|
+
runtime: (value: string, name: string, meta: ModuleExportMeta) => string;
|
|
632
789
|
ignoreExportAllDeclaration?: boolean;
|
|
633
790
|
rejectNonAsyncFunction?: boolean;
|
|
634
791
|
filter?: TransformWrapExportFilter;
|
|
635
792
|
};
|
|
636
|
-
|
|
793
|
+
type TransformWrapExportResult = {
|
|
637
794
|
exportNames: string[];
|
|
638
795
|
output: MagicString;
|
|
639
796
|
};
|
|
797
|
+
/**
|
|
798
|
+
* Replaces selected module-local export bindings with runtime wrappers.
|
|
799
|
+
*
|
|
800
|
+
* Conceptually:
|
|
801
|
+
*
|
|
802
|
+
* ```js
|
|
803
|
+
* export async function action() {}
|
|
804
|
+
* export const loader = async () => {}
|
|
805
|
+
* export default function Page() {}
|
|
806
|
+
* ```
|
|
807
|
+
*
|
|
808
|
+
* becomes:
|
|
809
|
+
*
|
|
810
|
+
* ```js
|
|
811
|
+
* async function action() {}
|
|
812
|
+
* let loader = async () => {}
|
|
813
|
+
* function Page() {}
|
|
814
|
+
*
|
|
815
|
+
* action = __WRAP__(action, 'action')
|
|
816
|
+
* export { action }
|
|
817
|
+
* loader = __WRAP__(loader, 'loader')
|
|
818
|
+
* export { loader }
|
|
819
|
+
* const $$wrap_Page = __WRAP__(Page, 'default')
|
|
820
|
+
* export { $$wrap_Page as default }
|
|
821
|
+
* ```
|
|
822
|
+
*
|
|
823
|
+
* Here, `__WRAP__(...)` represents the expression returned by `runtime`.
|
|
824
|
+
* Unlike `transformModuleExportWrap`, direct local references observe the
|
|
825
|
+
* wrapped value because the original binding itself is reassigned.
|
|
826
|
+
*
|
|
827
|
+
* Declaration rewrites are moved to the end of the module so each generated
|
|
828
|
+
* runtime call retains the original export token's source mapping. Wrappers for
|
|
829
|
+
* export specifiers and default exports are appended without explicit mappings.
|
|
830
|
+
*
|
|
831
|
+
* Generated `$$wrap_*` and `$$import_*` names are not deconflicted from user
|
|
832
|
+
* bindings, consistent with the other transform helpers.
|
|
833
|
+
*/
|
|
834
|
+
declare function transformWrapExport(input: string, viteAst: ESTree.Program, options: TransformWrapExportOptions): TransformWrapExportResult;
|
|
640
835
|
//#endregion
|
|
641
836
|
//#region src/transforms/proxy-export.d.ts
|
|
837
|
+
/** Selects which statically discovered exports become proxies. */
|
|
838
|
+
type TransformProxyExportFilter = (name: string, meta: ModuleExportMeta) => boolean;
|
|
642
839
|
type TransformProxyExportOptions = {
|
|
643
|
-
/**
|
|
840
|
+
/**
|
|
841
|
+
* Original module source used to preserve source mappings and initializer
|
|
842
|
+
* text. Required by `keep`.
|
|
843
|
+
*/
|
|
644
844
|
code?: string;
|
|
845
|
+
/**
|
|
846
|
+
* Returns the proxy expression for an export name. In `keep` mode, `value`
|
|
847
|
+
* contains the original initializer for a single identifier declaration.
|
|
848
|
+
*/
|
|
645
849
|
runtime: (name: string, meta?: {
|
|
646
850
|
value: string;
|
|
647
851
|
}) => string;
|
|
852
|
+
/**
|
|
853
|
+
* Removes a bare `export *` instead of rejecting it. With `keep`, the
|
|
854
|
+
* declaration is retained.
|
|
855
|
+
* @default false
|
|
856
|
+
*/
|
|
648
857
|
ignoreExportAllDeclaration?: boolean;
|
|
858
|
+
/** Rejects statically known values that are not async functions. */
|
|
649
859
|
rejectNonAsyncFunction?: boolean;
|
|
650
860
|
/**
|
|
651
|
-
*
|
|
861
|
+
* Selects exports before validation and proxy generation. Filtered exports
|
|
862
|
+
* are omitted from both the generated module and `exportNames`.
|
|
863
|
+
*
|
|
864
|
+
* Cannot be combined with `keep`.
|
|
865
|
+
* @default () => true
|
|
866
|
+
*/
|
|
867
|
+
filter?: TransformProxyExportFilter;
|
|
868
|
+
/**
|
|
869
|
+
* Retains non-export implementation code and passes a single identifier
|
|
870
|
+
* declaration's initializer to `runtime`. This is an escape hatch for Waku's
|
|
871
|
+
* `allowServer` transform.
|
|
872
|
+
*
|
|
873
|
+
* Requires `code` and cannot be combined with `filter`.
|
|
652
874
|
* @default false
|
|
653
875
|
*/
|
|
654
876
|
keep?: boolean;
|
|
655
877
|
};
|
|
656
|
-
|
|
657
|
-
directive: string;
|
|
658
|
-
} & TransformProxyExportOptions): {
|
|
659
|
-
exportNames: string[];
|
|
660
|
-
output: MagicString;
|
|
661
|
-
} | undefined;
|
|
662
|
-
declare function transformProxyExport(ast: Program, options: TransformProxyExportOptions): {
|
|
878
|
+
type TransformProxyExportResult = {
|
|
663
879
|
exportNames: string[];
|
|
664
880
|
output: MagicString;
|
|
665
881
|
};
|
|
882
|
+
declare function transformDirectiveProxyExport(ast: ESTree.Program, options: {
|
|
883
|
+
directive: string;
|
|
884
|
+
} & TransformProxyExportOptions): TransformProxyExportResult | undefined;
|
|
885
|
+
/**
|
|
886
|
+
* Replaces selected exports with proxies created by `runtime` and removes the
|
|
887
|
+
* original module implementation.
|
|
888
|
+
*
|
|
889
|
+
* Conceptually, with a filter that excludes `objectValue`:
|
|
890
|
+
*
|
|
891
|
+
* ```js
|
|
892
|
+
* import { dependency } from './dep'
|
|
893
|
+
* export async function action() {}
|
|
894
|
+
* export const objectValue = {}
|
|
895
|
+
* export { dependency as renamed }
|
|
896
|
+
* export default async () => {}
|
|
897
|
+
* ```
|
|
898
|
+
*
|
|
899
|
+
* becomes:
|
|
900
|
+
*
|
|
901
|
+
* ```js
|
|
902
|
+
* export const action = __PROXY__('action')
|
|
903
|
+
* export const renamed = __PROXY__('renamed')
|
|
904
|
+
* export default __PROXY__('default')
|
|
905
|
+
* ```
|
|
906
|
+
*
|
|
907
|
+
* Unlike `transformWrapExport`, this transform does not evaluate the original
|
|
908
|
+
* exports. Unknown values are represented only by their export names, so the
|
|
909
|
+
* caller must filter solely from the available static `ModuleExportMeta`.
|
|
910
|
+
* `keep` is a specialized mode that retains non-export implementation code and
|
|
911
|
+
* passes a single variable initializer to `runtime`.
|
|
912
|
+
*/
|
|
913
|
+
declare function transformProxyExport(viteAst: ESTree.Program, options: TransformProxyExportOptions): TransformProxyExportResult;
|
|
666
914
|
//#endregion
|
|
667
915
|
//#region src/transforms/utils.d.ts
|
|
668
|
-
declare function
|
|
916
|
+
declare function isDirective(node: Node): node is Directive;
|
|
917
|
+
declare function hasDirective(viteBody: ESTree.Program["body"], directive: string): boolean;
|
|
669
918
|
declare function extractNames(param: Pattern): string[];
|
|
670
919
|
declare function extractIdentifiers(param: Pattern, nodes?: Identifier[]): Identifier[];
|
|
671
920
|
declare function validateNonAsyncFunction(opts: {
|
|
672
921
|
rejectNonAsyncFunction?: boolean;
|
|
673
922
|
}, node: Node | ExportDefaultDeclaration["declaration"]): void;
|
|
923
|
+
declare function rejectNonAsyncFunction$1(opts: {
|
|
924
|
+
rejectNonAsyncFunction?: boolean;
|
|
925
|
+
}, pos: number): void;
|
|
674
926
|
//#endregion
|
|
675
927
|
//#region src/transforms/server-action.d.ts
|
|
676
|
-
|
|
928
|
+
type TransformServerActionServerOptions = {
|
|
677
929
|
runtime: (value: string, name: string) => string;
|
|
678
930
|
rejectNonAsyncFunction?: boolean;
|
|
679
931
|
encode?: (value: string) => string;
|
|
680
932
|
decode?: (value: string) => string;
|
|
681
|
-
}
|
|
933
|
+
};
|
|
934
|
+
type TransformServerActionServerResult = {
|
|
682
935
|
exportNames: string[];
|
|
683
936
|
output: MagicString;
|
|
684
937
|
referenceNames: string[];
|
|
@@ -687,19 +940,20 @@ declare function transformServerActionServer(input: string, ast: Program, option
|
|
|
687
940
|
names: string[];
|
|
688
941
|
referenceNames: string[];
|
|
689
942
|
};
|
|
943
|
+
declare function transformServerActionServer(input: string, ast: ESTree.Program, options: TransformServerActionServerOptions): TransformServerActionServerResult;
|
|
690
944
|
//#endregion
|
|
691
945
|
//#region src/transforms/expand-export-all.d.ts
|
|
692
946
|
interface TransformExpandExportAllContext {
|
|
693
947
|
resolve: (source: string, importer: string) => Promise<string | undefined>;
|
|
694
|
-
load: (id: string) => Promise<Program>;
|
|
948
|
+
load: (id: string) => Promise<ESTree.Program>;
|
|
695
949
|
}
|
|
696
950
|
interface TransformExpandExportAllOptions extends TransformExpandExportAllContext {
|
|
697
951
|
code: string;
|
|
698
|
-
ast: Program;
|
|
952
|
+
ast: ESTree.Program;
|
|
699
953
|
importer: string;
|
|
700
954
|
}
|
|
701
955
|
declare function transformExpandExportAll(options: TransformExpandExportAllOptions): Promise<{
|
|
702
956
|
code: string;
|
|
703
957
|
} | undefined>;
|
|
704
958
|
//#endregion
|
|
705
|
-
export {
|
|
959
|
+
export { ModuleExportSpecifier as A, TransformModuleExportEffectFilter as C, ModuleExportEntry as D, transformModuleExportEffect as E, findDirectives as F, transformHoistInlineDirective as I, TransformHoistInlineDirectiveMeta as M, TransformHoistInlineDirectiveOptions as N, ModuleExportGroup as O, TransformHoistInlineDirectiveResult as P, TransformModuleExportEffectContext as S, TransformModuleExportEffectResult as T, transformProxyExport as _, TransformServerActionServerResult as a, TransformWrapExportResult as b, extractNames as c, rejectNonAsyncFunction$1 as d, validateNonAsyncFunction as f, transformDirectiveProxyExport as g, TransformProxyExportResult as h, TransformServerActionServerOptions as i, scanModuleExports as j, ModuleExportMeta as k, hasDirective as l, TransformProxyExportOptions as m, TransformExpandExportAllOptions as n, transformServerActionServer as o, TransformProxyExportFilter as p, transformExpandExportAll as r, extractIdentifiers as s, TransformExpandExportAllContext as t, isDirective as u, TransformWrapExportFilter as v, TransformModuleExportEffectOptions as w, transformWrapExport as x, TransformWrapExportOptions as y };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as getPluginApi, o as RscPluginManager, r as PluginApi, s as RscPluginOptions, u as vitePluginRsc } from "./plugin-
|
|
1
|
+
import { c as getPluginApi, o as RscPluginManager, r as PluginApi, s as RscPluginOptions, u as vitePluginRsc } from "./plugin-CKqXjp8D.js";
|
|
2
2
|
export { type PluginApi, type RscPluginManager, type RscPluginOptions, vitePluginRsc as default, getPluginApi };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { r as vitePluginRsc, t as getPluginApi } from "./plugin-
|
|
1
|
+
import { r as vitePluginRsc, t as getPluginApi } from "./plugin-Cbs9j6lP.js";
|
|
2
2
|
export { vitePluginRsc as default, getPluginApi };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as __commonJSMin } from "./plugin-
|
|
1
|
+
import { a as __commonJSMin } from "./plugin-Cbs9j6lP.js";
|
|
2
2
|
//#region ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
3
3
|
var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4
4
|
let p = process || {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as TransformWrapExportFilter } from "./index-XXYjyFr6.js";
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
3
|
import { Plugin, ResolvedConfig, Rollup, ViteDevServer, parseAstAsync } from "vite";
|
|
4
4
|
//#region src/plugins/import-environment.d.ts
|
|
@@ -160,7 +160,8 @@ type RscPluginOptions = {
|
|
|
160
160
|
* - Require an entry chunk named "index"
|
|
161
161
|
* - Automatically include client entry deps in each client reference's dependencies
|
|
162
162
|
*
|
|
163
|
-
* Note: `import.meta.viteRsc.loadBootstrapScriptContent`
|
|
163
|
+
* Note: `getClientEntryUrl` and `import.meta.viteRsc.loadBootstrapScriptContent`
|
|
164
|
+
* cannot be used with this option.
|
|
164
165
|
*
|
|
165
166
|
* Use this when you manually handle client entry setup and preloading.
|
|
166
167
|
*
|
|
@@ -185,7 +186,7 @@ declare class RuntimeAsset {
|
|
|
185
186
|
constructor(value: string);
|
|
186
187
|
}
|
|
187
188
|
type AssetsManifest = {
|
|
188
|
-
|
|
189
|
+
clientEntryUrl?: string | RuntimeAsset;
|
|
189
190
|
clientEntryDeps?: AssetDeps;
|
|
190
191
|
clientReferenceDeps: Record<string, AssetDeps>;
|
|
191
192
|
serverResources?: Record<string, Pick<AssetDeps, "css">>;
|
|
@@ -196,7 +197,7 @@ type AssetDeps = {
|
|
|
196
197
|
css: (string | RuntimeAsset)[];
|
|
197
198
|
};
|
|
198
199
|
type ResolvedAssetsManifest = {
|
|
199
|
-
|
|
200
|
+
clientEntryUrl?: string;
|
|
200
201
|
clientEntryDeps?: ResolvedAssetDeps;
|
|
201
202
|
clientReferenceDeps: Record<string, ResolvedAssetDeps>;
|
|
202
203
|
serverResources?: Record<string, Pick<ResolvedAssetDeps, "css">>;
|