@vitejs/plugin-rsc 0.4.28 → 0.4.30
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 +2 -50
- package/dist/{browser-QU10IP0-.js → browser--ZREVnM9.js} +1 -1
- package/dist/{browser-BhJd-Orx.js → browser-7NhxQxuk.js} +1 -1
- package/dist/{browser-mbRygLxB.d.ts → browser-CQv7Z3J4.d.ts} +1 -1
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +3 -3
- package/dist/cjs-WQBk0zA_.js +104 -0
- package/dist/core/browser.d.ts +1 -1
- package/dist/core/browser.js +2 -2
- package/dist/core/rsc.d.ts +2 -2
- package/dist/core/rsc.js +2 -2
- package/dist/core/ssr.d.ts +2 -2
- package/dist/core/ssr.js +2 -2
- package/dist/{encryption-runtime-CJUalqt3.js → encryption-runtime-CugTJCLM.js} +2 -3
- package/dist/extra/browser.d.ts +1 -1
- package/dist/extra/browser.js +5 -6
- package/dist/extra/rsc.d.ts +1 -1
- package/dist/extra/rsc.js +11 -17
- package/dist/extra/ssr.js +8 -10
- package/dist/index-DWN3vCIQ.d.ts +89 -0
- package/dist/index.d.ts +3 -24
- package/dist/index.js +6 -4
- package/dist/{plugin-iKgvucKS.js → plugin-Bzocj-4a.js} +70 -496
- package/dist/{plugin-BFcMxUSS.d.ts → plugin-Cfy_9VpM.d.ts} +1 -9
- package/dist/plugin.d.ts +2 -1
- package/dist/plugin.js +5 -3
- package/dist/plugins/cjs.d.ts +6 -0
- package/dist/plugins/cjs.js +5 -0
- package/dist/react/browser.d.ts +3 -3
- package/dist/react/browser.js +2 -2
- package/dist/react/rsc.d.ts +3 -3
- package/dist/react/rsc.js +3 -3
- package/dist/react/ssr.d.ts +3 -3
- package/dist/react/ssr.js +3 -3
- package/dist/{rpc-tGuLT8PD.js → rpc-CUvSZurk.js} +2 -3
- package/dist/{rsc-CxDPDiLz.d.ts → rsc-3bkzqdsJ.d.ts} +1 -1
- package/dist/{rsc-VjVw_i-M.js → rsc-BdCB3621.js} +1 -1
- package/dist/{rsc-BwEwbLG4.js → rsc-CiAoLCx8.js} +1 -1
- package/dist/{rsc-BfBPoIV8.js → rsc-GFzFWyhT.js} +2 -3
- package/dist/rsc-html-stream/browser.js +1 -1
- package/dist/rsc-html-stream/ssr.js +1 -1
- package/dist/rsc.d.ts +4 -4
- package/dist/rsc.js +5 -5
- package/dist/{shared-CEyKoKAb.js → shared-CXg_u-4h.js} +1 -2
- package/dist/{ssr-CWjOQSe3.js → ssr-8BA2nj0-.js} +2 -2
- package/dist/{ssr-BoNKka-5.d.ts → ssr-CMjeQ9AS.d.ts} +1 -1
- package/dist/{ssr-BEKKb_cw.js → ssr-Cd4SbAaO.js} +1 -1
- package/dist/{ssr--rFiBtws.js → ssr-Cm2FP2zD.js} +1 -1
- package/dist/ssr.d.ts +3 -3
- package/dist/ssr.js +5 -5
- package/dist/transforms/index.d.ts +2 -0
- package/dist/transforms/index.js +4 -0
- package/dist/transforms-D1-2JfCh.js +330 -0
- package/dist/utils/encryption-runtime.d.ts +1 -1
- package/dist/utils/encryption-runtime.js +4 -4
- package/dist/utils/rpc.js +1 -1
- package/package.json +3 -2
- /package/dist/{browser-CuwQIlVY.d.ts → browser-DwWQeoll.d.ts} +0 -0
- /package/dist/{client-C1J4FCf5.js → client-C7Eok9hc.js} +0 -0
- /package/dist/{encryption-runtime-SgJRa9yj.d.ts → encryption-runtime-B8xcnJoN.d.ts} +0 -0
- /package/dist/{index-QWzVHuya.d.ts → index-CPkExgij.d.ts} +0 -0
- /package/dist/{rsc-CFtzqEG8.d.ts → rsc-JJjz3Z0i.d.ts} +0 -0
- /package/dist/{rsc-Cv3XEZqB.d.ts → rsc-c22DF1A7.d.ts} +0 -0
- /package/dist/{server-D0-DavPP.js → server-BTo03tXh.js} +0 -0
- /package/dist/{shared-BWHxNw3Q.js → shared-AvKUASD5.js} +0 -0
- /package/dist/{ssr-D6GTzOzx.d.ts → ssr-BrSGyrxe.d.ts} +0 -0
|
@@ -1,15 +1,7 @@
|
|
|
1
|
+
import { TransformWrapExportFilter } from "./index-DWN3vCIQ.js";
|
|
1
2
|
import MagicString from "magic-string";
|
|
2
3
|
import { Plugin, ResolvedConfig, Rollup, ViteDevServer, parseAstAsync } from "vite";
|
|
3
|
-
import { Program } from "estree";
|
|
4
4
|
|
|
5
|
-
//#region src/transforms/wrap-export.d.ts
|
|
6
|
-
type ExportMeta = {
|
|
7
|
-
declName?: string;
|
|
8
|
-
isFunction?: boolean;
|
|
9
|
-
defaultExportIdentifierName?: string;
|
|
10
|
-
};
|
|
11
|
-
type TransformWrapExportFilter = (name: string, meta: ExportMeta) => boolean;
|
|
12
|
-
//#endregion
|
|
13
5
|
//#region src/plugin.d.ts
|
|
14
6
|
type ClientReferenceMeta = {
|
|
15
7
|
importId: string;
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./index-DWN3vCIQ.js";
|
|
2
|
+
import { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-Cfy_9VpM.js";
|
|
2
3
|
export { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
|
package/dist/plugin.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import "./dist-DiJnRA1C.js";
|
|
2
2
|
import "./plugin-CZbI4rhS.js";
|
|
3
|
-
import
|
|
3
|
+
import "./transforms-D1-2JfCh.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
|
-
import "./rpc-
|
|
6
|
-
import "./
|
|
5
|
+
import "./rpc-CUvSZurk.js";
|
|
6
|
+
import { getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-Bzocj-4a.js";
|
|
7
|
+
import "./cjs-WQBk0zA_.js";
|
|
8
|
+
import "./shared-AvKUASD5.js";
|
|
7
9
|
|
|
8
10
|
export { vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
|
package/dist/react/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallServerCallback } from "../index-
|
|
2
|
-
import { setRequireModule } from "../browser-
|
|
3
|
-
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "../browser-
|
|
1
|
+
import { CallServerCallback } from "../index-CPkExgij.js";
|
|
2
|
+
import { setRequireModule } from "../browser-DwWQeoll.js";
|
|
3
|
+
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "../browser-CQv7Z3J4.js";
|
|
4
4
|
export { CallServerCallback, callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
|
package/dist/react/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../dist-DiJnRA1C.js";
|
|
2
|
-
import "../shared-
|
|
3
|
-
import { setRequireModule } from "../browser-
|
|
2
|
+
import "../shared-CXg_u-4h.js";
|
|
3
|
+
import { setRequireModule } from "../browser-7NhxQxuk.js";
|
|
4
4
|
import { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setServerCallback } from "../browser-D8OPzpF5.js";
|
|
5
5
|
|
|
6
6
|
export { callServer, createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, findSourceMapURL, setRequireModule, setServerCallback };
|
package/dist/react/rsc.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../index-
|
|
2
|
-
import { loadServerAction, setRequireModule } from "../rsc-
|
|
3
|
-
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "../rsc-
|
|
1
|
+
import "../index-CPkExgij.js";
|
|
2
|
+
import { loadServerAction, setRequireModule } from "../rsc-3bkzqdsJ.js";
|
|
3
|
+
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "../rsc-JJjz3Z0i.js";
|
|
4
4
|
export { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
|
package/dist/react/rsc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../dist-DiJnRA1C.js";
|
|
2
|
-
import "../shared-
|
|
3
|
-
import { loadServerAction, setRequireModule } from "../rsc-
|
|
4
|
-
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "../rsc-
|
|
2
|
+
import "../shared-CXg_u-4h.js";
|
|
3
|
+
import { loadServerAction, setRequireModule } from "../rsc-GFzFWyhT.js";
|
|
4
|
+
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "../rsc-BdCB3621.js";
|
|
5
5
|
|
|
6
6
|
export { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
|
package/dist/react/ssr.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../index-
|
|
2
|
-
import { setRequireModule } from "../ssr-
|
|
3
|
-
import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "../ssr-
|
|
1
|
+
import "../index-CPkExgij.js";
|
|
2
|
+
import { setRequireModule } from "../ssr-CMjeQ9AS.js";
|
|
3
|
+
import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "../ssr-BrSGyrxe.js";
|
|
4
4
|
export { callServer, createFromReadableStream, createServerReference, findSourceMapURL, setRequireModule };
|
package/dist/react/ssr.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../dist-DiJnRA1C.js";
|
|
2
|
-
import "../shared-
|
|
3
|
-
import { setRequireModule } from "../ssr
|
|
4
|
-
import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "../ssr-
|
|
2
|
+
import "../shared-CXg_u-4h.js";
|
|
3
|
+
import { setRequireModule } from "../ssr-Cm2FP2zD.js";
|
|
4
|
+
import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "../ssr-Cd4SbAaO.js";
|
|
5
5
|
|
|
6
6
|
export { callServer, createFromReadableStream, createServerReference, findSourceMapURL, setRequireModule };
|
|
@@ -22,11 +22,10 @@ function createRpcServer(handlers) {
|
|
|
22
22
|
}
|
|
23
23
|
function createRpcClient(options) {
|
|
24
24
|
async function callRpc(method, args) {
|
|
25
|
-
const
|
|
25
|
+
const body = encode({
|
|
26
26
|
method,
|
|
27
27
|
args
|
|
28
|
-
};
|
|
29
|
-
const body = encode(reqPayload).pipeThrough(new TextEncoderStream());
|
|
28
|
+
}).pipeThrough(new TextEncoderStream());
|
|
30
29
|
const res = await fetch(options.endpoint, {
|
|
31
30
|
method: "POST",
|
|
32
31
|
body,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createClientManifest, createServerDecodeClientManifest, createServerManifest } from "./rsc-
|
|
1
|
+
import { createClientManifest, createServerDecodeClientManifest, createServerManifest } from "./rsc-GFzFWyhT.js";
|
|
2
2
|
import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
|
|
3
3
|
import * as ReactClient from "@vitejs/plugin-rsc/vendor/react-server-dom/client.edge";
|
|
4
4
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { memoize, tinyassert } from "./dist-DiJnRA1C.js";
|
|
2
|
-
import { SERVER_DECODE_CLIENT_PREFIX, SERVER_REFERENCE_PREFIX, createReferenceCacheTag, removeReferenceCacheTag, setInternalRequire } from "./shared-
|
|
2
|
+
import { SERVER_DECODE_CLIENT_PREFIX, SERVER_REFERENCE_PREFIX, createReferenceCacheTag, removeReferenceCacheTag, setInternalRequire } from "./shared-CXg_u-4h.js";
|
|
3
3
|
import * as ReactServer from "@vitejs/plugin-rsc/vendor/react-server-dom/server.edge";
|
|
4
4
|
|
|
5
5
|
//#region src/core/rsc.ts
|
|
@@ -28,8 +28,7 @@ function setRequireModule(options) {
|
|
|
28
28
|
}
|
|
29
29
|
async function loadServerAction(id) {
|
|
30
30
|
const [file, name] = id.split("#");
|
|
31
|
-
|
|
32
|
-
return mod[name];
|
|
31
|
+
return (await requireModule(file))[name];
|
|
33
32
|
}
|
|
34
33
|
function createServerManifest() {
|
|
35
34
|
const cacheTag = import.meta.env.DEV ? createReferenceCacheTag() : "";
|
package/dist/rsc.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-
|
|
3
|
-
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-
|
|
4
|
-
import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-
|
|
1
|
+
import "./index-CPkExgij.js";
|
|
2
|
+
import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-3bkzqdsJ.js";
|
|
3
|
+
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-JJjz3Z0i.js";
|
|
4
|
+
import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-B8xcnJoN.js";
|
|
5
5
|
export { createClientManifest, createClientTemporaryReferenceSet, createFromReadableStream, createServerManifest, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, decryptActionBoundArgs, encodeReply, encryptActionBoundArgs, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
|
package/dist/rsc.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "./dist-DiJnRA1C.js";
|
|
2
|
-
import "./shared-
|
|
2
|
+
import "./shared-CXg_u-4h.js";
|
|
3
3
|
import "./encryption-utils-BDwwcMVT.js";
|
|
4
|
-
import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-
|
|
5
|
-
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-
|
|
6
|
-
import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-
|
|
7
|
-
import "./rsc-
|
|
4
|
+
import { createClientManifest, createServerManifest, loadServerAction, setRequireModule } from "./rsc-GFzFWyhT.js";
|
|
5
|
+
import { createClientTemporaryReferenceSet, createFromReadableStream, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, encodeReply, registerClientReference, registerServerReference, renderToReadableStream } from "./rsc-BdCB3621.js";
|
|
6
|
+
import { decryptActionBoundArgs, encryptActionBoundArgs } from "./encryption-runtime-CugTJCLM.js";
|
|
7
|
+
import "./rsc-CiAoLCx8.js";
|
|
8
8
|
|
|
9
9
|
export { createClientManifest, createClientTemporaryReferenceSet, createFromReadableStream, createServerManifest, createTemporaryReferenceSet, decodeAction, decodeFormState, decodeReply, decryptActionBoundArgs, encodeReply, encryptActionBoundArgs, loadServerAction, registerClientReference, registerServerReference, renderToReadableStream, setRequireModule };
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
const SERVER_REFERENCE_PREFIX = "$$server:";
|
|
3
3
|
const SERVER_DECODE_CLIENT_PREFIX = "$$decode-client:";
|
|
4
4
|
function createReferenceCacheTag() {
|
|
5
|
-
|
|
6
|
-
return "$$cache=" + cache;
|
|
5
|
+
return "$$cache=" + Math.random().toString(36).slice(2);
|
|
7
6
|
}
|
|
8
7
|
function removeReferenceCacheTag(id) {
|
|
9
8
|
return id.split("$$cache=")[0];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { toCssVirtual } from "./shared-
|
|
2
|
-
import { setRequireModule } from "./ssr
|
|
1
|
+
import { toCssVirtual } from "./shared-AvKUASD5.js";
|
|
2
|
+
import { setRequireModule } from "./ssr-Cm2FP2zD.js";
|
|
3
3
|
import * as clientReferences from "virtual:vite-rsc/client-references";
|
|
4
4
|
import assetsManifest from "virtual:vite-rsc/assets-manifest";
|
|
5
5
|
import * as ReactDOM from "react-dom";
|
package/dist/ssr.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { createServerConsumerManifest, setRequireModule } from "./ssr-
|
|
3
|
-
import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-
|
|
1
|
+
import "./index-CPkExgij.js";
|
|
2
|
+
import { createServerConsumerManifest, setRequireModule } from "./ssr-CMjeQ9AS.js";
|
|
3
|
+
import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-BrSGyrxe.js";
|
|
4
4
|
export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, findSourceMapURL, setRequireModule };
|
package/dist/ssr.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./dist-DiJnRA1C.js";
|
|
2
|
-
import "./shared-
|
|
3
|
-
import "./shared-
|
|
4
|
-
import { createServerConsumerManifest, setRequireModule } from "./ssr
|
|
5
|
-
import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-
|
|
6
|
-
import "./ssr-
|
|
2
|
+
import "./shared-CXg_u-4h.js";
|
|
3
|
+
import "./shared-AvKUASD5.js";
|
|
4
|
+
import { createServerConsumerManifest, setRequireModule } from "./ssr-Cm2FP2zD.js";
|
|
5
|
+
import { callServer, createFromReadableStream, createServerReference, findSourceMapURL } from "./ssr-Cd4SbAaO.js";
|
|
6
|
+
import "./ssr-8BA2nj0-.js";
|
|
7
7
|
|
|
8
8
|
export { callServer, createFromReadableStream, createServerConsumerManifest, createServerReference, findSourceMapURL, setRequireModule };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport } from "../index-DWN3vCIQ.js";
|
|
2
|
+
export { TransformProxyExportOptions, TransformWrapExportFilter, TransformWrapExportOptions, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import "../dist-DiJnRA1C.js";
|
|
2
|
+
import { getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport } from "../transforms-D1-2JfCh.js";
|
|
3
|
+
|
|
4
|
+
export { getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { tinyassert } from "./dist-DiJnRA1C.js";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
import { walk } from "estree-walker";
|
|
4
|
+
import { analyze, extract_names } from "periscopic";
|
|
5
|
+
|
|
6
|
+
//#region src/transforms/hoist.ts
|
|
7
|
+
function transformHoistInlineDirective(input, ast, { runtime, rejectNonAsyncFunction,...options }) {
|
|
8
|
+
const output = new MagicString(input);
|
|
9
|
+
const directive = typeof options.directive === "string" ? exactRegex(options.directive) : options.directive;
|
|
10
|
+
walk(ast, { enter(node) {
|
|
11
|
+
if (node.type === "ExportAllDeclaration") this.remove();
|
|
12
|
+
if (node.type === "ExportNamedDeclaration" && !node.declaration) this.remove();
|
|
13
|
+
} });
|
|
14
|
+
const analyzed = analyze(ast);
|
|
15
|
+
const names = [];
|
|
16
|
+
walk(ast, { enter(node, parent) {
|
|
17
|
+
if ((node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") && node.body.type === "BlockStatement") {
|
|
18
|
+
const match = matchDirective(node.body.body, directive);
|
|
19
|
+
if (!match) return;
|
|
20
|
+
if (!node.async && rejectNonAsyncFunction) throw Object.assign(/* @__PURE__ */ new Error(`"${directive}" doesn't allow non async function`), { pos: node.start });
|
|
21
|
+
const scope = analyzed.map.get(node);
|
|
22
|
+
tinyassert(scope);
|
|
23
|
+
const declName = node.type === "FunctionDeclaration" && node.id.name;
|
|
24
|
+
const originalName = declName || parent?.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.id.name || "anonymous_server_function";
|
|
25
|
+
const bindVars = [...scope.references].filter((ref) => {
|
|
26
|
+
if (ref === declName) return false;
|
|
27
|
+
const owner = scope.find_owner(ref);
|
|
28
|
+
return owner && owner !== scope && owner !== analyzed.scope;
|
|
29
|
+
});
|
|
30
|
+
let newParams = [...bindVars, ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
|
|
31
|
+
if (bindVars.length > 0 && options.decode) {
|
|
32
|
+
newParams = ["$$hoist_encoded", ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
|
|
33
|
+
output.appendLeft(node.body.body[0].start, `const [${bindVars.join(",")}] = ${options.decode("$$hoist_encoded")};\n`);
|
|
34
|
+
}
|
|
35
|
+
const newName = `$$hoist_${names.length}` + (originalName ? `_${originalName}` : "");
|
|
36
|
+
names.push(newName);
|
|
37
|
+
output.update(node.start, node.body.start, `\n;${options.noExport ? "" : "export "}${node.async ? "async " : ""}function ${newName}(${newParams}) `);
|
|
38
|
+
output.appendLeft(node.end, `;\n/* #__PURE__ */ Object.defineProperty(${newName}, "name", { value: ${JSON.stringify(originalName)} });\n`);
|
|
39
|
+
output.move(node.start, node.end, input.length);
|
|
40
|
+
let newCode = `/* #__PURE__ */ ${runtime(newName, newName, { directiveMatch: match })}`;
|
|
41
|
+
if (bindVars.length > 0) {
|
|
42
|
+
const bindArgs = options.encode ? options.encode("[" + bindVars.join(", ") + "]") : bindVars.join(", ");
|
|
43
|
+
newCode = `${newCode}.bind(null, ${bindArgs})`;
|
|
44
|
+
}
|
|
45
|
+
if (declName) {
|
|
46
|
+
newCode = `const ${declName} = ${newCode};`;
|
|
47
|
+
if (parent?.type === "ExportDefaultDeclaration") {
|
|
48
|
+
output.remove(parent.start, node.start);
|
|
49
|
+
newCode = `${newCode}\nexport default ${declName};`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
output.appendLeft(node.start, newCode);
|
|
53
|
+
}
|
|
54
|
+
} });
|
|
55
|
+
return {
|
|
56
|
+
output,
|
|
57
|
+
names
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const exactRegex = (s) => /* @__PURE__ */ new RegExp("^" + s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + "$");
|
|
61
|
+
function matchDirective(body, directive) {
|
|
62
|
+
for (const stable of body) if (stable.type === "ExpressionStatement" && stable.expression.type === "Literal" && typeof stable.expression.value === "string") {
|
|
63
|
+
const match = stable.expression.value.match(directive);
|
|
64
|
+
if (match) return match;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/transforms/wrap-export.ts
|
|
70
|
+
function transformWrapExport(input, ast, options) {
|
|
71
|
+
const output = new MagicString(input);
|
|
72
|
+
const exportNames = [];
|
|
73
|
+
const toAppend = [];
|
|
74
|
+
const filter = options.filter ?? (() => true);
|
|
75
|
+
function wrapSimple(start, end, exports) {
|
|
76
|
+
exportNames.push(...exports.map((e) => e.name));
|
|
77
|
+
const newCode = exports.map((e) => [filter(e.name, e.meta) && `${e.name} = /* #__PURE__ */ ${options.runtime(e.name, e.name, e.meta)};\n`, `export { ${e.name} };\n`]).flat().filter(Boolean).join("");
|
|
78
|
+
output.update(start, end, newCode);
|
|
79
|
+
output.move(start, end, input.length);
|
|
80
|
+
}
|
|
81
|
+
function wrapExport(name, exportName, meta = {}) {
|
|
82
|
+
exportNames.push(exportName);
|
|
83
|
+
if (!filter(exportName, meta)) {
|
|
84
|
+
toAppend.push(`export { ${name} as ${exportName} }`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
toAppend.push(`const $$wrap_${name} = /* #__PURE__ */ ${options.runtime(name, exportName, meta)}`, `export { $$wrap_${name} as ${exportName} }`);
|
|
88
|
+
}
|
|
89
|
+
function validateNonAsyncFunction(node) {
|
|
90
|
+
if (!options.rejectNonAsyncFunction) return;
|
|
91
|
+
if (node.type === "ClassDeclaration" || (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && !node.async) throw Object.assign(/* @__PURE__ */ new Error(`unsupported non async function`), { pos: node.start });
|
|
92
|
+
}
|
|
93
|
+
for (const node of ast.body) {
|
|
94
|
+
if (node.type === "ExportNamedDeclaration") if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
|
|
95
|
+
/**
|
|
96
|
+
* export function foo() {}
|
|
97
|
+
*/
|
|
98
|
+
validateNonAsyncFunction(node.declaration);
|
|
99
|
+
const name = node.declaration.id.name;
|
|
100
|
+
wrapSimple(node.start, node.declaration.start, [{
|
|
101
|
+
name,
|
|
102
|
+
meta: {
|
|
103
|
+
isFunction: true,
|
|
104
|
+
declName: name
|
|
105
|
+
}
|
|
106
|
+
}]);
|
|
107
|
+
} else if (node.declaration.type === "VariableDeclaration") {
|
|
108
|
+
/**
|
|
109
|
+
* export const foo = 1, bar = 2
|
|
110
|
+
*/
|
|
111
|
+
for (const decl of node.declaration.declarations) if (decl.init) validateNonAsyncFunction(decl.init);
|
|
112
|
+
if (node.declaration.kind === "const") output.update(node.declaration.start, node.declaration.start + 5, "let");
|
|
113
|
+
const names = node.declaration.declarations.flatMap((decl) => extract_names(decl.id));
|
|
114
|
+
let isFunction = false;
|
|
115
|
+
if (node.declaration.declarations.length === 1) {
|
|
116
|
+
const decl = node.declaration.declarations[0];
|
|
117
|
+
isFunction = decl.id.type === "Identifier" && (decl.init?.type === "ArrowFunctionExpression" || decl.init?.type === "FunctionExpression");
|
|
118
|
+
}
|
|
119
|
+
wrapSimple(node.start, node.declaration.start, names.map((name) => ({
|
|
120
|
+
name,
|
|
121
|
+
meta: {
|
|
122
|
+
isFunction,
|
|
123
|
+
declName: name
|
|
124
|
+
}
|
|
125
|
+
})));
|
|
126
|
+
} else node.declaration;
|
|
127
|
+
else if (node.source) {
|
|
128
|
+
/**
|
|
129
|
+
* export { foo, bar as car } from './foo'
|
|
130
|
+
*/
|
|
131
|
+
output.remove(node.start, node.end);
|
|
132
|
+
for (const spec of node.specifiers) {
|
|
133
|
+
tinyassert(spec.local.type === "Identifier");
|
|
134
|
+
tinyassert(spec.exported.type === "Identifier");
|
|
135
|
+
const name = spec.local.name;
|
|
136
|
+
toAppend.push(`import { ${name} as $$import_${name} } from ${node.source.raw}`);
|
|
137
|
+
wrapExport(`$$import_${name}`, spec.exported.name);
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
/**
|
|
141
|
+
* export { foo, bar as car }
|
|
142
|
+
*/
|
|
143
|
+
output.remove(node.start, node.end);
|
|
144
|
+
for (const spec of node.specifiers) {
|
|
145
|
+
tinyassert(spec.local.type === "Identifier");
|
|
146
|
+
tinyassert(spec.exported.type === "Identifier");
|
|
147
|
+
wrapExport(spec.local.name, spec.exported.name);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* export * from './foo'
|
|
152
|
+
*/
|
|
153
|
+
if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw Object.assign(/* @__PURE__ */ new Error("unsupported ExportAllDeclaration"), { pos: node.start });
|
|
154
|
+
/**
|
|
155
|
+
* export default function foo() {}
|
|
156
|
+
* export default class Foo {}
|
|
157
|
+
* export default () => {}
|
|
158
|
+
*/
|
|
159
|
+
if (node.type === "ExportDefaultDeclaration") {
|
|
160
|
+
validateNonAsyncFunction(node.declaration);
|
|
161
|
+
let localName;
|
|
162
|
+
let isFunction = false;
|
|
163
|
+
let declName;
|
|
164
|
+
let defaultExportIdentifierName;
|
|
165
|
+
if ((node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") && node.declaration.id) {
|
|
166
|
+
localName = node.declaration.id.name;
|
|
167
|
+
output.remove(node.start, node.declaration.start);
|
|
168
|
+
isFunction = node.declaration.type === "FunctionDeclaration";
|
|
169
|
+
declName = node.declaration.id.name;
|
|
170
|
+
} else {
|
|
171
|
+
localName = "$$default";
|
|
172
|
+
output.update(node.start, node.declaration.start, "const $$default = ");
|
|
173
|
+
if (node.declaration.type === "Identifier") defaultExportIdentifierName = node.declaration.name;
|
|
174
|
+
}
|
|
175
|
+
wrapExport(localName, "default", {
|
|
176
|
+
isFunction,
|
|
177
|
+
declName,
|
|
178
|
+
defaultExportIdentifierName
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (toAppend.length > 0) output.append([
|
|
183
|
+
"",
|
|
184
|
+
...toAppend,
|
|
185
|
+
""
|
|
186
|
+
].join(";\n"));
|
|
187
|
+
return {
|
|
188
|
+
exportNames,
|
|
189
|
+
output
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/transforms/utils.ts
|
|
195
|
+
function hasDirective(body, directive) {
|
|
196
|
+
return !!body.find((stmt) => stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string" && stmt.expression.value === directive);
|
|
197
|
+
}
|
|
198
|
+
function getExportNames(ast, options) {
|
|
199
|
+
const exportNames = [];
|
|
200
|
+
for (const node of ast.body) {
|
|
201
|
+
if (node.type === "ExportNamedDeclaration") if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration")
|
|
202
|
+
/**
|
|
203
|
+
* export function foo() {}
|
|
204
|
+
*/
|
|
205
|
+
exportNames.push(node.declaration.id.name);
|
|
206
|
+
else if (node.declaration.type === "VariableDeclaration")
|
|
207
|
+
/**
|
|
208
|
+
* export const foo = 1, bar = 2
|
|
209
|
+
*/
|
|
210
|
+
for (const decl of node.declaration.declarations) exportNames.push(...extract_names(decl.id));
|
|
211
|
+
else node.declaration;
|
|
212
|
+
else
|
|
213
|
+
/**
|
|
214
|
+
* export { foo, bar as car } from './foo'
|
|
215
|
+
* export { foo, bar as car }
|
|
216
|
+
*/
|
|
217
|
+
for (const spec of node.specifiers) {
|
|
218
|
+
tinyassert(spec.exported.type === "Identifier");
|
|
219
|
+
exportNames.push(spec.exported.name);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* export * from './foo'
|
|
223
|
+
*/
|
|
224
|
+
if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw new Error("unsupported ExportAllDeclaration");
|
|
225
|
+
/**
|
|
226
|
+
* export default function foo() {}
|
|
227
|
+
* export default class Foo {}
|
|
228
|
+
* export default () => {}
|
|
229
|
+
*/
|
|
230
|
+
if (node.type === "ExportDefaultDeclaration") exportNames.push("default");
|
|
231
|
+
}
|
|
232
|
+
return { exportNames };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/transforms/proxy-export.ts
|
|
237
|
+
function transformDirectiveProxyExport(ast, options) {
|
|
238
|
+
if (!hasDirective(ast.body, options.directive)) return;
|
|
239
|
+
return transformProxyExport(ast, options);
|
|
240
|
+
}
|
|
241
|
+
function transformProxyExport(ast, options) {
|
|
242
|
+
if (options.keep && typeof options.code !== "string") throw new Error("`keep` option requires `code`");
|
|
243
|
+
const output = new MagicString(options.code ?? " ".repeat(ast.end));
|
|
244
|
+
const exportNames = [];
|
|
245
|
+
function createExport(node, names) {
|
|
246
|
+
exportNames.push(...names);
|
|
247
|
+
const newCode = names.map((name) => (name === "default" ? `export default` : `export const ${name} =`) + ` /* #__PURE__ */ ${options.runtime(name)};\n`).join("");
|
|
248
|
+
output.update(node.start, node.end, newCode);
|
|
249
|
+
}
|
|
250
|
+
function validateNonAsyncFunction(node, ok) {
|
|
251
|
+
if (options.rejectNonAsyncFunction && !ok) throw Object.assign(/* @__PURE__ */ new Error(`unsupported non async function`), { pos: node.start });
|
|
252
|
+
}
|
|
253
|
+
for (const node of ast.body) {
|
|
254
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
255
|
+
if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
|
|
256
|
+
/**
|
|
257
|
+
* export function foo() {}
|
|
258
|
+
*/
|
|
259
|
+
validateNonAsyncFunction(node, node.declaration.type === "FunctionDeclaration" && node.declaration.async);
|
|
260
|
+
createExport(node, [node.declaration.id.name]);
|
|
261
|
+
} else if (node.declaration.type === "VariableDeclaration") {
|
|
262
|
+
/**
|
|
263
|
+
* export const foo = 1, bar = 2
|
|
264
|
+
*/
|
|
265
|
+
validateNonAsyncFunction(node, node.declaration.declarations.every((decl) => decl.init?.type === "ArrowFunctionExpression" && decl.init.async));
|
|
266
|
+
if (options.keep && options.code) {
|
|
267
|
+
if (node.declaration.declarations.length === 1) {
|
|
268
|
+
const decl = node.declaration.declarations[0];
|
|
269
|
+
if (decl.id.type === "Identifier" && decl.init) {
|
|
270
|
+
const name = decl.id.name;
|
|
271
|
+
const value = options.code.slice(decl.init.start, decl.init.end);
|
|
272
|
+
const newCode = `export const ${name} = /* #__PURE__ */ ${options.runtime(name, { value })};`;
|
|
273
|
+
output.update(node.start, node.end, newCode);
|
|
274
|
+
exportNames.push(name);
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const names = node.declaration.declarations.flatMap((decl) => extract_names(decl.id));
|
|
280
|
+
createExport(node, names);
|
|
281
|
+
} else node.declaration;
|
|
282
|
+
else {
|
|
283
|
+
/**
|
|
284
|
+
* export { foo, bar as car } from './foo'
|
|
285
|
+
* export { foo, bar as car }
|
|
286
|
+
*/
|
|
287
|
+
const names = [];
|
|
288
|
+
for (const spec of node.specifiers) {
|
|
289
|
+
tinyassert(spec.exported.type === "Identifier");
|
|
290
|
+
names.push(spec.exported.name);
|
|
291
|
+
}
|
|
292
|
+
createExport(node, names);
|
|
293
|
+
}
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* export * from './foo'
|
|
298
|
+
*/
|
|
299
|
+
if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw new Error("unsupported ExportAllDeclaration");
|
|
300
|
+
/**
|
|
301
|
+
* export default function foo() {}
|
|
302
|
+
* export default class Foo {}
|
|
303
|
+
* export default () => {}
|
|
304
|
+
*/
|
|
305
|
+
if (node.type === "ExportDefaultDeclaration") {
|
|
306
|
+
validateNonAsyncFunction(node, node.declaration.type === "Identifier" || node.declaration.type === "FunctionDeclaration" && node.declaration.async);
|
|
307
|
+
createExport(node, ["default"]);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (options.keep) continue;
|
|
311
|
+
output.remove(node.start, node.end);
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
exportNames,
|
|
315
|
+
output
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/transforms/server-action.ts
|
|
321
|
+
function transformServerActionServer(input, ast, options) {
|
|
322
|
+
if (hasDirective(ast.body, "use server")) return transformWrapExport(input, ast, options);
|
|
323
|
+
return transformHoistInlineDirective(input, ast, {
|
|
324
|
+
...options,
|
|
325
|
+
directive: "use server"
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
//#endregion
|
|
330
|
+
export { getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { decryptActionBoundArgs, encryptActionBoundArgs } from "../encryption-runtime-
|
|
1
|
+
import { decryptActionBoundArgs, encryptActionBoundArgs } from "../encryption-runtime-B8xcnJoN.js";
|
|
2
2
|
export { decryptActionBoundArgs, encryptActionBoundArgs };
|