rwsdk 0.1.16 → 0.1.17

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 (327) hide show
  1. package/dist/lib/$.d.mts +8 -0
  2. package/dist/lib/$.mjs +5 -0
  3. package/dist/lib/compileTsModule.d.mts +1 -0
  4. package/dist/lib/compileTsModule.mjs +27 -0
  5. package/dist/lib/constants.d.mts +4 -0
  6. package/dist/lib/constants.mjs +6 -0
  7. package/dist/lib/findWranglerConfig.d.mts +1 -0
  8. package/dist/lib/findWranglerConfig.mjs +12 -0
  9. package/dist/lib/getShortName.d.mts +1 -0
  10. package/dist/lib/getShortName.mjs +2 -0
  11. package/dist/lib/getSrcPaths.d.ts +15 -0
  12. package/dist/lib/getSrcPaths.js +80 -0
  13. package/dist/lib/hasPkgScript.d.mts +1 -0
  14. package/dist/lib/hasPkgScript.mjs +9 -0
  15. package/dist/lib/jsonUtils.d.mts +28 -0
  16. package/dist/lib/jsonUtils.mjs +167 -0
  17. package/dist/lib/setupEnvFiles.d.mts +4 -0
  18. package/dist/lib/setupEnvFiles.mjs +31 -0
  19. package/dist/lib/smokeTests/artifacts.d.mts +10 -0
  20. package/dist/lib/smokeTests/artifacts.mjs +164 -0
  21. package/dist/lib/smokeTests/browser.d.mts +48 -0
  22. package/dist/lib/smokeTests/browser.mjs +1041 -0
  23. package/dist/lib/smokeTests/cleanup.d.mts +5 -0
  24. package/dist/lib/smokeTests/cleanup.mjs +214 -0
  25. package/dist/lib/smokeTests/codeUpdates.d.mts +8 -0
  26. package/dist/lib/smokeTests/codeUpdates.mjs +229 -0
  27. package/dist/lib/smokeTests/constants.d.mts +5 -0
  28. package/dist/lib/smokeTests/constants.mjs +10 -0
  29. package/dist/lib/smokeTests/development.d.mts +11 -0
  30. package/dist/lib/smokeTests/development.mjs +209 -0
  31. package/dist/lib/smokeTests/environment.d.mts +14 -0
  32. package/dist/lib/smokeTests/environment.mjs +163 -0
  33. package/dist/lib/smokeTests/release.d.mts +61 -0
  34. package/dist/lib/smokeTests/release.mjs +526 -0
  35. package/dist/lib/smokeTests/reporting.d.mts +13 -0
  36. package/dist/lib/smokeTests/reporting.mjs +355 -0
  37. package/dist/lib/smokeTests/runSmokeTests.d.mts +5 -0
  38. package/dist/lib/smokeTests/runSmokeTests.mjs +144 -0
  39. package/dist/lib/smokeTests/state.d.mts +48 -0
  40. package/dist/lib/smokeTests/state.mjs +57 -0
  41. package/dist/lib/smokeTests/templates/SmokeTest.template.d.ts +1 -0
  42. package/dist/lib/smokeTests/templates/SmokeTest.template.js +81 -0
  43. package/dist/lib/smokeTests/templates/SmokeTestClient.template.d.ts +1 -0
  44. package/dist/lib/smokeTests/templates/SmokeTestClient.template.js +159 -0
  45. package/dist/lib/smokeTests/templates/smokeTestFunctions.template.d.ts +1 -0
  46. package/dist/lib/smokeTests/templates/smokeTestFunctions.template.js +19 -0
  47. package/dist/lib/smokeTests/types.d.mts +75 -0
  48. package/dist/lib/smokeTests/types.mjs +1 -0
  49. package/dist/lib/smokeTests/utils.d.mts +15 -0
  50. package/dist/lib/smokeTests/utils.mjs +147 -0
  51. package/dist/llms/index.d.ts +3 -0
  52. package/dist/llms/index.js +35 -0
  53. package/dist/llms/rules/interruptors.d.ts +1 -0
  54. package/dist/llms/rules/interruptors.js +243 -0
  55. package/dist/llms/rules/middleware.d.ts +1 -0
  56. package/dist/llms/rules/middleware.js +71 -0
  57. package/dist/llms/rules/react.d.ts +1 -0
  58. package/dist/llms/rules/react.js +106 -0
  59. package/dist/llms/rules/request-response.d.ts +1 -0
  60. package/dist/llms/rules/request-response.js +209 -0
  61. package/dist/runtime/client.d.ts +17 -0
  62. package/dist/runtime/client.js +74 -0
  63. package/dist/runtime/clientNavigation.d.ts +4 -0
  64. package/dist/runtime/clientNavigation.js +53 -0
  65. package/dist/runtime/clientNavigation.test.d.ts +1 -0
  66. package/dist/runtime/clientNavigation.test.js +55 -0
  67. package/dist/runtime/constants.d.ts +1 -0
  68. package/dist/runtime/constants.js +1 -0
  69. package/dist/runtime/entries/auth.d.ts +1 -0
  70. package/dist/runtime/entries/auth.js +1 -0
  71. package/dist/runtime/entries/client.d.ts +4 -0
  72. package/dist/runtime/entries/client.js +4 -0
  73. package/dist/runtime/entries/clientSSR.d.ts +1 -0
  74. package/dist/runtime/entries/clientSSR.js +1 -0
  75. package/dist/runtime/entries/navigation.d.ts +1 -0
  76. package/dist/runtime/entries/navigation.js +1 -0
  77. package/dist/runtime/entries/no-react-server.d.ts +0 -0
  78. package/dist/runtime/entries/no-react-server.js +2 -0
  79. package/dist/runtime/entries/react-server-only.d.ts +0 -0
  80. package/dist/runtime/entries/react-server-only.js +2 -0
  81. package/dist/runtime/entries/router.d.ts +2 -0
  82. package/dist/runtime/entries/router.js +2 -0
  83. package/dist/runtime/entries/ssr.d.ts +1 -0
  84. package/dist/runtime/entries/ssr.js +1 -0
  85. package/dist/runtime/entries/worker.d.ts +9 -0
  86. package/dist/runtime/entries/worker.js +9 -0
  87. package/dist/runtime/error.d.ts +6 -0
  88. package/dist/runtime/error.js +8 -0
  89. package/dist/runtime/imports/ClientOnly.d.ts +3 -0
  90. package/dist/runtime/imports/ClientOnly.js +8 -0
  91. package/dist/runtime/imports/client.d.ts +4 -0
  92. package/dist/runtime/imports/client.js +33 -0
  93. package/dist/runtime/imports/ssr.d.ts +5 -0
  94. package/dist/runtime/imports/ssr.js +20 -0
  95. package/dist/runtime/imports/worker.d.ts +5 -0
  96. package/dist/runtime/imports/worker.js +22 -0
  97. package/dist/runtime/lib/auth/index.d.ts +1 -0
  98. package/dist/runtime/lib/auth/index.js +1 -0
  99. package/dist/runtime/lib/auth/session.d.ts +50 -0
  100. package/dist/runtime/lib/auth/session.js +148 -0
  101. package/dist/runtime/lib/db/DOWorkerDialect.d.ts +29 -0
  102. package/dist/runtime/lib/db/DOWorkerDialect.js +66 -0
  103. package/dist/runtime/lib/db/SqliteDurableObject.d.ts +14 -0
  104. package/dist/runtime/lib/db/SqliteDurableObject.js +42 -0
  105. package/dist/runtime/lib/db/createDb.d.ts +2 -0
  106. package/dist/runtime/lib/db/createDb.js +33 -0
  107. package/dist/runtime/lib/db/index.d.ts +4 -0
  108. package/dist/runtime/lib/db/index.js +3 -0
  109. package/dist/runtime/lib/db/migrations.d.ts +23 -0
  110. package/dist/runtime/lib/db/migrations.js +34 -0
  111. package/dist/runtime/lib/db/typeInference/assert.d.ts +2 -0
  112. package/dist/runtime/lib/db/typeInference/assert.js +1 -0
  113. package/dist/runtime/lib/db/typeInference/builders/alterColumn.d.ts +27 -0
  114. package/dist/runtime/lib/db/typeInference/builders/alterColumn.js +1 -0
  115. package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +53 -0
  116. package/dist/runtime/lib/db/typeInference/builders/alterTable.js +1 -0
  117. package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +26 -0
  118. package/dist/runtime/lib/db/typeInference/builders/columnDefinition.js +1 -0
  119. package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +49 -0
  120. package/dist/runtime/lib/db/typeInference/builders/createTable.js +1 -0
  121. package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +17 -0
  122. package/dist/runtime/lib/db/typeInference/builders/createView.js +1 -0
  123. package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +11 -0
  124. package/dist/runtime/lib/db/typeInference/builders/dropTable.js +1 -0
  125. package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +12 -0
  126. package/dist/runtime/lib/db/typeInference/builders/dropView.js +1 -0
  127. package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +24 -0
  128. package/dist/runtime/lib/db/typeInference/builders/schema.js +1 -0
  129. package/dist/runtime/lib/db/typeInference/database.d.ts +27 -0
  130. package/dist/runtime/lib/db/typeInference/database.js +1 -0
  131. package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.d.ts +1 -0
  132. package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.js +360 -0
  133. package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.d.ts +1 -0
  134. package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.js +33 -0
  135. package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.d.ts +1 -0
  136. package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.js +143 -0
  137. package/dist/runtime/lib/db/typeInference/typetests/print.d.ts +3 -0
  138. package/dist/runtime/lib/db/typeInference/typetests/print.js +1 -0
  139. package/dist/runtime/lib/db/typeInference/typetests/testUtils.d.ts +2 -0
  140. package/dist/runtime/lib/db/typeInference/typetests/testUtils.js +1 -0
  141. package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.d.ts +1 -0
  142. package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.js +17 -0
  143. package/dist/runtime/lib/db/typeInference/utils.d.ts +82 -0
  144. package/dist/runtime/lib/db/typeInference/utils.js +2 -0
  145. package/dist/runtime/lib/debug.d.ts +2 -0
  146. package/dist/runtime/lib/debug.js +36 -0
  147. package/dist/runtime/lib/links.d.ts +14 -0
  148. package/dist/runtime/lib/links.js +38 -0
  149. package/dist/runtime/lib/realtime/client.d.ts +7 -0
  150. package/dist/runtime/lib/realtime/client.js +166 -0
  151. package/dist/runtime/lib/realtime/constants.d.ts +1 -0
  152. package/dist/runtime/lib/realtime/constants.js +1 -0
  153. package/dist/runtime/lib/realtime/durableObject.d.ts +29 -0
  154. package/dist/runtime/lib/realtime/durableObject.js +187 -0
  155. package/dist/runtime/lib/realtime/renderRealtimeClients.d.ts +7 -0
  156. package/dist/runtime/lib/realtime/renderRealtimeClients.js +6 -0
  157. package/dist/runtime/lib/realtime/shared.d.ts +10 -0
  158. package/dist/runtime/lib/realtime/shared.js +10 -0
  159. package/dist/runtime/lib/realtime/validateUpgradeRequest.d.ts +6 -0
  160. package/dist/runtime/lib/realtime/validateUpgradeRequest.js +29 -0
  161. package/dist/runtime/lib/realtime/worker.d.ts +3 -0
  162. package/dist/runtime/lib/realtime/worker.js +16 -0
  163. package/dist/runtime/lib/router.d.ts +56 -0
  164. package/dist/runtime/lib/router.js +210 -0
  165. package/dist/runtime/lib/router.test.d.ts +1 -0
  166. package/dist/runtime/lib/router.test.js +58 -0
  167. package/dist/runtime/lib/streams/consumeEventStream.d.ts +4 -0
  168. package/dist/runtime/lib/streams/consumeEventStream.js +13 -0
  169. package/dist/runtime/lib/turnstile/TurnstileScript.d.ts +1 -0
  170. package/dist/runtime/lib/turnstile/TurnstileScript.js +2 -0
  171. package/dist/runtime/lib/turnstile/turnstile.d.ts +3 -0
  172. package/dist/runtime/lib/turnstile/turnstile.js +3 -0
  173. package/dist/runtime/lib/turnstile/useTurnstile.d.ts +4 -0
  174. package/dist/runtime/lib/turnstile/useTurnstile.js +23 -0
  175. package/dist/runtime/lib/turnstile/verifyTurnstileToken.d.ts +4 -0
  176. package/dist/runtime/lib/turnstile/verifyTurnstileToken.js +15 -0
  177. package/dist/runtime/lib/utils.d.ts +1 -0
  178. package/dist/runtime/lib/utils.js +1 -0
  179. package/dist/runtime/register/client.d.ts +1 -0
  180. package/dist/runtime/register/client.js +5 -0
  181. package/dist/runtime/register/ssr.d.ts +3 -0
  182. package/dist/runtime/register/ssr.js +26 -0
  183. package/dist/runtime/register/worker.d.ts +4 -0
  184. package/dist/runtime/register/worker.js +42 -0
  185. package/dist/runtime/render/createClientManifest.d.ts +1 -0
  186. package/dist/runtime/render/createClientManifest.js +7 -0
  187. package/dist/runtime/render/createModuleMap.d.ts +1 -0
  188. package/dist/runtime/render/createModuleMap.js +13 -0
  189. package/dist/runtime/render/injectRSCPayload.d.ts +3 -0
  190. package/dist/runtime/render/injectRSCPayload.js +79 -0
  191. package/dist/runtime/render/renderRscThenableToHtmlStream.d.ts +9 -0
  192. package/dist/runtime/render/renderRscThenableToHtmlStream.js +49 -0
  193. package/dist/runtime/render/renderToRscStream.d.ts +5 -0
  194. package/dist/runtime/render/renderToRscStream.js +46 -0
  195. package/dist/runtime/render/renderToStream.d.ts +9 -0
  196. package/dist/runtime/render/renderToStream.js +27 -0
  197. package/dist/runtime/render/renderToString.d.ts +7 -0
  198. package/dist/runtime/render/renderToString.js +26 -0
  199. package/dist/runtime/render/transformRscToHtmlStream.d.ts +8 -0
  200. package/dist/runtime/render/transformRscToHtmlStream.js +19 -0
  201. package/dist/runtime/requestInfo/types.d.ts +11 -0
  202. package/dist/runtime/requestInfo/types.js +1 -0
  203. package/dist/runtime/requestInfo/worker.d.ts +5 -0
  204. package/dist/runtime/requestInfo/worker.js +33 -0
  205. package/dist/runtime/script.d.ts +5 -0
  206. package/dist/runtime/script.js +8 -0
  207. package/dist/runtime/ssrBridge.d.ts +2 -0
  208. package/dist/runtime/ssrBridge.js +11 -0
  209. package/dist/runtime/worker.d.ts +18 -0
  210. package/dist/runtime/worker.js +173 -0
  211. package/dist/scripts/__sdk.d.mts +1 -0
  212. package/dist/scripts/__sdk.mjs +14 -0
  213. package/dist/scripts/build-vendor-bundles.d.mts +1 -0
  214. package/dist/scripts/build-vendor-bundles.mjs +92 -0
  215. package/dist/scripts/debug-sync.d.mts +6 -0
  216. package/dist/scripts/debug-sync.mjs +224 -0
  217. package/dist/scripts/dev-init.d.mts +1 -0
  218. package/dist/scripts/dev-init.mjs +25 -0
  219. package/dist/scripts/ensure-deploy-env.d.mts +1 -0
  220. package/dist/scripts/ensure-deploy-env.mjs +271 -0
  221. package/dist/scripts/ensure-env.d.mts +1 -0
  222. package/dist/scripts/ensure-env.mjs +9 -0
  223. package/dist/scripts/migrate-new.d.mts +1 -0
  224. package/dist/scripts/migrate-new.mjs +51 -0
  225. package/dist/scripts/smoke-test.d.mts +1 -0
  226. package/dist/scripts/smoke-test.mjs +166 -0
  227. package/dist/scripts/worker-run.d.mts +1 -0
  228. package/dist/scripts/worker-run.mjs +82 -0
  229. package/dist/vite/aliasByEnvPlugin.d.mts +2 -0
  230. package/dist/vite/aliasByEnvPlugin.mjs +11 -0
  231. package/dist/vite/asyncSetupPlugin.d.mts +6 -0
  232. package/dist/vite/asyncSetupPlugin.mjs +23 -0
  233. package/dist/vite/checkIsUsingPrisma.d.mts +6 -0
  234. package/dist/vite/checkIsUsingPrisma.mjs +18 -0
  235. package/dist/vite/configPlugin.d.mts +9 -0
  236. package/dist/vite/configPlugin.mjs +169 -0
  237. package/dist/vite/copyPrismaWasmPlugin.d.mts +4 -0
  238. package/dist/vite/copyPrismaWasmPlugin.mjs +32 -0
  239. package/dist/vite/createDirectiveLookupPlugin.d.mts +21 -0
  240. package/dist/vite/createDirectiveLookupPlugin.mjs +231 -0
  241. package/dist/vite/customReactBuildPlugin.d.mts +4 -0
  242. package/dist/vite/customReactBuildPlugin.mjs +61 -0
  243. package/dist/vite/devServerTimingPlugin.d.mts +2 -0
  244. package/dist/vite/devServerTimingPlugin.mjs +24 -0
  245. package/dist/vite/directivesPlugin.d.mts +6 -0
  246. package/dist/vite/directivesPlugin.mjs +200 -0
  247. package/dist/vite/ensureAliasArray.d.mts +2 -0
  248. package/dist/vite/ensureAliasArray.mjs +17 -0
  249. package/dist/vite/findSpecifiers.d.mts +31 -0
  250. package/dist/vite/findSpecifiers.mjs +230 -0
  251. package/dist/vite/findSsrSpecifiers.d.mts +11 -0
  252. package/dist/vite/findSsrSpecifiers.mjs +67 -0
  253. package/dist/vite/hasDirective.d.mts +7 -0
  254. package/dist/vite/hasDirective.mjs +54 -0
  255. package/dist/vite/hasOwnCloudflareVitePlugin.d.mts +3 -0
  256. package/dist/vite/hasOwnCloudflareVitePlugin.mjs +14 -0
  257. package/dist/vite/index.d.mts +1 -0
  258. package/dist/vite/index.mjs +1 -0
  259. package/dist/vite/injectHmrPreambleJsxPlugin.d.mts +2 -0
  260. package/dist/vite/injectHmrPreambleJsxPlugin.mjs +22 -0
  261. package/dist/vite/injectVitePreamblePlugin.d.mts +4 -0
  262. package/dist/vite/injectVitePreamblePlugin.mjs +23 -0
  263. package/dist/vite/invalidateCacheIfPrismaClientChanged.d.mts +3 -0
  264. package/dist/vite/invalidateCacheIfPrismaClientChanged.mjs +27 -0
  265. package/dist/vite/invalidateModule.d.mts +6 -0
  266. package/dist/vite/invalidateModule.mjs +30 -0
  267. package/dist/vite/miniflareHMRPlugin.d.mts +10 -0
  268. package/dist/vite/miniflareHMRPlugin.mjs +209 -0
  269. package/dist/vite/miniflarePlugin.d.mts +9 -0
  270. package/dist/vite/miniflarePlugin.mjs +135 -0
  271. package/dist/vite/moveStaticAssetsPlugin.d.mts +4 -0
  272. package/dist/vite/moveStaticAssetsPlugin.mjs +12 -0
  273. package/dist/vite/normalizeModulePath.d.mts +1 -0
  274. package/dist/vite/normalizeModulePath.mjs +13 -0
  275. package/dist/vite/prismaPlugin.d.mts +4 -0
  276. package/dist/vite/prismaPlugin.mjs +43 -0
  277. package/dist/vite/reactConditionsResolverPlugin.d.mts +16 -0
  278. package/dist/vite/reactConditionsResolverPlugin.mjs +179 -0
  279. package/dist/vite/redwoodPlugin.d.mts +12 -0
  280. package/dist/vite/redwoodPlugin.mjs +105 -0
  281. package/dist/vite/requestUtils.d.mts +6 -0
  282. package/dist/vite/requestUtils.mjs +35 -0
  283. package/dist/vite/setupEnvFiles.d.mts +4 -0
  284. package/dist/vite/setupEnvFiles.mjs +31 -0
  285. package/dist/vite/ssrBridgePlugin.d.mts +7 -0
  286. package/dist/vite/ssrBridgePlugin.mjs +137 -0
  287. package/dist/vite/transformClientComponents.d.mts +12 -0
  288. package/dist/vite/transformClientComponents.mjs +116 -0
  289. package/dist/vite/transformClientComponents.test.d.mts +1 -0
  290. package/dist/vite/transformClientComponents.test.mjs +264 -0
  291. package/dist/vite/transformJsxScriptTagsPlugin.d.mts +8 -0
  292. package/dist/vite/transformJsxScriptTagsPlugin.mjs +315 -0
  293. package/dist/vite/transformJsxScriptTagsPlugin.test.d.mts +1 -0
  294. package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +334 -0
  295. package/dist/vite/transformServerFunctions.d.mts +16 -0
  296. package/dist/vite/transformServerFunctions.mjs +296 -0
  297. package/dist/vite/transformServerFunctions.test.d.mts +1 -0
  298. package/dist/vite/transformServerFunctions.test.mjs +124 -0
  299. package/dist/vite/useClientLookupPlugin.d.mts +5 -0
  300. package/dist/vite/useClientLookupPlugin.mjs +15 -0
  301. package/dist/vite/useClientPlugin.d.mts +8 -0
  302. package/dist/vite/useClientPlugin.mjs +295 -0
  303. package/dist/vite/useClientPlugin.test.d.mts +1 -0
  304. package/dist/vite/useClientPlugin.test.mjs +1204 -0
  305. package/dist/vite/useServerLookupPlugin.d.mts +5 -0
  306. package/dist/vite/useServerLookupPlugin.mjs +15 -0
  307. package/dist/vite/useServerPlugin.d.mts +1 -0
  308. package/dist/vite/useServerPlugin.mjs +1 -0
  309. package/dist/vite/virtualPlugin.d.mts +2 -0
  310. package/dist/vite/virtualPlugin.mjs +18 -0
  311. package/dist/vite/vitePreamblePlugin.d.mts +1 -0
  312. package/dist/vite/vitePreamblePlugin.mjs +11 -0
  313. package/dist/worker/__ssr_bridge.js +8947 -0
  314. package/dist/worker/__ssr_bridge.js.map +1 -0
  315. package/package.json +1 -1
  316. package/dist/vite/invalidateClientModule.d.mts +0 -2
  317. package/dist/vite/invalidateClientModule.mjs +0 -8
  318. package/dist/vite/invalidateModule copy.d.mts +0 -2
  319. package/dist/vite/invalidateModule copy.mjs +0 -14
  320. package/dist/vite/invalidateSSRModule.d.mts +0 -2
  321. package/dist/vite/invalidateSSRModule.mjs +0 -7
  322. package/dist/vite/mode.d.mts +0 -5
  323. package/dist/vite/mode.mjs +0 -25
  324. package/dist/vite/modePlugin.d.mts +0 -2
  325. package/dist/vite/modePlugin.mjs +0 -10
  326. /package/dist/vite/{isJsFile.d.ts → isJsFile.d.mts} +0 -0
  327. /package/dist/vite/{isJsFile.js → isJsFile.mjs} +0 -0
@@ -0,0 +1,526 @@
1
+ import { join, basename } from "path";
2
+ import { setTimeout } from "node:timers/promises";
3
+ import { log } from "./constants.mjs";
4
+ import { checkUrl, checkServerUp } from "./browser.mjs";
5
+ import { $ } from "../../lib/$.mjs";
6
+ import { execaCommand } from "execa";
7
+ import { existsSync, readFileSync } from "fs";
8
+ import { pathExists } from "fs-extra";
9
+ import { parse as parseJsonc } from "jsonc-parser";
10
+ import * as fs from "fs/promises";
11
+ import { extractLastJson, parseJson } from "../../lib/jsonUtils.mjs";
12
+ /**
13
+ * A mini expect-like utility for handling interactive CLI prompts and verifying output
14
+ * @param command The command to execute
15
+ * @param expectations Array of {expect, send} objects for interactive responses and verification
16
+ * @param options Additional options for command execution including working directory and environment
17
+ * @returns Promise that resolves when the command completes
18
+ */
19
+ export async function $expect(command, expectations, options = {
20
+ reject: true,
21
+ }) {
22
+ return new Promise((resolve, reject) => {
23
+ log("$expect starting with command: %s", command);
24
+ log("Working directory: %s", options.cwd ?? process.cwd());
25
+ log("Expected patterns: %O", expectations.map((e) => e.expect.toString()));
26
+ console.log(`Running command: ${command}`);
27
+ // Spawn the process with pipes for interaction
28
+ const childProcess = execaCommand(command, {
29
+ cwd: options.cwd ?? process.cwd(),
30
+ stdio: "pipe",
31
+ reject: false, // Never reject so we can handle the error ourselves
32
+ env: options.env ?? process.env,
33
+ });
34
+ log("Process spawned with PID: %s", childProcess.pid);
35
+ let stdout = "";
36
+ let stderr = "";
37
+ let buffer = "";
38
+ let lastMatchIndex = 0; // Track the index where the last match occurred
39
+ // Track patterns that have been matched
40
+ const matchHistory = new Map();
41
+ // Track current expectation index to process them in order
42
+ let currentExpectationIndex = 0;
43
+ // Initialize match count for each pattern
44
+ expectations.forEach(({ expect: expectPattern }) => {
45
+ matchHistory.set(expectPattern, 0);
46
+ log("Initialized pattern match count for: %s", expectPattern.toString());
47
+ });
48
+ // Collect stdout
49
+ childProcess.stdout?.on("data", (data) => {
50
+ const chunk = data.toString();
51
+ stdout += chunk;
52
+ buffer += chunk;
53
+ // Print to console
54
+ process.stdout.write(chunk);
55
+ // Only process expectations that haven't been fully matched yet
56
+ // and in the order they were provided
57
+ while (currentExpectationIndex < expectations.length) {
58
+ const { expect: expectPattern, send } = expectations[currentExpectationIndex];
59
+ const pattern = expectPattern instanceof RegExp
60
+ ? expectPattern
61
+ : new RegExp(expectPattern, "m");
62
+ // Only search in the unmatched portion of the buffer
63
+ const searchBuffer = buffer.substring(lastMatchIndex);
64
+ log("Testing pattern: %s against buffer from position %d (%d chars)", pattern.toString(), lastMatchIndex, searchBuffer.length);
65
+ // Enhanced debugging: show actual search buffer content
66
+ log("Search buffer content for debugging: %O", searchBuffer);
67
+ const match = searchBuffer.match(pattern);
68
+ if (match) {
69
+ // Found a match
70
+ const patternStr = expectPattern.toString();
71
+ const matchCount = matchHistory.get(expectPattern) || 0;
72
+ // Update the lastMatchIndex to point after this match
73
+ // Calculate the absolute position in the full buffer
74
+ const matchStartPosition = lastMatchIndex + match.index;
75
+ const matchEndPosition = matchStartPosition + match[0].length;
76
+ lastMatchIndex = matchEndPosition;
77
+ log(`Pattern matched: "${patternStr}" (occurrence #${matchCount + 1}) at position ${matchStartPosition}-${matchEndPosition}`);
78
+ // Only send a response if one is specified
79
+ if (send) {
80
+ log(`Sending response: "${send.replace(/\r/g, "\\r")}" to stdin`);
81
+ childProcess.stdin?.write(send);
82
+ }
83
+ else {
84
+ log(`Pattern "${patternStr}" matched (verification only)`);
85
+ }
86
+ // Increment the match count for this pattern
87
+ matchHistory.set(expectPattern, matchCount + 1);
88
+ log("Updated match count for %s: %d", patternStr, matchCount + 1);
89
+ // Move to the next expectation
90
+ currentExpectationIndex++;
91
+ // If we've processed all expectations but need to wait for stdin response,
92
+ // delay closing stdin until the next data event
93
+ if (currentExpectationIndex >= expectations.length && send) {
94
+ log("All patterns matched, closing stdin after last response");
95
+ childProcess.stdin?.end();
96
+ }
97
+ break; // Exit the while loop to process next chunk
98
+ }
99
+ else {
100
+ log("Pattern not matched. Attempting to diagnose the mismatch:");
101
+ // Try to find the closest substring that might partially match
102
+ const patternString = pattern.toString();
103
+ const patternCore = patternString.substring(1, patternString.lastIndexOf("/") > 0
104
+ ? patternString.lastIndexOf("/")
105
+ : patternString.length);
106
+ // Try partial matches to diagnose the issue
107
+ for (let i = 3; i < patternCore.length; i++) {
108
+ const partialPattern = patternCore.substring(0, i);
109
+ const partialRegex = new RegExp(partialPattern, "m");
110
+ const matches = partialRegex.test(searchBuffer);
111
+ log(" Partial pattern '%s': %s", partialPattern, matches ? "matched" : "not matched");
112
+ // Once we find where the matching starts to fail, stop
113
+ if (!matches)
114
+ break;
115
+ }
116
+ // Break the while loop as this pattern doesn't match yet
117
+ break;
118
+ }
119
+ }
120
+ // If all expectations have been matched, we can close stdin if not already closed
121
+ if (currentExpectationIndex >= expectations.length &&
122
+ childProcess.stdin?.writable) {
123
+ log("All patterns matched, ensuring stdin is closed");
124
+ childProcess.stdin.end();
125
+ }
126
+ });
127
+ // Collect stderr if needed
128
+ if (childProcess.stderr) {
129
+ childProcess.stderr.on("data", (data) => {
130
+ const chunk = data.toString();
131
+ stderr += chunk;
132
+ // Also write stderr to console
133
+ process.stderr.write(chunk);
134
+ });
135
+ }
136
+ // Handle process completion
137
+ childProcess.on("close", (code) => {
138
+ log("Process closed with code: %s", code);
139
+ // Log the number of matches for each pattern
140
+ log("Pattern match summary:");
141
+ for (const [pattern, count] of matchHistory.entries()) {
142
+ log(` - "${pattern.toString()}": ${count} matches`);
143
+ }
144
+ // Check if any required patterns were not matched
145
+ const unmatchedPatterns = Array.from(matchHistory.entries())
146
+ .filter(([_, count]) => count === 0)
147
+ .map(([pattern, _]) => pattern.toString());
148
+ if (unmatchedPatterns.length > 0) {
149
+ log("WARNING: Some expected patterns were not matched: %O", unmatchedPatterns);
150
+ }
151
+ log("$expect completed. Total stdout: %d bytes, stderr: %d bytes", stdout.length, stderr.length);
152
+ resolve({ stdout, stderr, code });
153
+ });
154
+ childProcess.on("error", (err) => {
155
+ log("Process error: %O", err);
156
+ if (options.reject) {
157
+ reject(new Error(`Failed to execute command: ${err.message}`));
158
+ }
159
+ else {
160
+ resolve({ stdout, stderr, code: null });
161
+ }
162
+ });
163
+ });
164
+ }
165
+ /**
166
+ * Ensures Cloudflare account ID is set in environment
167
+ * First checks wrangler cache, then environment variables, and finally guides the user
168
+ */
169
+ export async function ensureCloudflareAccountId(cwd, projectDir) {
170
+ // Skip if already set
171
+ if (process.env.CLOUDFLARE_ACCOUNT_ID) {
172
+ log("CLOUDFLARE_ACCOUNT_ID is already set: %s", process.env.CLOUDFLARE_ACCOUNT_ID);
173
+ console.log(`Using existing CLOUDFLARE_ACCOUNT_ID: ${process.env.CLOUDFLARE_ACCOUNT_ID}`);
174
+ return;
175
+ }
176
+ console.log("CLOUDFLARE_ACCOUNT_ID not set, checking wrangler cache...");
177
+ try {
178
+ // Check wrangler cache in the project directory, not the current working directory
179
+ projectDir = projectDir || cwd || process.cwd();
180
+ log("Looking for wrangler cache in project directory: %s", projectDir);
181
+ const accountCachePath = join(projectDir, "node_modules/.cache/wrangler/wrangler-account.json");
182
+ if (existsSync(accountCachePath)) {
183
+ try {
184
+ const accountCache = JSON.parse(readFileSync(accountCachePath, "utf8"));
185
+ if (accountCache.account?.id) {
186
+ const accountId = accountCache.account.id;
187
+ process.env.CLOUDFLARE_ACCOUNT_ID = accountId;
188
+ log("Found CLOUDFLARE_ACCOUNT_ID in wrangler cache: %s", accountId);
189
+ console.log(`✅ Setting CLOUDFLARE_ACCOUNT_ID to ${accountId} (from wrangler cache)`);
190
+ return;
191
+ }
192
+ }
193
+ catch (parseError) {
194
+ log("Failed to parse wrangler account cache: %O", parseError);
195
+ // Continue to other methods if cache parsing fails
196
+ }
197
+ }
198
+ else {
199
+ log("Wrangler account cache not found at: %s", accountCachePath);
200
+ }
201
+ // If we get here, we couldn't find the account ID in the cache
202
+ // Give clear guidance to the user
203
+ console.log("⚠️ Could not find Cloudflare account ID");
204
+ console.log("Please either:");
205
+ console.log(" 1. Run 'npx wrangler login' to authenticate with Cloudflare");
206
+ console.log(" 2. Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN environment variables");
207
+ // Try wrangler whoami as a final attempt
208
+ console.log("\nAttempting to get account info from wrangler...");
209
+ const result = await $({
210
+ cwd: projectDir,
211
+ stdio: "pipe",
212
+ }) `npx wrangler whoami`;
213
+ // First try regex pattern matching on the text output
214
+ if (result.stdout) {
215
+ const accountIdMatch = result.stdout.match(/Account ID: ([a-f0-9]{32})/);
216
+ if (accountIdMatch && accountIdMatch[1]) {
217
+ const accountId = accountIdMatch[1];
218
+ process.env.CLOUDFLARE_ACCOUNT_ID = accountId;
219
+ log("Extracted CLOUDFLARE_ACCOUNT_ID from whoami text: %s", accountId);
220
+ console.log(`✅ Setting CLOUDFLARE_ACCOUNT_ID to ${accountId} (from wrangler whoami)`);
221
+ return;
222
+ }
223
+ }
224
+ // Fallback: try to extract any JSON that might be in the output
225
+ const accountInfo = extractLastJson(result.stdout);
226
+ if (accountInfo && accountInfo.account && accountInfo.account.id) {
227
+ const accountId = accountInfo.account.id;
228
+ process.env.CLOUDFLARE_ACCOUNT_ID = accountId;
229
+ log("Extracted CLOUDFLARE_ACCOUNT_ID from whoami JSON: %s", accountId);
230
+ console.log(`✅ Setting CLOUDFLARE_ACCOUNT_ID to ${accountId} (from wrangler whoami)`);
231
+ return;
232
+ }
233
+ // If we get here, we've exhausted all options
234
+ throw new Error("Could not find Cloudflare account ID. Please login with 'npx wrangler login' or set CLOUDFLARE_ACCOUNT_ID manually.");
235
+ }
236
+ catch (error) {
237
+ log("Error during account ID detection: %O", error);
238
+ throw error;
239
+ }
240
+ }
241
+ /**
242
+ * Run the release command to deploy to Cloudflare
243
+ */
244
+ export async function runRelease(cwd, projectDir, resourceUniqueKey) {
245
+ log("Running release command");
246
+ console.log("\n🚀 Deploying worker to Cloudflare...");
247
+ try {
248
+ // Make sure we have an account ID
249
+ await ensureCloudflareAccountId(cwd, projectDir);
250
+ // Extract worker name from directory name to ensure consistency
251
+ const dirName = cwd ? basename(cwd) : "unknown-worker";
252
+ // Ensure resource unique key is included in worker name for tracking
253
+ if (resourceUniqueKey && !dirName.includes(resourceUniqueKey)) {
254
+ log(`Worker name doesn't contain our unique key, this is unexpected: ${dirName}, key: ${resourceUniqueKey}`);
255
+ console.log(`⚠️ Worker name doesn't contain our unique key. This might cause cleanup issues.`);
256
+ }
257
+ // Ensure the worker name in wrangler.jsonc matches our unique name
258
+ if (cwd) {
259
+ try {
260
+ const wranglerPath = join(cwd, "wrangler.jsonc");
261
+ if (await pathExists(wranglerPath)) {
262
+ log("Updating wrangler.jsonc to use our unique worker name: %s", dirName);
263
+ // Read the wrangler config - handle both jsonc and json formats
264
+ const wranglerContent = await fs.readFile(wranglerPath, "utf-8");
265
+ // Use parseJsonc which handles comments and is more tolerant
266
+ let wranglerConfig;
267
+ try {
268
+ wranglerConfig = parseJsonc(wranglerContent);
269
+ }
270
+ catch (parseError) {
271
+ // Fallback to standard JSON if jsonc parsing fails
272
+ log("JSONC parsing failed, trying standard JSON: %O", parseError);
273
+ wranglerConfig = JSON.parse(wranglerContent);
274
+ }
275
+ // Update the name
276
+ if (wranglerConfig.name !== dirName) {
277
+ wranglerConfig.name = dirName;
278
+ await fs.writeFile(wranglerPath, JSON.stringify(wranglerConfig, null, 2));
279
+ log("Updated wrangler.jsonc with unique worker name: %s", dirName);
280
+ }
281
+ }
282
+ }
283
+ catch (error) {
284
+ log("Error updating wrangler.jsonc: %O", error);
285
+ console.error(`Warning: Could not update wrangler.jsonc: ${error}`);
286
+ }
287
+ }
288
+ // Run release command with our interactive $expect utility
289
+ log("Running release command with interactive prompts");
290
+ const result = await $expect("npm run release", [
291
+ {
292
+ // Make the pattern more flexible to account for potential whitespace differences
293
+ expect: /Do you want to proceed with deployment\?\s*\(y\/N\)/i,
294
+ send: "y\r",
295
+ },
296
+ ], {
297
+ reject: false, // Add reject: false to prevent uncaught promise rejections
298
+ env: {
299
+ RWSDK_RENAME_WORKER: "1",
300
+ RWSDK_RENAME_DB: "1",
301
+ ...process.env,
302
+ },
303
+ cwd,
304
+ });
305
+ // Check exit code to ensure command succeeded
306
+ if (result.code !== 0) {
307
+ // Add more contextual information about the error
308
+ let errorMessage = `Release command failed with exit code ${result.code}`;
309
+ // Add stderr output to the error message if available
310
+ if (result.stderr && result.stderr.trim().length > 0) {
311
+ // Extract the most relevant part of the error message
312
+ const errorLines = result.stderr
313
+ .split("\n")
314
+ .filter((line) => line.includes("ERROR") ||
315
+ line.includes("error:") ||
316
+ line.includes("failed"))
317
+ .slice(0, 3) // Take just the first few error lines
318
+ .join("\n");
319
+ if (errorLines) {
320
+ errorMessage += `\nError details: ${errorLines}`;
321
+ }
322
+ }
323
+ log("ERROR: %s", errorMessage);
324
+ throw new Error(errorMessage);
325
+ }
326
+ const stdout = result.stdout;
327
+ // Extract deployment URL from output
328
+ log("Extracting deployment URL from output");
329
+ const urlMatch = stdout.match(/https:\/\/([a-zA-Z0-9-]+)\.redwoodjs\.workers\.dev/);
330
+ if (!urlMatch || !urlMatch[0]) {
331
+ log("ERROR: Could not extract deployment URL from release output");
332
+ // Log more details about the output for debugging
333
+ log("Release command stdout: %s", stdout);
334
+ if (result.stderr) {
335
+ log("Release command stderr: %s", result.stderr);
336
+ }
337
+ throw new Error("Could not extract deployment URL from release output");
338
+ }
339
+ const url = urlMatch[0];
340
+ const workerName = urlMatch[1];
341
+ log("Successfully deployed to %s (worker: %s)", url, workerName);
342
+ console.log(`✅ Successfully deployed to ${url}`);
343
+ return { url, workerName };
344
+ }
345
+ catch (error) {
346
+ log("ERROR: Failed to run release command: %O", error);
347
+ throw error;
348
+ }
349
+ }
350
+ /**
351
+ * Runs tests against the production deployment
352
+ */
353
+ export async function runReleaseTest(customPath = "/", artifactDir, resources, browserPath, headless = true, bail = false, skipClient = false, projectDir, realtime = false, skipHmr = false) {
354
+ log("Starting release test with path: %s", customPath || "/");
355
+ console.log("\n🚀 Testing production deployment");
356
+ try {
357
+ log("Running release process");
358
+ const { url, workerName } = await runRelease(resources.targetDir || "", projectDir || "", resources.resourceUniqueKey);
359
+ // Wait a moment before checking server availability
360
+ log("Waiting 1s before checking server...");
361
+ await setTimeout(1000);
362
+ // DRY: check both root and custom path
363
+ await checkServerUp(url, customPath);
364
+ // Now run the tests with the custom path
365
+ const testUrl = url +
366
+ (customPath === "/"
367
+ ? ""
368
+ : customPath.startsWith("/")
369
+ ? customPath
370
+ : "/" + customPath);
371
+ await checkUrl(testUrl, artifactDir, browserPath, headless, bail, skipClient, "Production", realtime, resources.targetDir, // Add target directory parameter
372
+ true);
373
+ log("Release test completed successfully");
374
+ // Store the worker name if we didn't set it earlier
375
+ if (resources && !resources.workerName) {
376
+ log("Storing worker name: %s", workerName);
377
+ resources.workerName = workerName;
378
+ }
379
+ // Mark that we created this worker during the test
380
+ if (resources) {
381
+ log("Marking worker %s as created during this test", workerName);
382
+ resources.workerCreatedDuringTest = true;
383
+ // Update the global state
384
+ if (resources.workerCreatedDuringTest !== undefined) {
385
+ resources.workerCreatedDuringTest = true;
386
+ }
387
+ }
388
+ }
389
+ catch (error) {
390
+ log("Error during release testing: %O", error);
391
+ throw error;
392
+ }
393
+ }
394
+ /**
395
+ * Check if a resource name includes a specific resource unique key
396
+ * This is used to identify resources created during our tests
397
+ */
398
+ export function isRelatedToTest(resourceName, resourceUniqueKey) {
399
+ return resourceName.includes(resourceUniqueKey);
400
+ }
401
+ /**
402
+ * Delete the worker using wrangler
403
+ */
404
+ export async function deleteWorker(name, cwd, resourceUniqueKey) {
405
+ console.log(`Cleaning up: Deleting worker ${name}...`);
406
+ // Safety check: if we have a resourceUniqueKey, verify this worker name contains it
407
+ if (resourceUniqueKey && !isRelatedToTest(name, resourceUniqueKey)) {
408
+ log(`Worker ${name} does not contain unique key ${resourceUniqueKey}, not deleting for safety`);
409
+ console.log(`⚠️ Worker ${name} does not seem to be created by this test, skipping deletion for safety`);
410
+ return;
411
+ }
412
+ try {
413
+ // Use our $expect utility to handle any confirmation prompts
414
+ log("Running wrangler delete command with interactive prompts");
415
+ await $expect(`npx wrangler delete ${name}`, [
416
+ {
417
+ expect: "Are you sure you want to delete",
418
+ send: "y\r",
419
+ },
420
+ ], {
421
+ cwd,
422
+ });
423
+ console.log(`✅ Worker ${name} deleted successfully`);
424
+ }
425
+ catch (error) {
426
+ console.error(`Failed to delete worker ${name}: ${error}`);
427
+ // Retry with force flag if the first attempt failed
428
+ try {
429
+ console.log("Retrying with force flag...");
430
+ await $expect(`npx wrangler delete ${name} --yes --force`, [
431
+ {
432
+ expect: "Are you sure you want to delete",
433
+ send: "y\r",
434
+ },
435
+ ], {
436
+ cwd,
437
+ });
438
+ console.log(`✅ Worker ${name} force deleted successfully`);
439
+ }
440
+ catch (retryError) {
441
+ console.error(`Failed to force delete worker ${name}: ${retryError}`);
442
+ }
443
+ }
444
+ }
445
+ /**
446
+ * List D1 databases using wrangler
447
+ */
448
+ export async function listD1Databases(cwd) {
449
+ log("Listing D1 databases");
450
+ try {
451
+ const result = await $({
452
+ cwd,
453
+ stdio: "pipe",
454
+ }) `npx wrangler d1 list --json`;
455
+ // Parse the JSON output to extract the last valid JSON
456
+ const data = parseJson(result.stdout, []);
457
+ if (Array.isArray(data)) {
458
+ log("Found %d D1 databases in parsed array", data.length);
459
+ return data;
460
+ }
461
+ else if (data.databases && Array.isArray(data.databases)) {
462
+ log("Found %d D1 databases in 'databases' property", data.databases.length);
463
+ return data.databases;
464
+ }
465
+ // If nothing worked, return an empty array
466
+ log("Could not parse JSON from output, returning empty array");
467
+ return [];
468
+ }
469
+ catch (error) {
470
+ log("Error listing D1 databases: %O", error);
471
+ console.error(`Failed to list D1 databases: ${error}`);
472
+ return [];
473
+ }
474
+ }
475
+ /**
476
+ * Delete a D1 database using wrangler
477
+ */
478
+ export async function deleteD1Database(name, cwd, resourceUniqueKey) {
479
+ console.log(`Cleaning up: Deleting D1 database ${name}...`);
480
+ try {
481
+ // First check if the database exists
482
+ const databases = await listD1Databases(cwd);
483
+ const exists = databases.some((db) => db.name === name);
484
+ if (!exists) {
485
+ log(`D1 database ${name} not found, skipping deletion`);
486
+ console.log(`⚠️ D1 database ${name} not found, skipping deletion`);
487
+ return;
488
+ }
489
+ // Extra safety check: if we have a resourceUniqueKey, verify this database is related to our test
490
+ if (resourceUniqueKey && !isRelatedToTest(name, resourceUniqueKey)) {
491
+ log(`D1 database ${name} does not contain unique key ${resourceUniqueKey}, not deleting for safety`);
492
+ console.log(`⚠️ D1 database ${name} does not seem to be created by this test, skipping deletion for safety`);
493
+ return;
494
+ }
495
+ // Use our $expect utility to handle any confirmation prompts
496
+ log("Running wrangler d1 delete command with interactive prompts");
497
+ await $expect(`npx wrangler d1 delete ${name}`, [
498
+ {
499
+ expect: "Are you sure you want to delete",
500
+ send: "y\r",
501
+ },
502
+ ], {
503
+ cwd,
504
+ });
505
+ console.log(`✅ D1 database ${name} deleted successfully`);
506
+ }
507
+ catch (error) {
508
+ console.error(`Failed to delete D1 database ${name}: ${error}`);
509
+ // Retry with force flag if the first attempt failed
510
+ try {
511
+ console.log("Retrying with force flag...");
512
+ await $expect(`npx wrangler d1 delete ${name} --yes --force`, [
513
+ {
514
+ expect: "Are you sure you want to delete",
515
+ send: "y\r",
516
+ },
517
+ ], {
518
+ cwd,
519
+ });
520
+ console.log(`✅ D1 database ${name} force deleted successfully`);
521
+ }
522
+ catch (retryError) {
523
+ console.error(`Failed to force delete D1 database ${name}: ${retryError}`);
524
+ }
525
+ }
526
+ }
@@ -0,0 +1,13 @@
1
+ import { SmokeTestResult } from "./types.mjs";
2
+ /**
3
+ * Generates the final test report without doing any resource cleanup.
4
+ */
5
+ export declare function generateFinalReport(): Promise<void>;
6
+ /**
7
+ * Updates the test status in the state object and reports the result.
8
+ */
9
+ export declare function reportSmokeTestResult(result: SmokeTestResult, type: string, phase?: string, environment?: string): void;
10
+ /**
11
+ * Initialize test statuses based on test options
12
+ */
13
+ export declare function initializeTestStatus(): void;