devflare 1.0.0-next.4 → 1.0.0-next.41

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 (577) hide show
  1. package/LICENSE +21 -0
  2. package/LLM.md +15966 -2139
  3. package/README.md +393 -605
  4. package/bin/devflare.js +22 -14
  5. package/dist/_chunks/account-BtWcv3X9.js +462 -0
  6. package/dist/_chunks/account-resources-CsmVowJp.js +159 -0
  7. package/dist/_chunks/ai-CBEuLdoP.js +322 -0
  8. package/dist/_chunks/api-TzdliH-6.js +568 -0
  9. package/dist/_chunks/build-C0pZGUL7.js +24 -0
  10. package/dist/_chunks/build-artifacts-CGdnp2BT.js +483 -0
  11. package/dist/_chunks/cli-DPeh2U50.js +1128 -0
  12. package/dist/_chunks/cloudflare-BaloqI3H.js +157 -0
  13. package/dist/_chunks/colors-DiK6wPJ5.js +13 -0
  14. package/dist/_chunks/command-utils-BsfkmTqh.js +45 -0
  15. package/dist/_chunks/compiler-uoyAQ8zW.js +424 -0
  16. package/dist/_chunks/config-D5u-bEkn.js +78 -0
  17. package/dist/_chunks/config-path-DCPto4XB.js +42 -0
  18. package/dist/_chunks/context-CX50Y2Kb.js +2250 -0
  19. package/dist/_chunks/decorators-QmV57ixr.js +19 -0
  20. package/dist/_chunks/dependencies-C2oxFjU_.js +57 -0
  21. package/dist/_chunks/deploy-C2siy20T.js +915 -0
  22. package/dist/_chunks/dev-CvRHmRFZ.js +3456 -0
  23. package/dist/_chunks/doctor-C0g8X36G.js +219 -0
  24. package/dist/_chunks/durable-object-DMtH0XYX.js +234 -0
  25. package/dist/_chunks/env-S0_nMVz1.js +125 -0
  26. package/dist/_chunks/family-DXC5SdFK.js +143 -0
  27. package/dist/_chunks/generated-artifacts-dMJY4KAt.js +32 -0
  28. package/dist/_chunks/glob-CmQOvunB.js +56 -0
  29. package/dist/_chunks/init-DnkJOmpW.js +165 -0
  30. package/dist/_chunks/loader-DLXO60RO.js +1153 -0
  31. package/dist/_chunks/local-dev-vars-CTSa-wvF.js +81 -0
  32. package/dist/_chunks/local-hyperdrive-CJ90j46O.js +119 -0
  33. package/dist/_chunks/local-media-bindings-DsAW4AMF.js +335 -0
  34. package/dist/_chunks/local-secrets-DMmEOygL.js +123 -0
  35. package/dist/_chunks/local-workflow-entrypoints-Wip3o1u8.js +90 -0
  36. package/dist/_chunks/login-BmnDzDlH.js +51 -0
  37. package/dist/_chunks/package-metadata-DjHBLB-z.js +39 -0
  38. package/dist/_chunks/preferences-BKp_7XJx.js +241 -0
  39. package/dist/_chunks/preview-BhqDmq8I.js +456 -0
  40. package/dist/_chunks/preview-registry-ClAbLTHH.js +1186 -0
  41. package/dist/_chunks/preview-resources-DdXj8LMM.js +358 -0
  42. package/dist/_chunks/previews-Dlr13x5M.js +1134 -0
  43. package/dist/_chunks/productions-D3AnOHac.js +411 -0
  44. package/dist/_chunks/ref-CYJNAAe_.js +178 -0
  45. package/dist/_chunks/remote-CZnP-HLJ.js +79 -0
  46. package/dist/_chunks/remote-config-D39BY9ji.js +132 -0
  47. package/dist/_chunks/resolve-package-Y84HB3Nt.js +133 -0
  48. package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
  49. package/dist/_chunks/routes-C3FqES2W.js +796 -0
  50. package/dist/_chunks/runtime-FvXvfuZ2.js +550 -0
  51. package/dist/_chunks/schema-normalization-DWVleVxo.js +477 -0
  52. package/dist/_chunks/secrets-70eN0Q6C.js +95 -0
  53. package/dist/_chunks/token-kguIDmej.js +333 -0
  54. package/dist/_chunks/tokens-iVcgNXi-.js +221 -0
  55. package/dist/_chunks/types-OrLbzv4I.js +476 -0
  56. package/dist/_chunks/ui-BUoZApvE.js +103 -0
  57. package/dist/_chunks/usage-BBTGzjon.js +272 -0
  58. package/dist/_chunks/vite-CsI0E-uV.js +1235 -0
  59. package/dist/_chunks/vite-utils-OVLMV605.js +183 -0
  60. package/dist/_chunks/worker-CS1jgNFE.js +410 -0
  61. package/dist/_chunks/worker-bundler-dTTnYU3n.js +458 -0
  62. package/dist/_chunks/worker-entrypoint-CQW77lG8.js +247 -0
  63. package/dist/_chunks/workerName-CFJsLZA-.js +23 -0
  64. package/dist/bridge/client.d.ts +49 -7
  65. package/dist/bridge/client.d.ts.map +1 -1
  66. package/dist/bridge/gateway-runtime.d.ts +8 -0
  67. package/dist/bridge/gateway-runtime.d.ts.map +1 -0
  68. package/dist/bridge/index.d.ts +6 -6
  69. package/dist/bridge/index.d.ts.map +1 -1
  70. package/dist/bridge/log.d.ts +5 -0
  71. package/dist/bridge/log.d.ts.map +1 -0
  72. package/dist/bridge/miniflare.d.ts +75 -2
  73. package/dist/bridge/miniflare.d.ts.map +1 -1
  74. package/dist/bridge/proxy.d.ts +12 -11
  75. package/dist/bridge/proxy.d.ts.map +1 -1
  76. package/dist/bridge/server.d.ts +2 -1
  77. package/dist/bridge/server.d.ts.map +1 -1
  78. package/dist/bridge/v2/body-streams.d.ts +53 -0
  79. package/dist/bridge/v2/body-streams.d.ts.map +1 -0
  80. package/dist/bridge/v2/codec.d.ts +106 -0
  81. package/dist/bridge/v2/codec.d.ts.map +1 -0
  82. package/dist/bridge/v2/control-messages.d.ts +46 -0
  83. package/dist/bridge/v2/control-messages.d.ts.map +1 -0
  84. package/dist/bridge/v2/frames.d.ts +109 -0
  85. package/dist/bridge/v2/frames.d.ts.map +1 -0
  86. package/dist/bridge/v2/index.d.ts +11 -0
  87. package/dist/bridge/v2/index.d.ts.map +1 -0
  88. package/dist/bridge/v2/serialization.d.ts +48 -0
  89. package/dist/bridge/v2/serialization.d.ts.map +1 -0
  90. package/dist/bridge/v2/transport.d.ts +31 -0
  91. package/dist/bridge/v2/transport.d.ts.map +1 -0
  92. package/dist/bridge/v2/value-codec.d.ts +61 -0
  93. package/dist/bridge/v2/value-codec.d.ts.map +1 -0
  94. package/dist/bridge/{serialization.d.ts → v2/value-serialization.d.ts} +40 -18
  95. package/dist/bridge/v2/value-serialization.d.ts.map +1 -0
  96. package/dist/bridge/{protocol.d.ts → v2/wire.d.ts} +32 -8
  97. package/dist/bridge/v2/wire.d.ts.map +1 -0
  98. package/dist/bridge/v2/ws-relay.d.ts +53 -0
  99. package/dist/bridge/v2/ws-relay.d.ts.map +1 -0
  100. package/dist/browser-shim/handler.d.ts +2 -2
  101. package/dist/browser-shim/handler.d.ts.map +1 -1
  102. package/dist/browser-shim/index.d.ts +2 -2
  103. package/dist/browser-shim/server.d.ts +63 -0
  104. package/dist/browser-shim/server.d.ts.map +1 -1
  105. package/dist/browser.d.ts +4621 -0
  106. package/dist/browser.d.ts.map +1 -0
  107. package/dist/browser.js +80 -0
  108. package/dist/bundler/defaults.d.ts +23 -0
  109. package/dist/bundler/defaults.d.ts.map +1 -0
  110. package/dist/bundler/do-bundler.d.ts +7 -0
  111. package/dist/bundler/do-bundler.d.ts.map +1 -1
  112. package/dist/bundler/index.d.ts +3 -1
  113. package/dist/bundler/index.d.ts.map +1 -1
  114. package/dist/bundler/rolldown-shared.d.ts +53 -0
  115. package/dist/bundler/rolldown-shared.d.ts.map +1 -0
  116. package/dist/bundler/worker-bundler.d.ts +13 -0
  117. package/dist/bundler/worker-bundler.d.ts.map +1 -0
  118. package/dist/bundler/worker-compat.d.ts +4 -0
  119. package/dist/bundler/worker-compat.d.ts.map +1 -0
  120. package/dist/cli/build-manifest.d.ts +66 -0
  121. package/dist/cli/build-manifest.d.ts.map +1 -0
  122. package/dist/cli/command-utils.d.ts +18 -0
  123. package/dist/cli/command-utils.d.ts.map +1 -0
  124. package/dist/cli/commands/account.d.ts +2 -2
  125. package/dist/cli/commands/account.d.ts.map +1 -1
  126. package/dist/cli/commands/ai.d.ts +1 -1
  127. package/dist/cli/commands/ai.d.ts.map +1 -1
  128. package/dist/cli/commands/build-artifacts.d.ts +40 -0
  129. package/dist/cli/commands/build-artifacts.d.ts.map +1 -0
  130. package/dist/cli/commands/build.d.ts +2 -2
  131. package/dist/cli/commands/build.d.ts.map +1 -1
  132. package/dist/cli/commands/config.d.ts +4 -0
  133. package/dist/cli/commands/config.d.ts.map +1 -0
  134. package/dist/cli/commands/deploy/metadata.d.ts +18 -0
  135. package/dist/cli/commands/deploy/metadata.d.ts.map +1 -0
  136. package/dist/cli/commands/deploy/prepare.d.ts +23 -0
  137. package/dist/cli/commands/deploy/prepare.d.ts.map +1 -0
  138. package/dist/cli/commands/deploy/runtime.d.ts +4 -0
  139. package/dist/cli/commands/deploy/runtime.d.ts.map +1 -0
  140. package/dist/cli/commands/deploy/verification.d.ts +36 -0
  141. package/dist/cli/commands/deploy/verification.d.ts.map +1 -0
  142. package/dist/cli/commands/deploy.d.ts +2 -2
  143. package/dist/cli/commands/deploy.d.ts.map +1 -1
  144. package/dist/cli/commands/dev.d.ts +9 -1
  145. package/dist/cli/commands/dev.d.ts.map +1 -1
  146. package/dist/cli/commands/doctor.d.ts +2 -2
  147. package/dist/cli/commands/doctor.d.ts.map +1 -1
  148. package/dist/cli/commands/init.d.ts +2 -2
  149. package/dist/cli/commands/init.d.ts.map +1 -1
  150. package/dist/cli/commands/login.d.ts +4 -0
  151. package/dist/cli/commands/login.d.ts.map +1 -0
  152. package/dist/cli/commands/previews-support/cleanup.d.ts +9 -0
  153. package/dist/cli/commands/previews-support/cleanup.d.ts.map +1 -0
  154. package/dist/cli/commands/previews-support/family.d.ts +10 -0
  155. package/dist/cli/commands/previews-support/family.d.ts.map +1 -0
  156. package/dist/cli/commands/previews-support/render.d.ts +8 -0
  157. package/dist/cli/commands/previews-support/render.d.ts.map +1 -0
  158. package/dist/cli/commands/previews-support/theme.d.ts +10 -0
  159. package/dist/cli/commands/previews-support/theme.d.ts.map +1 -0
  160. package/dist/cli/commands/previews-support/types.d.ts +70 -0
  161. package/dist/cli/commands/previews-support/types.d.ts.map +1 -0
  162. package/dist/cli/commands/previews.d.ts +4 -0
  163. package/dist/cli/commands/previews.d.ts.map +1 -0
  164. package/dist/cli/commands/productions.d.ts +4 -0
  165. package/dist/cli/commands/productions.d.ts.map +1 -0
  166. package/dist/cli/commands/remote.d.ts +1 -1
  167. package/dist/cli/commands/remote.d.ts.map +1 -1
  168. package/dist/cli/commands/secrets.d.ts +4 -0
  169. package/dist/cli/commands/secrets.d.ts.map +1 -0
  170. package/dist/cli/commands/token.d.ts +4 -0
  171. package/dist/cli/commands/token.d.ts.map +1 -0
  172. package/dist/cli/commands/type-generation/discovery.d.ts +7 -0
  173. package/dist/cli/commands/type-generation/discovery.d.ts.map +1 -0
  174. package/dist/cli/commands/type-generation/generator.d.ts +112 -0
  175. package/dist/cli/commands/type-generation/generator.d.ts.map +1 -0
  176. package/dist/cli/commands/type-generation/models.d.ts +27 -0
  177. package/dist/cli/commands/type-generation/models.d.ts.map +1 -0
  178. package/dist/cli/commands/types.d.ts +2 -2
  179. package/dist/cli/commands/types.d.ts.map +1 -1
  180. package/dist/cli/commands/worker.d.ts +4 -0
  181. package/dist/cli/commands/worker.d.ts.map +1 -0
  182. package/dist/cli/config-path.d.ts +6 -0
  183. package/dist/cli/config-path.d.ts.map +1 -0
  184. package/dist/cli/dependencies.d.ts +2 -1
  185. package/dist/cli/dependencies.d.ts.map +1 -1
  186. package/dist/cli/deploy-strategy.d.ts +17 -0
  187. package/dist/cli/deploy-strategy.d.ts.map +1 -0
  188. package/dist/cli/deploy-target.d.ts +17 -0
  189. package/dist/cli/deploy-target.d.ts.map +1 -0
  190. package/dist/cli/generated-artifacts.d.ts +12 -0
  191. package/dist/cli/generated-artifacts.d.ts.map +1 -0
  192. package/dist/cli/help-pages/pages/account.d.ts +3 -0
  193. package/dist/cli/help-pages/pages/account.d.ts.map +1 -0
  194. package/dist/cli/help-pages/pages/core.d.ts +4 -0
  195. package/dist/cli/help-pages/pages/core.d.ts.map +1 -0
  196. package/dist/cli/help-pages/pages/index.d.ts +3 -0
  197. package/dist/cli/help-pages/pages/index.d.ts.map +1 -0
  198. package/dist/cli/help-pages/pages/misc.d.ts +3 -0
  199. package/dist/cli/help-pages/pages/misc.d.ts.map +1 -0
  200. package/dist/cli/help-pages/pages/previews.d.ts +3 -0
  201. package/dist/cli/help-pages/pages/previews.d.ts.map +1 -0
  202. package/dist/cli/help-pages/pages/productions.d.ts +3 -0
  203. package/dist/cli/help-pages/pages/productions.d.ts.map +1 -0
  204. package/dist/cli/help-pages/render.d.ts +12 -0
  205. package/dist/cli/help-pages/render.d.ts.map +1 -0
  206. package/dist/cli/help-pages/shared.d.ts +15 -0
  207. package/dist/cli/help-pages/shared.d.ts.map +1 -0
  208. package/dist/cli/help-pages/types.d.ts +23 -0
  209. package/dist/cli/help-pages/types.d.ts.map +1 -0
  210. package/dist/cli/help.d.ts +6 -0
  211. package/dist/cli/help.d.ts.map +1 -0
  212. package/dist/cli/index.d.ts +1 -0
  213. package/dist/cli/index.d.ts.map +1 -1
  214. package/dist/cli/index.js +2 -0
  215. package/dist/cli/package-metadata.d.ts +16 -0
  216. package/dist/cli/package-metadata.d.ts.map +1 -0
  217. package/dist/cli/preview-bindings.d.ts +49 -0
  218. package/dist/cli/preview-bindings.d.ts.map +1 -0
  219. package/dist/cli/preview.d.ts +10 -0
  220. package/dist/cli/preview.d.ts.map +1 -0
  221. package/dist/cli/ui.d.ts +37 -0
  222. package/dist/cli/ui.d.ts.map +1 -0
  223. package/dist/cli/workspace-build-guard.d.ts +14 -0
  224. package/dist/cli/workspace-build-guard.d.ts.map +1 -0
  225. package/dist/cli/wrangler-auth.d.ts +1 -1
  226. package/dist/cloudflare/account-core.d.ts +6 -0
  227. package/dist/cloudflare/account-core.d.ts.map +1 -0
  228. package/dist/cloudflare/account-resources.d.ts +40 -0
  229. package/dist/cloudflare/account-resources.d.ts.map +1 -0
  230. package/dist/cloudflare/account-status.d.ts +11 -0
  231. package/dist/cloudflare/account-status.d.ts.map +1 -0
  232. package/dist/cloudflare/account-workers.d.ts +14 -0
  233. package/dist/cloudflare/account-workers.d.ts.map +1 -0
  234. package/dist/cloudflare/account.d.ts +7 -64
  235. package/dist/cloudflare/account.d.ts.map +1 -1
  236. package/dist/cloudflare/api.d.ts +71 -3
  237. package/dist/cloudflare/api.d.ts.map +1 -1
  238. package/dist/cloudflare/auth.d.ts +1 -1
  239. package/dist/cloudflare/auth.d.ts.map +1 -1
  240. package/dist/cloudflare/index.d.ts +61 -6
  241. package/dist/cloudflare/index.d.ts.map +1 -1
  242. package/dist/cloudflare/index.js +4 -13
  243. package/dist/cloudflare/known-permission-group-ids.generated.d.ts +10 -0
  244. package/dist/cloudflare/known-permission-group-ids.generated.d.ts.map +1 -0
  245. package/dist/cloudflare/kv-namespace.d.ts +4 -0
  246. package/dist/cloudflare/kv-namespace.d.ts.map +1 -0
  247. package/dist/cloudflare/preferences.d.ts +7 -0
  248. package/dist/cloudflare/preferences.d.ts.map +1 -1
  249. package/dist/cloudflare/preview-registry-cache.d.ts +6 -0
  250. package/dist/cloudflare/preview-registry-cache.d.ts.map +1 -0
  251. package/dist/cloudflare/preview-registry-inference.d.ts +14 -0
  252. package/dist/cloudflare/preview-registry-inference.d.ts.map +1 -0
  253. package/dist/cloudflare/preview-registry-records.d.ts +4 -0
  254. package/dist/cloudflare/preview-registry-records.d.ts.map +1 -0
  255. package/dist/cloudflare/preview-registry-shape.d.ts +47 -0
  256. package/dist/cloudflare/preview-registry-shape.d.ts.map +1 -0
  257. package/dist/cloudflare/preview-registry-store.d.ts +14 -0
  258. package/dist/cloudflare/preview-registry-store.d.ts.map +1 -0
  259. package/dist/cloudflare/preview-registry-transport.d.ts +4 -0
  260. package/dist/cloudflare/preview-registry-transport.d.ts.map +1 -0
  261. package/dist/cloudflare/preview-registry-types.d.ts +103 -0
  262. package/dist/cloudflare/preview-registry-types.d.ts.map +1 -0
  263. package/dist/cloudflare/preview-registry.d.ts +42 -0
  264. package/dist/cloudflare/preview-registry.d.ts.map +1 -0
  265. package/dist/cloudflare/preview-urls.d.ts +3 -0
  266. package/dist/cloudflare/preview-urls.d.ts.map +1 -0
  267. package/dist/cloudflare/registry-schema.d.ts +253 -0
  268. package/dist/cloudflare/registry-schema.d.ts.map +1 -0
  269. package/dist/cloudflare/remote-config.d.ts.map +1 -1
  270. package/dist/cloudflare/tokens.d.ts +44 -0
  271. package/dist/cloudflare/tokens.d.ts.map +1 -0
  272. package/dist/cloudflare/types.d.ts +124 -7
  273. package/dist/cloudflare/types.d.ts.map +1 -1
  274. package/dist/cloudflare/usage.d.ts +31 -3
  275. package/dist/cloudflare/usage.d.ts.map +1 -1
  276. package/dist/config/binding-resolution-helpers.d.ts +41 -0
  277. package/dist/config/binding-resolution-helpers.d.ts.map +1 -0
  278. package/dist/config/compatibility.d.ts +3 -0
  279. package/dist/config/compatibility.d.ts.map +1 -0
  280. package/dist/config/compiler/bindings.d.ts +14 -0
  281. package/dist/config/compiler/bindings.d.ts.map +1 -0
  282. package/dist/config/compiler/core-helpers.d.ts +6 -0
  283. package/dist/config/compiler/core-helpers.d.ts.map +1 -0
  284. package/dist/config/compiler/do-workers.d.ts +34 -0
  285. package/dist/config/compiler/do-workers.d.ts.map +1 -0
  286. package/dist/config/compiler/paths.d.ts +18 -0
  287. package/dist/config/compiler/paths.d.ts.map +1 -0
  288. package/dist/config/compiler/types.d.ts +270 -0
  289. package/dist/config/compiler/types.d.ts.map +1 -0
  290. package/dist/config/compiler.d.ts +22 -134
  291. package/dist/config/compiler.d.ts.map +1 -1
  292. package/dist/config/define.d.ts +8 -5
  293. package/dist/config/define.d.ts.map +1 -1
  294. package/dist/config/deploy-resources.d.ts +58 -0
  295. package/dist/config/deploy-resources.d.ts.map +1 -0
  296. package/dist/config/env-vars.d.ts +309 -0
  297. package/dist/config/env-vars.d.ts.map +1 -0
  298. package/dist/config/framework-providers.d.ts +9 -0
  299. package/dist/config/framework-providers.d.ts.map +1 -0
  300. package/dist/config/index.d.ts +12 -5
  301. package/dist/config/index.d.ts.map +1 -1
  302. package/dist/config/loader.d.ts +2 -1
  303. package/dist/config/loader.d.ts.map +1 -1
  304. package/dist/config/local-dev-vars.d.ts +15 -0
  305. package/dist/config/local-dev-vars.d.ts.map +1 -0
  306. package/dist/config/preview-resources.d.ts +83 -0
  307. package/dist/config/preview-resources.d.ts.map +1 -0
  308. package/dist/config/preview.d.ts +29 -0
  309. package/dist/config/preview.d.ts.map +1 -0
  310. package/dist/config/ref.d.ts +16 -25
  311. package/dist/config/ref.d.ts.map +1 -1
  312. package/dist/config/resolve-phased.d.ts +72 -0
  313. package/dist/config/resolve-phased.d.ts.map +1 -0
  314. package/dist/config/resolve.d.ts +11 -0
  315. package/dist/config/resolve.d.ts.map +1 -0
  316. package/dist/config/resource-resolution.d.ts +80 -0
  317. package/dist/config/resource-resolution.d.ts.map +1 -0
  318. package/dist/config/schema-bindings.d.ts +1495 -0
  319. package/dist/config/schema-bindings.d.ts.map +1 -0
  320. package/dist/config/schema-build.d.ts +67 -0
  321. package/dist/config/schema-build.d.ts.map +1 -0
  322. package/dist/config/schema-env.d.ts +3023 -0
  323. package/dist/config/schema-env.d.ts.map +1 -0
  324. package/dist/config/schema-normalization.d.ts +184 -0
  325. package/dist/config/schema-normalization.d.ts.map +1 -0
  326. package/dist/config/schema-runtime.d.ts +500 -0
  327. package/dist/config/schema-runtime.d.ts.map +1 -0
  328. package/dist/config/schema-types-bindings-platform.d.ts +378 -0
  329. package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
  330. package/dist/config/schema-types-bindings-resources.d.ts +550 -0
  331. package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
  332. package/dist/config/schema-types-bindings.d.ts +254 -0
  333. package/dist/config/schema-types-bindings.d.ts.map +1 -0
  334. package/dist/config/schema-types-build.d.ts +86 -0
  335. package/dist/config/schema-types-build.d.ts.map +1 -0
  336. package/dist/config/schema-types-runtime.d.ts +917 -0
  337. package/dist/config/schema-types-runtime.d.ts.map +1 -0
  338. package/dist/config/schema-types.d.ts +424 -0
  339. package/dist/config/schema-types.d.ts.map +1 -0
  340. package/dist/config/schema.d.ts +4537 -2214
  341. package/dist/config/schema.d.ts.map +1 -1
  342. package/dist/config/service-bindings-validation.d.ts +36 -0
  343. package/dist/config/service-bindings-validation.d.ts.map +1 -0
  344. package/dist/config-entry.d.ts +7 -0
  345. package/dist/config-entry.d.ts.map +1 -0
  346. package/dist/config-entry.js +3 -0
  347. package/dist/decorators/durable-object.d.ts.map +1 -1
  348. package/dist/decorators/index.d.ts +2 -2
  349. package/dist/decorators/index.js +2 -9
  350. package/dist/dev-server/d1-migrations.d.ts +36 -0
  351. package/dist/dev-server/d1-migrations.d.ts.map +1 -0
  352. package/dist/dev-server/dev-server-state.d.ts +59 -0
  353. package/dist/dev-server/dev-server-state.d.ts.map +1 -0
  354. package/dist/dev-server/gateway-script.d.ts +21 -0
  355. package/dist/dev-server/gateway-script.d.ts.map +1 -0
  356. package/dist/dev-server/index.d.ts +1 -1
  357. package/dist/dev-server/miniflare-bindings.d.ts +59 -0
  358. package/dist/dev-server/miniflare-bindings.d.ts.map +1 -0
  359. package/dist/dev-server/miniflare-dev-config.d.ts +36 -0
  360. package/dist/dev-server/miniflare-dev-config.d.ts.map +1 -0
  361. package/dist/dev-server/miniflare-log.d.ts +20 -0
  362. package/dist/dev-server/miniflare-log.d.ts.map +1 -0
  363. package/dist/dev-server/miniflare-worker-config.d.ts +74 -0
  364. package/dist/dev-server/miniflare-worker-config.d.ts.map +1 -0
  365. package/dist/dev-server/reload-queue.d.ts +13 -0
  366. package/dist/dev-server/reload-queue.d.ts.map +1 -0
  367. package/dist/dev-server/runtime-stdio.d.ts +8 -0
  368. package/dist/dev-server/runtime-stdio.d.ts.map +1 -0
  369. package/dist/dev-server/server-startup-helpers.d.ts +84 -0
  370. package/dist/dev-server/server-startup-helpers.d.ts.map +1 -0
  371. package/dist/dev-server/server.d.ts +2 -0
  372. package/dist/dev-server/server.d.ts.map +1 -1
  373. package/dist/dev-server/vite-process.d.ts +15 -0
  374. package/dist/dev-server/vite-process.d.ts.map +1 -0
  375. package/dist/dev-server/vite-utils.d.ts +19 -1
  376. package/dist/dev-server/vite-utils.d.ts.map +1 -1
  377. package/dist/dev-server/worker-source-watcher.d.ts +17 -0
  378. package/dist/dev-server/worker-source-watcher.d.ts.map +1 -0
  379. package/dist/dev-server/worker-surface-paths.d.ts +6 -0
  380. package/dist/dev-server/worker-surface-paths.d.ts.map +1 -0
  381. package/dist/env.d.ts +10 -0
  382. package/dist/env.d.ts.map +1 -1
  383. package/dist/index.d.ts +8 -12
  384. package/dist/index.d.ts.map +1 -1
  385. package/dist/index.js +9 -298
  386. package/dist/runtime/context-events.d.ts +13 -0
  387. package/dist/runtime/context-events.d.ts.map +1 -0
  388. package/dist/runtime/context-types.d.ts +82 -0
  389. package/dist/runtime/context-types.d.ts.map +1 -0
  390. package/dist/runtime/context.d.ts +20 -44
  391. package/dist/runtime/context.d.ts.map +1 -1
  392. package/dist/runtime/exports.d.ts +70 -55
  393. package/dist/runtime/exports.d.ts.map +1 -1
  394. package/dist/runtime/index.d.ts +10 -3
  395. package/dist/runtime/index.d.ts.map +1 -1
  396. package/dist/runtime/index.js +5 -111
  397. package/dist/runtime/middleware.d.ts +102 -60
  398. package/dist/runtime/middleware.d.ts.map +1 -1
  399. package/dist/runtime/router/index.d.ts +7 -0
  400. package/dist/runtime/router/index.d.ts.map +1 -0
  401. package/dist/runtime/router/types.d.ts +24 -0
  402. package/dist/runtime/router/types.d.ts.map +1 -0
  403. package/dist/runtime/validation.d.ts +18 -4
  404. package/dist/runtime/validation.d.ts.map +1 -1
  405. package/dist/secrets/local-secrets.d.ts +46 -0
  406. package/dist/secrets/local-secrets.d.ts.map +1 -0
  407. package/dist/shims/local-hyperdrive.d.ts +12 -0
  408. package/dist/shims/local-hyperdrive.d.ts.map +1 -0
  409. package/dist/shims/local-media-bindings.d.ts +19 -0
  410. package/dist/shims/local-media-bindings.d.ts.map +1 -0
  411. package/dist/shims/local-worker-loader.d.ts +3 -0
  412. package/dist/shims/local-worker-loader.d.ts.map +1 -0
  413. package/dist/sveltekit/index.d.ts +1 -1
  414. package/dist/sveltekit/index.d.ts.map +1 -1
  415. package/dist/sveltekit/index.js +313 -167
  416. package/dist/sveltekit/local-bindings.d.ts +4 -0
  417. package/dist/sveltekit/local-bindings.d.ts.map +1 -0
  418. package/dist/sveltekit/platform.d.ts +20 -2
  419. package/dist/sveltekit/platform.d.ts.map +1 -1
  420. package/dist/test/ai-search.d.ts +39 -0
  421. package/dist/test/ai-search.d.ts.map +1 -0
  422. package/dist/test/binding-hints.d.ts +10 -0
  423. package/dist/test/binding-hints.d.ts.map +1 -0
  424. package/dist/test/cf.d.ts +49 -35
  425. package/dist/test/cf.d.ts.map +1 -1
  426. package/dist/test/containers.d.ts +87 -0
  427. package/dist/test/containers.d.ts.map +1 -0
  428. package/dist/test/email.d.ts +16 -7
  429. package/dist/test/email.d.ts.map +1 -1
  430. package/dist/test/index.d.ts +18 -21
  431. package/dist/test/index.d.ts.map +1 -1
  432. package/dist/test/index.js +4495 -70
  433. package/dist/test/offline-bindings.d.ts +81 -0
  434. package/dist/test/offline-bindings.d.ts.map +1 -0
  435. package/dist/test/queue.d.ts.map +1 -1
  436. package/dist/test/remote-ai.d.ts.map +1 -1
  437. package/dist/test/remote-cloudflare.d.ts +13 -0
  438. package/dist/test/remote-cloudflare.d.ts.map +1 -0
  439. package/dist/test/remote-vectorize.d.ts.map +1 -1
  440. package/dist/test/resolve-service-bindings.d.ts +64 -4
  441. package/dist/test/resolve-service-bindings.d.ts.map +1 -1
  442. package/dist/test/scheduled.d.ts.map +1 -1
  443. package/dist/test/should-skip.d.ts +14 -18
  444. package/dist/test/should-skip.d.ts.map +1 -1
  445. package/dist/test/simple-context-bindings.d.ts +13 -0
  446. package/dist/test/simple-context-bindings.d.ts.map +1 -0
  447. package/dist/test/simple-context-durable-objects.d.ts +6 -0
  448. package/dist/test/simple-context-durable-objects.d.ts.map +1 -0
  449. package/dist/test/simple-context-env.d.ts +35 -0
  450. package/dist/test/simple-context-env.d.ts.map +1 -0
  451. package/dist/test/simple-context-gateway-script.d.ts +2 -0
  452. package/dist/test/simple-context-gateway-script.d.ts.map +1 -0
  453. package/dist/test/simple-context-handlers.d.ts +12 -0
  454. package/dist/test/simple-context-handlers.d.ts.map +1 -0
  455. package/dist/test/simple-context-lifecycle.d.ts +32 -0
  456. package/dist/test/simple-context-lifecycle.d.ts.map +1 -0
  457. package/dist/test/simple-context-mfconfig.d.ts +10 -0
  458. package/dist/test/simple-context-mfconfig.d.ts.map +1 -0
  459. package/dist/test/simple-context-multi-worker.d.ts +16 -0
  460. package/dist/test/simple-context-multi-worker.d.ts.map +1 -0
  461. package/dist/test/simple-context-paths.d.ts +40 -0
  462. package/dist/test/simple-context-paths.d.ts.map +1 -0
  463. package/dist/test/simple-context-runtime.d.ts +19 -0
  464. package/dist/test/simple-context-runtime.d.ts.map +1 -0
  465. package/dist/test/simple-context-startup.d.ts +11 -0
  466. package/dist/test/simple-context-startup.d.ts.map +1 -0
  467. package/dist/test/simple-context-transport.d.ts +14 -0
  468. package/dist/test/simple-context-transport.d.ts.map +1 -0
  469. package/dist/test/simple-context.d.ts +8 -27
  470. package/dist/test/simple-context.d.ts.map +1 -1
  471. package/dist/test/tail.d.ts +3 -2
  472. package/dist/test/tail.d.ts.map +1 -1
  473. package/dist/test/utilities/artifacts.d.ts +11 -0
  474. package/dist/test/utilities/artifacts.d.ts.map +1 -0
  475. package/dist/test/utilities/context.d.ts +39 -0
  476. package/dist/test/utilities/context.d.ts.map +1 -0
  477. package/dist/test/utilities/d1.d.ts +21 -0
  478. package/dist/test/utilities/d1.d.ts.map +1 -0
  479. package/dist/test/utilities/env.d.ts +40 -0
  480. package/dist/test/utilities/env.d.ts.map +1 -0
  481. package/dist/test/utilities/kv.d.ts +11 -0
  482. package/dist/test/utilities/kv.d.ts.map +1 -0
  483. package/dist/test/utilities/media.d.ts +16 -0
  484. package/dist/test/utilities/media.d.ts.map +1 -0
  485. package/dist/test/utilities/platform.d.ts +41 -0
  486. package/dist/test/utilities/platform.d.ts.map +1 -0
  487. package/dist/test/utilities/queue.d.ts +5 -0
  488. package/dist/test/utilities/queue.d.ts.map +1 -0
  489. package/dist/test/utilities/r2.d.ts +2 -0
  490. package/dist/test/utilities/r2.d.ts.map +1 -0
  491. package/dist/test/utilities/workflows.d.ts +26 -0
  492. package/dist/test/utilities/workflows.d.ts.map +1 -0
  493. package/dist/test/utilities.d.ts +10 -98
  494. package/dist/test/utilities.d.ts.map +1 -1
  495. package/dist/test/worker.d.ts +6 -0
  496. package/dist/test/worker.d.ts.map +1 -1
  497. package/dist/transform/durable-object.d.ts.map +1 -1
  498. package/dist/transform/index.d.ts +2 -2
  499. package/dist/transform/worker-entrypoint.d.ts +5 -0
  500. package/dist/transform/worker-entrypoint.d.ts.map +1 -1
  501. package/dist/utils/entrypoint-discovery.d.ts +6 -3
  502. package/dist/utils/entrypoint-discovery.d.ts.map +1 -1
  503. package/dist/utils/glob.d.ts.map +1 -1
  504. package/dist/utils/resolve-package.d.ts.map +1 -1
  505. package/dist/utils/send-email.d.ts +15 -0
  506. package/dist/utils/send-email.d.ts.map +1 -0
  507. package/dist/utils/send-email.js +163 -0
  508. package/dist/vite/config-file.d.ts +25 -0
  509. package/dist/vite/config-file.d.ts.map +1 -0
  510. package/dist/vite/index.d.ts +3 -2
  511. package/dist/vite/index.d.ts.map +1 -1
  512. package/dist/vite/index.js +2 -339
  513. package/dist/vite/plugin-config-hook.d.ts +28 -0
  514. package/dist/vite/plugin-config-hook.d.ts.map +1 -0
  515. package/dist/vite/plugin-context.d.ts +27 -0
  516. package/dist/vite/plugin-context.d.ts.map +1 -0
  517. package/dist/vite/plugin-durable-objects.d.ts +18 -0
  518. package/dist/vite/plugin-durable-objects.d.ts.map +1 -0
  519. package/dist/vite/plugin-programmatic.d.ts +44 -0
  520. package/dist/vite/plugin-programmatic.d.ts.map +1 -0
  521. package/dist/vite/plugin-service-bindings.d.ts +13 -0
  522. package/dist/vite/plugin-service-bindings.d.ts.map +1 -0
  523. package/dist/vite/plugin-transform.d.ts +41 -0
  524. package/dist/vite/plugin-transform.d.ts.map +1 -0
  525. package/dist/vite/plugin.d.ts +10 -41
  526. package/dist/vite/plugin.d.ts.map +1 -1
  527. package/dist/worker-entry/composed-worker.d.ts +7 -0
  528. package/dist/worker-entry/composed-worker.d.ts.map +1 -0
  529. package/dist/worker-entry/durable-object-discovery.d.ts +20 -0
  530. package/dist/worker-entry/durable-object-discovery.d.ts.map +1 -0
  531. package/dist/worker-entry/extensions.d.ts +5 -0
  532. package/dist/worker-entry/extensions.d.ts.map +1 -0
  533. package/dist/worker-entry/routes.d.ts +22 -0
  534. package/dist/worker-entry/routes.d.ts.map +1 -0
  535. package/dist/worker-entry/surface-paths.d.ts +26 -0
  536. package/dist/worker-entry/surface-paths.d.ts.map +1 -0
  537. package/dist/workflows/local-workflow-entrypoints.d.ts +7 -0
  538. package/dist/workflows/local-workflow-entrypoints.d.ts.map +1 -0
  539. package/package.json +159 -116
  540. package/R2.md +0 -170
  541. package/dist/account-rvrj687w.js +0 -397
  542. package/dist/ai-dx4fr9jh.js +0 -107
  543. package/dist/bridge/protocol.d.ts.map +0 -1
  544. package/dist/bridge/serialization.d.ts.map +0 -1
  545. package/dist/browser-shim/worker.d.ts +0 -14
  546. package/dist/browser-shim/worker.d.ts.map +0 -1
  547. package/dist/build-mnf6v8gd.js +0 -53
  548. package/dist/deploy-nhceck39.js +0 -70
  549. package/dist/dev-pa8dhm20.js +0 -2162
  550. package/dist/doctor-fmgb3d28.js +0 -190
  551. package/dist/durable-object-t4kbb0yt.js +0 -13
  552. package/dist/index-07q6yxyc.js +0 -168
  553. package/dist/index-18hvb6gb.js +0 -194
  554. package/dist/index-1xpj0m4r.js +0 -57
  555. package/dist/index-37x76zdn.js +0 -4
  556. package/dist/index-3t6rypgc.js +0 -13
  557. package/dist/index-67qcae0f.js +0 -183
  558. package/dist/index-a855bdsx.js +0 -18
  559. package/dist/index-d8bdkx2h.js +0 -109
  560. package/dist/index-ep3445yc.js +0 -2225
  561. package/dist/index-gz1gndna.js +0 -307
  562. package/dist/index-hcex3rgh.js +0 -266
  563. package/dist/index-m2q41jwa.js +0 -462
  564. package/dist/index-n7rs26ft.js +0 -77
  565. package/dist/index-pf5s73n9.js +0 -1413
  566. package/dist/index-rbht7m9r.js +0 -36
  567. package/dist/index-tfyxa77h.js +0 -850
  568. package/dist/index-tk6ej9dj.js +0 -94
  569. package/dist/index-z14anrqp.js +0 -226
  570. package/dist/init-f9mgmew3.js +0 -186
  571. package/dist/remote-q59qk463.js +0 -97
  572. package/dist/test/bridge-context.d.ts +0 -76
  573. package/dist/test/bridge-context.d.ts.map +0 -1
  574. package/dist/test/multi-worker-context.d.ts +0 -114
  575. package/dist/test/multi-worker-context.d.ts.map +0 -1
  576. package/dist/types-5nyrz1sz.js +0 -454
  577. package/dist/worker-entrypoint-m9th0rg0.js +0 -13
@@ -0,0 +1,1235 @@
1
+ import { d as resolveConfigEnvVars } from "./preview-BhqDmq8I.js";
2
+ import { i as resolveConfigPath, o as loadResolvedConfig, r as loadConfig, s as resolveResources, u as resolveConfigForEnvironment } from "./loader-DLXO60RO.js";
3
+ import { o as normalizeDOBinding } from "./schema-normalization-DWVleVxo.js";
4
+ import { c as writeWranglerConfig, i as isolateViteBuildOutputPaths, n as compileConfig, o as rebaseWranglerConfigPaths, r as compileToProgrammaticConfig, t as compileBuildConfig } from "./compiler-uoyAQ8zW.js";
5
+ import { s as resolveServiceBindings, t as discoverRoutes } from "./routes-C3FqES2W.js";
6
+ import { n as findDurableObjectClasses } from "./durable-object-DMtH0XYX.js";
7
+ import { r as SUPPORTED_WORKER_EXTENSIONS } from "./worker-entrypoint-CQW77lG8.js";
8
+ import { i as findFiles, t as DEFAULT_DO_PATTERN } from "./glob-CmQOvunB.js";
9
+ import { dirname, isAbsolute, relative, resolve } from "pathe";
10
+ //#region src/worker-entry/durable-object-discovery.ts
11
+ /**
12
+ * Walk the glob `pattern` under `cwd` and return a map of file path →
13
+ * Durable Object class names declared in that file. Files that fail to read
14
+ * or contain no DO classes are omitted. Respects `.gitignore` automatically
15
+ * (via `findFiles`).
16
+ */
17
+ async function discoverDurableObjectFiles(cwd, pattern) {
18
+ const result = /* @__PURE__ */ new Map();
19
+ const matchedFiles = await findFiles(pattern, { cwd });
20
+ const fs = await import("node:fs/promises");
21
+ for (const filePath of matchedFiles) try {
22
+ const classNames = findDurableObjectClasses(await fs.readFile(filePath, "utf-8"));
23
+ if (classNames.length > 0) result.set(filePath, classNames);
24
+ } catch (error) {
25
+ console.warn(`[devflare] Failed to read DO file: ${filePath}`, error);
26
+ }
27
+ return result;
28
+ }
29
+ /**
30
+ * Vite-plugin-shaped wrapper around `discoverDurableObjectFiles`. Returns a
31
+ * `DODiscoveryResult` carrying the discovered file map plus the auxiliary
32
+ * worker name.
33
+ */
34
+ async function discoverDurableObjects(projectRoot, pattern, workerName) {
35
+ return {
36
+ files: await discoverDurableObjectFiles(projectRoot, pattern),
37
+ workerName
38
+ };
39
+ }
40
+ //#endregion
41
+ //#region src/vite/plugin-config-hook.ts
42
+ /**
43
+ * Try to load the devflare config without throwing. Returns `null` if the
44
+ * config does not exist (the plugin still works without one).
45
+ */
46
+ async function tryLoadDevflareConfig(cwd, configPath, command) {
47
+ try {
48
+ return await loadConfig({
49
+ cwd,
50
+ configFile: configPath
51
+ });
52
+ } catch (error) {
53
+ if (command === "build") console.warn("[devflare] Could not load config:", error);
54
+ return null;
55
+ }
56
+ }
57
+ /**
58
+ * Build the `define` map injecting `__DEVFLARE_WORKER_NAME__` as a build-time
59
+ * constant. Caller is responsible for merging this into any existing `define`.
60
+ */
61
+ function buildWorkerNameDefine(lfConfig, existing) {
62
+ const workerNameValue = lfConfig.name ?? "unknown";
63
+ return {
64
+ ...existing,
65
+ __DEVFLARE_WORKER_NAME__: JSON.stringify(workerNameValue)
66
+ };
67
+ }
68
+ /**
69
+ * Build the `server.proxy` config that forwards WebSocket upgrades to the
70
+ * Miniflare bridge. Returns `null` when no patterns are configured.
71
+ */
72
+ function buildWebSocketProxyConfig(lfConfig, bridgePort, wsProxyPatterns) {
73
+ const patterns = [...wsProxyPatterns];
74
+ if (lfConfig.wsRoutes && lfConfig.wsRoutes.length > 0) {
75
+ for (const route of lfConfig.wsRoutes) if (!patterns.includes(route.pattern)) patterns.push(route.pattern);
76
+ }
77
+ if (patterns.length === 0) return null;
78
+ const proxyConfig = {};
79
+ for (const pattern of patterns) proxyConfig[pattern] = {
80
+ target: `http://127.0.0.1:${bridgePort}`,
81
+ changeOrigin: true,
82
+ ws: true,
83
+ configure: (proxy) => {
84
+ proxy.on("error", (err) => {
85
+ console.error(`[devflare] Proxy error: ${err.message}`);
86
+ });
87
+ }
88
+ };
89
+ if (Object.keys(proxyConfig).length === 0) return null;
90
+ console.log(`[devflare] WebSocket proxy configured for: ${patterns.join(", ")}`);
91
+ return proxyConfig;
92
+ }
93
+ /**
94
+ * Build the additional Vite config returned by the plugin's `config()` hook.
95
+ * Loads the devflare config, derives `define` and (in dev under
96
+ * `DEVFLARE_DEV`) `server.proxy`. Returns `undefined` when there is nothing
97
+ * to merge.
98
+ */
99
+ async function buildPluginConfigHookResult(cwd, options, command, existingDefine) {
100
+ const lfConfig = await tryLoadDevflareConfig(cwd, options.configPath, command);
101
+ const returnConfig = {};
102
+ if (lfConfig) returnConfig.define = buildWorkerNameDefine(lfConfig, existingDefine);
103
+ if (command === "serve" && process.env.DEVFLARE_DEV && lfConfig) {
104
+ const proxyConfig = buildWebSocketProxyConfig(lfConfig, options.bridgePort ?? 8787, options.wsProxyPatterns);
105
+ if (proxyConfig) returnConfig.server = { proxy: proxyConfig };
106
+ }
107
+ return Object.keys(returnConfig).length > 0 ? returnConfig : void 0;
108
+ }
109
+ //#endregion
110
+ //#region src/worker-entry/surface-paths.ts
111
+ const defaultEntriesFor = (surface) => SUPPORTED_WORKER_EXTENSIONS.map((ext) => `src/${surface}${ext}`);
112
+ const DEFAULT_FETCH_ENTRY_FILES = defaultEntriesFor("fetch");
113
+ const DEFAULT_QUEUE_ENTRY_FILES = defaultEntriesFor("queue");
114
+ const DEFAULT_SCHEDULED_ENTRY_FILES = defaultEntriesFor("scheduled");
115
+ const DEFAULT_EMAIL_ENTRY_FILES = defaultEntriesFor("email");
116
+ const DEFAULT_TAIL_ENTRY_FILES = defaultEntriesFor("tail");
117
+ /**
118
+ * Path prefixes that are known framework / bundler build outputs.
119
+ * A handler path that lives under one of these will not exist on disk
120
+ * until the framework's own build (e.g. `vite build`, `svelte-kit build`)
121
+ * has run, which happens AFTER devflare resolves surface paths.
122
+ */
123
+ const BUILD_OUTPUT_PATH_PREFIXES = [
124
+ ".svelte-kit/",
125
+ ".adapter-cloudflare/",
126
+ ".next/",
127
+ ".nuxt/",
128
+ ".output/",
129
+ ".vercel/",
130
+ "dist/",
131
+ "build/",
132
+ ".vinxi/",
133
+ ".solid/"
134
+ ];
135
+ /** Returns true when the path looks like a framework build output. */
136
+ function looksLikeBuildArtifactPath(configuredPath) {
137
+ const normalised = configuredPath.replace(/\\/g, "/").replace(/^\.\//, "");
138
+ return BUILD_OUTPUT_PATH_PREFIXES.some((prefix) => normalised.startsWith(prefix));
139
+ }
140
+ async function resolveWorkerHandlerPath(cwd, configuredPath, defaultEntries, surfaceName = "worker") {
141
+ if (configuredPath === false) return null;
142
+ const fs = await import("node:fs/promises");
143
+ if (typeof configuredPath === "string" && configuredPath) {
144
+ const absolutePath = resolve(cwd, configuredPath);
145
+ try {
146
+ await fs.access(absolutePath);
147
+ return absolutePath;
148
+ } catch {
149
+ if (looksLikeBuildArtifactPath(configuredPath)) throw new Error(`Configured ${surfaceName} handler "${configuredPath}" was not found.\n\nThis path looks like a framework build output (e.g. SvelteKit / Vite / Next).\nDevflare resolves handler paths BEFORE your framework runs its build, so the file\ndoes not exist yet at this stage.\n\nRecommended fix — point devflare at the build artifact via wrangler passthrough\ninstead of files.${surfaceName}, so devflare skips composition and lets your\nframework write the worker entry that wrangler/vite then picks up:\n\n files: { ${surfaceName}: false },\n wrangler: {\n passthrough: { main: '${configuredPath}' }\n }\n\nAlternatively, run your framework build (e.g. \`vite build\`) before \`devflare build\`,\nor move the handler to a source file that exists at config time.`);
150
+ throw new Error(`Configured ${surfaceName} handler "${configuredPath}" was not found`);
151
+ }
152
+ }
153
+ for (const defaultEntry of defaultEntries) {
154
+ const absolutePath = resolve(cwd, defaultEntry);
155
+ try {
156
+ await fs.access(absolutePath);
157
+ return absolutePath;
158
+ } catch {}
159
+ }
160
+ return null;
161
+ }
162
+ async function resolveWorkerSurfacePaths(cwd, config) {
163
+ return {
164
+ fetch: await resolveWorkerHandlerPath(cwd, config.files?.fetch, DEFAULT_FETCH_ENTRY_FILES, "fetch"),
165
+ queue: await resolveWorkerHandlerPath(cwd, config.files?.queue, DEFAULT_QUEUE_ENTRY_FILES, "queue"),
166
+ scheduled: await resolveWorkerHandlerPath(cwd, config.files?.scheduled, DEFAULT_SCHEDULED_ENTRY_FILES, "scheduled"),
167
+ email: await resolveWorkerHandlerPath(cwd, config.files?.email, DEFAULT_EMAIL_ENTRY_FILES, "email"),
168
+ tail: await resolveWorkerHandlerPath(cwd, config.files?.tail, DEFAULT_TAIL_ENTRY_FILES, "tail")
169
+ };
170
+ }
171
+ function hasWorkerSurfacePaths(surfacePaths) {
172
+ return Object.values(surfacePaths).some((surfacePath) => typeof surfacePath === "string" && surfacePath.length > 0);
173
+ }
174
+ //#endregion
175
+ //#region src/worker-entry/composed-worker.ts
176
+ /**
177
+ * Minimal structured codegen helper used to emit the composed worker module.
178
+ * Each method appends a discrete "section" to the output; sections are joined
179
+ * by a single newline when rendered, which matches the shape previously
180
+ * produced by the hand-written template literal.
181
+ */
182
+ var CodeBuilder = class {
183
+ sections = [];
184
+ importStatement(specifiers, from) {
185
+ this.sections.push(`import { ${specifiers.join(", ")} } from '${from}'`);
186
+ return this;
187
+ }
188
+ importNamespace(identifier, from) {
189
+ this.sections.push(`import * as ${identifier} from '${from}'`);
190
+ return this;
191
+ }
192
+ reExport(names, from) {
193
+ this.sections.push(`export { ${names.join(", ")} } from '${from}'`);
194
+ return this;
195
+ }
196
+ constDeclaration(name, value) {
197
+ this.sections.push(`const ${name} = ${value}`);
198
+ return this;
199
+ }
200
+ classDeclaration(body) {
201
+ this.sections.push(body);
202
+ return this;
203
+ }
204
+ exportDefault(body) {
205
+ this.sections.push(`export default ${body}`);
206
+ return this;
207
+ }
208
+ raw(text) {
209
+ this.sections.push(text);
210
+ return this;
211
+ }
212
+ blank() {
213
+ this.sections.push("");
214
+ return this;
215
+ }
216
+ toString() {
217
+ return this.sections.join("\n");
218
+ }
219
+ };
220
+ const DEV_ONLY_EMAIL_HOOKS_SOURCE = `
221
+ function __devflareCreateEmailHeaders(rawBody) {
222
+ const headers = new Headers()
223
+ const lines = rawBody.split(/\\r?\\n/)
224
+
225
+ for (const line of lines) {
226
+ if (line.trim() === '') {
227
+ break
228
+ }
229
+
230
+ const colonIndex = line.indexOf(':')
231
+ if (colonIndex <= 0) {
232
+ continue
233
+ }
234
+
235
+ headers.append(line.slice(0, colonIndex).trim(), line.slice(colonIndex + 1).trim())
236
+ }
237
+
238
+ return headers
239
+ }
240
+
241
+ function __devflareCreateEmailRawStream(rawBody) {
242
+ return new ReadableStream({
243
+ start(controller) {
244
+ controller.enqueue(new TextEncoder().encode(rawBody))
245
+ controller.close()
246
+ }
247
+ })
248
+ }
249
+
250
+ async function __devflareHandleInternalEmail(request, env, ctx) {
251
+ if (!__devflareEmailHandler) {
252
+ return new Response('Email handler not configured', { status: 501 })
253
+ }
254
+
255
+ const from = request.headers.get('x-devflare-email-from') || 'unknown@example.com'
256
+ const to = request.headers.get('x-devflare-email-to') || 'worker@example.com'
257
+ const rawBody = await request.text()
258
+ const emailMessage = {
259
+ from,
260
+ to,
261
+ headers: __devflareCreateEmailHeaders(rawBody),
262
+ raw: __devflareCreateEmailRawStream(rawBody),
263
+ rawSize: rawBody.length,
264
+ setReject(reason) {
265
+ console.warn('[Devflare email rejected]', reason)
266
+ },
267
+ async forward(rcptTo) {
268
+ console.log('[Devflare email forwarded]', rcptTo)
269
+ return Promise.resolve()
270
+ },
271
+ async reply(message) {
272
+ console.log('[Devflare email reply sent]', message?.from)
273
+ return Promise.resolve()
274
+ }
275
+ }
276
+
277
+ const __devflareEvent = createEmailEvent(emailMessage, env, ctx)
278
+
279
+ await runWithEventContext(
280
+ __devflareEvent,
281
+ () => __devflareEmailHandler(__devflareEvent, env, ctx)
282
+ )
283
+
284
+ return new Response(JSON.stringify({ ok: true, from, to }), {
285
+ headers: { 'Content-Type': 'application/json' }
286
+ })
287
+ }
288
+ `;
289
+ function emitDevOnlyEmailHooks(builder, options) {
290
+ if (!options.enabled) return;
291
+ builder.raw(DEV_ONLY_EMAIL_HOOKS_SOURCE);
292
+ }
293
+ const RESOLVE_HANDLER_DECLARATION = `const __devflareResolveHandler = (module, namedExport) => {
294
+ const defaultExport = module.default
295
+
296
+ if (typeof defaultExport === 'function') {
297
+ return defaultExport
298
+ }
299
+
300
+ if (defaultExport && typeof defaultExport[namedExport] === 'function') {
301
+ return defaultExport[namedExport].bind(defaultExport)
302
+ }
303
+
304
+ if (typeof module[namedExport] === 'function') {
305
+ return module[namedExport]
306
+ }
307
+
308
+ return null
309
+ }`;
310
+ function buildDefaultExportBody(options) {
311
+ const devOnlyEmailEntry = options.includeDevOnlyHooks ? `const url = new URL(request.url)
312
+
313
+ if (
314
+ request.headers.get('x-devflare-event') === 'email'
315
+ && url.pathname === '/_devflare/internal/email'
316
+ ) {
317
+ return __devflareHandleInternalEmail(request, env, ctx)
318
+ }
319
+
320
+ ` : "";
321
+ return `{
322
+ ...(${options.hasFetchDispatch ? "true" : "false"}
323
+ ? {
324
+ async fetch(request, env, ctx) {
325
+ ${devOnlyEmailEntry}const __devflareInitialRouteMatch = __devflareHasRoutes ? matchFetchRoute(__devflareRoutes, request) : null
326
+ const __devflareEvent = createFetchEvent(request, env, ctx, {
327
+ params: __devflareInitialRouteMatch?.params ?? {}
328
+ })
329
+ return runWithEventContext(
330
+ __devflareEvent,
331
+ () => invokeFetchModule(
332
+ __devflareFetchModule,
333
+ __devflareEvent,
334
+ __devflareHasRoutes
335
+ ? createRouteResolve(__devflareRoutes, __devflareEvent)
336
+ : undefined
337
+ )
338
+ )
339
+ }
340
+ }
341
+ : {}),
342
+ ...(__devflareQueueHandler
343
+ ? {
344
+ async queue(batch, env, ctx) {
345
+ assertExplicitQueueHandlerStyle(__devflareQueueHandler)
346
+ const __devflareEvent = createQueueEvent(batch, env, ctx)
347
+ return runWithEventContext(
348
+ __devflareEvent,
349
+ () => __devflareQueueHandler(__devflareEvent, env, ctx)
350
+ )
351
+ }
352
+ }
353
+ : {}),
354
+ ...(__devflareScheduledHandler
355
+ ? {
356
+ async scheduled(controller, env, ctx) {
357
+ assertExplicitScheduledHandlerStyle(__devflareScheduledHandler)
358
+ const __devflareEvent = createScheduledEvent(controller, env, ctx)
359
+ return runWithEventContext(
360
+ __devflareEvent,
361
+ () => __devflareScheduledHandler(__devflareEvent, env, ctx)
362
+ )
363
+ }
364
+ }
365
+ : {}),
366
+ ...(__devflareEmailHandler
367
+ ? {
368
+ async email(message, env, ctx) {
369
+ const __devflareEvent = createEmailEvent(message, env, ctx)
370
+ return runWithEventContext(
371
+ __devflareEvent,
372
+ () => __devflareEmailHandler(__devflareEvent, env, ctx)
373
+ )
374
+ }
375
+ }
376
+ : {}),
377
+ ...(__devflareTailHandler
378
+ ? {
379
+ async tail(events, env, ctx) {
380
+ const __devflareEvent = createTailEvent(events, env, ctx)
381
+ return runWithEventContext(
382
+ __devflareEvent,
383
+ () => __devflareTailHandler.length >= 2
384
+ ? __devflareTailHandler(events, env, ctx)
385
+ : __devflareTailHandler(__devflareEvent, env, ctx)
386
+ )
387
+ }
388
+ }
389
+ : {})
390
+ }`;
391
+ }
392
+ function getComposedWorkerEntrypointSource(surfaceImportPaths, configuredLocalSendEmailBindings = {}, durableObjectExports = [], routeImports = [], options = {}) {
393
+ const includeDevOnlyHooks = options.includeDevOnlyHooks ?? options.devInternalEmail === true;
394
+ const importsBuilder = new CodeBuilder();
395
+ importsBuilder.importStatement([
396
+ "assertExplicitQueueHandlerStyle",
397
+ "assertExplicitScheduledHandlerStyle",
398
+ "createEmailEvent",
399
+ "createFetchEvent",
400
+ "createQueueEvent",
401
+ "createRouteResolve",
402
+ "createScheduledEvent",
403
+ "createTailEvent",
404
+ "invokeFetchModule",
405
+ "matchFetchRoute",
406
+ "runWithEventContext",
407
+ "setLocalSendEmailBindings"
408
+ ], "devflare/runtime");
409
+ const fallbackModules = [
410
+ {
411
+ identifier: "__devflareFetchModule",
412
+ importPath: surfaceImportPaths.fetch
413
+ },
414
+ {
415
+ identifier: "__devflareQueueModule",
416
+ importPath: surfaceImportPaths.queue
417
+ },
418
+ {
419
+ identifier: "__devflareScheduledModule",
420
+ importPath: surfaceImportPaths.scheduled
421
+ },
422
+ {
423
+ identifier: "__devflareEmailModule",
424
+ importPath: surfaceImportPaths.email
425
+ },
426
+ {
427
+ identifier: "__devflareTailModule",
428
+ importPath: surfaceImportPaths.tail
429
+ }
430
+ ];
431
+ const fallbacksBuilder = new CodeBuilder();
432
+ for (const { identifier, importPath } of fallbackModules) if (importPath) importsBuilder.importNamespace(identifier, importPath);
433
+ else fallbacksBuilder.constDeclaration(identifier, "{}");
434
+ for (const routeImport of routeImports) importsBuilder.importNamespace(routeImport.identifier, routeImport.importPath);
435
+ const reExportsBuilder = new CodeBuilder();
436
+ for (const { classNames, importPath } of durableObjectExports) reExportsBuilder.reExport(classNames, importPath);
437
+ const routeManifestEntries = routeImports.map(({ identifier, filePath, routePath, segmentsJson }) => {
438
+ return `\t{ filePath: ${JSON.stringify(filePath)}, routePath: ${JSON.stringify(routePath)}, segments: ${segmentsJson}, module: ${identifier} }`;
439
+ });
440
+ const builder = new CodeBuilder();
441
+ builder.raw(importsBuilder.toString());
442
+ builder.raw(fallbacksBuilder.toString());
443
+ builder.raw(reExportsBuilder.toString());
444
+ builder.blank();
445
+ builder.raw(`setLocalSendEmailBindings(${JSON.stringify(configuredLocalSendEmailBindings)})`);
446
+ builder.blank();
447
+ builder.constDeclaration("__devflareHasFetchModule", surfaceImportPaths.fetch ? "true" : "false");
448
+ builder.raw(`const __devflareRoutes = [\n${routeManifestEntries.join(",\n")}\n]`);
449
+ builder.constDeclaration("__devflareHasRoutes", "__devflareRoutes.length > 0");
450
+ builder.blank();
451
+ builder.raw(RESOLVE_HANDLER_DECLARATION);
452
+ builder.blank();
453
+ builder.constDeclaration("__devflareQueueHandler", "__devflareResolveHandler(__devflareQueueModule, 'queue')");
454
+ builder.constDeclaration("__devflareScheduledHandler", "__devflareResolveHandler(__devflareScheduledModule, 'scheduled')");
455
+ builder.constDeclaration("__devflareEmailHandler", "__devflareResolveHandler(__devflareEmailModule, 'email')");
456
+ builder.constDeclaration("__devflareTailHandler", "__devflareResolveHandler(__devflareTailModule, 'tail')");
457
+ emitDevOnlyEmailHooks(builder, { enabled: includeDevOnlyHooks });
458
+ builder.blank();
459
+ builder.exportDefault(buildDefaultExportBody({
460
+ hasFetchDispatch: Boolean(surfaceImportPaths.fetch) || routeImports.length > 0 || includeDevOnlyHooks,
461
+ includeDevOnlyHooks
462
+ }));
463
+ builder.raw("");
464
+ return builder.toString();
465
+ }
466
+ function toImportSpecifier(fromFilePath, toFilePath) {
467
+ const specifier = relative(dirname(fromFilePath), toFilePath).replace(/\\/g, "/");
468
+ return specifier.startsWith(".") ? specifier : `./${specifier}`;
469
+ }
470
+ function createGeneratedRouteModuleImports(entryPath, routeDiscovery) {
471
+ if (!routeDiscovery) return [];
472
+ return routeDiscovery.routes.map((route, index) => ({
473
+ identifier: `__devflareRouteModule${index}`,
474
+ importPath: toImportSpecifier(entryPath, route.absolutePath),
475
+ filePath: route.filePath,
476
+ routePath: route.routePath,
477
+ segmentsJson: JSON.stringify(route.segments)
478
+ }));
479
+ }
480
+ async function createGeneratedDurableObjectExports(entryPath, cwd, config) {
481
+ if (config.files?.durableObjects === false || !config.bindings?.durableObjects) return [];
482
+ const localClassNames = new Set(Object.values(config.bindings.durableObjects).map((binding) => normalizeDOBinding(binding)).filter((binding) => binding.kind === "local").map((binding) => binding.className));
483
+ if (localClassNames.size === 0) return [];
484
+ const discoveredFiles = await discoverDurableObjectFiles(cwd, typeof config.files?.durableObjects === "string" ? config.files.durableObjects : DEFAULT_DO_PATTERN);
485
+ const exports = [];
486
+ const discoveredClassNames = /* @__PURE__ */ new Set();
487
+ for (const [filePath, allClassNames] of discoveredFiles) {
488
+ const classNames = allClassNames.filter((className) => localClassNames.has(className));
489
+ if (classNames.length === 0) continue;
490
+ for (const className of classNames) discoveredClassNames.add(className);
491
+ exports.push({
492
+ importPath: toImportSpecifier(entryPath, filePath),
493
+ filePath,
494
+ classNames
495
+ });
496
+ }
497
+ const missingClassNames = Array.from(localClassNames).filter((className) => !discoveredClassNames.has(className));
498
+ if (missingClassNames.length > 0) throw new Error(`Failed to discover local Durable Object class${missingClassNames.length === 1 ? "" : "es"} ${missingClassNames.join(", ")} for worker composition. Ensure files.durableObjects matches the source file pattern for your do.* files.`);
499
+ return exports;
500
+ }
501
+ /**
502
+ * Returns true when the resolved config has any composition signal other than
503
+ * `files.fetch` (queue / scheduled / email handler files, durable-object
504
+ * bindings, sendEmail bindings, or routes). Used to decide whether a missing
505
+ * build-artifact fetch path can be safely deferred to wrangler/vite.
506
+ */
507
+ function mayRequireCompositionBesidesFetch(config) {
508
+ const files = config.files ?? {};
509
+ if (typeof files.queue === "string" && files.queue) return true;
510
+ if (typeof files.scheduled === "string" && files.scheduled) return true;
511
+ if (typeof files.email === "string" && files.email) return true;
512
+ if (typeof files.tail === "string" && files.tail) return true;
513
+ if (files.durableObjects) return true;
514
+ if (files.routes) return true;
515
+ const bindings = config.bindings ?? {};
516
+ const doBindings = bindings.durableObjects;
517
+ if (doBindings && Object.keys(doBindings).length > 0) return true;
518
+ const sendEmail = bindings.sendEmail;
519
+ if (sendEmail && Object.keys(sendEmail).length > 0) return true;
520
+ return false;
521
+ }
522
+ function needsComposedWorkerEntrypoint(cwd, surfacePaths, config, routeDiscovery) {
523
+ if (Boolean(surfacePaths.queue || surfacePaths.scheduled || surfacePaths.email || surfacePaths.tail || routeDiscovery?.routes.length)) return true;
524
+ if (!surfacePaths.fetch) return false;
525
+ const assetsDirectory = config.assets?.directory;
526
+ if (assetsDirectory) {
527
+ const generatedAssetsWorkerPath = resolve(cwd, assetsDirectory, "_worker.js");
528
+ if (surfacePaths.fetch === generatedAssetsWorkerPath) return false;
529
+ }
530
+ return Boolean(surfacePaths.fetch);
531
+ }
532
+ async function prepareComposedWorkerEntrypoint(cwd, config, environment, options = {}) {
533
+ const resolvedConfig = resolveConfigForEnvironment(config, environment);
534
+ if (resolvedConfig.wrangler?.passthrough && Object.prototype.hasOwnProperty.call(resolvedConfig.wrangler.passthrough, "main")) return null;
535
+ const configuredFetch = resolvedConfig.files?.fetch;
536
+ if (typeof configuredFetch === "string" && looksLikeBuildArtifactPath(configuredFetch)) {
537
+ const fs = await import("node:fs/promises");
538
+ const fetchAbsolute = resolve(cwd, configuredFetch);
539
+ let fetchExists = true;
540
+ try {
541
+ await fs.access(fetchAbsolute);
542
+ } catch {
543
+ fetchExists = false;
544
+ }
545
+ if (!fetchExists && !mayRequireCompositionBesidesFetch(resolvedConfig)) return null;
546
+ }
547
+ const surfacePaths = await resolveWorkerSurfacePaths(cwd, resolvedConfig);
548
+ const routeDiscovery = await discoverRoutes(cwd, resolvedConfig);
549
+ if (!needsComposedWorkerEntrypoint(cwd, surfacePaths, resolvedConfig, routeDiscovery)) return null;
550
+ const fs = await import("node:fs/promises");
551
+ const entryDir = resolve(cwd, ".devflare", "worker-entrypoints");
552
+ const entryPath = resolve(entryDir, "main.ts");
553
+ await fs.mkdir(entryDir, { recursive: true });
554
+ const surfaceImportPaths = {
555
+ fetch: surfacePaths.fetch ? toImportSpecifier(entryPath, surfacePaths.fetch) : null,
556
+ queue: surfacePaths.queue ? toImportSpecifier(entryPath, surfacePaths.queue) : null,
557
+ scheduled: surfacePaths.scheduled ? toImportSpecifier(entryPath, surfacePaths.scheduled) : null,
558
+ email: surfacePaths.email ? toImportSpecifier(entryPath, surfacePaths.email) : null,
559
+ tail: surfacePaths.tail ? toImportSpecifier(entryPath, surfacePaths.tail) : null
560
+ };
561
+ const durableObjectExports = await createGeneratedDurableObjectExports(entryPath, cwd, resolvedConfig);
562
+ const routeImports = createGeneratedRouteModuleImports(entryPath, routeDiscovery);
563
+ await fs.writeFile(entryPath, getComposedWorkerEntrypointSource(surfaceImportPaths, resolvedConfig.bindings?.sendEmail ?? {}, durableObjectExports, routeImports, options));
564
+ return entryPath;
565
+ }
566
+ //#endregion
567
+ //#region src/vite/plugin-durable-objects.ts
568
+ const VIRTUAL_DO_ENTRY = "virtual:devflare-do-entry";
569
+ const RESOLVED_VIRTUAL_DO_ENTRY = "\0" + VIRTUAL_DO_ENTRY;
570
+ /**
571
+ * Generate virtual DO entry module code
572
+ */
573
+ function generateVirtualDOEntry(discovery) {
574
+ const lines = [
575
+ "// Auto-generated by devflare — DO entry module",
576
+ "// Re-exports all Durable Object classes discovered from files.durableObjects pattern",
577
+ ""
578
+ ];
579
+ for (const [filePath, classNames] of discovery.files) {
580
+ const normalizedPath = filePath.replace(/\\/g, "/");
581
+ lines.push(`export { ${classNames.join(", ")} } from '${normalizedPath}'`);
582
+ }
583
+ lines.push("");
584
+ lines.push("// Default fetch handler for DO worker");
585
+ lines.push("export default {");
586
+ lines.push(" async fetch(request: Request): Promise<Response> {");
587
+ lines.push(" return new Response(\"Devflare DO Worker\", { status: 200 })");
588
+ lines.push(" }");
589
+ lines.push("}");
590
+ return lines.join("\n");
591
+ }
592
+ /**
593
+ * Create auxiliary worker config for Durable Objects
594
+ */
595
+ function createAuxiliaryWorkerConfig(wranglerConfig, discovery) {
596
+ const doBindings = wranglerConfig.durable_objects?.bindings?.map((binding) => ({
597
+ name: binding.name,
598
+ class_name: binding.class_name
599
+ })) ?? [];
600
+ return { config: {
601
+ name: discovery.workerName,
602
+ main: VIRTUAL_DO_ENTRY,
603
+ compatibility_date: wranglerConfig.compatibility_date,
604
+ compatibility_flags: wranglerConfig.compatibility_flags,
605
+ durable_objects: { bindings: doBindings },
606
+ migrations: wranglerConfig.migrations,
607
+ kv_namespaces: wranglerConfig.kv_namespaces,
608
+ d1_databases: wranglerConfig.d1_databases,
609
+ r2_buckets: wranglerConfig.r2_buckets,
610
+ browser: wranglerConfig.browser
611
+ } };
612
+ }
613
+ function logDiscoveredDurableObjects(projectRoot, discovery) {
614
+ if (!discovery || discovery.files.size === 0) return;
615
+ console.log(`[devflare] Discovered ${discovery.files.size} DO file(s):`);
616
+ for (const [filePath, classes] of discovery.files) console.log(` • ${filePath.replace(projectRoot, ".")} → ${classes.join(", ")}`);
617
+ }
618
+ //#endregion
619
+ //#region src/vite/plugin-service-bindings.ts
620
+ const VIRTUAL_SERVICE_WORKER_PREFIX = "virtual:devflare-service-worker/";
621
+ const RESOLVED_VIRTUAL_SERVICE_WORKER_PREFIX = "\0" + VIRTUAL_SERVICE_WORKER_PREFIX;
622
+ function virtualServiceWorkerId(workerName) {
623
+ return `${VIRTUAL_SERVICE_WORKER_PREFIX}${encodeURIComponent(workerName)}`;
624
+ }
625
+ function resolvedVirtualServiceWorkerId(workerName) {
626
+ return `${RESOLVED_VIRTUAL_SERVICE_WORKER_PREFIX}${encodeURIComponent(workerName)}`;
627
+ }
628
+ function objectEntries(record) {
629
+ return record ? Object.entries(record) : [];
630
+ }
631
+ function toWranglerDurableObjectBinding(name, value) {
632
+ if (typeof value === "string") return {
633
+ name,
634
+ class_name: value
635
+ };
636
+ return {
637
+ name,
638
+ class_name: value.className,
639
+ script_name: value.scriptName
640
+ };
641
+ }
642
+ function toWranglerWorkerConfig(worker) {
643
+ const queueProducers = worker.queueProducers ? objectEntries(worker.queueProducers).map(([binding, producer]) => ({
644
+ binding,
645
+ queue: producer.queueName
646
+ })) : void 0;
647
+ const queueConsumers = worker.queueConsumers ? objectEntries(worker.queueConsumers).map(([queue, consumer]) => ({
648
+ queue,
649
+ ...consumer.maxBatchSize !== void 0 && { max_batch_size: consumer.maxBatchSize },
650
+ ...consumer.maxBatchTimeout !== void 0 && { max_batch_timeout: consumer.maxBatchTimeout },
651
+ ...consumer.maxRetries !== void 0 && { max_retries: consumer.maxRetries },
652
+ ...typeof consumer.deadLetterQueue === "string" && { dead_letter_queue: consumer.deadLetterQueue },
653
+ ...consumer.maxConcurrency !== void 0 && { max_concurrency: consumer.maxConcurrency },
654
+ ...consumer.retryDelay !== void 0 && { retry_delay: consumer.retryDelay }
655
+ })) : void 0;
656
+ const queues = queueProducers || queueConsumers ? {
657
+ ...queueProducers && { producers: queueProducers },
658
+ ...queueConsumers && { consumers: queueConsumers }
659
+ } : void 0;
660
+ const durableObjectBindings = worker.durableObjects ? objectEntries(worker.durableObjects).map(([name, value]) => toWranglerDurableObjectBinding(name, value)) : [];
661
+ const serviceBindings = worker.serviceBindings ? objectEntries(worker.serviceBindings).map(([binding, target]) => ({
662
+ binding,
663
+ service: target.name,
664
+ ...target.entrypoint && { entrypoint: target.entrypoint }
665
+ })) : [];
666
+ return {
667
+ name: worker.name,
668
+ main: virtualServiceWorkerId(worker.name),
669
+ compatibility_date: worker.compatibilityDate,
670
+ ...worker.compatibilityFlags && { compatibility_flags: worker.compatibilityFlags },
671
+ ...worker.bindings && { vars: worker.bindings },
672
+ ...worker.kvNamespaces && { kv_namespaces: objectEntries(worker.kvNamespaces).map(([binding, id]) => ({
673
+ binding,
674
+ id
675
+ })) },
676
+ ...worker.r2Buckets && { r2_buckets: objectEntries(worker.r2Buckets).map(([binding, bucket_name]) => ({
677
+ binding,
678
+ bucket_name
679
+ })) },
680
+ ...worker.d1Databases && { d1_databases: objectEntries(worker.d1Databases).map(([binding, database_id]) => ({
681
+ binding,
682
+ database_id,
683
+ database_name: database_id
684
+ })) },
685
+ ...durableObjectBindings.length > 0 && { durable_objects: { bindings: durableObjectBindings } },
686
+ ...serviceBindings.length > 0 && { services: serviceBindings },
687
+ ...queues && { queues }
688
+ };
689
+ }
690
+ function createAuxiliaryServiceWorkerConfigs(resolution) {
691
+ if (!resolution || resolution.workers.length === 0) return {
692
+ auxiliaryWorkers: [],
693
+ virtualModules: /* @__PURE__ */ new Map()
694
+ };
695
+ const virtualModules = /* @__PURE__ */ new Map();
696
+ return {
697
+ auxiliaryWorkers: resolution.workers.map((worker) => {
698
+ virtualModules.set(resolvedVirtualServiceWorkerId(worker.name), worker.script);
699
+ return { config: toWranglerWorkerConfig(worker) };
700
+ }),
701
+ virtualModules
702
+ };
703
+ }
704
+ //#endregion
705
+ //#region src/vite/plugin-context.ts
706
+ const CONFIG_DIR$2 = ".devflare";
707
+ function removeDevflareHandledServeBindings(config) {
708
+ const next = { ...config };
709
+ delete next.workflows;
710
+ delete next.media;
711
+ return next;
712
+ }
713
+ /**
714
+ * Compile a DevflareConfig into the bundle of artefacts the Vite plugin
715
+ * exposes to consumers (wrangler config, cloudflare-plugin programmatic
716
+ * config, auxiliary DO worker, discovered DOs).
717
+ *
718
+ * Mode discriminator:
719
+ * - `'serve'` — materialize names into stable local identifiers
720
+ * (miniflare-friendly).
721
+ * - `'build'` — preserve names in the emitted Wrangler artefact so deploy
722
+ * can later resolve them against the real Cloudflare account.
723
+ */
724
+ async function buildPluginContextState(projectRoot, devflareConfig, environment, mode = "serve", configDir = projectRoot) {
725
+ const effectiveConfig = await resolveConfigEnvVars(mode === "build" ? await resolveResources(devflareConfig, {
726
+ phase: "build",
727
+ environment
728
+ }) : await resolveResources(devflareConfig, {
729
+ phase: "local",
730
+ environment
731
+ }), {
732
+ cwd: configDir,
733
+ mode: mode === "build" ? "build" : "dev"
734
+ });
735
+ const compiledWranglerConfig = mode === "build" ? compileBuildConfig(effectiveConfig) : compileConfig(effectiveConfig);
736
+ const wranglerConfig = mode === "build" ? isolateViteBuildOutputPaths(projectRoot, compiledWranglerConfig) : removeDevflareHandledServeBindings(compiledWranglerConfig);
737
+ const cloudflareConfig = { ...mode === "build" ? isolateViteBuildOutputPaths(projectRoot, compileToProgrammaticConfig(effectiveConfig, environment, { preserveNamedBindings: true })) : removeDevflareHandledServeBindings(compileToProgrammaticConfig(effectiveConfig, environment)) };
738
+ const composedMainEntry = mode === "build" ? null : await prepareComposedWorkerEntrypoint(projectRoot, effectiveConfig, environment);
739
+ if (composedMainEntry) {
740
+ const relativeMain = relative(projectRoot, composedMainEntry);
741
+ wranglerConfig.main = relativeMain;
742
+ cloudflareConfig.main = relativeMain;
743
+ }
744
+ let durableObjects = null;
745
+ let auxiliaryWorkerConfig = null;
746
+ let serviceWorkerVirtualModules = /* @__PURE__ */ new Map();
747
+ let serviceAuxiliaryWorkerConfigs = [];
748
+ const doPatternConfig = effectiveConfig.files?.durableObjects;
749
+ const doPattern = typeof doPatternConfig === "string" ? doPatternConfig : DEFAULT_DO_PATTERN;
750
+ if (doPatternConfig !== false) {
751
+ const doWorkerName = `${wranglerConfig.name}-do`;
752
+ const discovery = await discoverDurableObjects(projectRoot, doPattern, doWorkerName);
753
+ if (discovery.files.size > 0) {
754
+ durableObjects = discovery;
755
+ if (wranglerConfig.durable_objects?.bindings) for (const binding of wranglerConfig.durable_objects.bindings) binding.script_name = doWorkerName;
756
+ if (cloudflareConfig.durable_objects) {
757
+ const doConfig = cloudflareConfig.durable_objects;
758
+ for (const binding of doConfig.bindings) binding.script_name = doWorkerName;
759
+ }
760
+ auxiliaryWorkerConfig = createAuxiliaryWorkerConfig(wranglerConfig, discovery);
761
+ }
762
+ }
763
+ if (mode === "serve" && effectiveConfig.bindings?.services) {
764
+ const serviceWorkers = createAuxiliaryServiceWorkerConfigs(await resolveServiceBindings(effectiveConfig, configDir));
765
+ serviceAuxiliaryWorkerConfigs = serviceWorkers.auxiliaryWorkers;
766
+ serviceWorkerVirtualModules = serviceWorkers.virtualModules;
767
+ }
768
+ return {
769
+ wranglerConfig,
770
+ cloudflareConfig,
771
+ auxiliaryWorkerConfigs: [...auxiliaryWorkerConfig ? [auxiliaryWorkerConfig] : [], ...serviceAuxiliaryWorkerConfigs],
772
+ serviceWorkerVirtualModules,
773
+ durableObjects,
774
+ auxiliaryWorkerConfig
775
+ };
776
+ }
777
+ async function ensureGeneratedConfigDir$1(projectRoot) {
778
+ const configDir = resolve(projectRoot, CONFIG_DIR$2);
779
+ const fs = await import("node:fs/promises");
780
+ await fs.mkdir(configDir, { recursive: true });
781
+ const gitignorePath = resolve(configDir, ".gitignore");
782
+ try {
783
+ await fs.access(gitignorePath);
784
+ } catch {
785
+ await fs.writeFile(gitignorePath, "*\n", "utf-8");
786
+ }
787
+ return configDir;
788
+ }
789
+ async function writeGeneratedWranglerConfig(projectRoot, wranglerConfig) {
790
+ const configDir = await ensureGeneratedConfigDir$1(projectRoot);
791
+ await writeWranglerConfig(configDir, rebaseWranglerConfigPaths(projectRoot, configDir, wranglerConfig), "wrangler.jsonc");
792
+ }
793
+ async function resolvePluginConfigPath(projectRoot, configPath) {
794
+ if (configPath) return isAbsolute(configPath) ? configPath : resolve(projectRoot, configPath);
795
+ return await resolveConfigPath(projectRoot) ?? null;
796
+ }
797
+ //#endregion
798
+ //#region src/vite/plugin-transform.ts
799
+ const TRANSFORMABLE_EXTENSIONS = [
800
+ ".ts",
801
+ ".tsx",
802
+ ".js"
803
+ ];
804
+ /**
805
+ * Returns `true` when devflare may rewrite the given module. Skips
806
+ * `node_modules` and any file that isn't a `.ts`/`.tsx`/`.js`.
807
+ */
808
+ function isTransformCandidate(id) {
809
+ if (id.includes("node_modules")) return false;
810
+ return TRANSFORMABLE_EXTENSIONS.some((ext) => id.endsWith(ext));
811
+ }
812
+ /**
813
+ * Worker-entrypoint instrumentation step.
814
+ *
815
+ * Only handles `worker.ts` / `worker.js` files and only when
816
+ * `shouldTransformWorker` accepts them. Returns `null` when this step does
817
+ * not apply, so the caller can fall through to other transforms.
818
+ */
819
+ async function runWorkerEntryTransform(code, id) {
820
+ if (!id.endsWith("worker.ts") && !id.endsWith("worker.js")) return null;
821
+ const { shouldTransformWorker, transformWorkerEntrypoint } = await import("./worker-entrypoint-CQW77lG8.js").then((n) => n.n);
822
+ if (!shouldTransformWorker(code, id)) return null;
823
+ const result = transformWorkerEntrypoint(code, id);
824
+ if (!result) return null;
825
+ return {
826
+ code: result.code,
827
+ map: result.map
828
+ };
829
+ }
830
+ /**
831
+ * Durable Object class transform step.
832
+ *
833
+ * Only runs when the user opted in via `doTransforms` and the source mentions
834
+ * `DurableObject` or the `@durableObject` decorator. Returns `null` when this
835
+ * step does not apply.
836
+ */
837
+ async function runDurableObjectTransform(code, id, options) {
838
+ if (!options.doTransforms) return null;
839
+ if (!code.includes("DurableObject") && !code.includes("@durableObject")) return null;
840
+ const { transformDurableObject } = await import("./durable-object-DMtH0XYX.js").then((n) => n.t);
841
+ return transformDurableObject(code, id);
842
+ }
843
+ /**
844
+ * Apply devflare's source-level transforms to a single module.
845
+ *
846
+ * Order:
847
+ * 1. Worker-entrypoint instrumentation (`runWorkerEntryTransform`)
848
+ * 2. Durable Object class transform (`runDurableObjectTransform`)
849
+ *
850
+ * Returns `null` when no transform applies, mirroring Vite's transform-hook
851
+ * contract.
852
+ */
853
+ async function runDevflareTransform(code, id, options) {
854
+ if (!isTransformCandidate(id)) return null;
855
+ const workerResult = await runWorkerEntryTransform(code, id);
856
+ if (workerResult) return workerResult;
857
+ return await runDurableObjectTransform(code, id, options);
858
+ }
859
+ //#endregion
860
+ //#region src/vite/plugin-programmatic.ts
861
+ async function loadProgrammaticDevflareConfig(options) {
862
+ const cwd = options.cwd ?? process.cwd();
863
+ const strategy = options.resolve ?? "offline-local";
864
+ return {
865
+ cwd,
866
+ devflareConfig: await resolveConfigEnvVars(strategy === "remote" ? await loadResolvedConfig({
867
+ cwd,
868
+ configFile: options.configPath,
869
+ environment: options.environment
870
+ }) : await resolveResources(await loadConfig({
871
+ cwd,
872
+ configFile: options.configPath
873
+ }), {
874
+ phase: "local",
875
+ environment: options.environment
876
+ }), {
877
+ cwd,
878
+ configPath: options.configPath,
879
+ mode: strategy === "remote" ? "build" : "dev"
880
+ })
881
+ };
882
+ }
883
+ /**
884
+ * Single canonical builder for programmatic config artifacts.
885
+ *
886
+ * Both public helpers (`getCloudflareConfig`, `getDevflareConfigs`) project
887
+ * out of this. The function loads the devflare config, prepares the composed
888
+ * worker entrypoint, compiles the wrangler config, derives the matching
889
+ * cloudflare-vite-plugin config (with optional `programmatic` projection),
890
+ * and discovers auxiliary DO workers when applicable.
891
+ */
892
+ async function buildProgrammaticArtifacts(options, mode) {
893
+ const { cwd, devflareConfig } = await loadProgrammaticDevflareConfig(options);
894
+ const composedMainEntry = await prepareComposedWorkerEntrypoint(cwd, devflareConfig);
895
+ const wranglerConfig = compileConfig(devflareConfig);
896
+ const cloudflareConfig = mode === "programmatic" ? compileToProgrammaticConfig(devflareConfig) : { ...wranglerConfig };
897
+ if (composedMainEntry) {
898
+ const relativeMain = relative(cwd, composedMainEntry);
899
+ wranglerConfig.main = relativeMain;
900
+ cloudflareConfig.main = relativeMain;
901
+ }
902
+ const auxiliaryWorkers = [];
903
+ const doPatternConfig = devflareConfig.files?.durableObjects;
904
+ const doPattern = typeof doPatternConfig === "string" ? doPatternConfig : DEFAULT_DO_PATTERN;
905
+ if (doPatternConfig !== false) {
906
+ const doWorkerName = `${wranglerConfig.name}-do`;
907
+ const discovery = await discoverDurableObjects(cwd, doPattern, doWorkerName);
908
+ if (discovery.files.size > 0) {
909
+ if (cloudflareConfig.durable_objects) {
910
+ const doConfig = cloudflareConfig.durable_objects;
911
+ for (const binding of doConfig.bindings) binding.script_name = doWorkerName;
912
+ }
913
+ auxiliaryWorkers.push(createAuxiliaryWorkerConfig(wranglerConfig, discovery));
914
+ }
915
+ }
916
+ if (devflareConfig.bindings?.services) {
917
+ const serviceBindingResolution = await resolveServiceBindings(devflareConfig, cwd);
918
+ auxiliaryWorkers.push(...createAuxiliaryServiceWorkerConfigs(serviceBindingResolution).auxiliaryWorkers);
919
+ }
920
+ return {
921
+ cwd,
922
+ devflareConfig,
923
+ composedMainEntry,
924
+ wranglerConfig,
925
+ cloudflareConfig,
926
+ auxiliaryWorkers
927
+ };
928
+ }
929
+ /**
930
+ * Get cloudflare config for programmatic use with @cloudflare/vite-plugin.
931
+ * Call this in vite.config.ts before setting up plugins.
932
+ *
933
+ * By default the config is resolved **offline** using local stable
934
+ * identifiers (no Cloudflare credentials required — matches the Miniflare /
935
+ * workerd behaviour of `vite dev`). Pass `{ resolve: 'remote' }` to restore
936
+ * the legacy behaviour that talks to the Cloudflare API and fails without
937
+ * credentials (e.g. when you want the programmatic config to reflect real
938
+ * production IDs during an automation script).
939
+ */
940
+ async function getCloudflareConfig(options = {}) {
941
+ const { cloudflareConfig } = await buildProgrammaticArtifacts(options, "programmatic");
942
+ return cloudflareConfig;
943
+ }
944
+ /**
945
+ * Get auxiliary worker configs for Durable Objects
946
+ * Use this when configuring @cloudflare/vite-plugin's auxiliaryWorkers option
947
+ *
948
+ * @example
949
+ * ```ts
950
+ * const { cloudflareConfig, auxiliaryWorkers } = await getDevflareConfigs()
951
+ *
952
+ * cloudflare({
953
+ * config: cloudflareConfig,
954
+ * auxiliaryWorkers
955
+ * })
956
+ * ```
957
+ */
958
+ async function getDevflareConfigs(options = {}) {
959
+ const { cloudflareConfig, auxiliaryWorkers } = await buildProgrammaticArtifacts(options, "wrangler");
960
+ return {
961
+ cloudflareConfig,
962
+ auxiliaryWorkers
963
+ };
964
+ }
965
+ //#endregion
966
+ //#region src/vite/plugin.ts
967
+ const CONFIG_DIR$1 = ".devflare";
968
+ function createPluginState() {
969
+ return {
970
+ context: {
971
+ wranglerConfig: null,
972
+ cloudflareConfig: null,
973
+ projectRoot: process.cwd(),
974
+ auxiliaryWorkerConfig: null,
975
+ auxiliaryWorkerConfigs: [],
976
+ serviceWorkerVirtualModules: /* @__PURE__ */ new Map(),
977
+ durableObjects: null
978
+ },
979
+ projectRoot: process.cwd(),
980
+ devflareConfig: null,
981
+ resolvedPluginConfigPath: null
982
+ };
983
+ }
984
+ /**
985
+ * Reload `devflare.config.ts`, rebuild the plugin context state, mutate the
986
+ * shared plugin state in-place, and write the generated wrangler config to
987
+ * disk. Used by both `configResolved` (initial load) and the `configureServer`
988
+ * watcher (HMR reload).
989
+ */
990
+ async function loadAndApplyConfig(state, options, mode, onContextUpdated) {
991
+ state.devflareConfig = await loadConfig({
992
+ cwd: state.projectRoot,
993
+ configFile: options.configPath
994
+ });
995
+ const pluginState = await buildPluginContextState(state.projectRoot, state.devflareConfig, options.environment, mode, state.resolvedPluginConfigPath ? dirname(state.resolvedPluginConfigPath) : state.projectRoot);
996
+ Object.assign(state.context, {
997
+ projectRoot: state.projectRoot,
998
+ ...pluginState
999
+ });
1000
+ onContextUpdated(state.context);
1001
+ logDiscoveredDurableObjects(state.projectRoot, pluginState.durableObjects);
1002
+ await writeGeneratedWranglerConfig(state.projectRoot, pluginState.wranglerConfig);
1003
+ }
1004
+ let lastPluginContext = createPluginState().context;
1005
+ /**
1006
+ * Get the compiled config context
1007
+ * Can be used by other plugins or CLI commands
1008
+ */
1009
+ function getPluginContext() {
1010
+ return lastPluginContext;
1011
+ }
1012
+ /**
1013
+ * Devflare Vite Plugin
1014
+ *
1015
+ * @example
1016
+ * ```ts
1017
+ * // vite.config.ts
1018
+ * import { defineConfig } from 'vite'
1019
+ * import { sveltekit } from '@sveltejs/kit/vite'
1020
+ * import { devflarePlugin, getPluginContext } from 'devflare/vite'
1021
+ * import { cloudflare } from '@cloudflare/vite-plugin'
1022
+ *
1023
+ * export default defineConfig(async () => {
1024
+ * // First, run devflare to get context
1025
+ * const lfPlugin = devflarePlugin()
1026
+ *
1027
+ * return {
1028
+ * plugins: [
1029
+ * lfPlugin,
1030
+ * sveltekit(),
1031
+ * // Access context after configResolved
1032
+ * cloudflare({
1033
+ * config: getPluginContext().cloudflareConfig,
1034
+ * auxiliaryWorkers: getPluginContext().auxiliaryWorkerConfigs.length > 0
1035
+ * ? getPluginContext().auxiliaryWorkerConfigs
1036
+ * : undefined
1037
+ * })
1038
+ * ]
1039
+ * }
1040
+ * })
1041
+ * ```
1042
+ */
1043
+ function devflarePlugin(options = {}) {
1044
+ const { configPath, environment, doTransforms = true, watchConfig = true, bridgePort = process.env.DEVFLARE_BRIDGE_PORT ? Number.parseInt(process.env.DEVFLARE_BRIDGE_PORT, 10) : void 0, wsProxyPatterns = [] } = options;
1045
+ const state = createPluginState();
1046
+ return {
1047
+ name: "devflare",
1048
+ enforce: "pre",
1049
+ async config(config, { command }) {
1050
+ return buildPluginConfigHookResult(config.root ?? process.cwd(), {
1051
+ configPath,
1052
+ bridgePort,
1053
+ wsProxyPatterns
1054
+ }, command, config.define ?? {});
1055
+ },
1056
+ resolveId(id) {
1057
+ if (id === "virtual:devflare-do-entry") return RESOLVED_VIRTUAL_DO_ENTRY;
1058
+ if (id.startsWith("virtual:devflare-service-worker/")) return "\0" + id;
1059
+ return null;
1060
+ },
1061
+ async load(id) {
1062
+ if (id === "\0virtual:devflare-do-entry") {
1063
+ if (!state.context.durableObjects) return "// No Durable Objects configured\nexport default { fetch: () => new Response(\"No DOs\") }";
1064
+ return generateVirtualDOEntry(state.context.durableObjects);
1065
+ }
1066
+ if (id.startsWith("\0virtual:devflare-service-worker/")) return state.context.serviceWorkerVirtualModules.get(id) ?? null;
1067
+ return null;
1068
+ },
1069
+ async configResolved(config) {
1070
+ state.projectRoot = config.root;
1071
+ state.context.projectRoot = state.projectRoot;
1072
+ state.resolvedPluginConfigPath = await resolvePluginConfigPath(state.projectRoot, configPath);
1073
+ try {
1074
+ await loadAndApplyConfig(state, {
1075
+ configPath,
1076
+ environment
1077
+ }, config.command === "build" ? "build" : "serve", (ctx) => {
1078
+ lastPluginContext = ctx;
1079
+ });
1080
+ if (config.command === "serve") {
1081
+ console.log("[devflare] Config generated to .devflare/wrangler.jsonc");
1082
+ if (state.context.auxiliaryWorkerConfig) console.log("[devflare] ✓ Auxiliary DO worker configured");
1083
+ }
1084
+ if (config.command === "build") console.log(`[devflare] Generated ${CONFIG_DIR$1}/wrangler.jsonc`);
1085
+ } catch (error) {
1086
+ if (error instanceof Error) console.error("[devflare] Config error:", error.message);
1087
+ throw error;
1088
+ }
1089
+ },
1090
+ configureServer(server) {
1091
+ if (!watchConfig) return;
1092
+ const fullConfigPath = state.resolvedPluginConfigPath ?? resolve(state.projectRoot, configPath || "devflare.config.ts");
1093
+ server.watcher.add(fullConfigPath);
1094
+ server.watcher.on("change", async (changedPath) => {
1095
+ if (changedPath === fullConfigPath) {
1096
+ console.log("[devflare] Config changed, reloading...");
1097
+ try {
1098
+ await loadAndApplyConfig(state, {
1099
+ configPath,
1100
+ environment
1101
+ }, "serve", (ctx) => {
1102
+ lastPluginContext = ctx;
1103
+ });
1104
+ console.log("[devflare] Config reloaded");
1105
+ server.ws.send({
1106
+ type: "full-reload",
1107
+ path: "*"
1108
+ });
1109
+ } catch (error) {
1110
+ console.error("[devflare] Failed to reload config:", error);
1111
+ }
1112
+ }
1113
+ });
1114
+ },
1115
+ async transform(code, id) {
1116
+ return runDevflareTransform(code, id, { doTransforms });
1117
+ }
1118
+ };
1119
+ }
1120
+ //#endregion
1121
+ //#region src/vite/config-file.ts
1122
+ const CONFIG_DIR = ".devflare";
1123
+ const GENERATED_VITE_CONFIG_FILENAME = "vite.config.mjs";
1124
+ function hasInlineViteConfig(viteConfig) {
1125
+ return Boolean(viteConfig && Object.keys(viteConfig).length > 0);
1126
+ }
1127
+ function resolveEffectiveViteProject(detection, config, environment) {
1128
+ const hasDevflareConfig = hasInlineViteConfig(resolveConfigForEnvironment(config, environment).vite);
1129
+ return {
1130
+ ...detection,
1131
+ hasDevflareViteConfig: hasDevflareConfig,
1132
+ shouldStartVite: detection.shouldStartVite || hasDevflareConfig,
1133
+ wantsViteIntegration: detection.wantsViteIntegration || hasDevflareConfig
1134
+ };
1135
+ }
1136
+ function isPromiseLike(value) {
1137
+ return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
1138
+ }
1139
+ function normalizePluginOptions(pluginOption) {
1140
+ if (typeof pluginOption === "undefined") return [];
1141
+ return Array.isArray(pluginOption) ? pluginOption : [pluginOption];
1142
+ }
1143
+ function removePluginByName(pluginOption, pluginName) {
1144
+ if (Array.isArray(pluginOption)) {
1145
+ const filteredPlugins = pluginOption.map((nestedPlugin) => removePluginByName(nestedPlugin, pluginName)).filter((nestedPlugin) => typeof nestedPlugin !== "undefined");
1146
+ return filteredPlugins.length > 0 ? filteredPlugins : void 0;
1147
+ }
1148
+ if (!pluginOption || typeof pluginOption === "boolean" || isPromiseLike(pluginOption)) return pluginOption;
1149
+ return pluginOption.name === pluginName ? void 0 : pluginOption;
1150
+ }
1151
+ function withInjectedDevflarePlugin(config, pluginOptions) {
1152
+ const existingPlugins = normalizePluginOptions(config.plugins).map((pluginOption) => removePluginByName(pluginOption, "devflare")).filter((pluginOption) => typeof pluginOption !== "undefined");
1153
+ return {
1154
+ ...config,
1155
+ plugins: [devflarePlugin(pluginOptions), ...existingPlugins]
1156
+ };
1157
+ }
1158
+ async function resolveViteUserConfig(configEnv, options = {}) {
1159
+ const { loadConfigFromFile, mergeConfig } = await import("vite");
1160
+ const cwd = options.cwd ?? process.cwd();
1161
+ const inlineViteConfig = resolveConfigForEnvironment(await loadConfig({
1162
+ cwd,
1163
+ configFile: options.configPath
1164
+ }), options.environment).vite ?? {};
1165
+ const mergedConfig = mergeConfig(options.localConfigPath ? (await loadConfigFromFile(configEnv, options.localConfigPath, cwd))?.config ?? {} : {}, inlineViteConfig);
1166
+ return withInjectedDevflarePlugin(mergedConfig.root ? mergedConfig : {
1167
+ ...mergedConfig,
1168
+ root: cwd
1169
+ }, {
1170
+ configPath: options.configPath,
1171
+ environment: options.environment,
1172
+ bridgePort: options.bridgePort
1173
+ });
1174
+ }
1175
+ async function ensureGeneratedConfigDir(cwd) {
1176
+ const fs = await import("node:fs/promises");
1177
+ const { resolve } = await import("pathe");
1178
+ const configDir = resolve(cwd, CONFIG_DIR);
1179
+ await fs.mkdir(configDir, { recursive: true });
1180
+ const gitignorePath = resolve(configDir, ".gitignore");
1181
+ try {
1182
+ await fs.access(gitignorePath);
1183
+ } catch {
1184
+ await fs.writeFile(gitignorePath, "*\n", "utf-8");
1185
+ }
1186
+ return configDir;
1187
+ }
1188
+ async function resolveDevflarePackageRoot(currentFilePath) {
1189
+ const fs = await import("node:fs/promises");
1190
+ const { dirname, resolve } = await import("pathe");
1191
+ let currentDir = dirname(currentFilePath);
1192
+ while (true) {
1193
+ const packageJsonPath = resolve(currentDir, "package.json");
1194
+ try {
1195
+ if (JSON.parse(await fs.readFile(packageJsonPath, "utf-8")).name === "devflare") return currentDir;
1196
+ } catch {}
1197
+ const parentDir = dirname(currentDir);
1198
+ if (parentDir === currentDir) break;
1199
+ currentDir = parentDir;
1200
+ }
1201
+ throw new Error("Could not resolve the devflare package root for generated Vite config imports.");
1202
+ }
1203
+ async function resolveGeneratedViteImportPath(configDir) {
1204
+ const { fileURLToPath } = await import("node:url");
1205
+ const { extname, normalize, relative, resolve } = await import("pathe");
1206
+ const currentFilePath = normalize(fileURLToPath(import.meta.url));
1207
+ const currentExtension = extname(currentFilePath);
1208
+ const packageRoot = await resolveDevflarePackageRoot(currentFilePath);
1209
+ const relativeImportPath = relative(configDir, currentFilePath.includes("/dist/") ? resolve(packageRoot, "dist/vite/index.js") : resolve(packageRoot, `src/vite/index${currentExtension}`));
1210
+ return relativeImportPath.startsWith(".") ? relativeImportPath : `./${relativeImportPath}`;
1211
+ }
1212
+ async function writeGeneratedViteConfig(options) {
1213
+ const fs = await import("node:fs/promises");
1214
+ const { resolve } = await import("pathe");
1215
+ const configDir = await ensureGeneratedConfigDir(options.cwd);
1216
+ const generatedConfigPath = resolve(configDir, GENERATED_VITE_CONFIG_FILENAME);
1217
+ const viteImportPath = await resolveGeneratedViteImportPath(configDir);
1218
+ const content = `import { defineConfig } from 'vite'
1219
+ import { resolveViteUserConfig } from ${JSON.stringify(viteImportPath)}
1220
+
1221
+ export default defineConfig(async (env) => {
1222
+ return await resolveViteUserConfig(env, {
1223
+ cwd: ${JSON.stringify(options.cwd)},
1224
+ configPath: ${JSON.stringify(options.configPath)},
1225
+ environment: ${JSON.stringify(options.environment)},
1226
+ localConfigPath: ${JSON.stringify(options.localConfigPath)},
1227
+ bridgePort: ${JSON.stringify(options.bridgePort)}
1228
+ })
1229
+ })
1230
+ `;
1231
+ await fs.writeFile(generatedConfigPath, content, "utf-8");
1232
+ return generatedConfigPath;
1233
+ }
1234
+ //#endregion
1235
+ export { devflarePlugin as a, getDevflareConfigs as c, DEFAULT_FETCH_ENTRY_FILES as d, DEFAULT_QUEUE_ENTRY_FILES as f, discoverDurableObjectFiles as g, resolveWorkerSurfacePaths as h, writeGeneratedViteConfig as i, prepareComposedWorkerEntrypoint as l, hasWorkerSurfacePaths as m, resolveEffectiveViteProject as n, getPluginContext as o, DEFAULT_SCHEDULED_ENTRY_FILES as p, resolveViteUserConfig as r, getCloudflareConfig as s, hasInlineViteConfig as t, DEFAULT_EMAIL_ENTRY_FILES as u };