rwsdk 1.0.0-alpha.2 → 1.0.0-alpha.20-test.20250929144616

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 (214) hide show
  1. package/dist/lib/constants.mjs +1 -2
  2. package/dist/lib/e2e/browser.d.mts +10 -0
  3. package/dist/lib/e2e/browser.mjs +123 -0
  4. package/dist/lib/e2e/dev.d.mts +8 -0
  5. package/dist/lib/e2e/dev.mjs +242 -0
  6. package/dist/lib/e2e/environment.d.mts +10 -0
  7. package/dist/lib/e2e/environment.mjs +210 -0
  8. package/dist/lib/e2e/index.d.mts +8 -0
  9. package/dist/lib/e2e/index.mjs +8 -0
  10. package/dist/lib/e2e/poll.d.mts +8 -0
  11. package/dist/lib/e2e/poll.mjs +31 -0
  12. package/dist/lib/e2e/release.d.mts +56 -0
  13. package/dist/lib/e2e/release.mjs +559 -0
  14. package/dist/lib/e2e/retry.d.mts +4 -0
  15. package/dist/lib/e2e/retry.mjs +16 -0
  16. package/dist/lib/e2e/setup.d.mts +2 -0
  17. package/dist/lib/e2e/setup.mjs +1 -0
  18. package/dist/lib/e2e/tarball.d.mts +14 -0
  19. package/dist/lib/e2e/tarball.mjs +99 -0
  20. package/dist/lib/e2e/testHarness.d.mts +132 -0
  21. package/dist/lib/e2e/testHarness.mjs +436 -0
  22. package/dist/lib/e2e/types.d.mts +32 -0
  23. package/dist/lib/getShortName.mjs +6 -2
  24. package/dist/lib/getShortName.test.d.mts +1 -0
  25. package/dist/lib/getShortName.test.mjs +25 -0
  26. package/dist/lib/getSrcPaths.js +2 -2
  27. package/dist/lib/hasPkgScript.d.mts +4 -1
  28. package/dist/lib/hasPkgScript.mjs +9 -6
  29. package/dist/lib/hasPkgScript.test.d.mts +1 -0
  30. package/dist/lib/hasPkgScript.test.mjs +33 -0
  31. package/dist/lib/jsonUtils.mjs +3 -0
  32. package/dist/lib/jsonUtils.test.d.mts +1 -0
  33. package/dist/lib/jsonUtils.test.mjs +90 -0
  34. package/dist/lib/normalizeModulePath.d.mts +5 -0
  35. package/dist/lib/normalizeModulePath.mjs +1 -1
  36. package/dist/lib/normalizeModulePath.test.d.mts +1 -0
  37. package/dist/lib/{normalizeModulePath.test.js → normalizeModulePath.test.mjs} +21 -2
  38. package/dist/lib/setupEnvFiles.mjs +2 -2
  39. package/dist/lib/smokeTests/artifacts.mjs +2 -2
  40. package/dist/lib/smokeTests/browser.d.mts +1 -1
  41. package/dist/lib/smokeTests/browser.mjs +8 -100
  42. package/dist/lib/smokeTests/cleanup.mjs +6 -9
  43. package/dist/lib/smokeTests/codeUpdates.mjs +5 -5
  44. package/dist/lib/smokeTests/development.mjs +3 -224
  45. package/dist/lib/smokeTests/environment.d.mts +3 -11
  46. package/dist/lib/smokeTests/environment.mjs +17 -151
  47. package/dist/lib/smokeTests/release.d.mts +2 -49
  48. package/dist/lib/smokeTests/release.mjs +4 -504
  49. package/dist/lib/smokeTests/reporting.mjs +2 -2
  50. package/dist/lib/smokeTests/runSmokeTests.mjs +4 -4
  51. package/dist/lib/smokeTests/utils.mjs +3 -3
  52. package/dist/lib/testUtils/stubEnvVars.mjs +1 -1
  53. package/dist/llms/rules/middleware.d.ts +1 -1
  54. package/dist/llms/rules/middleware.js +4 -4
  55. package/dist/runtime/client/client.d.ts +2 -2
  56. package/dist/runtime/client/client.js +2 -2
  57. package/dist/runtime/client/navigation.test.js +1 -1
  58. package/dist/runtime/client/types.d.ts +1 -1
  59. package/dist/runtime/entries/client.d.ts +2 -2
  60. package/dist/runtime/entries/client.js +2 -2
  61. package/dist/runtime/entries/router.d.ts +1 -1
  62. package/dist/runtime/entries/router.js +1 -1
  63. package/dist/runtime/entries/worker.d.ts +5 -6
  64. package/dist/runtime/entries/worker.js +5 -6
  65. package/dist/runtime/imports/worker.js +1 -1
  66. package/dist/runtime/lib/auth/session.d.ts +2 -2
  67. package/dist/runtime/lib/auth/session.js +5 -5
  68. package/dist/runtime/lib/db/DOWorkerDialect.d.ts +1 -1
  69. package/dist/runtime/lib/db/DOWorkerDialect.js +1 -1
  70. package/dist/runtime/lib/db/SqliteDurableObject.js +2 -2
  71. package/dist/runtime/lib/db/index.d.ts +2 -2
  72. package/dist/runtime/lib/db/index.js +2 -2
  73. package/dist/runtime/lib/db/migrations.d.ts +1 -1
  74. package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +3 -3
  75. package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +1 -1
  76. package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +2 -2
  77. package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +1 -1
  78. package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +1 -1
  79. package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +1 -1
  80. package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +3 -3
  81. package/dist/runtime/lib/db/typeInference/database.d.ts +2 -2
  82. package/dist/runtime/lib/memoizeOnId.test.d.ts +1 -0
  83. package/dist/runtime/lib/memoizeOnId.test.js +49 -0
  84. package/dist/runtime/lib/realtime/client.js +2 -2
  85. package/dist/runtime/lib/realtime/durableObject.js +1 -1
  86. package/dist/runtime/lib/realtime/protocol.test.d.ts +1 -0
  87. package/dist/runtime/lib/realtime/protocol.test.js +107 -0
  88. package/dist/runtime/lib/realtime/shared.test.d.ts +1 -0
  89. package/dist/runtime/lib/realtime/shared.test.js +18 -0
  90. package/dist/runtime/lib/realtime/validateUpgradeRequest.test.d.ts +1 -0
  91. package/dist/runtime/lib/realtime/validateUpgradeRequest.test.js +66 -0
  92. package/dist/runtime/lib/realtime/worker.d.ts +1 -1
  93. package/dist/runtime/lib/realtime/worker.js +2 -2
  94. package/dist/runtime/lib/router.d.ts +1 -1
  95. package/dist/runtime/lib/router.js +40 -22
  96. package/dist/runtime/lib/router.test.js +591 -3
  97. package/dist/runtime/lib/rwContext.d.ts +22 -0
  98. package/dist/runtime/lib/rwContext.js +1 -0
  99. package/dist/runtime/lib/stitchDocumentAndAppStreams.d.ts +18 -0
  100. package/dist/runtime/lib/stitchDocumentAndAppStreams.js +143 -0
  101. package/dist/runtime/lib/turnstile/useTurnstile.js +1 -1
  102. package/dist/runtime/lib/turnstile/verifyTurnstileToken.d.ts +2 -1
  103. package/dist/runtime/lib/turnstile/verifyTurnstileToken.js +6 -6
  104. package/dist/runtime/lib/turnstile/verifyTurnstileToken.test.d.ts +1 -0
  105. package/dist/runtime/lib/turnstile/verifyTurnstileToken.test.js +49 -0
  106. package/dist/runtime/register/worker.d.ts +1 -1
  107. package/dist/runtime/register/worker.js +34 -22
  108. package/dist/runtime/render/assembleDocument.d.ts +6 -0
  109. package/dist/runtime/render/assembleDocument.js +22 -0
  110. package/dist/runtime/render/createThenableFromReadableStream.d.ts +1 -0
  111. package/dist/runtime/render/createThenableFromReadableStream.js +9 -0
  112. package/dist/runtime/render/normalizeActionResult.d.ts +1 -0
  113. package/dist/runtime/render/normalizeActionResult.js +43 -0
  114. package/dist/runtime/render/preloads.d.ts +3 -3
  115. package/dist/runtime/render/preloads.js +2 -3
  116. package/dist/runtime/render/{renderRscThenableToHtmlStream.d.ts → renderDocumentHtmlStream.d.ts} +3 -3
  117. package/dist/runtime/render/renderDocumentHtmlStream.js +39 -0
  118. package/dist/runtime/render/renderHtmlStream.d.ts +7 -0
  119. package/dist/runtime/render/renderHtmlStream.js +31 -0
  120. package/dist/runtime/render/renderToRscStream.d.ts +5 -3
  121. package/dist/runtime/render/renderToRscStream.js +12 -41
  122. package/dist/runtime/render/renderToStream.d.ts +3 -2
  123. package/dist/runtime/render/renderToStream.js +17 -10
  124. package/dist/runtime/render/stylesheets.d.ts +2 -2
  125. package/dist/runtime/render/stylesheets.js +2 -3
  126. package/dist/runtime/requestInfo/types.d.ts +0 -2
  127. package/dist/runtime/requestInfo/worker.d.ts +1 -1
  128. package/dist/runtime/requestInfo/worker.js +1 -9
  129. package/dist/runtime/script.js +1 -1
  130. package/dist/runtime/ssrBridge.d.ts +3 -2
  131. package/dist/runtime/ssrBridge.js +3 -2
  132. package/dist/runtime/worker.d.ts +2 -1
  133. package/dist/runtime/worker.js +13 -16
  134. package/dist/scripts/addon.d.mts +1 -0
  135. package/dist/scripts/addon.mjs +75 -0
  136. package/dist/scripts/debug-sync.mjs +106 -137
  137. package/dist/scripts/ensure-deploy-env.mjs +6 -6
  138. package/dist/scripts/migrate-new.mjs +3 -4
  139. package/dist/scripts/smoke-test.mjs +2 -2
  140. package/dist/scripts/worker-run.mjs +7 -9
  141. package/dist/vite/buildApp.d.mts +2 -1
  142. package/dist/vite/buildApp.mjs +10 -6
  143. package/dist/vite/checkIsUsingPrisma.d.mts +4 -0
  144. package/dist/vite/checkIsUsingPrisma.mjs +2 -2
  145. package/dist/vite/checkIsUsingPrisma.test.d.mts +1 -0
  146. package/dist/vite/checkIsUsingPrisma.test.mjs +30 -0
  147. package/dist/vite/configPlugin.mjs +55 -15
  148. package/dist/vite/createDirectiveLookupPlugin.d.mts +9 -0
  149. package/dist/vite/createDirectiveLookupPlugin.mjs +34 -30
  150. package/dist/vite/createDirectiveLookupPlugin.test.d.mts +1 -0
  151. package/dist/vite/createDirectiveLookupPlugin.test.mjs +40 -0
  152. package/dist/vite/createViteAwareResolver.d.mts +1 -2
  153. package/dist/vite/createViteAwareResolver.mjs +1 -1
  154. package/dist/vite/directiveModulesDevPlugin.d.mts +4 -1
  155. package/dist/vite/directiveModulesDevPlugin.mjs +9 -8
  156. package/dist/vite/directiveModulesDevPlugin.test.d.mts +1 -0
  157. package/dist/vite/directiveModulesDevPlugin.test.mjs +59 -0
  158. package/dist/vite/directivesPlugin.d.mts +1 -0
  159. package/dist/vite/directivesPlugin.mjs +4 -4
  160. package/dist/vite/directivesPlugin.test.d.mts +1 -0
  161. package/dist/vite/directivesPlugin.test.mjs +24 -0
  162. package/dist/vite/ensureAliasArray.test.d.mts +1 -0
  163. package/dist/vite/ensureAliasArray.test.mjs +71 -0
  164. package/dist/vite/findSpecifiers.mjs +3 -2
  165. package/dist/vite/findSpecifiers.test.d.mts +1 -0
  166. package/dist/vite/findSpecifiers.test.mjs +202 -0
  167. package/dist/vite/findSsrSpecifiers.mjs +1 -1
  168. package/dist/vite/findSsrSpecifiers.test.d.mts +1 -0
  169. package/dist/vite/findSsrSpecifiers.test.mjs +99 -0
  170. package/dist/vite/getViteEsbuild.mjs +1 -1
  171. package/dist/vite/hasDirective.d.mts +6 -3
  172. package/dist/vite/hasDirective.mjs +43 -27
  173. package/dist/vite/hasDirective.test.d.mts +1 -0
  174. package/dist/vite/hasDirective.test.mjs +107 -0
  175. package/dist/vite/index.d.mts +1 -1
  176. package/dist/vite/invalidateCacheIfPrismaClientChanged.mjs +2 -2
  177. package/dist/vite/isJsFile.test.d.mts +1 -0
  178. package/dist/vite/isJsFile.test.mjs +38 -0
  179. package/dist/vite/{reactConditionsResolverPlugin.d.mts → knownDepsResolverPlugin.d.mts} +3 -3
  180. package/dist/vite/{reactConditionsResolverPlugin.mjs → knownDepsResolverPlugin.mjs} +29 -24
  181. package/dist/vite/linkerPlugin.d.mts +8 -0
  182. package/dist/vite/linkerPlugin.mjs +32 -24
  183. package/dist/vite/linkerPlugin.test.d.mts +1 -0
  184. package/dist/vite/linkerPlugin.test.mjs +41 -0
  185. package/dist/vite/miniflareHMRPlugin.d.mts +5 -0
  186. package/dist/vite/miniflareHMRPlugin.mjs +7 -7
  187. package/dist/vite/miniflareHMRPlugin.test.d.mts +1 -0
  188. package/dist/vite/miniflareHMRPlugin.test.mjs +42 -0
  189. package/dist/vite/prismaPlugin.mjs +1 -1
  190. package/dist/vite/redwoodPlugin.d.mts +9 -0
  191. package/dist/vite/redwoodPlugin.mjs +44 -20
  192. package/dist/vite/redwoodPlugin.test.d.mts +1 -0
  193. package/dist/vite/redwoodPlugin.test.mjs +34 -0
  194. package/dist/vite/resolveForcedPaths.d.mts +4 -0
  195. package/dist/vite/resolveForcedPaths.mjs +9 -0
  196. package/dist/vite/runDirectivesScan.d.mts +22 -1
  197. package/dist/vite/runDirectivesScan.mjs +109 -61
  198. package/dist/vite/runDirectivesScan.test.d.mts +1 -0
  199. package/dist/vite/runDirectivesScan.test.mjs +73 -0
  200. package/dist/vite/ssrBridgePlugin.mjs +10 -3
  201. package/dist/vite/transformClientComponents.mjs +8 -6
  202. package/dist/vite/transformClientComponents.test.mjs +117 -59
  203. package/dist/vite/transformJsxScriptTagsPlugin.mjs +1 -1
  204. package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +2 -2
  205. package/dist/vite/transformServerFunctions.d.mts +1 -1
  206. package/dist/vite/transformServerFunctions.mjs +5 -5
  207. package/dist/vite/transformServerFunctions.test.mjs +3 -3
  208. package/package.json +61 -47
  209. package/dist/runtime/imports/resolveSSRValue.d.ts +0 -1
  210. package/dist/runtime/imports/resolveSSRValue.js +0 -8
  211. package/dist/runtime/render/renderRscThenableToHtmlStream.js +0 -54
  212. package/dist/runtime/render/transformRscToHtmlStream.d.ts +0 -8
  213. package/dist/runtime/render/transformRscToHtmlStream.js +0 -19
  214. /package/dist/lib/{normalizeModulePath.test.d.ts → e2e/types.mjs} +0 -0
@@ -1,10 +1,15 @@
1
1
  import debug from "debug";
2
- import { ROOT_DIR } from "../lib/constants.mjs";
3
2
  import enhancedResolve from "enhanced-resolve";
3
+ import { ROOT_DIR } from "../lib/constants.mjs";
4
4
  import { ensureAliasArray } from "./ensureAliasArray.mjs";
5
- const log = debug("rwsdk:vite:react-conditions-resolver-plugin");
6
- const REACT_PREFIXES = ["react", "react-dom", "react-server-dom-webpack"];
7
- export const ENV_REACT_IMPORTS = {
5
+ const log = debug("rwsdk:vite:known-deps-resolver-plugin");
6
+ const KNOWN_PREFIXES = [
7
+ "react",
8
+ "react-dom",
9
+ "react-server-dom-webpack",
10
+ "rwsdk",
11
+ ];
12
+ export const ENV_PREDEFINED_IMPORTS = {
8
13
  worker: [
9
14
  "react",
10
15
  "react-dom",
@@ -42,10 +47,10 @@ export const ENV_RESOLVERS = {
42
47
  conditionNames: ["browser", "default"],
43
48
  }),
44
49
  };
45
- function resolveReactImport(id, envName, projectRootDir, isReactImportKnown = false) {
46
- if (!isReactImportKnown) {
47
- const isReactImport = REACT_PREFIXES.some((prefix) => id === prefix || id.startsWith(`${prefix}/`));
48
- if (!isReactImport) {
50
+ function resolveKnownImport(id, envName, projectRootDir, isPrefixedImport = false) {
51
+ if (!isPrefixedImport) {
52
+ const isKnownImport = KNOWN_PREFIXES.some((prefix) => id === prefix || id.startsWith(`${prefix}/`));
53
+ if (!isKnownImport) {
49
54
  return undefined;
50
55
  }
51
56
  }
@@ -70,13 +75,13 @@ function resolveReactImport(id, envName, projectRootDir, isReactImportKnown = fa
70
75
  }
71
76
  return resolved;
72
77
  }
73
- function resolveEnvImportMappings(env, projectRootDir) {
78
+ function resolvePredefinedEnvImportMappings(env, projectRootDir) {
74
79
  process.env.VERBOSE &&
75
80
  log("Resolving environment import mappings for env=%s", env);
76
81
  const mappings = new Map();
77
- const reactImports = ENV_REACT_IMPORTS[env];
78
- for (const importRequest of reactImports) {
79
- const resolved = resolveReactImport(importRequest, env, projectRootDir, true);
82
+ const predefinedImports = ENV_PREDEFINED_IMPORTS[env];
83
+ for (const importRequest of predefinedImports) {
84
+ const resolved = resolveKnownImport(importRequest, env, projectRootDir, true);
80
85
  if (resolved) {
81
86
  mappings.set(importRequest, resolved);
82
87
  process.env.VERBOSE &&
@@ -87,27 +92,27 @@ function resolveEnvImportMappings(env, projectRootDir) {
87
92
  log("Environment import mappings complete for env=%s: %d mappings", env, mappings.size);
88
93
  return mappings;
89
94
  }
90
- export const reactConditionsResolverPlugin = ({ projectRootDir, }) => {
91
- log("Initializing react conditions resolver plugin");
95
+ export const knownDepsResolverPlugin = ({ projectRootDir, }) => {
96
+ log("Initializing known dependencies resolver plugin");
92
97
  let isBuild = false;
93
98
  const ENV_IMPORT_MAPPINGS = Object.fromEntries(Object.keys(ENV_RESOLVERS).map((env) => [
94
99
  env,
95
- resolveEnvImportMappings(env, projectRootDir),
100
+ resolvePredefinedEnvImportMappings(env, projectRootDir),
96
101
  ]));
97
102
  // Log a clean summary instead of all the individual mappings
98
103
  const totalMappings = Object.values(ENV_IMPORT_MAPPINGS).reduce((sum, mappings) => sum + mappings.size, 0);
99
- log("React conditions resolver configured with %d total mappings across %d environments", totalMappings, Object.keys(ENV_IMPORT_MAPPINGS).length);
104
+ log("Known dependencies resolver configured with %d total mappings across %d environments", totalMappings, Object.keys(ENV_IMPORT_MAPPINGS).length);
100
105
  function createEsbuildResolverPlugin(envName, mappings) {
101
106
  if (!mappings) {
102
107
  return null;
103
108
  }
104
109
  return {
105
- name: `rwsdk:react-conditions-resolver-esbuild-${envName}`,
110
+ name: `rwsdk:known-dependencies-resolver-esbuild-${envName}`,
106
111
  setup(build) {
107
112
  build.onResolve({ filter: /.*/ }, (args) => {
108
113
  let resolved = mappings.get(args.path);
109
114
  if (!resolved) {
110
- resolved = resolveReactImport(args.path, envName, projectRootDir);
115
+ resolved = resolveKnownImport(args.path, envName, projectRootDir);
111
116
  }
112
117
  if (resolved && args.importer !== "") {
113
118
  if (args.path === "react-server-dom-webpack/client.edge") {
@@ -123,7 +128,7 @@ export const reactConditionsResolverPlugin = ({ projectRootDir, }) => {
123
128
  }
124
129
  return [
125
130
  {
126
- name: "rwsdk:react-conditions-resolver:config",
131
+ name: "rwsdk:known-dependencies-resolver:config",
127
132
  enforce: "post",
128
133
  config(config, { command }) {
129
134
  isBuild = command === "build";
@@ -133,7 +138,7 @@ export const reactConditionsResolverPlugin = ({ projectRootDir, }) => {
133
138
  log("Setting up resolve aliases and optimizeDeps for each environment");
134
139
  // Set up aliases and optimizeDeps for each environment
135
140
  for (const [envName, mappings] of Object.entries(ENV_IMPORT_MAPPINGS)) {
136
- const reactImports = ENV_REACT_IMPORTS[envName];
141
+ const predefinedImports = ENV_PREDEFINED_IMPORTS[envName];
137
142
  // Ensure environment config exists
138
143
  if (!config.environments) {
139
144
  config.environments = {};
@@ -151,7 +156,7 @@ export const reactConditionsResolverPlugin = ({ projectRootDir, }) => {
151
156
  envConfig.optimizeDeps.esbuildOptions.plugins ??= [];
152
157
  envConfig.optimizeDeps.esbuildOptions.plugins.push(esbuildPlugin);
153
158
  envConfig.optimizeDeps.include ??= [];
154
- envConfig.optimizeDeps.include.push(...reactImports);
159
+ envConfig.optimizeDeps.include.push(...predefinedImports);
155
160
  log("Added esbuild plugin and optimizeDeps includes for environment: %s", envName);
156
161
  }
157
162
  const aliases = ensureAliasArray(envConfig);
@@ -161,12 +166,12 @@ export const reactConditionsResolverPlugin = ({ projectRootDir, }) => {
161
166
  process.env.VERBOSE &&
162
167
  log("Added alias for env=%s: %s -> %s", envName, find, replacement);
163
168
  }
164
- log("Environment %s configured with %d aliases and %d optimizeDeps includes", envName, mappings.size, reactImports.length);
169
+ log("Environment %s configured with %d aliases and %d optimizeDeps includes", envName, mappings.size, predefinedImports.length);
165
170
  }
166
171
  },
167
172
  },
168
173
  {
169
- name: "rwsdk:react-conditions-resolver:resolveId",
174
+ name: "rwsdk:known-dependencies-resolver:resolveId",
170
175
  enforce: "pre",
171
176
  async resolveId(id, importer) {
172
177
  // Skip during directive scanning to avoid performance issues
@@ -188,7 +193,7 @@ export const reactConditionsResolverPlugin = ({ projectRootDir, }) => {
188
193
  }
189
194
  let resolved = mappings.get(id);
190
195
  if (!resolved) {
191
- resolved = resolveReactImport(id, envName, projectRootDir);
196
+ resolved = resolveKnownImport(id, envName, projectRootDir);
192
197
  }
193
198
  if (resolved) {
194
199
  process.env.VERBOSE &&
@@ -1,4 +1,12 @@
1
1
  import type { Plugin } from "vite";
2
+ export declare function linkWorkerBundle({ code, manifestContent, projectRootDir, }: {
3
+ code: string;
4
+ manifestContent: string;
5
+ projectRootDir: string;
6
+ }): {
7
+ code: string;
8
+ map: null;
9
+ };
2
10
  export declare const linkerPlugin: ({ projectRootDir, }: {
3
11
  projectRootDir: string;
4
12
  }) => Plugin;
@@ -1,9 +1,32 @@
1
- import path from "node:path";
1
+ import debug from "debug";
2
2
  import fsp from "node:fs/promises";
3
+ import path from "node:path";
3
4
  import { CLIENT_MANIFEST_RELATIVE_PATH } from "../lib/constants.mjs";
4
- import debug from "debug";
5
5
  import { normalizeModulePath } from "../lib/normalizeModulePath.mjs";
6
6
  const log = debug("rwsdk:vite:linker-plugin");
7
+ export function linkWorkerBundle({ code, manifestContent, projectRootDir, }) {
8
+ let newCode = code;
9
+ const manifest = JSON.parse(manifestContent);
10
+ // 1. Replace the manifest placeholder with the actual manifest content.
11
+ log("Injecting manifest into worker bundle");
12
+ newCode = newCode.replace('"__RWSDK_MANIFEST_PLACEHOLDER__"', manifestContent);
13
+ // 2. Replace asset placeholders with their final hashed paths.
14
+ log("Replacing asset placeholders in final worker bundle");
15
+ for (const [key, value] of Object.entries(manifest)) {
16
+ const normalizedKey = normalizeModulePath(key, projectRootDir, {
17
+ isViteStyle: false,
18
+ });
19
+ newCode = newCode.replaceAll(`rwsdk_asset:${normalizedKey}`, `/${value.file}`);
20
+ }
21
+ // 3. Deprefix any remaining placeholders that were not in the manifest.
22
+ // This handles public assets that don't go through the bundler.
23
+ log("Deprefixing remaining asset placeholders");
24
+ newCode = newCode.replaceAll("rwsdk_asset:", "");
25
+ return {
26
+ code: newCode,
27
+ map: null,
28
+ };
29
+ }
7
30
  export const linkerPlugin = ({ projectRootDir, }) => {
8
31
  return {
9
32
  name: "rwsdk:linker",
@@ -13,29 +36,14 @@ export const linkerPlugin = ({ projectRootDir, }) => {
13
36
  return null;
14
37
  }
15
38
  log("Rendering final worker chunk");
16
- let newCode = code;
17
- // Read the manifest from the filesystem.
18
39
  const manifestContent = await fsp.readFile(path.resolve(projectRootDir, CLIENT_MANIFEST_RELATIVE_PATH), "utf-8");
19
- const manifest = JSON.parse(manifestContent);
20
- // 1. Replace the manifest placeholder with the actual manifest content.
21
- log("Injecting manifest into worker bundle");
22
- newCode = newCode.replace('"__RWSDK_MANIFEST_PLACEHOLDER__"', manifestContent);
23
- // 2. Replace asset placeholders with their final hashed paths.
24
- log("Replacing asset placeholders in final worker bundle");
25
- for (const [key, value] of Object.entries(manifest)) {
26
- const normalizedKey = normalizeModulePath(key, projectRootDir, {
27
- isViteStyle: false,
28
- });
29
- newCode = newCode.replaceAll(`rwsdk_asset:${normalizedKey}`, `/${value.file}`);
30
- }
31
- // 3. Deprefix any remaining placeholders that were not in the manifest.
32
- // This handles public assets that don't go through the bundler.
33
- log("Deprefixing remaining asset placeholders");
34
- newCode = newCode.replaceAll("rwsdk_asset:", "");
35
- return {
36
- code: newCode,
37
- map: null,
38
- };
40
+ const result = linkWorkerBundle({
41
+ code,
42
+ manifestContent,
43
+ projectRootDir,
44
+ });
45
+ log("Final worker chunk rendered");
46
+ return result;
39
47
  },
40
48
  };
41
49
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { linkWorkerBundle } from "./linkerPlugin.mjs";
3
+ describe("linkWorkerBundle", () => {
4
+ const projectRootDir = "/test/project";
5
+ const manifest = {
6
+ "src/styles.css": { file: "assets/styles.123.css" },
7
+ "src/logo.svg": { file: "assets/logo.abc.svg" },
8
+ };
9
+ const manifestContent = JSON.stringify(manifest);
10
+ it("should replace the manifest placeholder", () => {
11
+ const code = `const manifest = "__RWSDK_MANIFEST_PLACEHOLDER__";`;
12
+ const result = linkWorkerBundle({
13
+ code,
14
+ manifestContent,
15
+ projectRootDir,
16
+ });
17
+ expect(result.code).toContain(`const manifest = ${manifestContent};`);
18
+ });
19
+ it("should replace asset placeholders with hashed paths from the manifest", () => {
20
+ const code = `
21
+ const stylesheet = "rwsdk_asset:/src/styles.css";
22
+ const logo = "rwsdk_asset:/src/logo.svg";
23
+ `;
24
+ const result = linkWorkerBundle({
25
+ code,
26
+ manifestContent,
27
+ projectRootDir,
28
+ });
29
+ expect(result.code).toContain(`const stylesheet = "/assets/styles.123.css";`);
30
+ expect(result.code).toContain(`const logo = "/assets/logo.abc.svg";`);
31
+ });
32
+ it("should deprefix remaining asset placeholders not in the manifest", () => {
33
+ const code = `const publicImg = "rwsdk_asset:/images/photo.jpg";`;
34
+ const result = linkWorkerBundle({
35
+ code,
36
+ manifestContent,
37
+ projectRootDir,
38
+ });
39
+ expect(result.code).toContain(`const publicImg = "/images/photo.jpg";`);
40
+ });
41
+ });
@@ -1,4 +1,9 @@
1
1
  import { Plugin } from "vite";
2
+ export declare const hasEntryAsAncestor: ({ module, entryFile, seen, }: {
3
+ module: any;
4
+ entryFile: string;
5
+ seen?: Set<any>;
6
+ }) => boolean;
2
7
  export declare const miniflareHMRPlugin: (givenOptions: {
3
8
  clientFiles: Set<string>;
4
9
  serverFiles: Set<string>;
@@ -1,13 +1,13 @@
1
+ import debug from "debug";
2
+ import { readFile } from "node:fs/promises";
1
3
  import { resolve } from "node:path";
2
4
  import colors from "picocolors";
3
- import { readFile } from "node:fs/promises";
4
- import debug from "debug";
5
- import { VIRTUAL_SSR_PREFIX } from "./ssrBridgePlugin.mjs";
5
+ import { getShortName } from "../lib/getShortName.mjs";
6
6
  import { normalizeModulePath } from "../lib/normalizeModulePath.mjs";
7
7
  import { hasDirective as sourceHasDirective } from "./hasDirective.mjs";
8
- import { isJsFile } from "./isJsFile.mjs";
9
8
  import { invalidateModule } from "./invalidateModule.mjs";
10
- import { getShortName } from "../lib/getShortName.mjs";
9
+ import { isJsFile } from "./isJsFile.mjs";
10
+ import { VIRTUAL_SSR_PREFIX } from "./ssrBridgePlugin.mjs";
11
11
  const log = debug("rwsdk:vite:hmr-plugin");
12
12
  let hasErrored = false;
13
13
  const hasDirective = async (filepath, directive) => {
@@ -17,7 +17,7 @@ const hasDirective = async (filepath, directive) => {
17
17
  const content = await readFile(filepath, "utf-8");
18
18
  return sourceHasDirective(content, directive);
19
19
  };
20
- const hasEntryAsAncestor = (module, entryFile, seen = new Set()) => {
20
+ export const hasEntryAsAncestor = ({ module, entryFile, seen = new Set(), }) => {
21
21
  // Prevent infinite recursion
22
22
  if (seen.has(module)) {
23
23
  return false;
@@ -28,7 +28,7 @@ const hasEntryAsAncestor = (module, entryFile, seen = new Set()) => {
28
28
  if (importer.file === entryFile)
29
29
  return true;
30
30
  // Recursively check importers
31
- if (hasEntryAsAncestor(importer, entryFile, seen))
31
+ if (hasEntryAsAncestor({ module: importer, entryFile, seen }))
32
32
  return true;
33
33
  }
34
34
  return false;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { hasEntryAsAncestor } from "./miniflareHMRPlugin.mjs";
3
+ const createModule = (file) => ({
4
+ file,
5
+ importers: new Set(),
6
+ });
7
+ describe("hasEntryAsAncestor", () => {
8
+ it("should return true if the entry file is a direct importer", () => {
9
+ const entry = createModule("entry.js");
10
+ const mod = createModule("mod.js");
11
+ mod.importers.add(entry);
12
+ expect(hasEntryAsAncestor({ module: mod, entryFile: "entry.js" })).toBe(true);
13
+ });
14
+ it("should return true if the entry file is an indirect importer", () => {
15
+ const entry = createModule("entry.js");
16
+ const importer1 = createModule("importer1.js");
17
+ const mod = createModule("mod.js");
18
+ importer1.importers.add(entry);
19
+ mod.importers.add(importer1);
20
+ expect(hasEntryAsAncestor({ module: mod, entryFile: "entry.js" })).toBe(true);
21
+ });
22
+ it("should return false if the entry file is not an importer", () => {
23
+ const entry = createModule("entry.js");
24
+ const other = createModule("other.js");
25
+ const mod = createModule("mod.js");
26
+ mod.importers.add(other);
27
+ expect(hasEntryAsAncestor({ module: mod, entryFile: "entry.js" })).toBe(false);
28
+ });
29
+ it("should handle circular dependencies", () => {
30
+ const entry = createModule("entry.js");
31
+ const modA = createModule("modA.js");
32
+ const modB = createModule("modB.js");
33
+ modA.importers.add(entry);
34
+ modA.importers.add(modB);
35
+ modB.importers.add(modA);
36
+ expect(hasEntryAsAncestor({ module: modB, entryFile: "entry.js" })).toBe(true);
37
+ });
38
+ it("should return false for a module with no importers", () => {
39
+ const mod = createModule("mod.js");
40
+ expect(hasEntryAsAncestor({ module: mod, entryFile: "entry.js" })).toBe(false);
41
+ });
42
+ });
@@ -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;
@@ -1,12 +1,21 @@
1
1
  import { InlineConfig } from "vite";
2
+ import { unstable_readConfig } from "wrangler";
2
3
  export type RedwoodPluginOptions = {
3
4
  silent?: boolean;
4
5
  rootDir?: string;
5
6
  includeCloudflarePlugin?: boolean;
6
7
  includeReactPlugin?: boolean;
7
8
  configPath?: string;
9
+ forceClientPaths?: string[];
10
+ forceServerPaths?: string[];
8
11
  entry?: {
9
12
  worker?: string;
10
13
  };
11
14
  };
15
+ export declare const determineWorkerEntryPathname: ({ projectRootDir, workerConfigPath, options, readConfig, }: {
16
+ projectRootDir: string;
17
+ workerConfigPath: string;
18
+ options: RedwoodPluginOptions;
19
+ readConfig?: typeof unstable_readConfig;
20
+ }) => Promise<string>;
12
21
  export declare const redwoodPlugin: (options?: RedwoodPluginOptions) => Promise<InlineConfig["plugins"]>;
@@ -1,37 +1,38 @@
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";
30
- const determineWorkerEntryPathname = async (projectRootDir, workerConfigPath, options) => {
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";
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);
33
34
  }
34
- const workerConfig = unstable_readConfig({ config: workerConfigPath });
35
+ const workerConfig = readConfig({ config: workerConfigPath });
35
36
  return resolve(projectRootDir, workerConfig.main ?? "src/worker.tsx");
36
37
  };
37
38
  const clientFiles = new Set();
@@ -39,11 +40,33 @@ 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)
45
64
  : await findWranglerConfig(projectRootDir));
46
- const workerEntryPathname = await determineWorkerEntryPathname(projectRootDir, workerConfigPath, options);
65
+ const workerEntryPathname = await determineWorkerEntryPathname({
66
+ projectRootDir,
67
+ workerConfigPath,
68
+ options,
69
+ });
47
70
  const shouldIncludeCloudflarePlugin = options.includeCloudflarePlugin ??
48
71
  !(await hasOwnCloudflareVitePlugin({ rootProjectDir: projectRootDir }));
49
72
  const shouldIncludeReactPlugin = options.includeReactPlugin ??
@@ -68,6 +91,7 @@ export const redwoodPlugin = async (options = {}) => {
68
91
  clientFiles,
69
92
  serverFiles,
70
93
  projectRootDir,
94
+ workerEntryPathname,
71
95
  }),
72
96
  configPlugin({
73
97
  silent: options.silent ?? false,
@@ -82,7 +106,7 @@ export const redwoodPlugin = async (options = {}) => {
82
106
  serverFiles,
83
107
  projectRootDir,
84
108
  }),
85
- reactConditionsResolverPlugin({ projectRootDir }),
109
+ knownDepsResolverPlugin({ projectRootDir }),
86
110
  tsconfigPaths({ root: projectRootDir }),
87
111
  shouldIncludeCloudflarePlugin
88
112
  ? cloudflare({
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import path from "node:path";
2
+ import { describe, expect, it } from "vitest";
3
+ import { determineWorkerEntryPathname } from "./redwoodPlugin.mjs";
4
+ describe("determineWorkerEntryPathname", () => {
5
+ const projectRootDir = "/test/project";
6
+ it("should use the entry path from options if provided", async () => {
7
+ const result = await determineWorkerEntryPathname({
8
+ projectRootDir,
9
+ workerConfigPath: "/test/project/wrangler.toml",
10
+ options: { entry: { worker: "src/custom-worker.ts" } },
11
+ });
12
+ expect(result).toBe(path.join(projectRootDir, "src/custom-worker.ts"));
13
+ });
14
+ it("should use the main path from wrangler config if no entry option is provided", async () => {
15
+ const readConfig = () => ({ main: "src/wrangler-worker.tsx" });
16
+ const result = await determineWorkerEntryPathname({
17
+ projectRootDir,
18
+ workerConfigPath: "/test/project/wrangler.toml",
19
+ options: {},
20
+ readConfig: readConfig,
21
+ });
22
+ expect(result).toBe(path.join(projectRootDir, "src/wrangler-worker.tsx"));
23
+ });
24
+ it("should use the default path if wrangler config has no main property", async () => {
25
+ const readConfig = () => ({});
26
+ const result = await determineWorkerEntryPathname({
27
+ projectRootDir,
28
+ workerConfigPath: "/test/project/wrangler.toml",
29
+ options: {},
30
+ readConfig: readConfig,
31
+ });
32
+ expect(result).toBe(path.join(projectRootDir, "src/worker.tsx"));
33
+ });
34
+ });
@@ -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
+ }
@@ -1,7 +1,28 @@
1
1
  import { Environment, ResolvedConfig } from "vite";
2
- export declare const runDirectivesScan: ({ rootConfig, environments, clientFiles, serverFiles, }: {
2
+ type Resolver = (context: {}, path: string, request: string, resolveContext: {}, callback: (err: Error | null, result?: string | false) => void) => void;
3
+ export declare function resolveModuleWithEnvironment({ path, importer, importerEnv, clientResolver, workerResolver, }: {
4
+ path: string;
5
+ importer?: string;
6
+ importerEnv: "client" | "worker";
7
+ clientResolver: Resolver;
8
+ workerResolver: Resolver;
9
+ }): Promise<{
10
+ id: string;
11
+ } | null>;
12
+ export declare function classifyModule({ contents, inheritedEnv, }: {
13
+ contents: string;
14
+ inheritedEnv: "client" | "worker";
15
+ }): {
16
+ moduleEnv: "client" | "worker";
17
+ isClient: boolean;
18
+ isServer: boolean;
19
+ };
20
+ export type EsbuildLoader = "js" | "jsx" | "ts" | "tsx" | "default";
21
+ export declare const runDirectivesScan: ({ rootConfig, environments, clientFiles, serverFiles, entries: initialEntries, }: {
3
22
  rootConfig: ResolvedConfig;
4
23
  environments: Record<string, Environment>;
5
24
  clientFiles: Set<string>;
6
25
  serverFiles: Set<string>;
26
+ entries?: string[];
7
27
  }) => Promise<void>;
28
+ export {};