rwsdk 0.1.16 → 0.1.17-test.20250715200658
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/dist/lib/$.d.mts +8 -0
- package/dist/lib/$.mjs +5 -0
- package/dist/lib/constants.d.mts +4 -0
- package/dist/lib/constants.mjs +6 -0
- package/dist/lib/findWranglerConfig.d.mts +1 -0
- package/dist/lib/findWranglerConfig.mjs +12 -0
- package/dist/lib/getShortName.d.mts +1 -0
- package/dist/lib/getShortName.mjs +2 -0
- package/dist/lib/getSrcPaths.d.ts +15 -0
- package/dist/lib/getSrcPaths.js +80 -0
- package/dist/lib/hasPkgScript.d.mts +1 -0
- package/dist/lib/hasPkgScript.mjs +9 -0
- package/dist/lib/jsonUtils.d.mts +28 -0
- package/dist/lib/jsonUtils.mjs +167 -0
- package/dist/lib/setupEnvFiles.d.mts +4 -0
- package/dist/lib/setupEnvFiles.mjs +31 -0
- package/dist/lib/smokeTests/artifacts.d.mts +10 -0
- package/dist/lib/smokeTests/artifacts.mjs +164 -0
- package/dist/lib/smokeTests/browser.d.mts +48 -0
- package/dist/lib/smokeTests/browser.mjs +1041 -0
- package/dist/lib/smokeTests/cleanup.d.mts +5 -0
- package/dist/lib/smokeTests/cleanup.mjs +214 -0
- package/dist/lib/smokeTests/codeUpdates.d.mts +8 -0
- package/dist/lib/smokeTests/codeUpdates.mjs +229 -0
- package/dist/lib/smokeTests/constants.d.mts +5 -0
- package/dist/lib/smokeTests/constants.mjs +10 -0
- package/dist/lib/smokeTests/development.d.mts +11 -0
- package/dist/lib/smokeTests/development.mjs +209 -0
- package/dist/lib/smokeTests/environment.d.mts +14 -0
- package/dist/lib/smokeTests/environment.mjs +163 -0
- package/dist/lib/smokeTests/release.d.mts +61 -0
- package/dist/lib/smokeTests/release.mjs +526 -0
- package/dist/lib/smokeTests/reporting.d.mts +13 -0
- package/dist/lib/smokeTests/reporting.mjs +355 -0
- package/dist/lib/smokeTests/runSmokeTests.d.mts +5 -0
- package/dist/lib/smokeTests/runSmokeTests.mjs +144 -0
- package/dist/lib/smokeTests/state.d.mts +48 -0
- package/dist/lib/smokeTests/state.mjs +57 -0
- package/dist/lib/smokeTests/templates/SmokeTest.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/SmokeTest.template.js +81 -0
- package/dist/lib/smokeTests/templates/SmokeTestClient.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/SmokeTestClient.template.js +159 -0
- package/dist/lib/smokeTests/templates/smokeTestFunctions.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/smokeTestFunctions.template.js +19 -0
- package/dist/lib/smokeTests/types.d.mts +75 -0
- package/dist/lib/smokeTests/utils.d.mts +15 -0
- package/dist/lib/smokeTests/utils.mjs +147 -0
- package/dist/llms/index.d.ts +3 -0
- package/dist/llms/index.js +35 -0
- package/dist/llms/rules/interruptors.d.ts +1 -0
- package/dist/llms/rules/interruptors.js +243 -0
- package/dist/llms/rules/middleware.d.ts +1 -0
- package/dist/llms/rules/middleware.js +71 -0
- package/dist/llms/rules/react.d.ts +1 -0
- package/dist/llms/rules/react.js +106 -0
- package/dist/llms/rules/request-response.d.ts +1 -0
- package/dist/llms/rules/request-response.js +209 -0
- package/dist/runtime/client.d.ts +17 -0
- package/dist/runtime/client.js +74 -0
- package/dist/runtime/clientNavigation.d.ts +4 -0
- package/dist/runtime/clientNavigation.js +53 -0
- package/dist/runtime/clientNavigation.test.d.ts +1 -0
- package/dist/runtime/clientNavigation.test.js +55 -0
- package/dist/runtime/constants.d.ts +1 -0
- package/dist/runtime/constants.js +1 -0
- package/dist/runtime/entries/auth.d.ts +1 -0
- package/dist/runtime/entries/auth.js +1 -0
- package/dist/runtime/entries/client.d.ts +4 -0
- package/dist/runtime/entries/client.js +4 -0
- package/dist/runtime/entries/clientSSR.d.ts +1 -0
- package/dist/runtime/entries/clientSSR.js +1 -0
- package/dist/runtime/entries/no-react-server.d.ts +0 -0
- package/dist/runtime/entries/no-react-server.js +2 -0
- package/dist/runtime/entries/react-server-only.d.ts +0 -0
- package/dist/runtime/entries/react-server-only.js +2 -0
- package/dist/runtime/entries/router.d.ts +2 -0
- package/dist/runtime/entries/router.js +2 -0
- package/dist/runtime/entries/ssr.d.ts +1 -0
- package/dist/runtime/entries/ssr.js +1 -0
- package/dist/runtime/entries/worker.d.ts +9 -0
- package/dist/runtime/entries/worker.js +9 -0
- package/dist/runtime/error.d.ts +6 -0
- package/dist/runtime/error.js +8 -0
- package/dist/runtime/imports/ClientOnly.d.ts +3 -0
- package/dist/runtime/imports/ClientOnly.js +8 -0
- package/dist/runtime/imports/client.d.ts +4 -0
- package/dist/runtime/imports/client.js +33 -0
- package/dist/runtime/imports/ssr.d.ts +5 -0
- package/dist/runtime/imports/ssr.js +20 -0
- package/dist/runtime/imports/worker.d.ts +5 -0
- package/dist/runtime/imports/worker.js +22 -0
- package/dist/runtime/lib/auth/index.d.ts +1 -0
- package/dist/runtime/lib/auth/index.js +1 -0
- package/dist/runtime/lib/auth/session.d.ts +50 -0
- package/dist/runtime/lib/auth/session.js +148 -0
- package/dist/runtime/lib/db/DOWorkerDialect.d.ts +29 -0
- package/dist/runtime/lib/db/DOWorkerDialect.js +66 -0
- package/dist/runtime/lib/db/SqliteDurableObject.d.ts +14 -0
- package/dist/runtime/lib/db/SqliteDurableObject.js +42 -0
- package/dist/runtime/lib/db/createDb.d.ts +2 -0
- package/dist/runtime/lib/db/createDb.js +33 -0
- package/dist/runtime/lib/db/index.d.ts +4 -0
- package/dist/runtime/lib/db/index.js +3 -0
- package/dist/runtime/lib/db/migrations.d.ts +23 -0
- package/dist/runtime/lib/db/migrations.js +34 -0
- package/dist/runtime/lib/db/typeInference/assert.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/assert.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.d.ts +27 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +53 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +26 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +49 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +17 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +11 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +12 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +24 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.js +1 -0
- package/dist/runtime/lib/db/typeInference/database.d.ts +27 -0
- package/dist/runtime/lib/db/typeInference/database.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.js +360 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.js +33 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.js +143 -0
- package/dist/runtime/lib/db/typeInference/typetests/print.d.ts +3 -0
- package/dist/runtime/lib/db/typeInference/typetests/print.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.js +17 -0
- package/dist/runtime/lib/db/typeInference/utils.d.ts +82 -0
- package/dist/runtime/lib/db/typeInference/utils.js +2 -0
- package/dist/runtime/lib/debug.d.ts +2 -0
- package/dist/runtime/lib/debug.js +36 -0
- package/dist/runtime/lib/links.d.ts +14 -0
- package/dist/runtime/lib/links.js +38 -0
- package/dist/runtime/lib/realtime/client.d.ts +7 -0
- package/dist/runtime/lib/realtime/client.js +166 -0
- package/dist/runtime/lib/realtime/constants.d.ts +1 -0
- package/dist/runtime/lib/realtime/constants.js +1 -0
- package/dist/runtime/lib/realtime/durableObject.d.ts +29 -0
- package/dist/runtime/lib/realtime/durableObject.js +187 -0
- package/dist/runtime/lib/realtime/renderRealtimeClients.d.ts +7 -0
- package/dist/runtime/lib/realtime/renderRealtimeClients.js +6 -0
- package/dist/runtime/lib/realtime/shared.d.ts +10 -0
- package/dist/runtime/lib/realtime/shared.js +10 -0
- package/dist/runtime/lib/realtime/validateUpgradeRequest.d.ts +6 -0
- package/dist/runtime/lib/realtime/validateUpgradeRequest.js +29 -0
- package/dist/runtime/lib/realtime/worker.d.ts +3 -0
- package/dist/runtime/lib/realtime/worker.js +16 -0
- package/dist/runtime/lib/router.d.ts +56 -0
- package/dist/runtime/lib/router.js +210 -0
- package/dist/runtime/lib/router.test.d.ts +1 -0
- package/dist/runtime/lib/router.test.js +58 -0
- package/dist/runtime/lib/streams/consumeEventStream.d.ts +4 -0
- package/dist/runtime/lib/streams/consumeEventStream.js +13 -0
- package/dist/runtime/lib/turnstile/TurnstileScript.d.ts +1 -0
- package/dist/runtime/lib/turnstile/TurnstileScript.js +2 -0
- package/dist/runtime/lib/turnstile/turnstile.d.ts +3 -0
- package/dist/runtime/lib/turnstile/turnstile.js +3 -0
- package/dist/runtime/lib/turnstile/useTurnstile.d.ts +4 -0
- package/dist/runtime/lib/turnstile/useTurnstile.js +23 -0
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.d.ts +4 -0
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.js +15 -0
- package/dist/runtime/lib/utils.d.ts +1 -0
- package/dist/runtime/lib/utils.js +1 -0
- package/dist/runtime/register/client.d.ts +1 -0
- package/dist/runtime/register/client.js +5 -0
- package/dist/runtime/register/ssr.d.ts +3 -0
- package/dist/runtime/register/ssr.js +26 -0
- package/dist/runtime/register/worker.d.ts +4 -0
- package/dist/runtime/register/worker.js +42 -0
- package/dist/runtime/render/createClientManifest.d.ts +1 -0
- package/dist/runtime/render/createClientManifest.js +7 -0
- package/dist/runtime/render/createModuleMap.d.ts +1 -0
- package/dist/runtime/render/createModuleMap.js +13 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.d.ts +9 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.js +49 -0
- package/dist/runtime/render/renderToRscStream.d.ts +5 -0
- package/dist/runtime/render/renderToRscStream.js +46 -0
- package/dist/runtime/render/renderToStream.d.ts +9 -0
- package/dist/runtime/render/renderToStream.js +27 -0
- package/dist/runtime/render/renderToString.d.ts +7 -0
- package/dist/runtime/render/renderToString.js +26 -0
- package/dist/runtime/render/transformRscToHtmlStream.d.ts +8 -0
- package/dist/runtime/render/transformRscToHtmlStream.js +19 -0
- package/dist/runtime/requestInfo/types.d.ts +11 -0
- package/dist/runtime/requestInfo/types.js +1 -0
- package/dist/runtime/requestInfo/worker.d.ts +5 -0
- package/dist/runtime/requestInfo/worker.js +33 -0
- package/dist/runtime/script.d.ts +5 -0
- package/dist/runtime/script.js +8 -0
- package/dist/runtime/ssrBridge.d.ts +2 -0
- package/dist/runtime/ssrBridge.js +11 -0
- package/dist/runtime/worker.d.ts +18 -0
- package/dist/runtime/worker.js +173 -0
- package/dist/scripts/__sdk.d.mts +1 -0
- package/dist/scripts/__sdk.mjs +14 -0
- package/dist/scripts/debug-sync.d.mts +6 -0
- package/dist/scripts/debug-sync.mjs +224 -0
- package/dist/scripts/dev-init.d.mts +1 -0
- package/dist/scripts/dev-init.mjs +25 -0
- package/dist/scripts/ensure-deploy-env.d.mts +1 -0
- package/dist/scripts/ensure-deploy-env.mjs +271 -0
- package/dist/scripts/ensure-env.d.mts +1 -0
- package/dist/scripts/ensure-env.mjs +9 -0
- package/dist/scripts/migrate-new.d.mts +1 -0
- package/dist/scripts/migrate-new.mjs +51 -0
- package/dist/scripts/smoke-test.d.mts +1 -0
- package/dist/scripts/smoke-test.mjs +166 -0
- package/dist/scripts/worker-run.d.mts +1 -0
- package/dist/scripts/worker-run.mjs +82 -0
- package/dist/vite/checkIsUsingPrisma.d.mts +6 -0
- package/dist/vite/checkIsUsingPrisma.mjs +18 -0
- package/dist/vite/configPlugin.d.mts +9 -0
- package/dist/vite/configPlugin.mjs +169 -0
- package/dist/vite/createDirectiveLookupPlugin.d.mts +21 -0
- package/dist/vite/createDirectiveLookupPlugin.mjs +231 -0
- package/dist/vite/devServerTimingPlugin.d.mts +2 -0
- package/dist/vite/devServerTimingPlugin.mjs +24 -0
- package/dist/vite/directivesPlugin.d.mts +6 -0
- package/dist/vite/directivesPlugin.mjs +200 -0
- package/dist/vite/ensureAliasArray.d.mts +2 -0
- package/dist/vite/ensureAliasArray.mjs +17 -0
- package/dist/vite/findSpecifiers.d.mts +31 -0
- package/dist/vite/findSpecifiers.mjs +230 -0
- package/dist/vite/findSsrSpecifiers.d.mts +11 -0
- package/dist/vite/findSsrSpecifiers.mjs +67 -0
- package/dist/vite/hasDirective.d.mts +7 -0
- package/dist/vite/hasDirective.mjs +54 -0
- package/dist/vite/hasOwnCloudflareVitePlugin.d.mts +3 -0
- package/dist/vite/hasOwnCloudflareVitePlugin.mjs +14 -0
- package/dist/vite/index.d.mts +1 -0
- package/dist/vite/index.mjs +1 -0
- package/dist/vite/injectVitePreamblePlugin.d.mts +4 -0
- package/dist/vite/injectVitePreamblePlugin.mjs +23 -0
- package/dist/vite/invalidateCacheIfPrismaClientChanged.d.mts +3 -0
- package/dist/vite/invalidateCacheIfPrismaClientChanged.mjs +27 -0
- package/dist/vite/invalidateModule.d.mts +6 -0
- package/dist/vite/invalidateModule.mjs +30 -0
- package/dist/vite/miniflareHMRPlugin.d.mts +10 -0
- package/dist/vite/miniflareHMRPlugin.mjs +209 -0
- package/dist/vite/moveStaticAssetsPlugin.d.mts +4 -0
- package/dist/vite/moveStaticAssetsPlugin.mjs +12 -0
- package/dist/vite/normalizeModulePath.d.mts +1 -0
- package/dist/vite/normalizeModulePath.mjs +13 -0
- package/dist/vite/prismaPlugin.d.mts +4 -0
- package/dist/vite/prismaPlugin.mjs +43 -0
- package/dist/vite/reactConditionsResolverPlugin.d.mts +16 -0
- package/dist/vite/reactConditionsResolverPlugin.mjs +179 -0
- package/dist/vite/redwoodPlugin.d.mts +12 -0
- package/dist/vite/redwoodPlugin.mjs +105 -0
- package/dist/vite/ssrBridgePlugin.d.mts +7 -0
- package/dist/vite/ssrBridgePlugin.mjs +137 -0
- package/dist/vite/transformClientComponents.d.mts +12 -0
- package/dist/vite/transformClientComponents.mjs +116 -0
- package/dist/vite/transformClientComponents.test.d.mts +1 -0
- package/dist/vite/transformClientComponents.test.mjs +264 -0
- package/dist/vite/transformJsxScriptTagsPlugin.d.mts +8 -0
- package/dist/vite/transformJsxScriptTagsPlugin.mjs +315 -0
- package/dist/vite/transformJsxScriptTagsPlugin.test.d.mts +1 -0
- package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +334 -0
- package/dist/vite/transformServerFunctions.d.mts +16 -0
- package/dist/vite/transformServerFunctions.mjs +296 -0
- package/dist/vite/transformServerFunctions.test.d.mts +1 -0
- package/dist/vite/transformServerFunctions.test.mjs +124 -0
- package/dist/vite/useClientLookupPlugin.d.mts +5 -0
- package/dist/vite/useClientLookupPlugin.mjs +15 -0
- package/dist/vite/useServerLookupPlugin.d.mts +5 -0
- package/dist/vite/useServerLookupPlugin.mjs +15 -0
- package/dist/vite/useServerPlugin.d.mts +1 -0
- package/dist/vite/useServerPlugin.mjs +1 -0
- package/dist/vite/virtualPlugin.d.mts +2 -0
- package/dist/vite/virtualPlugin.mjs +18 -0
- package/dist/vite/vitePreamblePlugin.d.mts +1 -0
- package/dist/vite/vitePreamblePlugin.mjs +11 -0
- package/package.json +1 -1
- package/dist/runtime/lib/db/typeInference/builders/table.d.ts +0 -10
- package/dist/vite/invalidateClientModule.d.mts +0 -2
- package/dist/vite/invalidateClientModule.mjs +0 -8
- package/dist/vite/invalidateModule copy.d.mts +0 -2
- package/dist/vite/invalidateModule copy.mjs +0 -14
- package/dist/vite/invalidateSSRModule.d.mts +0 -2
- package/dist/vite/invalidateSSRModule.mjs +0 -7
- package/dist/vite/mode.d.mts +0 -5
- package/dist/vite/mode.mjs +0 -25
- package/dist/vite/modePlugin.d.mts +0 -2
- package/dist/vite/modePlugin.mjs +0 -10
- /package/dist/{runtime/lib/db/typeInference/builders/table.js → lib/smokeTests/types.mjs} +0 -0
- /package/dist/vite/{isJsFile.d.ts → isJsFile.d.mts} +0 -0
- /package/dist/vite/{isJsFile.js → isJsFile.mjs} +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
import { SSR_BRIDGE_PATH } from "../lib/constants.mjs";
|
|
3
|
+
import { findSsrImportSpecifiers } from "./findSsrSpecifiers.mjs";
|
|
4
|
+
const log = debug("rwsdk:vite:ssr-bridge-plugin");
|
|
5
|
+
export const VIRTUAL_SSR_PREFIX = "virtual:rwsdk:ssr:";
|
|
6
|
+
export const ssrBridgePlugin = ({ clientFiles, serverFiles, }) => {
|
|
7
|
+
log("Initializing SSR bridge plugin with SSR_BRIDGE_PATH=%s", SSR_BRIDGE_PATH);
|
|
8
|
+
let devServer;
|
|
9
|
+
let isDev = false;
|
|
10
|
+
const ssrBridgePlugin = {
|
|
11
|
+
name: "rwsdk:ssr-bridge",
|
|
12
|
+
enforce: "pre",
|
|
13
|
+
async configureServer(server) {
|
|
14
|
+
devServer = server;
|
|
15
|
+
log("Configured dev server");
|
|
16
|
+
},
|
|
17
|
+
config(_, { command, isPreview }) {
|
|
18
|
+
isDev = !isPreview && command === "serve";
|
|
19
|
+
log("Config: command=%s, isPreview=%s, isDev=%s", command, isPreview, isDev);
|
|
20
|
+
},
|
|
21
|
+
configEnvironment(env, config) {
|
|
22
|
+
log("Configuring environment: env=%s", env);
|
|
23
|
+
if (env === "worker") {
|
|
24
|
+
// Configure esbuild to mark rwsdk/__ssr paths as external for worker environment
|
|
25
|
+
log("Configuring esbuild options for worker environment");
|
|
26
|
+
config.optimizeDeps ??= {};
|
|
27
|
+
config.optimizeDeps.esbuildOptions ??= {};
|
|
28
|
+
config.optimizeDeps.esbuildOptions.plugins ??= [];
|
|
29
|
+
config.optimizeDeps.include ??= [];
|
|
30
|
+
config.optimizeDeps.esbuildOptions.plugins.push({
|
|
31
|
+
name: "rwsdk-ssr-external",
|
|
32
|
+
setup(build) {
|
|
33
|
+
log("Setting up esbuild plugin to mark rwsdk/__ssr paths as external for worker");
|
|
34
|
+
build.onResolve({ filter: /.*$/ }, (args) => {
|
|
35
|
+
process.env.VERBOSE &&
|
|
36
|
+
log("Esbuild onResolve called for path=%s, args=%O", args.path, args);
|
|
37
|
+
if (args.path === "rwsdk/__ssr_bridge") {
|
|
38
|
+
log("Marking as external: %s", args.path);
|
|
39
|
+
return {
|
|
40
|
+
path: args.path,
|
|
41
|
+
external: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
log("Worker environment esbuild configuration complete");
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
async resolveId(id) {
|
|
51
|
+
process.env.VERBOSE &&
|
|
52
|
+
log("Resolving id=%s, environment=%s, isDev=%s", id, this.environment?.name, isDev);
|
|
53
|
+
if (isDev) {
|
|
54
|
+
// context(justinvdm, 27 May 2025): In dev, we need to dynamically load
|
|
55
|
+
// SSR modules, so we return the virtual id so that the dynamic loading
|
|
56
|
+
// can happen in load()
|
|
57
|
+
if (id.startsWith(VIRTUAL_SSR_PREFIX)) {
|
|
58
|
+
log("Returning virtual SSR id for dev: %s", id);
|
|
59
|
+
return id;
|
|
60
|
+
}
|
|
61
|
+
// context(justinvdm, 28 May 2025): The SSR bridge module is a special case -
|
|
62
|
+
// it is the entry point for all SSR modules, so to trigger the
|
|
63
|
+
// same dynamic loading logic as other SSR modules (as the case above),
|
|
64
|
+
// we return a virtual id
|
|
65
|
+
if (id === "rwsdk/__ssr_bridge" && this.environment.name === "worker") {
|
|
66
|
+
const virtualId = `${VIRTUAL_SSR_PREFIX}${id}`;
|
|
67
|
+
log("Bridge module case (dev): id=%s matches rwsdk/__ssr_bridge in worker environment, returning virtual id=%s", id, virtualId);
|
|
68
|
+
return virtualId;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// context(justinvdm, 27 May 2025): In builds, since all SSR import chains
|
|
73
|
+
// originate at SSR bridge module, we return the path to the already built
|
|
74
|
+
// SSR bridge bundle - SSR env builds it, worker build tries to resolve it
|
|
75
|
+
// here and uses it
|
|
76
|
+
if (id === "rwsdk/__ssr_bridge" && this.environment.name === "worker") {
|
|
77
|
+
log("Bridge module case (build): id=%s matches rwsdk/__ssr_bridge in worker environment, returning SSR_BRIDGE_PATH=%s", id, SSR_BRIDGE_PATH);
|
|
78
|
+
return SSR_BRIDGE_PATH;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
process.env.VERBOSE && log("No resolution for id=%s", id);
|
|
82
|
+
},
|
|
83
|
+
async load(id) {
|
|
84
|
+
process.env.VERBOSE &&
|
|
85
|
+
log("Loading id=%s, isDev=%s, environment=%s", id, isDev, this.environment.name);
|
|
86
|
+
if (id.startsWith(VIRTUAL_SSR_PREFIX) &&
|
|
87
|
+
this.environment.name === "worker") {
|
|
88
|
+
const realId = id.slice(VIRTUAL_SSR_PREFIX.length);
|
|
89
|
+
log("Virtual SSR module load: id=%s, realId=%s", id, realId);
|
|
90
|
+
if (isDev) {
|
|
91
|
+
log("Dev mode: fetching SSR module for realPath=%s", realId);
|
|
92
|
+
const result = await devServer?.environments.ssr.fetchModule(realId);
|
|
93
|
+
process.env.VERBOSE &&
|
|
94
|
+
log("Fetch module result: id=%s, result=%O", realId, result);
|
|
95
|
+
const code = "code" in result ? result.code : undefined;
|
|
96
|
+
if (realId.endsWith(".css")) {
|
|
97
|
+
process.env.VERBOSE &&
|
|
98
|
+
log("Not a JS file, returning code: %s", code);
|
|
99
|
+
return code ?? "";
|
|
100
|
+
}
|
|
101
|
+
log("Fetched SSR module code length: %d", code?.length || 0);
|
|
102
|
+
const { imports, dynamicImports } = findSsrImportSpecifiers(realId, code || "", log);
|
|
103
|
+
const allSpecifiers = [
|
|
104
|
+
...new Set([...imports, ...dynamicImports]),
|
|
105
|
+
].map((id) => id.startsWith("/@id/") ? id.slice("/@id/".length) : id);
|
|
106
|
+
const switchCases = allSpecifiers
|
|
107
|
+
.map((specifier) => ` case "${specifier}": void import("${VIRTUAL_SSR_PREFIX}${specifier}");`)
|
|
108
|
+
.join("\n");
|
|
109
|
+
const transformedCode = `
|
|
110
|
+
await (async function(__vite_ssr_import__, __vite_ssr_dynamic_import__) {${code}})(
|
|
111
|
+
__ssrImport.bind(null, false),
|
|
112
|
+
__ssrImport.bind(null, true)
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
function __ssrImport(isDynamic, id, ...args) {
|
|
116
|
+
id = id.startsWith('/@id/') ? id.slice('/@id/'.length) : id;
|
|
117
|
+
|
|
118
|
+
switch (id) {
|
|
119
|
+
${switchCases}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return isDynamic
|
|
123
|
+
? __vite_ssr_dynamic_import__("/@id/${VIRTUAL_SSR_PREFIX}" + id, ...args)
|
|
124
|
+
: __vite_ssr_import__("/@id/${VIRTUAL_SSR_PREFIX}" + id, ...args);
|
|
125
|
+
}
|
|
126
|
+
`;
|
|
127
|
+
log("Transformed SSR module code length: %d", transformedCode.length);
|
|
128
|
+
process.env.VERBOSE &&
|
|
129
|
+
log("Transformed SSR module code for realId=%s: %s", realId, transformedCode);
|
|
130
|
+
return transformedCode;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
process.env.VERBOSE && log("No load handling for id=%s", id);
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
return ssrBridgePlugin;
|
|
137
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface TransformContext {
|
|
2
|
+
environmentName: string;
|
|
3
|
+
clientFiles?: Set<string>;
|
|
4
|
+
isEsbuild?: boolean;
|
|
5
|
+
addClientModule?: (environment: string, id: string) => void;
|
|
6
|
+
}
|
|
7
|
+
interface TransformResult {
|
|
8
|
+
code: string;
|
|
9
|
+
map?: any;
|
|
10
|
+
}
|
|
11
|
+
export declare function transformClientComponents(code: string, normalizedId: string, ctx: TransformContext): Promise<TransformResult | undefined>;
|
|
12
|
+
export type { TransformContext, TransformResult };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import MagicString from "magic-string";
|
|
2
|
+
import debug from "debug";
|
|
3
|
+
import { hasDirective } from "./hasDirective.mjs";
|
|
4
|
+
import { findExports } from "./findSpecifiers.mjs";
|
|
5
|
+
const logVite = debug("rwsdk:vite:transform-client-components:vite");
|
|
6
|
+
const logEsbuild = debug("rwsdk:vite:transform-client-components:esbuild");
|
|
7
|
+
export async function transformClientComponents(code, normalizedId, ctx) {
|
|
8
|
+
const log = ctx.isEsbuild ? logEsbuild : logVite;
|
|
9
|
+
log("Called transformClientComponents for id: id=%s", normalizedId);
|
|
10
|
+
if (!hasDirective(code, "use client")) {
|
|
11
|
+
log("Skipping: no 'use client' directive in id=%s", normalizedId);
|
|
12
|
+
process.env.VERBOSE &&
|
|
13
|
+
log(":VERBOSE: Returning code unchanged for id=%s:\n%s", normalizedId, code);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
log("Processing 'use client' module: id=%s", normalizedId);
|
|
17
|
+
ctx.addClientModule?.(ctx.environmentName, normalizedId);
|
|
18
|
+
// Parse exports using the findExports helper
|
|
19
|
+
const exportInfos = findExports(normalizedId, code, log);
|
|
20
|
+
const processedExports = [];
|
|
21
|
+
let defaultExportInfo;
|
|
22
|
+
// Helper to get the computed local name (with alias suffix if present)
|
|
23
|
+
function getComputedLocalName(info) {
|
|
24
|
+
return `${info.local}${info.alias ? `_${info.alias}` : ""}`;
|
|
25
|
+
}
|
|
26
|
+
// Convert ExportInfo to ProcessedExportInfo
|
|
27
|
+
exportInfos.forEach((exportInfo, idx) => {
|
|
28
|
+
if (exportInfo.isDefault) {
|
|
29
|
+
defaultExportInfo = {
|
|
30
|
+
local: exportInfo.alias || "default",
|
|
31
|
+
exported: "default",
|
|
32
|
+
isDefault: true,
|
|
33
|
+
statementIdx: idx,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// For aliases like "export { MyComponent as CustomName }", we need:
|
|
38
|
+
// - local: "MyComponent" (the original name)
|
|
39
|
+
// - exported: "CustomName" (the alias name)
|
|
40
|
+
// - alias: "CustomName" (to generate MyComponent_CustomName)
|
|
41
|
+
const hasAlias = exportInfo.alias && exportInfo.originalName;
|
|
42
|
+
processedExports.push({
|
|
43
|
+
local: exportInfo.originalName || exportInfo.name, // Use originalName if available
|
|
44
|
+
exported: exportInfo.name, // The exported name (alias if present)
|
|
45
|
+
isDefault: false,
|
|
46
|
+
statementIdx: idx,
|
|
47
|
+
alias: hasAlias ? exportInfo.alias : undefined,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
// 3. Client/SSR files: just remove the directive
|
|
52
|
+
if (ctx.environmentName === "ssr" || ctx.environmentName === "client") {
|
|
53
|
+
log(":isEsbuild=%s: Handling SSR virtual module: %s", !!ctx.isEsbuild, normalizedId);
|
|
54
|
+
// Remove 'use client' directive using magic-string
|
|
55
|
+
const s = new MagicString(code);
|
|
56
|
+
// Find and remove "use client" directives
|
|
57
|
+
const directiveRegex = /^(\s*)(['"]use client['"])\s*;?\s*\n?/gm;
|
|
58
|
+
let match;
|
|
59
|
+
while ((match = directiveRegex.exec(code)) !== null) {
|
|
60
|
+
const start = match.index;
|
|
61
|
+
const end = match.index + match[0].length;
|
|
62
|
+
s.remove(start, end);
|
|
63
|
+
process.env.VERBOSE &&
|
|
64
|
+
log("Removed 'use client' directive from normalizedId=%s", normalizedId);
|
|
65
|
+
break; // Only remove the first one
|
|
66
|
+
}
|
|
67
|
+
const sourceMap = s.generateMap({
|
|
68
|
+
source: normalizedId,
|
|
69
|
+
includeContent: true,
|
|
70
|
+
hires: true,
|
|
71
|
+
});
|
|
72
|
+
process.env.VERBOSE &&
|
|
73
|
+
log(":VERBOSE: SSR transformed code for %s:\n%s", normalizedId, s.toString());
|
|
74
|
+
return {
|
|
75
|
+
code: s.toString(),
|
|
76
|
+
map: sourceMap,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// 4. Non-SSR files: replace all implementation with registerClientReference logic
|
|
80
|
+
// Generate completely new code for worker/client environments
|
|
81
|
+
const s = new MagicString("");
|
|
82
|
+
// Add import declaration
|
|
83
|
+
s.append('import { registerClientReference } from "rwsdk/worker";\n');
|
|
84
|
+
// Compute unique computed local names first
|
|
85
|
+
const computedLocalNames = new Map(processedExports.map((info) => [getComputedLocalName(info), info]));
|
|
86
|
+
// Add registerClientReference assignments for unique names
|
|
87
|
+
for (const [computedLocalName, correspondingInfo] of computedLocalNames) {
|
|
88
|
+
log(":isEsbuild=%s: Registering client reference for named export: %s as %s", !!ctx.isEsbuild, correspondingInfo.local, correspondingInfo.exported);
|
|
89
|
+
s.append(`const ${computedLocalName} = registerClientReference("${normalizedId}", "${correspondingInfo.exported}");\n`);
|
|
90
|
+
}
|
|
91
|
+
// Add grouped export statement for named exports (preserving order and alias)
|
|
92
|
+
if (processedExports.length > 0) {
|
|
93
|
+
const exportNames = Array.from(computedLocalNames.entries()).map(([computedLocalName, correspondingInfo]) => correspondingInfo.local === correspondingInfo.exported
|
|
94
|
+
? computedLocalName
|
|
95
|
+
: `${computedLocalName} as ${correspondingInfo.exported}`);
|
|
96
|
+
log(":isEsbuild=%s: Exporting named exports: %O", !!ctx.isEsbuild, exportNames);
|
|
97
|
+
s.append(`export { ${exportNames.join(", ")} };\n`);
|
|
98
|
+
}
|
|
99
|
+
// Add default export if present
|
|
100
|
+
if (defaultExportInfo) {
|
|
101
|
+
log(":isEsbuild=%s: Registering client reference for default export: %s", !!ctx.isEsbuild, defaultExportInfo.exported);
|
|
102
|
+
s.append(`export default registerClientReference("${normalizedId}", "${defaultExportInfo.exported}");\n`);
|
|
103
|
+
}
|
|
104
|
+
const sourceMap = s.generateMap({
|
|
105
|
+
source: normalizedId,
|
|
106
|
+
includeContent: true,
|
|
107
|
+
hires: true,
|
|
108
|
+
});
|
|
109
|
+
const finalResult = s.toString();
|
|
110
|
+
process.env.VERBOSE &&
|
|
111
|
+
log(":VERBOSE: Transformed code (env=%s, normalizedId=%s):\n%s", normalizedId, ctx.environmentName, finalResult);
|
|
112
|
+
return {
|
|
113
|
+
code: finalResult,
|
|
114
|
+
map: sourceMap,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { transformClientComponents } from "./transformClientComponents.mjs";
|
|
3
|
+
describe("transformClientComponents", () => {
|
|
4
|
+
async function transform(code) {
|
|
5
|
+
const result = await transformClientComponents(code, "/test/file.tsx", {
|
|
6
|
+
environmentName: "worker",
|
|
7
|
+
});
|
|
8
|
+
return result?.code;
|
|
9
|
+
}
|
|
10
|
+
it("transforms arrow function component", async () => {
|
|
11
|
+
expect((await transform(`"use client"
|
|
12
|
+
|
|
13
|
+
export const Component = () => {
|
|
14
|
+
return jsx('div', { children: 'Hello' });
|
|
15
|
+
}
|
|
16
|
+
`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
17
|
+
const Component = registerClientReference("/test/file.tsx", "Component");
|
|
18
|
+
export { Component };
|
|
19
|
+
`);
|
|
20
|
+
});
|
|
21
|
+
it("transforms async arrow function component", async () => {
|
|
22
|
+
expect((await transform(`"use client"
|
|
23
|
+
|
|
24
|
+
export const Component = async () => {
|
|
25
|
+
return jsx('div', { children: 'Hello' });
|
|
26
|
+
}
|
|
27
|
+
`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
28
|
+
const Component = registerClientReference("/test/file.tsx", "Component");
|
|
29
|
+
export { Component };
|
|
30
|
+
`);
|
|
31
|
+
});
|
|
32
|
+
it("transforms function declaration component", async () => {
|
|
33
|
+
expect((await transform(`"use client"
|
|
34
|
+
|
|
35
|
+
export function Component() {
|
|
36
|
+
return jsx('div', { children: 'Hello' });
|
|
37
|
+
}`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
38
|
+
const Component = registerClientReference("/test/file.tsx", "Component");
|
|
39
|
+
export { Component };
|
|
40
|
+
`);
|
|
41
|
+
});
|
|
42
|
+
it("transforms default export arrow function component", async () => {
|
|
43
|
+
expect((await transform(`"use client"
|
|
44
|
+
|
|
45
|
+
export default () => {
|
|
46
|
+
return jsx('div', { children: 'Hello' });
|
|
47
|
+
}`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
48
|
+
export default registerClientReference("/test/file.tsx", "default");
|
|
49
|
+
`);
|
|
50
|
+
});
|
|
51
|
+
it("transforms default export function declaration component", async () => {
|
|
52
|
+
expect((await transform(`"use client"
|
|
53
|
+
|
|
54
|
+
export default function Component({ prop1, prop2 }) {
|
|
55
|
+
return jsx('div', { children: 'Hello' });
|
|
56
|
+
}`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
57
|
+
export default registerClientReference("/test/file.tsx", "default");
|
|
58
|
+
`);
|
|
59
|
+
});
|
|
60
|
+
it("transforms mixed export styles (inline, grouped, and default)", async () => {
|
|
61
|
+
expect((await transform(`"use client"
|
|
62
|
+
|
|
63
|
+
export const First = () => {
|
|
64
|
+
return jsx('div', { children: 'First' });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const Second = () => {
|
|
68
|
+
return jsx('div', { children: 'Second' });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function Third() {
|
|
72
|
+
return jsx('div', { children: 'Third' });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const Fourth = () => {
|
|
76
|
+
return jsx('div', { children: 'Fourth' });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default function Main() {
|
|
80
|
+
return jsx('div', { children: 'Main' });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { Second, Third }
|
|
84
|
+
export { Fourth as AnotherName }`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
85
|
+
const First = registerClientReference("/test/file.tsx", "First");
|
|
86
|
+
const Second = registerClientReference("/test/file.tsx", "Second");
|
|
87
|
+
const Third = registerClientReference("/test/file.tsx", "Third");
|
|
88
|
+
const Fourth_AnotherName = registerClientReference("/test/file.tsx", "AnotherName");
|
|
89
|
+
export { First, Second, Third, Fourth_AnotherName as AnotherName };
|
|
90
|
+
export default registerClientReference("/test/file.tsx", "default");
|
|
91
|
+
`);
|
|
92
|
+
});
|
|
93
|
+
it("transforms function declaration that is exported default separately", async () => {
|
|
94
|
+
expect((await transform(`
|
|
95
|
+
"use client"
|
|
96
|
+
|
|
97
|
+
function Component({ prop1, prop2 }) {
|
|
98
|
+
return jsx('div', { children: 'Hello' });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default Component;`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
102
|
+
export default registerClientReference("/test/file.tsx", "default");
|
|
103
|
+
`);
|
|
104
|
+
});
|
|
105
|
+
it("Works in dev", async () => {
|
|
106
|
+
expect((await transform(`"use client"
|
|
107
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
108
|
+
import { sendMessage } from "./functions";
|
|
109
|
+
import { useState } from "react";
|
|
110
|
+
import { consumeEventStream } from "rwsdk/client";
|
|
111
|
+
|
|
112
|
+
export function Chat() {
|
|
113
|
+
const [message, setMessage] = useState("");
|
|
114
|
+
const [reply, setReply] = useState("");
|
|
115
|
+
const onClick = async () => {
|
|
116
|
+
setReply("");
|
|
117
|
+
(await sendMessage(message)).pipeTo(
|
|
118
|
+
consumeEventStream({
|
|
119
|
+
onChunk: (event) => {
|
|
120
|
+
setReply(
|
|
121
|
+
(prev) => prev + (event.data === "[DONE]" ? "" : JSON.parse(event.data).response)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
return /* @__PURE__ */ jsxDEV("div", { children: [
|
|
128
|
+
/* @__PURE__ */ jsxDEV(
|
|
129
|
+
"input",
|
|
130
|
+
{
|
|
131
|
+
type: "text",
|
|
132
|
+
value: message,
|
|
133
|
+
placeholder: "Type a message...",
|
|
134
|
+
onChange: (e) => setMessage(e.target.value),
|
|
135
|
+
style: {
|
|
136
|
+
width: "80%",
|
|
137
|
+
padding: "10px",
|
|
138
|
+
marginRight: "8px",
|
|
139
|
+
borderRadius: "4px",
|
|
140
|
+
border: "1px solid #ccc"
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
void 0,
|
|
144
|
+
false,
|
|
145
|
+
{
|
|
146
|
+
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
147
|
+
lineNumber: 28,
|
|
148
|
+
columnNumber: 7
|
|
149
|
+
},
|
|
150
|
+
this
|
|
151
|
+
),
|
|
152
|
+
/* @__PURE__ */ jsxDEV(
|
|
153
|
+
"button",
|
|
154
|
+
{
|
|
155
|
+
onClick,
|
|
156
|
+
style: {
|
|
157
|
+
padding: "10px 20px",
|
|
158
|
+
borderRadius: "4px",
|
|
159
|
+
border: "none",
|
|
160
|
+
backgroundColor: "#007bff",
|
|
161
|
+
color: "white",
|
|
162
|
+
cursor: "pointer"
|
|
163
|
+
},
|
|
164
|
+
children: "Send"
|
|
165
|
+
},
|
|
166
|
+
void 0,
|
|
167
|
+
false,
|
|
168
|
+
{
|
|
169
|
+
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
170
|
+
lineNumber: 41,
|
|
171
|
+
columnNumber: 7
|
|
172
|
+
},
|
|
173
|
+
this
|
|
174
|
+
),
|
|
175
|
+
/* @__PURE__ */ jsxDEV("div", { children: reply }, void 0, false, {
|
|
176
|
+
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
177
|
+
lineNumber: 54,
|
|
178
|
+
columnNumber: 7
|
|
179
|
+
}, this)
|
|
180
|
+
] }, void 0, true, {
|
|
181
|
+
fileName: "/Users/justin/rw/sdk/experiments/ai-stream/src/app/pages/Chat/Chat.tsx",
|
|
182
|
+
lineNumber: 27,
|
|
183
|
+
columnNumber: 5
|
|
184
|
+
}, this);
|
|
185
|
+
}
|
|
186
|
+
`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
187
|
+
const Chat = registerClientReference("/test/file.tsx", "Chat");
|
|
188
|
+
export { Chat };
|
|
189
|
+
`);
|
|
190
|
+
});
|
|
191
|
+
it("Does not transform when 'use client' is not directive", async () => {
|
|
192
|
+
expect(await transform(`const message = "use client";`)).toEqual(undefined);
|
|
193
|
+
});
|
|
194
|
+
it("properly handles export alias", async () => {
|
|
195
|
+
expect((await transform(`"use client"
|
|
196
|
+
|
|
197
|
+
const MyComponent = () => {
|
|
198
|
+
return jsx('div', { children: 'Hello' });
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export { MyComponent as CustomName }`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
202
|
+
const MyComponent_CustomName = registerClientReference("/test/file.tsx", "CustomName");
|
|
203
|
+
export { MyComponent_CustomName as CustomName };
|
|
204
|
+
`);
|
|
205
|
+
});
|
|
206
|
+
it("correctly processes multiple component exports", async () => {
|
|
207
|
+
expect((await transform(`"use client"
|
|
208
|
+
|
|
209
|
+
const First = () => jsx('div', { children: 'First' });
|
|
210
|
+
const Second = () => jsx('div', { children: 'Second' });
|
|
211
|
+
const Third = () => jsx('div', { children: 'Third' });
|
|
212
|
+
|
|
213
|
+
export { First, Second, Third }`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
214
|
+
const First = registerClientReference("/test/file.tsx", "First");
|
|
215
|
+
const Second = registerClientReference("/test/file.tsx", "Second");
|
|
216
|
+
const Third = registerClientReference("/test/file.tsx", "Third");
|
|
217
|
+
export { First, Second, Third };
|
|
218
|
+
`);
|
|
219
|
+
});
|
|
220
|
+
it("handles combination of JSX and non-JSX exports", async () => {
|
|
221
|
+
expect((await transform(`"use client"
|
|
222
|
+
|
|
223
|
+
const Component = () => jsx('div', {});
|
|
224
|
+
const data = { value: 42 };
|
|
225
|
+
const helper = () => console.log('helper');
|
|
226
|
+
|
|
227
|
+
export { Component, data, helper }`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
228
|
+
const Component = registerClientReference("/test/file.tsx", "Component");
|
|
229
|
+
const data = registerClientReference("/test/file.tsx", "data");
|
|
230
|
+
const helper = registerClientReference("/test/file.tsx", "helper");
|
|
231
|
+
export { Component, data, helper };
|
|
232
|
+
`);
|
|
233
|
+
});
|
|
234
|
+
it("transforms multiple exports aliases for the same component", async () => {
|
|
235
|
+
expect((await transform(`"use client"
|
|
236
|
+
|
|
237
|
+
export const Slot = () => {
|
|
238
|
+
return jsx('div', { children: 'Slot' });
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export { Slot, Slot as Root }
|
|
242
|
+
`)) ?? "").toEqual(`import { registerClientReference } from "rwsdk/worker";
|
|
243
|
+
const Slot = registerClientReference("/test/file.tsx", "Slot");
|
|
244
|
+
const Slot_Root = registerClientReference("/test/file.tsx", "Root");
|
|
245
|
+
export { Slot, Slot_Root as Root };
|
|
246
|
+
`);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
describe("transformClientComponents logic branches (from transformClientComponents.mts)", () => {
|
|
250
|
+
it("returns code as-is if file does not start with 'use client'", async () => {
|
|
251
|
+
const code = "const foo = 1;";
|
|
252
|
+
const result = await transformClientComponents(code, "/test/file.tsx", {
|
|
253
|
+
environmentName: "worker",
|
|
254
|
+
});
|
|
255
|
+
expect(result).toBeUndefined();
|
|
256
|
+
});
|
|
257
|
+
it("removes directive but does not transform if not a virtual SSR file", async () => {
|
|
258
|
+
const code = '"use client"\nexport const foo = 1;';
|
|
259
|
+
const result = await transformClientComponents(code, "/test/file.tsx", {
|
|
260
|
+
environmentName: "ssr",
|
|
261
|
+
});
|
|
262
|
+
expect(result?.code).toEqual("export const foo = 1;");
|
|
263
|
+
});
|
|
264
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Plugin } from "vite";
|
|
2
|
+
export declare function transformJsxScriptTagsCode(code: string, manifest?: Record<string, any>): Promise<{
|
|
3
|
+
code: string;
|
|
4
|
+
map: null;
|
|
5
|
+
} | undefined>;
|
|
6
|
+
export declare const transformJsxScriptTagsPlugin: ({ manifestPath, }: {
|
|
7
|
+
manifestPath: string;
|
|
8
|
+
}) => Plugin;
|