rwsdk 1.0.0-alpha.8 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/dist/lib/constants.mjs +1 -2
  2. package/dist/lib/e2e/browser.d.mts +1 -1
  3. package/dist/lib/e2e/browser.mjs +21 -5
  4. package/dist/lib/e2e/dev.mjs +62 -52
  5. package/dist/lib/e2e/environment.d.mts +2 -6
  6. package/dist/lib/e2e/environment.mjs +167 -158
  7. package/dist/lib/e2e/index.d.mts +5 -4
  8. package/dist/lib/e2e/index.mjs +5 -4
  9. package/dist/lib/e2e/poll.d.mts +8 -0
  10. package/dist/lib/e2e/poll.mjs +31 -0
  11. package/dist/lib/e2e/release.d.mts +1 -1
  12. package/dist/lib/e2e/release.mjs +56 -34
  13. package/dist/lib/e2e/retry.d.mts +4 -0
  14. package/dist/lib/e2e/retry.mjs +16 -0
  15. package/dist/lib/e2e/setup.d.mts +2 -0
  16. package/dist/lib/e2e/setup.mjs +1 -0
  17. package/dist/lib/e2e/tarball.d.mts +3 -3
  18. package/dist/lib/e2e/tarball.mjs +28 -118
  19. package/dist/lib/e2e/testHarness.d.mts +74 -40
  20. package/dist/lib/e2e/testHarness.mjs +320 -271
  21. package/dist/lib/e2e/types.d.mts +1 -0
  22. package/dist/lib/getShortName.mjs +1 -2
  23. package/dist/lib/getShortName.test.mjs +2 -2
  24. package/dist/lib/getSrcPaths.js +2 -2
  25. package/dist/lib/hasPkgScript.test.mjs +2 -2
  26. package/dist/lib/jsonUtils.test.mjs +2 -2
  27. package/dist/lib/normalizeModulePath.test.mjs +2 -2
  28. package/dist/lib/setupEnvFiles.mjs +2 -2
  29. package/dist/lib/smokeTests/artifacts.mjs +2 -2
  30. package/dist/lib/smokeTests/browser.d.mts +1 -1
  31. package/dist/lib/smokeTests/browser.mjs +6 -7
  32. package/dist/lib/smokeTests/cleanup.mjs +6 -9
  33. package/dist/lib/smokeTests/codeUpdates.mjs +5 -5
  34. package/dist/lib/smokeTests/development.mjs +2 -2
  35. package/dist/lib/smokeTests/environment.d.mts +2 -3
  36. package/dist/lib/smokeTests/environment.mjs +17 -3
  37. package/dist/lib/smokeTests/release.d.mts +2 -2
  38. package/dist/lib/smokeTests/release.mjs +3 -3
  39. package/dist/lib/smokeTests/reporting.mjs +2 -2
  40. package/dist/lib/smokeTests/runSmokeTests.mjs +4 -4
  41. package/dist/lib/smokeTests/utils.mjs +3 -3
  42. package/dist/lib/testUtils/stubEnvVars.mjs +1 -1
  43. package/dist/llms/rules/middleware.d.ts +1 -1
  44. package/dist/llms/rules/middleware.js +4 -4
  45. package/dist/runtime/client/client.d.ts +2 -2
  46. package/dist/runtime/client/client.js +2 -2
  47. package/dist/runtime/client/navigation.test.js +1 -1
  48. package/dist/runtime/client/types.d.ts +1 -1
  49. package/dist/runtime/entries/client.d.ts +2 -2
  50. package/dist/runtime/entries/client.js +2 -2
  51. package/dist/runtime/entries/router.d.ts +1 -1
  52. package/dist/runtime/entries/router.js +1 -1
  53. package/dist/runtime/entries/worker.d.ts +5 -6
  54. package/dist/runtime/entries/worker.js +5 -6
  55. package/dist/runtime/imports/worker.js +1 -1
  56. package/dist/runtime/lib/auth/session.d.ts +2 -2
  57. package/dist/runtime/lib/auth/session.js +5 -5
  58. package/dist/runtime/lib/db/DOWorkerDialect.d.ts +1 -1
  59. package/dist/runtime/lib/db/DOWorkerDialect.js +1 -1
  60. package/dist/runtime/lib/db/SqliteDurableObject.js +2 -2
  61. package/dist/runtime/lib/db/index.d.ts +2 -2
  62. package/dist/runtime/lib/db/index.js +2 -2
  63. package/dist/runtime/lib/db/migrations.d.ts +1 -1
  64. package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +3 -3
  65. package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +1 -1
  66. package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +2 -2
  67. package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +1 -1
  68. package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +1 -1
  69. package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +1 -1
  70. package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +3 -3
  71. package/dist/runtime/lib/db/typeInference/database.d.ts +2 -2
  72. package/dist/runtime/lib/memoizeOnId.test.js +1 -1
  73. package/dist/runtime/lib/realtime/client.js +2 -2
  74. package/dist/runtime/lib/realtime/durableObject.js +1 -1
  75. package/dist/runtime/lib/realtime/protocol.test.js +1 -1
  76. package/dist/runtime/lib/realtime/shared.test.js +1 -1
  77. package/dist/runtime/lib/realtime/validateUpgradeRequest.test.js +1 -1
  78. package/dist/runtime/lib/realtime/worker.js +2 -2
  79. package/dist/runtime/lib/router.d.ts +1 -1
  80. package/dist/runtime/lib/router.test.js +2 -3
  81. package/dist/runtime/lib/rwContext.d.ts +1 -1
  82. package/dist/runtime/lib/stitchDocumentAndAppStreams.d.ts +18 -0
  83. package/dist/runtime/lib/stitchDocumentAndAppStreams.js +143 -0
  84. package/dist/runtime/lib/turnstile/useTurnstile.js +1 -1
  85. package/dist/runtime/lib/turnstile/verifyTurnstileToken.test.js +1 -1
  86. package/dist/runtime/register/worker.d.ts +1 -1
  87. package/dist/runtime/register/worker.js +34 -22
  88. package/dist/runtime/render/assembleDocument.d.ts +1 -1
  89. package/dist/runtime/render/createThenableFromReadableStream.js +1 -1
  90. package/dist/runtime/render/preloads.d.ts +2 -2
  91. package/dist/runtime/render/renderDocumentHtmlStream.js +6 -6
  92. package/dist/runtime/render/renderHtmlStream.d.ts +1 -1
  93. package/dist/runtime/render/renderToRscStream.d.ts +4 -1
  94. package/dist/runtime/render/renderToRscStream.js +11 -1
  95. package/dist/runtime/render/renderToStream.d.ts +1 -1
  96. package/dist/runtime/render/renderToStream.js +2 -2
  97. package/dist/runtime/render/stylesheets.d.ts +1 -1
  98. package/dist/runtime/requestInfo/types.d.ts +0 -2
  99. package/dist/runtime/requestInfo/worker.d.ts +1 -1
  100. package/dist/runtime/requestInfo/worker.js +1 -9
  101. package/dist/runtime/script.js +1 -1
  102. package/dist/runtime/ssrBridge.d.ts +2 -2
  103. package/dist/runtime/ssrBridge.js +2 -2
  104. package/dist/runtime/worker.d.ts +1 -1
  105. package/dist/runtime/worker.js +3 -11
  106. package/dist/scripts/addon.d.mts +1 -0
  107. package/dist/scripts/addon.mjs +70 -0
  108. package/dist/scripts/debug-sync.mjs +106 -137
  109. package/dist/scripts/ensure-deploy-env.mjs +6 -6
  110. package/dist/scripts/migrate-new.mjs +3 -4
  111. package/dist/scripts/smoke-test.mjs +2 -2
  112. package/dist/scripts/worker-run.mjs +7 -9
  113. package/dist/vite/buildApp.d.mts +2 -1
  114. package/dist/vite/buildApp.mjs +10 -6
  115. package/dist/vite/checkIsUsingPrisma.test.mjs +1 -1
  116. package/dist/vite/configPlugin.mjs +35 -17
  117. package/dist/vite/createDirectiveLookupPlugin.mjs +1 -1
  118. package/dist/vite/createDirectiveLookupPlugin.test.mjs +2 -2
  119. package/dist/vite/createViteAwareResolver.d.mts +1 -2
  120. package/dist/vite/createViteAwareResolver.mjs +1 -1
  121. package/dist/vite/directiveModulesDevPlugin.d.mts +2 -1
  122. package/dist/vite/directiveModulesDevPlugin.mjs +6 -5
  123. package/dist/vite/directiveModulesDevPlugin.test.mjs +2 -2
  124. package/dist/vite/directivesPlugin.mjs +3 -3
  125. package/dist/vite/directivesPlugin.test.mjs +1 -1
  126. package/dist/vite/ensureAliasArray.test.mjs +1 -1
  127. package/dist/vite/findSpecifiers.mjs +1 -1
  128. package/dist/vite/findSpecifiers.test.mjs +2 -2
  129. package/dist/vite/findSsrSpecifiers.mjs +1 -1
  130. package/dist/vite/findSsrSpecifiers.test.mjs +1 -1
  131. package/dist/vite/getViteEsbuild.mjs +1 -1
  132. package/dist/vite/hasDirective.d.mts +6 -3
  133. package/dist/vite/hasDirective.mjs +43 -27
  134. package/dist/vite/hasDirective.test.mjs +73 -75
  135. package/dist/vite/index.d.mts +1 -1
  136. package/dist/vite/invalidateCacheIfPrismaClientChanged.mjs +2 -2
  137. package/dist/vite/isJsFile.test.mjs +1 -1
  138. package/dist/vite/{reactConditionsResolverPlugin.d.mts → knownDepsResolverPlugin.d.mts} +3 -3
  139. package/dist/vite/{reactConditionsResolverPlugin.mjs → knownDepsResolverPlugin.mjs} +29 -24
  140. package/dist/vite/linkerPlugin.mjs +2 -2
  141. package/dist/vite/linkerPlugin.test.mjs +1 -1
  142. package/dist/vite/miniflareHMRPlugin.mjs +5 -5
  143. package/dist/vite/miniflareHMRPlugin.test.mjs +1 -1
  144. package/dist/vite/prismaPlugin.mjs +1 -1
  145. package/dist/vite/redwoodPlugin.d.mts +2 -0
  146. package/dist/vite/redwoodPlugin.mjs +37 -17
  147. package/dist/vite/redwoodPlugin.test.mjs +2 -2
  148. package/dist/vite/resolveForcedPaths.d.mts +4 -0
  149. package/dist/vite/resolveForcedPaths.mjs +9 -0
  150. package/dist/vite/runDirectivesScan.d.mts +3 -1
  151. package/dist/vite/runDirectivesScan.mjs +60 -20
  152. package/dist/vite/runDirectivesScan.test.mjs +2 -2
  153. package/dist/vite/ssrBridgePlugin.mjs +10 -3
  154. package/dist/vite/transformClientComponents.mjs +8 -6
  155. package/dist/vite/transformClientComponents.test.mjs +117 -59
  156. package/dist/vite/transformJsxScriptTagsPlugin.mjs +1 -1
  157. package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +2 -2
  158. package/dist/vite/transformServerFunctions.d.mts +1 -1
  159. package/dist/vite/transformServerFunctions.mjs +5 -5
  160. package/dist/vite/transformServerFunctions.test.mjs +3 -3
  161. package/package.json +60 -50
  162. package/dist/runtime/imports/resolveSSRValue.d.ts +0 -1
  163. package/dist/runtime/imports/resolveSSRValue.js +0 -8
  164. package/dist/runtime/lib/injectHtmlAtMarker.d.ts +0 -11
  165. package/dist/runtime/lib/injectHtmlAtMarker.js +0 -90
@@ -1,7 +1,7 @@
1
1
  import { resolve } from "node:path";
2
- import { invalidateCacheIfPrismaClientChanged } from "./invalidateCacheIfPrismaClientChanged.mjs";
3
2
  import { checkPrismaStatus } from "./checkIsUsingPrisma.mjs";
4
3
  import { ensureAliasArray } from "./ensureAliasArray.mjs";
4
+ import { invalidateCacheIfPrismaClientChanged } from "./invalidateCacheIfPrismaClientChanged.mjs";
5
5
  export const prismaPlugin = async ({ projectRootDir, }) => {
6
6
  if (!checkPrismaStatus({ projectRootDir }).isUsingPrisma) {
7
7
  return;
@@ -6,6 +6,8 @@ export type RedwoodPluginOptions = {
6
6
  includeCloudflarePlugin?: boolean;
7
7
  includeReactPlugin?: boolean;
8
8
  configPath?: string;
9
+ forceClientPaths?: string[];
10
+ forceServerPaths?: string[];
9
11
  entry?: {
10
12
  worker?: string;
11
13
  };
@@ -1,32 +1,33 @@
1
+ import { cloudflare } from "@cloudflare/vite-plugin";
1
2
  import { resolve } from "node:path";
2
3
  import { unstable_readConfig } from "wrangler";
3
- import { cloudflare } from "@cloudflare/vite-plugin";
4
4
  import { devServerConstantPlugin } from "./devServerConstant.mjs";
5
5
  import { hasOwnCloudflareVitePlugin } from "./hasOwnCloudflareVitePlugin.mjs";
6
6
  import { hasOwnReactVitePlugin } from "./hasOwnReactVitePlugin.mjs";
7
7
  import reactPlugin from "@vitejs/plugin-react";
8
8
  import tsconfigPaths from "vite-tsconfig-paths";
9
- import { transformJsxScriptTagsPlugin } from "./transformJsxScriptTagsPlugin.mjs";
10
- import { directivesPlugin } from "./directivesPlugin.mjs";
11
- import { useClientLookupPlugin } from "./useClientLookupPlugin.mjs";
12
- import { useServerLookupPlugin } from "./useServerLookupPlugin.mjs";
13
- import { miniflareHMRPlugin } from "./miniflareHMRPlugin.mjs";
14
- import { moveStaticAssetsPlugin } from "./moveStaticAssetsPlugin.mjs";
15
- import { configPlugin } from "./configPlugin.mjs";
9
+ import { pathExists } from "fs-extra";
16
10
  import { $ } from "../lib/$.mjs";
17
- import { reactConditionsResolverPlugin } from "./reactConditionsResolverPlugin.mjs";
18
11
  import { findWranglerConfig } from "../lib/findWranglerConfig.mjs";
19
- import { pathExists } from "fs-extra";
20
- import { injectVitePreamble } from "./injectVitePreamblePlugin.mjs";
21
- import { vitePreamblePlugin } from "./vitePreamblePlugin.mjs";
22
- import { prismaPlugin } from "./prismaPlugin.mjs";
23
- import { ssrBridgePlugin } from "./ssrBridgePlugin.mjs";
24
12
  import { hasPkgScript } from "../lib/hasPkgScript.mjs";
13
+ import { configPlugin } from "./configPlugin.mjs";
25
14
  import { devServerTimingPlugin } from "./devServerTimingPlugin.mjs";
26
- import { manifestPlugin } from "./manifestPlugin.mjs";
27
- import { linkerPlugin } from "./linkerPlugin.mjs";
28
15
  import { directiveModulesDevPlugin } from "./directiveModulesDevPlugin.mjs";
29
16
  import { directivesFilteringPlugin } from "./directivesFilteringPlugin.mjs";
17
+ import { directivesPlugin } from "./directivesPlugin.mjs";
18
+ import { injectVitePreamble } from "./injectVitePreamblePlugin.mjs";
19
+ import { knownDepsResolverPlugin } from "./knownDepsResolverPlugin.mjs";
20
+ import { linkerPlugin } from "./linkerPlugin.mjs";
21
+ import { manifestPlugin } from "./manifestPlugin.mjs";
22
+ import { miniflareHMRPlugin } from "./miniflareHMRPlugin.mjs";
23
+ import { moveStaticAssetsPlugin } from "./moveStaticAssetsPlugin.mjs";
24
+ import { prismaPlugin } from "./prismaPlugin.mjs";
25
+ import { resolveForcedPaths } from "./resolveForcedPaths.mjs";
26
+ import { ssrBridgePlugin } from "./ssrBridgePlugin.mjs";
27
+ import { transformJsxScriptTagsPlugin } from "./transformJsxScriptTagsPlugin.mjs";
28
+ import { useClientLookupPlugin } from "./useClientLookupPlugin.mjs";
29
+ import { useServerLookupPlugin } from "./useServerLookupPlugin.mjs";
30
+ import { vitePreamblePlugin } from "./vitePreamblePlugin.mjs";
30
31
  export const determineWorkerEntryPathname = async ({ projectRootDir, workerConfigPath, options, readConfig = unstable_readConfig, }) => {
31
32
  if (options.entry?.worker) {
32
33
  return resolve(projectRootDir, options.entry.worker);
@@ -39,6 +40,24 @@ const serverFiles = new Set();
39
40
  const clientEntryPoints = new Set();
40
41
  export const redwoodPlugin = async (options = {}) => {
41
42
  const projectRootDir = process.cwd();
43
+ if (options.forceClientPaths) {
44
+ const clientPaths = await resolveForcedPaths({
45
+ patterns: options.forceClientPaths,
46
+ projectRootDir,
47
+ });
48
+ for (const p of clientPaths) {
49
+ clientFiles.add(p);
50
+ }
51
+ }
52
+ if (options.forceServerPaths) {
53
+ const serverPaths = await resolveForcedPaths({
54
+ patterns: options.forceServerPaths,
55
+ projectRootDir,
56
+ });
57
+ for (const p of serverPaths) {
58
+ serverFiles.add(p);
59
+ }
60
+ }
42
61
  const workerConfigPath = options.configPath ??
43
62
  (process.env.RWSDK_WRANGLER_CONFIG
44
63
  ? resolve(projectRootDir, process.env.RWSDK_WRANGLER_CONFIG)
@@ -72,6 +91,7 @@ export const redwoodPlugin = async (options = {}) => {
72
91
  clientFiles,
73
92
  serverFiles,
74
93
  projectRootDir,
94
+ workerEntryPathname,
75
95
  }),
76
96
  configPlugin({
77
97
  silent: options.silent ?? false,
@@ -86,7 +106,7 @@ export const redwoodPlugin = async (options = {}) => {
86
106
  serverFiles,
87
107
  projectRootDir,
88
108
  }),
89
- reactConditionsResolverPlugin({ projectRootDir }),
109
+ knownDepsResolverPlugin({ projectRootDir }),
90
110
  tsconfigPaths({ root: projectRootDir }),
91
111
  shouldIncludeCloudflarePlugin
92
112
  ? cloudflare({
@@ -1,6 +1,6 @@
1
- import { describe, it, expect } from "vitest";
2
- import { determineWorkerEntryPathname } from "./redwoodPlugin.mjs";
3
1
  import path from "node:path";
2
+ import { describe, expect, it } from "vitest";
3
+ import { determineWorkerEntryPathname } from "./redwoodPlugin.mjs";
4
4
  describe("determineWorkerEntryPathname", () => {
5
5
  const projectRootDir = "/test/project";
6
6
  it("should use the entry path from options if provided", async () => {
@@ -0,0 +1,4 @@
1
+ export declare function resolveForcedPaths({ patterns, projectRootDir, }: {
2
+ patterns: string[];
3
+ projectRootDir: string;
4
+ }): Promise<string[]>;
@@ -0,0 +1,9 @@
1
+ import { glob } from "glob";
2
+ import { normalizeModulePath } from "../lib/normalizeModulePath.mjs";
3
+ export async function resolveForcedPaths({ patterns, projectRootDir, }) {
4
+ return (await glob(patterns, {
5
+ cwd: projectRootDir,
6
+ absolute: true,
7
+ realpath: true,
8
+ })).map((filepath) => normalizeModulePath(filepath, projectRootDir));
9
+ }
@@ -17,10 +17,12 @@ export declare function classifyModule({ contents, inheritedEnv, }: {
17
17
  isClient: boolean;
18
18
  isServer: boolean;
19
19
  };
20
- export declare const runDirectivesScan: ({ rootConfig, environments, clientFiles, serverFiles, }: {
20
+ export type EsbuildLoader = "js" | "jsx" | "ts" | "tsx" | "default";
21
+ export declare const runDirectivesScan: ({ rootConfig, environments, clientFiles, serverFiles, entries: initialEntries, }: {
21
22
  rootConfig: ResolvedConfig;
22
23
  environments: Record<string, Environment>;
23
24
  clientFiles: Set<string>;
24
25
  serverFiles: Set<string>;
26
+ entries?: string[];
25
27
  }) => Promise<void>;
26
28
  export {};
@@ -1,11 +1,14 @@
1
+ // @ts-ignore
2
+ import { compile } from "@mdx-js/mdx";
3
+ import debug from "debug";
1
4
  import fsp from "node:fs/promises";
2
- import { hasDirective } from "./hasDirective.mjs";
3
5
  import path from "node:path";
4
- import debug from "debug";
5
- import { getViteEsbuild } from "./getViteEsbuild.mjs";
6
+ import { INTERMEDIATES_OUTPUT_DIR } from "../lib/constants.mjs";
6
7
  import { normalizeModulePath } from "../lib/normalizeModulePath.mjs";
7
8
  import { externalModules } from "./constants.mjs";
8
- import { createViteAwareResolver, } from "./createViteAwareResolver.mjs";
9
+ import { createViteAwareResolver } from "./createViteAwareResolver.mjs";
10
+ import { getViteEsbuild } from "./getViteEsbuild.mjs";
11
+ import { hasDirective } from "./hasDirective.mjs";
9
12
  const log = debug("rwsdk:vite:run-directives-scan");
10
13
  // Copied from Vite's source code.
11
14
  // https://github.com/vitejs/vite/blob/main/packages/vite/src/shared/utils.ts
@@ -48,13 +51,13 @@ export function classifyModule({ contents, inheritedEnv, }) {
48
51
  }
49
52
  return { moduleEnv, isClient, isServer };
50
53
  }
51
- export const runDirectivesScan = async ({ rootConfig, environments, clientFiles, serverFiles, }) => {
52
- console.log("\n🔍 Scanning for 'use client' and 'use server' directives...");
54
+ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles, serverFiles, entries: initialEntries, }) => {
55
+ deferredLog("\n (rwsdk) Scanning for 'use client' and 'use server' directives...");
53
56
  // Set environment variable to indicate scanning is in progress
54
57
  process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE = "true";
55
58
  try {
56
59
  const esbuild = await getViteEsbuild(rootConfig.root);
57
- const input = environments.worker.config.build.rollupOptions?.input;
60
+ const input = initialEntries ?? environments.worker.config.build.rollupOptions?.input;
58
61
  let entries;
59
62
  if (Array.isArray(input)) {
60
63
  entries = input;
@@ -72,7 +75,9 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
72
75
  log("No entries found for directives scan in worker environment, skipping.");
73
76
  return;
74
77
  }
75
- const absoluteEntries = entries.map((entry) => path.resolve(rootConfig.root, entry));
78
+ // Filter out virtual modules since they can't be scanned by esbuild
79
+ const realEntries = entries.filter((entry) => !entry.includes("virtual:"));
80
+ const absoluteEntries = realEntries.map((entry) => path.resolve(rootConfig.root, entry));
76
81
  log("Starting directives scan for worker environment with entries:", absoluteEntries);
77
82
  const workerResolver = createViteAwareResolver(rootConfig, environments.worker);
78
83
  const clientResolver = createViteAwareResolver(rootConfig, environments.client);
@@ -91,7 +96,7 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
91
96
  setup(build) {
92
97
  // Match Vite's behavior by externalizing assets and special queries.
93
98
  // This prevents esbuild from trying to bundle them, which would fail.
94
- const scriptFilter = /\.(c|m)?[jt]sx?$/;
99
+ const scriptFilter = /\.(c|m)?[jt]sx?$|\.mdx$/;
95
100
  const specialQueryFilter = /[?&](?:url|raw|worker|sharedworker|inline)\b/;
96
101
  // This regex is used to identify if a path has any file extension.
97
102
  const hasExtensionRegex = /\.[^/]+$/;
@@ -159,7 +164,7 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
159
164
  log("Marking as external:", args.path, "resolved to:", resolvedPath);
160
165
  return { external: true };
161
166
  });
162
- build.onLoad({ filter: /\.(m|c)?[jt]sx?$/ }, async (args) => {
167
+ build.onLoad({ filter: /\.(m|c)?[jt]sx?$|\.mdx$/ }, async (args) => {
163
168
  log("onLoad called for:", args.path);
164
169
  if (!args.path.startsWith("/") ||
165
170
  args.path.includes("virtual:") ||
@@ -172,25 +177,52 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
172
177
  return null;
173
178
  }
174
179
  try {
175
- const contents = await readFileWithCache(args.path);
180
+ const originalContents = await readFileWithCache(args.path);
176
181
  const inheritedEnv = args.pluginData?.inheritedEnv || "worker";
177
182
  const { moduleEnv, isClient, isServer } = classifyModule({
178
- contents,
183
+ contents: originalContents,
179
184
  inheritedEnv,
180
185
  });
181
186
  // Store the definitive environment for this module, so it can be used when it becomes an importer.
182
- moduleEnvironments.set(args.path, moduleEnv);
183
- log("Set environment for", args.path, "to", moduleEnv);
187
+ const realPath = await fsp.realpath(args.path);
188
+ moduleEnvironments.set(realPath, moduleEnv);
189
+ log("Set environment for", realPath, "to", moduleEnv);
184
190
  // Finally, populate the output sets if the file has a directive.
185
191
  if (isClient) {
186
- log("Discovered 'use client' in:", args.path);
187
- clientFiles.add(normalizeModulePath(args.path, rootConfig.root));
192
+ log("Discovered 'use client' in:", realPath);
193
+ clientFiles.add(normalizeModulePath(realPath, rootConfig.root));
188
194
  }
189
195
  if (isServer) {
190
- log("Discovered 'use server' in:", args.path);
191
- serverFiles.add(normalizeModulePath(args.path, rootConfig.root));
196
+ log("Discovered 'use server' in:", realPath);
197
+ serverFiles.add(normalizeModulePath(realPath, rootConfig.root));
192
198
  }
193
- return { contents, loader: "default" };
199
+ let code;
200
+ let loader;
201
+ if (args.path.endsWith(".mdx")) {
202
+ const result = await compile(originalContents, {
203
+ jsx: true,
204
+ jsxImportSource: "react",
205
+ });
206
+ code = String(result.value);
207
+ loader = "tsx";
208
+ }
209
+ else if (/\.(m|c)?tsx$/.test(args.path)) {
210
+ code = originalContents;
211
+ loader = "tsx";
212
+ }
213
+ else if (/\.(m|c)?ts$/.test(args.path)) {
214
+ code = originalContents;
215
+ loader = "ts";
216
+ }
217
+ else if (/\.(m|c)?jsx$/.test(args.path)) {
218
+ code = originalContents;
219
+ loader = "jsx";
220
+ }
221
+ else {
222
+ code = originalContents;
223
+ loader = "js";
224
+ }
225
+ return { contents: code, loader };
194
226
  }
195
227
  catch (e) {
196
228
  log("Could not read file during scan, skipping:", args.path, e);
@@ -203,6 +235,7 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
203
235
  entryPoints: absoluteEntries,
204
236
  bundle: true,
205
237
  write: false,
238
+ outdir: path.join(INTERMEDIATES_OUTPUT_DIR, "directive-scan"),
206
239
  platform: "node",
207
240
  format: "esm",
208
241
  logLevel: "silent",
@@ -215,6 +248,13 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
215
248
  finally {
216
249
  // Always clear the scanning flag when done
217
250
  delete process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE;
218
- console.log(" Scan complete.");
251
+ deferredLog(" (rwsdk) Done scanning for 'use client' and 'use server' directives.");
252
+ process.env.VERBOSE &&
253
+ log("Client/server files after scanning: client=%O, server=%O", Array.from(clientFiles), Array.from(serverFiles));
219
254
  }
220
255
  };
256
+ const deferredLog = (message) => {
257
+ setTimeout(() => {
258
+ console.log(message);
259
+ }, 500);
260
+ };
@@ -1,5 +1,5 @@
1
- import { describe, it, expect, vi } from "vitest";
2
- import { resolveModuleWithEnvironment, classifyModule, } from "./runDirectivesScan.mjs";
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { classifyModule, resolveModuleWithEnvironment, } from "./runDirectivesScan.mjs";
3
3
  describe("runDirectivesScan helpers", () => {
4
4
  describe("resolveModuleWithEnvironment", () => {
5
5
  it("should use the client resolver when importerEnv is 'client'", async () => {
@@ -1,7 +1,7 @@
1
1
  import debug from "debug";
2
- import { findSsrImportCallSites } from "./findSsrSpecifiers.mjs";
3
- import { INTERMEDIATE_SSR_BRIDGE_PATH } from "../lib/constants.mjs";
4
2
  import MagicString from "magic-string";
3
+ import { INTERMEDIATE_SSR_BRIDGE_PATH } from "../lib/constants.mjs";
4
+ import { findSsrImportCallSites } from "./findSsrSpecifiers.mjs";
5
5
  const log = debug("rwsdk:vite:ssr-bridge-plugin");
6
6
  export const VIRTUAL_SSR_PREFIX = "virtual:rwsdk:ssr:";
7
7
  export const ssrBridgePlugin = ({ clientFiles, serverFiles, }) => {
@@ -34,7 +34,8 @@ export const ssrBridgePlugin = ({ clientFiles, serverFiles, }) => {
34
34
  build.onResolve({ filter: /.*$/ }, (args) => {
35
35
  process.env.VERBOSE &&
36
36
  log("Esbuild onResolve called for path=%s, args=%O", args.path, args);
37
- if (args.path === "rwsdk/__ssr_bridge") {
37
+ if (args.path === "rwsdk/__ssr_bridge" ||
38
+ args.path.startsWith(VIRTUAL_SSR_PREFIX)) {
38
39
  log("Marking as external: %s", args.path);
39
40
  return {
40
41
  path: args.path,
@@ -77,6 +78,12 @@ export const ssrBridgePlugin = ({ clientFiles, serverFiles, }) => {
77
78
  }
78
79
  else {
79
80
  // In build mode, the behavior depends on the build pass
81
+ if (id.startsWith(VIRTUAL_SSR_PREFIX)) {
82
+ if (this.environment.name === "worker") {
83
+ log("Virtual SSR module case (build-worker pass): resolving to external");
84
+ return { id, external: true };
85
+ }
86
+ }
80
87
  if (id === "rwsdk/__ssr_bridge" && this.environment.name === "worker") {
81
88
  if (process.env.RWSDK_BUILD_PASS === "worker") {
82
89
  // First pass: resolve to a temporary, external path
@@ -1,11 +1,12 @@
1
- import MagicString from "magic-string";
2
1
  import debug from "debug";
3
- import { hasDirective } from "./hasDirective.mjs";
2
+ import MagicString from "magic-string";
4
3
  import { findExports } from "./findSpecifiers.mjs";
4
+ import { hasDirective } from "./hasDirective.mjs";
5
5
  const logVite = debug("rwsdk:vite:transform-client-components:vite");
6
6
  const logEsbuild = debug("rwsdk:vite:transform-client-components:esbuild");
7
7
  export async function transformClientComponents(code, normalizedId, ctx) {
8
- if (!hasDirective(code, "use client")) {
8
+ if (!ctx.clientFiles?.has(normalizedId) &&
9
+ !hasDirective(code, "use client")) {
9
10
  return;
10
11
  }
11
12
  const log = ctx.isEsbuild ? logEsbuild : logVite;
@@ -76,13 +77,14 @@ export async function transformClientComponents(code, normalizedId, ctx) {
76
77
  // 4. Non-SSR files: replace all implementation with registerClientReference logic
77
78
  // Generate completely new code for worker/client environments
78
79
  const s = new MagicString("");
79
- // Add import declaration
80
+ s.append('import { ssrLoadModule } from "rwsdk/__ssr_bridge";\n');
80
81
  s.append('import { registerClientReference } from "rwsdk/worker";\n');
82
+ s.append(`const SSRModule = await ssrLoadModule("${normalizedId}");\n`);
81
83
  // Compute unique computed local names first
82
84
  const computedLocalNames = new Map(processedExports.map((info) => [getComputedLocalName(info), info]));
83
85
  // Add registerClientReference assignments for unique names
84
86
  for (const [computedLocalName, correspondingInfo] of computedLocalNames) {
85
- s.append(`const ${computedLocalName} = registerClientReference("${normalizedId}", "${correspondingInfo.exported}");\n`);
87
+ s.append(`const ${computedLocalName} = registerClientReference(SSRModule, "${normalizedId}", "${correspondingInfo.exported}");\n`);
86
88
  }
87
89
  // Add grouped export statement for named exports (preserving order and alias)
88
90
  if (processedExports.length > 0) {
@@ -94,7 +96,7 @@ export async function transformClientComponents(code, normalizedId, ctx) {
94
96
  // Add default export if present
95
97
  if (defaultExportInfo) {
96
98
  log(":isEsbuild=%s: Registering client reference for default export: %s", !!ctx.isEsbuild, defaultExportInfo.exported);
97
- s.append(`export default registerClientReference("${normalizedId}", "${defaultExportInfo.exported}");\n`);
99
+ s.append(`export default registerClientReference(SSRModule, "${normalizedId}", "${defaultExportInfo.exported}");\n`);
98
100
  }
99
101
  const sourceMap = s.generateMap({
100
102
  source: normalizedId,