devflare 1.0.0-next.14 → 1.0.0-next.16

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 (380) hide show
  1. package/LLM.md +9360 -1784
  2. package/README.md +391 -32
  3. package/bin/devflare.js +17 -7
  4. package/dist/account-0w8wdzjv.js +475 -0
  5. package/dist/account-eygq6qx7.js +475 -0
  6. package/dist/account-fw8nafav.js +475 -0
  7. package/dist/account-pzq69nys.js +475 -0
  8. package/dist/account-s66jb15j.js +475 -0
  9. package/dist/api-d6ekexs5.js +25 -0
  10. package/dist/bridge/index.d.ts +1 -1
  11. package/dist/bridge/index.d.ts.map +1 -1
  12. package/dist/bridge/miniflare.d.ts.map +1 -1
  13. package/dist/bridge/protocol.d.ts +1 -1
  14. package/dist/bridge/protocol.d.ts.map +1 -1
  15. package/dist/bridge/proxy.d.ts +0 -4
  16. package/dist/bridge/proxy.d.ts.map +1 -1
  17. package/dist/bridge/serialization.d.ts.map +1 -1
  18. package/dist/bridge/server.d.ts +1 -1
  19. package/dist/bridge/server.d.ts.map +1 -1
  20. package/dist/browser-shim/handler.d.ts +1 -1
  21. package/dist/browser-shim/handler.d.ts.map +1 -1
  22. package/dist/browser.d.ts +1651 -34
  23. package/dist/browser.d.ts.map +1 -1
  24. package/dist/build-1kmkwqgh.js +53 -0
  25. package/dist/build-506kjhcm.js +53 -0
  26. package/dist/build-66866ahs.js +53 -0
  27. package/dist/build-g1adm3ww.js +53 -0
  28. package/dist/build-p3r3117t.js +53 -0
  29. package/dist/bundler/do-bundler.d.ts.map +1 -1
  30. package/dist/bundler/rolldown-shared.d.ts +24 -0
  31. package/dist/bundler/rolldown-shared.d.ts.map +1 -0
  32. package/dist/bundler/worker-bundler.d.ts +0 -1
  33. package/dist/bundler/worker-bundler.d.ts.map +1 -1
  34. package/dist/cli/command-utils.d.ts +18 -0
  35. package/dist/cli/command-utils.d.ts.map +1 -0
  36. package/dist/cli/commands/account.d.ts +1 -1
  37. package/dist/cli/commands/account.d.ts.map +1 -1
  38. package/dist/cli/commands/build-artifacts.d.ts +27 -0
  39. package/dist/cli/commands/build-artifacts.d.ts.map +1 -0
  40. package/dist/cli/commands/build.d.ts.map +1 -1
  41. package/dist/cli/commands/config.d.ts +4 -0
  42. package/dist/cli/commands/config.d.ts.map +1 -0
  43. package/dist/cli/commands/deploy.d.ts.map +1 -1
  44. package/dist/cli/commands/dev.d.ts.map +1 -1
  45. package/dist/cli/commands/doctor.d.ts.map +1 -1
  46. package/dist/cli/commands/init.d.ts.map +1 -1
  47. package/dist/cli/commands/login.d.ts +4 -0
  48. package/dist/cli/commands/login.d.ts.map +1 -0
  49. package/dist/cli/commands/previews-support/cleanup.d.ts +9 -0
  50. package/dist/cli/commands/previews-support/cleanup.d.ts.map +1 -0
  51. package/dist/cli/commands/previews-support/family.d.ts +10 -0
  52. package/dist/cli/commands/previews-support/family.d.ts.map +1 -0
  53. package/dist/cli/commands/previews-support/render.d.ts +8 -0
  54. package/dist/cli/commands/previews-support/render.d.ts.map +1 -0
  55. package/dist/cli/commands/previews-support/theme.d.ts +10 -0
  56. package/dist/cli/commands/previews-support/theme.d.ts.map +1 -0
  57. package/dist/cli/commands/previews-support/types.d.ts +70 -0
  58. package/dist/cli/commands/previews-support/types.d.ts.map +1 -0
  59. package/dist/cli/commands/previews.d.ts +4 -0
  60. package/dist/cli/commands/previews.d.ts.map +1 -0
  61. package/dist/cli/commands/productions.d.ts +4 -0
  62. package/dist/cli/commands/productions.d.ts.map +1 -0
  63. package/dist/cli/commands/token.d.ts +4 -0
  64. package/dist/cli/commands/token.d.ts.map +1 -0
  65. package/dist/cli/commands/type-generation/discovery.d.ts +7 -0
  66. package/dist/cli/commands/type-generation/discovery.d.ts.map +1 -0
  67. package/dist/cli/commands/type-generation/generator.d.ts +44 -0
  68. package/dist/cli/commands/type-generation/generator.d.ts.map +1 -0
  69. package/dist/cli/commands/type-generation/models.d.ts +27 -0
  70. package/dist/cli/commands/type-generation/models.d.ts.map +1 -0
  71. package/dist/cli/commands/types.d.ts.map +1 -1
  72. package/dist/cli/commands/worker.d.ts +4 -0
  73. package/dist/cli/commands/worker.d.ts.map +1 -0
  74. package/dist/cli/config-path.d.ts +2 -1
  75. package/dist/cli/config-path.d.ts.map +1 -1
  76. package/dist/cli/deploy-strategy.d.ts +17 -0
  77. package/dist/cli/deploy-strategy.d.ts.map +1 -0
  78. package/dist/cli/deploy-target.d.ts +17 -0
  79. package/dist/cli/deploy-target.d.ts.map +1 -0
  80. package/dist/cli/generated-artifacts.d.ts +12 -0
  81. package/dist/cli/generated-artifacts.d.ts.map +1 -0
  82. package/dist/cli/help-pages/pages/account.d.ts +3 -0
  83. package/dist/cli/help-pages/pages/account.d.ts.map +1 -0
  84. package/dist/cli/help-pages/pages/core.d.ts +4 -0
  85. package/dist/cli/help-pages/pages/core.d.ts.map +1 -0
  86. package/dist/cli/help-pages/pages/index.d.ts +3 -0
  87. package/dist/cli/help-pages/pages/index.d.ts.map +1 -0
  88. package/dist/cli/help-pages/pages/misc.d.ts +3 -0
  89. package/dist/cli/help-pages/pages/misc.d.ts.map +1 -0
  90. package/dist/cli/help-pages/pages/previews.d.ts +3 -0
  91. package/dist/cli/help-pages/pages/previews.d.ts.map +1 -0
  92. package/dist/cli/help-pages/pages/productions.d.ts +3 -0
  93. package/dist/cli/help-pages/pages/productions.d.ts.map +1 -0
  94. package/dist/cli/help-pages/render.d.ts +12 -0
  95. package/dist/cli/help-pages/render.d.ts.map +1 -0
  96. package/dist/cli/help-pages/shared.d.ts +15 -0
  97. package/dist/cli/help-pages/shared.d.ts.map +1 -0
  98. package/dist/cli/help-pages/types.d.ts +23 -0
  99. package/dist/cli/help-pages/types.d.ts.map +1 -0
  100. package/dist/cli/help.d.ts +6 -0
  101. package/dist/cli/help.d.ts.map +1 -0
  102. package/dist/cli/index.d.ts +1 -0
  103. package/dist/cli/index.d.ts.map +1 -1
  104. package/dist/cli/preview-bindings.d.ts +42 -0
  105. package/dist/cli/preview-bindings.d.ts.map +1 -0
  106. package/dist/cli/preview.d.ts +11 -0
  107. package/dist/cli/preview.d.ts.map +1 -0
  108. package/dist/cli/ui.d.ts +37 -0
  109. package/dist/cli/ui.d.ts.map +1 -0
  110. package/dist/cli/workspace-build-guard.d.ts +14 -0
  111. package/dist/cli/workspace-build-guard.d.ts.map +1 -0
  112. package/dist/cloudflare/account-core.d.ts +6 -0
  113. package/dist/cloudflare/account-core.d.ts.map +1 -0
  114. package/dist/cloudflare/account-resources.d.ts +40 -0
  115. package/dist/cloudflare/account-resources.d.ts.map +1 -0
  116. package/dist/cloudflare/account-status.d.ts +11 -0
  117. package/dist/cloudflare/account-status.d.ts.map +1 -0
  118. package/dist/cloudflare/account-workers.d.ts +14 -0
  119. package/dist/cloudflare/account-workers.d.ts.map +1 -0
  120. package/dist/cloudflare/account.d.ts +7 -64
  121. package/dist/cloudflare/account.d.ts.map +1 -1
  122. package/dist/cloudflare/api.d.ts +4 -0
  123. package/dist/cloudflare/api.d.ts.map +1 -1
  124. package/dist/cloudflare/index.d.ts +57 -2
  125. package/dist/cloudflare/index.d.ts.map +1 -1
  126. package/dist/cloudflare/kv-namespace.d.ts +3 -0
  127. package/dist/cloudflare/kv-namespace.d.ts.map +1 -0
  128. package/dist/cloudflare/preferences.d.ts.map +1 -1
  129. package/dist/cloudflare/preview-registry-cache.d.ts +6 -0
  130. package/dist/cloudflare/preview-registry-cache.d.ts.map +1 -0
  131. package/dist/cloudflare/preview-registry-records.d.ts +61 -0
  132. package/dist/cloudflare/preview-registry-records.d.ts.map +1 -0
  133. package/dist/cloudflare/preview-registry-store.d.ts +14 -0
  134. package/dist/cloudflare/preview-registry-store.d.ts.map +1 -0
  135. package/dist/cloudflare/preview-registry-types.d.ts +103 -0
  136. package/dist/cloudflare/preview-registry-types.d.ts.map +1 -0
  137. package/dist/cloudflare/preview-registry.d.ts +42 -0
  138. package/dist/cloudflare/preview-registry.d.ts.map +1 -0
  139. package/dist/cloudflare/registry-schema.d.ts +253 -0
  140. package/dist/cloudflare/registry-schema.d.ts.map +1 -0
  141. package/dist/cloudflare/tokens.d.ts +18 -0
  142. package/dist/cloudflare/tokens.d.ts.map +1 -0
  143. package/dist/cloudflare/types.d.ts +122 -5
  144. package/dist/cloudflare/types.d.ts.map +1 -1
  145. package/dist/cloudflare/usage.d.ts.map +1 -1
  146. package/dist/config/compiler.d.ts +4 -0
  147. package/dist/config/compiler.d.ts.map +1 -1
  148. package/dist/config/framework-providers.d.ts +9 -0
  149. package/dist/config/framework-providers.d.ts.map +1 -0
  150. package/dist/config/index.d.ts +5 -3
  151. package/dist/config/index.d.ts.map +1 -1
  152. package/dist/config/loader.d.ts +1 -0
  153. package/dist/config/loader.d.ts.map +1 -1
  154. package/dist/config/preview-resources.d.ts +77 -0
  155. package/dist/config/preview-resources.d.ts.map +1 -0
  156. package/dist/config/preview.d.ts +31 -0
  157. package/dist/config/preview.d.ts.map +1 -0
  158. package/dist/config/ref.d.ts +0 -22
  159. package/dist/config/ref.d.ts.map +1 -1
  160. package/dist/config/resolve.d.ts +1 -0
  161. package/dist/config/resolve.d.ts.map +1 -1
  162. package/dist/config/resource-resolution.d.ts +60 -0
  163. package/dist/config/resource-resolution.d.ts.map +1 -0
  164. package/dist/config/schema-bindings.d.ts +693 -0
  165. package/dist/config/schema-bindings.d.ts.map +1 -0
  166. package/dist/config/schema-build.d.ts +67 -0
  167. package/dist/config/schema-build.d.ts.map +1 -0
  168. package/dist/config/schema-env.d.ts +1341 -0
  169. package/dist/config/schema-env.d.ts.map +1 -0
  170. package/dist/config/schema-normalization.d.ts +64 -0
  171. package/dist/config/schema-normalization.d.ts.map +1 -0
  172. package/dist/config/schema-runtime.d.ts +230 -0
  173. package/dist/config/schema-runtime.d.ts.map +1 -0
  174. package/dist/config/schema.d.ts +640 -3669
  175. package/dist/config/schema.d.ts.map +1 -1
  176. package/dist/config-entry.d.ts +5 -0
  177. package/dist/config-entry.d.ts.map +1 -0
  178. package/dist/config-fjwke42y.js +59 -0
  179. package/dist/config-hwdqjse7.js +59 -0
  180. package/dist/config-pxvewrhv.js +59 -0
  181. package/dist/config-q0g5qdga.js +59 -0
  182. package/dist/decorators/durable-object.d.ts.map +1 -1
  183. package/dist/deploy-7nmzc9r8.js +609 -0
  184. package/dist/deploy-csfhdr64.js +691 -0
  185. package/dist/deploy-ex4g5avz.js +621 -0
  186. package/dist/deploy-jnb0bhka.js +609 -0
  187. package/dist/deploy-tp0g6qdp.js +609 -0
  188. package/dist/deploy-ykpcjkc2.js +690 -0
  189. package/dist/{dev-c1xc1gq9.js → dev-2pd33m28.js} +392 -348
  190. package/dist/dev-7ef5e2j1.js +2409 -0
  191. package/dist/dev-8nssqatr.js +2409 -0
  192. package/dist/dev-grznx8fn.js +2409 -0
  193. package/dist/dev-server/d1-migrations.d.ts +14 -0
  194. package/dist/dev-server/d1-migrations.d.ts.map +1 -0
  195. package/dist/dev-server/gateway-script.d.ts +8 -0
  196. package/dist/dev-server/gateway-script.d.ts.map +1 -0
  197. package/dist/dev-server/runtime-stdio.d.ts.map +1 -1
  198. package/dist/dev-server/server.d.ts.map +1 -1
  199. package/dist/dev-server/vite-process.d.ts +14 -0
  200. package/dist/dev-server/vite-process.d.ts.map +1 -0
  201. package/dist/dev-server/vite-utils.d.ts +1 -1
  202. package/dist/dev-server/vite-utils.d.ts.map +1 -1
  203. package/dist/dev-server/worker-source-watcher.d.ts +11 -0
  204. package/dist/dev-server/worker-source-watcher.d.ts.map +1 -0
  205. package/dist/dev-server/worker-surface-paths.d.ts +6 -0
  206. package/dist/dev-server/worker-surface-paths.d.ts.map +1 -0
  207. package/dist/{doctor-z4ffybce.js → doctor-04ammrrh.js} +67 -31
  208. package/dist/doctor-fmjj65mc.js +245 -0
  209. package/dist/doctor-fzkznce1.js +245 -0
  210. package/dist/doctor-sa5xv1bz.js +245 -0
  211. package/dist/index-091sh1ma.js +1229 -0
  212. package/dist/index-0apbm26n.js +788 -0
  213. package/dist/index-0eqksag4.js +418 -0
  214. package/dist/{index-dr6sbp8d.js → index-0kfzdywd.js} +15 -2
  215. package/dist/index-0w826dsr.js +379 -0
  216. package/dist/{index-rfhx0yd5.js → index-11m5a8wd.js} +110 -32
  217. package/dist/{index-xxwbb2nt.js → index-1sp39f2f.js} +114 -58
  218. package/dist/index-2jnrqbny.js +1301 -0
  219. package/dist/index-2pb7b9mw.js +378 -0
  220. package/dist/{index-0kzg8wed.js → index-2x53aqjm.js} +1071 -890
  221. package/dist/index-3ke5d2vn.js +1229 -0
  222. package/dist/index-43dq8yx8.js +788 -0
  223. package/dist/index-4rrttqj5.js +378 -0
  224. package/dist/index-4v9bc2pc.js +1367 -0
  225. package/dist/index-61jsjnsv.js +280 -0
  226. package/dist/index-6jef5emv.js +176 -0
  227. package/dist/index-6psz1h4c.js +788 -0
  228. package/dist/index-72mve6vh.js +168 -0
  229. package/dist/{index-zbvmtcn2.js → index-74198nxd.js} +179 -77
  230. package/dist/index-7g8zyws4.js +192 -0
  231. package/dist/index-7kcxjhta.js +456 -0
  232. package/dist/index-7v583xan.js +418 -0
  233. package/dist/index-7x0ybbtx.js +133 -0
  234. package/dist/index-816krz9p.js +52 -0
  235. package/dist/index-82f1z98k.js +41 -0
  236. package/dist/index-8t5nb4qx.js +133 -0
  237. package/dist/index-9az6s7ad.js +52 -0
  238. package/dist/{index-59df49vn.js → index-9ba1etyz.js} +29 -51
  239. package/dist/{index-001mw014.js → index-9fbtk7gv.js} +134 -248
  240. package/dist/index-9n6djthj.js +490 -0
  241. package/dist/index-aabgympv.js +39 -0
  242. package/dist/index-b8m6883k.js +74 -0
  243. package/dist/{index-5yxg30va.js → index-cgbvmse6.js} +15 -6
  244. package/dist/index-d8etnfef.js +1229 -0
  245. package/dist/index-e9yw4d6y.js +133 -0
  246. package/dist/index-epw1jxz5.js +1204 -0
  247. package/dist/index-f85s8gj3.js +2649 -0
  248. package/dist/index-fe2ngvh7.js +1229 -0
  249. package/dist/index-fvsadj32.js +192 -0
  250. package/dist/index-gs4y9gdf.js +456 -0
  251. package/dist/{index-fef08w43.js → index-h18pxvzs.js} +7 -6
  252. package/dist/index-hfj1a2c4.js +2649 -0
  253. package/dist/{index-8gtqgb3q.js → index-hjy8ctpc.js} +14 -92
  254. package/dist/index-htzf0py1.js +1204 -0
  255. package/dist/index-j185x270.js +897 -0
  256. package/dist/index-jb75kwa4.js +519 -0
  257. package/dist/index-jwd8pcb2.js +897 -0
  258. package/dist/index-k29yjhv0.js +52 -0
  259. package/dist/index-k6vq6kkt.js +456 -0
  260. package/dist/{index-vky23txa.js → index-m3fmw6mx.js} +2 -2
  261. package/dist/index-maxpsfk8.js +402 -0
  262. package/dist/index-mbdmrner.js +402 -0
  263. package/dist/index-mea5bc45.js +418 -0
  264. package/dist/index-mqekt778.js +185 -0
  265. package/dist/index-na3mnm1k.js +74 -0
  266. package/dist/index-p03n4qet.js +1367 -0
  267. package/dist/index-p296ban8.js +191 -0
  268. package/dist/index-pnbs1b8k.js +280 -0
  269. package/dist/index-q4kaz181.js +1207 -0
  270. package/dist/index-ry131z23.js +378 -0
  271. package/dist/index-sgb7c8nm.js +402 -0
  272. package/dist/index-sqrksgb2.js +133 -0
  273. package/dist/index-stgn34cr.js +148 -0
  274. package/dist/{index-v8vvsn9x.js → index-t08te69w.js} +1 -18
  275. package/dist/index-thna1tkd.js +280 -0
  276. package/dist/index-v5nmqthy.js +74 -0
  277. package/dist/{index-n932ytmq.js → index-vt4yxkmf.js} +2 -2
  278. package/dist/index-wyq6c6yj.js +402 -0
  279. package/dist/index-wztc9stx.js +418 -0
  280. package/dist/index-x9cwdxw5.js +456 -0
  281. package/dist/index-xk9djfjp.js +519 -0
  282. package/dist/index-yc0gcchc.js +418 -0
  283. package/dist/index-yqbxjysa.js +897 -0
  284. package/dist/index-yzddwp02.js +788 -0
  285. package/dist/index-zfhq6s96.js +74 -0
  286. package/dist/index-zt22fe2j.js +54 -0
  287. package/dist/index-zyt5byt6.js +2649 -0
  288. package/dist/index.d.ts +2 -2
  289. package/dist/index.d.ts.map +1 -1
  290. package/dist/{init-na2atvz2.js → init-r4hnxan3.js} +24 -17
  291. package/dist/login-2hnz4m4n.js +77 -0
  292. package/dist/login-5bsxxpvc.js +77 -0
  293. package/dist/login-6tzvczw2.js +77 -0
  294. package/dist/login-bhaw72zc.js +77 -0
  295. package/dist/login-x8tgckqm.js +77 -0
  296. package/dist/previews-3rn8mz2c.js +1168 -0
  297. package/dist/previews-d487qde5.js +1200 -0
  298. package/dist/previews-gm3z0syj.js +1168 -0
  299. package/dist/previews-j9ymq4ys.js +1169 -0
  300. package/dist/previews-q031mx34.js +1168 -0
  301. package/dist/productions-120xg0aq.js +505 -0
  302. package/dist/productions-5ev5qweg.js +505 -0
  303. package/dist/productions-me3tdvr9.js +505 -0
  304. package/dist/productions-p5rbgp2f.js +505 -0
  305. package/dist/productions-x9p0pym1.js +505 -0
  306. package/dist/runtime/context-events.d.ts +13 -0
  307. package/dist/runtime/context-events.d.ts.map +1 -0
  308. package/dist/runtime/context-types.d.ts +82 -0
  309. package/dist/runtime/context-types.d.ts.map +1 -0
  310. package/dist/runtime/context.d.ts +6 -267
  311. package/dist/runtime/context.d.ts.map +1 -1
  312. package/dist/runtime/exports.d.ts +3 -3
  313. package/dist/runtime/index.d.ts +1 -1
  314. package/dist/runtime/index.d.ts.map +1 -1
  315. package/dist/runtime/middleware.d.ts +8 -38
  316. package/dist/runtime/middleware.d.ts.map +1 -1
  317. package/dist/src/browser.js +23 -14
  318. package/dist/src/cli/index.js +3 -1
  319. package/dist/src/cloudflare/index.js +49 -2
  320. package/dist/src/config-entry.js +14 -0
  321. package/dist/src/index.js +33 -20
  322. package/dist/src/runtime/index.js +3 -9
  323. package/dist/src/sveltekit/index.js +10 -7
  324. package/dist/src/test/index.js +16 -18
  325. package/dist/src/vite/index.js +7 -4
  326. package/dist/sveltekit/platform.d.ts +1 -1
  327. package/dist/sveltekit/platform.d.ts.map +1 -1
  328. package/dist/test/cf.d.ts +10 -10
  329. package/dist/test/email.d.ts.map +1 -1
  330. package/dist/test/index.d.ts +1 -6
  331. package/dist/test/index.d.ts.map +1 -1
  332. package/dist/test/queue.d.ts.map +1 -1
  333. package/dist/test/remote-ai.d.ts.map +1 -1
  334. package/dist/test/remote-cloudflare.d.ts +13 -0
  335. package/dist/test/remote-cloudflare.d.ts.map +1 -0
  336. package/dist/test/remote-vectorize.d.ts.map +1 -1
  337. package/dist/test/resolve-service-bindings.d.ts.map +1 -1
  338. package/dist/test/scheduled.d.ts.map +1 -1
  339. package/dist/test/should-skip.d.ts +0 -18
  340. package/dist/test/should-skip.d.ts.map +1 -1
  341. package/dist/test/simple-context-durable-objects.d.ts +6 -0
  342. package/dist/test/simple-context-durable-objects.d.ts.map +1 -0
  343. package/dist/test/simple-context-gateway-script.d.ts +2 -0
  344. package/dist/test/simple-context-gateway-script.d.ts.map +1 -0
  345. package/dist/test/simple-context-paths.d.ts +40 -0
  346. package/dist/test/simple-context-paths.d.ts.map +1 -0
  347. package/dist/test/simple-context.d.ts +1 -23
  348. package/dist/test/simple-context.d.ts.map +1 -1
  349. package/dist/test/tail.d.ts.map +1 -1
  350. package/dist/test/worker.d.ts.map +1 -1
  351. package/dist/token-kedhcret.js +419 -0
  352. package/dist/token-m8jmnjwk.js +419 -0
  353. package/dist/{types-sffr9681.js → types-0sqwkp7x.js} +244 -139
  354. package/dist/types-1gwr2ex6.js +572 -0
  355. package/dist/types-6e5yx6km.js +572 -0
  356. package/dist/types-p0gckpn6.js +572 -0
  357. package/dist/utils/send-email.d.ts.map +1 -1
  358. package/dist/vite/config-file.d.ts.map +1 -1
  359. package/dist/vite/plugin.d.ts.map +1 -1
  360. package/dist/worker-0srh2jfr.js +513 -0
  361. package/dist/worker-4xrfd10a.js +513 -0
  362. package/dist/worker-entry/composed-worker.d.ts +0 -7
  363. package/dist/worker-entry/composed-worker.d.ts.map +1 -1
  364. package/dist/worker-entry/surface-paths.d.ts +15 -0
  365. package/dist/worker-entry/surface-paths.d.ts.map +1 -0
  366. package/dist/worker-qtam8grz.js +513 -0
  367. package/dist/worker-qzm0b7br.js +513 -0
  368. package/dist/worker-y9ha6g44.js +513 -0
  369. package/package.json +17 -10
  370. package/R2.md +0 -200
  371. package/dist/account-8psavtg6.js +0 -420
  372. package/dist/build-n639efmn.js +0 -101
  373. package/dist/deploy-zvnq6xh7.js +0 -117
  374. package/dist/index-2q3pmzrx.js +0 -90
  375. package/dist/index-f4q0jbnj.js +0 -195
  376. package/dist/index-n7rs26ft.js +0 -77
  377. package/dist/index-tfyxa77h.js +0 -850
  378. package/dist/index-wyf3s77s.js +0 -343
  379. package/dist/test/multi-worker-context.d.ts +0 -114
  380. package/dist/test/multi-worker-context.d.ts.map +0 -1
@@ -0,0 +1,897 @@
1
+ import {
2
+ discoverRoutes
3
+ } from "./index-1p814k7s.js";
4
+ import {
5
+ DEFAULT_DO_PATTERN,
6
+ findFiles
7
+ } from "./index-rbht7m9r.js";
8
+ import {
9
+ findDurableObjectClasses
10
+ } from "./index-9wt9x09k.js";
11
+ import {
12
+ compileConfig,
13
+ compileToProgrammaticConfig,
14
+ isolateViteBuildOutputPaths,
15
+ rebaseWranglerConfigPaths,
16
+ writeWranglerConfig
17
+ } from "./index-61jsjnsv.js";
18
+ import {
19
+ loadConfig,
20
+ loadResolvedConfig,
21
+ normalizeDOBinding,
22
+ resolveConfigForEnvironment,
23
+ resolveConfigForLocalRuntime,
24
+ resolveConfigPath,
25
+ resolveConfigResources
26
+ } from "./index-43dq8yx8.js";
27
+ import {
28
+ __require
29
+ } from "./index-37x76zdn.js";
30
+
31
+ // src/vite/plugin.ts
32
+ import { isAbsolute, resolve as resolve3 } from "pathe";
33
+
34
+ // src/worker-entry/composed-worker.ts
35
+ import { dirname, relative, resolve as resolve2 } from "pathe";
36
+
37
+ // src/worker-entry/surface-paths.ts
38
+ import { resolve } from "pathe";
39
+ var DEFAULT_FETCH_ENTRY_FILES = [
40
+ "src/fetch.ts",
41
+ "src/fetch.js",
42
+ "src/fetch.mts",
43
+ "src/fetch.mjs"
44
+ ];
45
+ var DEFAULT_QUEUE_ENTRY_FILES = [
46
+ "src/queue.ts",
47
+ "src/queue.js",
48
+ "src/queue.mts",
49
+ "src/queue.mjs"
50
+ ];
51
+ var DEFAULT_SCHEDULED_ENTRY_FILES = [
52
+ "src/scheduled.ts",
53
+ "src/scheduled.js",
54
+ "src/scheduled.mts",
55
+ "src/scheduled.mjs"
56
+ ];
57
+ var DEFAULT_EMAIL_ENTRY_FILES = [
58
+ "src/email.ts",
59
+ "src/email.js",
60
+ "src/email.mts",
61
+ "src/email.mjs"
62
+ ];
63
+ async function resolveWorkerHandlerPath(cwd, configuredPath, defaultEntries, surfaceName = "worker") {
64
+ if (configuredPath === false) {
65
+ return null;
66
+ }
67
+ const fs = await import("node:fs/promises");
68
+ if (typeof configuredPath === "string" && configuredPath) {
69
+ const absolutePath = resolve(cwd, configuredPath);
70
+ try {
71
+ await fs.access(absolutePath);
72
+ return absolutePath;
73
+ } catch {
74
+ throw new Error(`Configured ${surfaceName} handler "${configuredPath}" was not found`);
75
+ }
76
+ }
77
+ for (const defaultEntry of defaultEntries) {
78
+ const absolutePath = resolve(cwd, defaultEntry);
79
+ try {
80
+ await fs.access(absolutePath);
81
+ return absolutePath;
82
+ } catch {
83
+ continue;
84
+ }
85
+ }
86
+ return null;
87
+ }
88
+ async function resolveWorkerSurfacePaths(cwd, config) {
89
+ return {
90
+ fetch: await resolveWorkerHandlerPath(cwd, config.files?.fetch, DEFAULT_FETCH_ENTRY_FILES, "fetch"),
91
+ queue: await resolveWorkerHandlerPath(cwd, config.files?.queue, DEFAULT_QUEUE_ENTRY_FILES, "queue"),
92
+ scheduled: await resolveWorkerHandlerPath(cwd, config.files?.scheduled, DEFAULT_SCHEDULED_ENTRY_FILES, "scheduled"),
93
+ email: await resolveWorkerHandlerPath(cwd, config.files?.email, DEFAULT_EMAIL_ENTRY_FILES, "email")
94
+ };
95
+ }
96
+ function hasWorkerSurfacePaths(surfacePaths) {
97
+ return Object.values(surfacePaths).some((surfacePath) => typeof surfacePath === "string" && surfacePath.length > 0);
98
+ }
99
+
100
+ // src/worker-entry/composed-worker.ts
101
+ function toImportSpecifier(fromFilePath, toFilePath) {
102
+ const specifier = relative(dirname(fromFilePath), toFilePath).replace(/\\/g, "/");
103
+ return specifier.startsWith(".") ? specifier : `./${specifier}`;
104
+ }
105
+ function createGeneratedRouteModuleImports(entryPath, routeDiscovery) {
106
+ if (!routeDiscovery) {
107
+ return [];
108
+ }
109
+ return routeDiscovery.routes.map((route, index) => ({
110
+ identifier: `__devflareRouteModule${index}`,
111
+ importPath: toImportSpecifier(entryPath, route.absolutePath),
112
+ filePath: route.filePath,
113
+ routePath: route.routePath,
114
+ segmentsJson: JSON.stringify(route.segments)
115
+ }));
116
+ }
117
+ async function createGeneratedDurableObjectExports(entryPath, cwd, config) {
118
+ if (config.files?.durableObjects === false || !config.bindings?.durableObjects) {
119
+ return [];
120
+ }
121
+ const localClassNames = new Set(Object.values(config.bindings.durableObjects).map((binding) => normalizeDOBinding(binding)).filter((binding) => !binding.scriptName).map((binding) => binding.className));
122
+ if (localClassNames.size === 0) {
123
+ return [];
124
+ }
125
+ const fs = await import("node:fs/promises");
126
+ const pattern = typeof config.files?.durableObjects === "string" ? config.files.durableObjects : DEFAULT_DO_PATTERN;
127
+ const matchedFiles = await findFiles(pattern, { cwd });
128
+ const exports = [];
129
+ const discoveredClassNames = new Set;
130
+ for (const filePath of matchedFiles) {
131
+ try {
132
+ const code = await fs.readFile(filePath, "utf-8");
133
+ const classNames = findDurableObjectClasses(code).filter((className) => localClassNames.has(className));
134
+ if (classNames.length === 0) {
135
+ continue;
136
+ }
137
+ for (const className of classNames) {
138
+ discoveredClassNames.add(className);
139
+ }
140
+ exports.push({
141
+ importPath: toImportSpecifier(entryPath, filePath),
142
+ filePath,
143
+ classNames
144
+ });
145
+ } catch {
146
+ continue;
147
+ }
148
+ }
149
+ const missingClassNames = Array.from(localClassNames).filter((className) => !discoveredClassNames.has(className));
150
+ if (missingClassNames.length > 0) {
151
+ 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.`);
152
+ }
153
+ return exports;
154
+ }
155
+ function needsComposedWorkerEntrypoint(cwd, surfacePaths, config, routeDiscovery) {
156
+ const hasAdditionalWorkerSurfaces = Boolean(surfacePaths.queue || surfacePaths.scheduled || surfacePaths.email || routeDiscovery?.routes.length);
157
+ if (hasAdditionalWorkerSurfaces) {
158
+ return true;
159
+ }
160
+ if (!surfacePaths.fetch) {
161
+ return false;
162
+ }
163
+ const assetsDirectory = config.assets?.directory;
164
+ if (assetsDirectory) {
165
+ const generatedAssetsWorkerPath = resolve2(cwd, assetsDirectory, "_worker.js");
166
+ if (surfacePaths.fetch === generatedAssetsWorkerPath) {
167
+ return false;
168
+ }
169
+ }
170
+ return Boolean(surfacePaths.fetch);
171
+ }
172
+ function getComposedWorkerEntrypointSource(surfaceImportPaths, configuredLocalSendEmailBindings = {}, durableObjectExports = [], routeImports = [], options = {}) {
173
+ const importLines = [`import { createEmailEvent, createFetchEvent, createQueueEvent, createRouteResolve, createScheduledEvent, invokeFetchModule, matchFetchRoute, runWithEventContext, setLocalSendEmailBindings } from 'devflare/runtime'`];
174
+ const moduleFallbackLines = [];
175
+ const durableObjectExportLines = durableObjectExports.map(({ classNames, importPath }) => `export { ${classNames.join(", ")} } from '${importPath}'`);
176
+ const localSendEmailBindings = JSON.stringify(configuredLocalSendEmailBindings);
177
+ const routeManifestEntries = routeImports.map(({ identifier, filePath, routePath, segmentsJson }) => {
178
+ return ` { filePath: ${JSON.stringify(filePath)}, routePath: ${JSON.stringify(routePath)}, segments: ${segmentsJson}, module: ${identifier} }`;
179
+ });
180
+ const registerSurfaceModule = (identifier, importPath) => {
181
+ if (importPath) {
182
+ importLines.push(`import * as ${identifier} from '${importPath}'`);
183
+ return;
184
+ }
185
+ moduleFallbackLines.push(`const ${identifier} = {}`);
186
+ };
187
+ registerSurfaceModule("__devflareFetchModule", surfaceImportPaths.fetch);
188
+ registerSurfaceModule("__devflareQueueModule", surfaceImportPaths.queue);
189
+ registerSurfaceModule("__devflareScheduledModule", surfaceImportPaths.scheduled);
190
+ registerSurfaceModule("__devflareEmailModule", surfaceImportPaths.email);
191
+ for (const routeImport of routeImports) {
192
+ importLines.push(`import * as ${routeImport.identifier} from '${routeImport.importPath}'`);
193
+ }
194
+ const includeDevInternalEmail = options.devInternalEmail === true;
195
+ const devInternalEmailHelpers = includeDevInternalEmail ? `
196
+ function __devflareCreateEmailHeaders(rawBody) {
197
+ const headers = new Headers()
198
+ const lines = rawBody.split(/\\r?\\n/)
199
+
200
+ for (const line of lines) {
201
+ if (line.trim() === '') {
202
+ break
203
+ }
204
+
205
+ const colonIndex = line.indexOf(':')
206
+ if (colonIndex <= 0) {
207
+ continue
208
+ }
209
+
210
+ headers.append(line.slice(0, colonIndex).trim(), line.slice(colonIndex + 1).trim())
211
+ }
212
+
213
+ return headers
214
+ }
215
+
216
+ function __devflareCreateEmailRawStream(rawBody) {
217
+ return new ReadableStream({
218
+ start(controller) {
219
+ controller.enqueue(new TextEncoder().encode(rawBody))
220
+ controller.close()
221
+ }
222
+ })
223
+ }
224
+
225
+ async function __devflareHandleInternalEmail(request, env, ctx) {
226
+ if (!__devflareEmailHandler) {
227
+ return new Response('Email handler not configured', { status: 501 })
228
+ }
229
+
230
+ const from = request.headers.get('x-devflare-email-from') || 'unknown@example.com'
231
+ const to = request.headers.get('x-devflare-email-to') || 'worker@example.com'
232
+ const rawBody = await request.text()
233
+ const emailMessage = {
234
+ from,
235
+ to,
236
+ headers: __devflareCreateEmailHeaders(rawBody),
237
+ raw: __devflareCreateEmailRawStream(rawBody),
238
+ rawSize: rawBody.length,
239
+ setReject(reason) {
240
+ console.warn('[Devflare email rejected]', reason)
241
+ },
242
+ async forward(rcptTo) {
243
+ console.log('[Devflare email forwarded]', rcptTo)
244
+ return Promise.resolve()
245
+ },
246
+ async reply(message) {
247
+ console.log('[Devflare email reply sent]', message?.from)
248
+ return Promise.resolve()
249
+ }
250
+ }
251
+
252
+ const __devflareEvent = createEmailEvent(emailMessage, env, ctx)
253
+
254
+ await runWithEventContext(
255
+ __devflareEvent,
256
+ () => __devflareEmailHandler(__devflareEvent, env, ctx)
257
+ )
258
+
259
+ return new Response(JSON.stringify({ ok: true, from, to }), {
260
+ headers: { 'Content-Type': 'application/json' }
261
+ })
262
+ }
263
+ ` : "";
264
+ return `
265
+ ${importLines.join(`
266
+ `)}
267
+ ${moduleFallbackLines.join(`
268
+ `)}
269
+ ${durableObjectExportLines.join(`
270
+ `)}
271
+
272
+ setLocalSendEmailBindings(${localSendEmailBindings})
273
+
274
+ const __devflareHasFetchModule = ${surfaceImportPaths.fetch ? "true" : "false"}
275
+ const __devflareRoutes = [
276
+ ${routeManifestEntries.join(`,
277
+ `)}
278
+ ]
279
+ const __devflareHasRoutes = __devflareRoutes.length > 0
280
+
281
+ const __devflareResolveHandler = (module, namedExport) => {
282
+ const defaultExport = module.default
283
+
284
+ if (typeof defaultExport === 'function') {
285
+ return defaultExport
286
+ }
287
+
288
+ if (defaultExport && typeof defaultExport[namedExport] === 'function') {
289
+ return defaultExport[namedExport].bind(defaultExport)
290
+ }
291
+
292
+ if (typeof module[namedExport] === 'function') {
293
+ return module[namedExport]
294
+ }
295
+
296
+ return null
297
+ }
298
+
299
+ const __devflareQueueHandler = __devflareResolveHandler(__devflareQueueModule, 'queue')
300
+ const __devflareScheduledHandler = __devflareResolveHandler(__devflareScheduledModule, 'scheduled')
301
+ const __devflareEmailHandler = __devflareResolveHandler(__devflareEmailModule, 'email')
302
+ ${devInternalEmailHelpers}
303
+
304
+ export default {
305
+ ...(${surfaceImportPaths.fetch || routeImports.length > 0 || includeDevInternalEmail ? "true" : "false"}
306
+ ? {
307
+ async fetch(request, env, ctx) {
308
+ ${includeDevInternalEmail ? `const url = new URL(request.url)
309
+
310
+ if (
311
+ request.headers.get('x-devflare-event') === 'email'
312
+ && url.pathname === '/_devflare/internal/email'
313
+ ) {
314
+ return __devflareHandleInternalEmail(request, env, ctx)
315
+ }
316
+
317
+ ` : ""}const __devflareInitialRouteMatch = __devflareHasRoutes ? matchFetchRoute(__devflareRoutes, request) : null
318
+ const __devflareEvent = createFetchEvent(request, env, ctx, {
319
+ params: __devflareInitialRouteMatch?.params ?? {}
320
+ })
321
+ return runWithEventContext(
322
+ __devflareEvent,
323
+ () => invokeFetchModule(
324
+ __devflareFetchModule,
325
+ __devflareEvent,
326
+ __devflareHasRoutes
327
+ ? createRouteResolve(__devflareRoutes, __devflareEvent)
328
+ : undefined
329
+ )
330
+ )
331
+ }
332
+ }
333
+ : {}),
334
+ ...(__devflareQueueHandler
335
+ ? {
336
+ async queue(batch, env, ctx) {
337
+ const __devflareEvent = createQueueEvent(batch, env, ctx)
338
+ return runWithEventContext(
339
+ __devflareEvent,
340
+ () => __devflareQueueHandler(__devflareEvent, env, ctx)
341
+ )
342
+ }
343
+ }
344
+ : {}),
345
+ ...(__devflareScheduledHandler
346
+ ? {
347
+ async scheduled(controller, env, ctx) {
348
+ const __devflareEvent = createScheduledEvent(controller, env, ctx)
349
+ return runWithEventContext(
350
+ __devflareEvent,
351
+ () => __devflareScheduledHandler(__devflareEvent, env, ctx)
352
+ )
353
+ }
354
+ }
355
+ : {}),
356
+ ...(__devflareEmailHandler
357
+ ? {
358
+ async email(message, env, ctx) {
359
+ const __devflareEvent = createEmailEvent(message, env, ctx)
360
+ return runWithEventContext(
361
+ __devflareEvent,
362
+ () => __devflareEmailHandler(__devflareEvent, env, ctx)
363
+ )
364
+ }
365
+ }
366
+ : {})
367
+ }
368
+ `.trimStart();
369
+ }
370
+ async function prepareComposedWorkerEntrypoint(cwd, config, environment, options = {}) {
371
+ const resolvedConfig = resolveConfigForEnvironment(config, environment);
372
+ if (resolvedConfig.wrangler?.passthrough && Object.prototype.hasOwnProperty.call(resolvedConfig.wrangler.passthrough, "main")) {
373
+ return null;
374
+ }
375
+ const surfacePaths = await resolveWorkerSurfacePaths(cwd, resolvedConfig);
376
+ const routeDiscovery = await discoverRoutes(cwd, resolvedConfig);
377
+ if (!needsComposedWorkerEntrypoint(cwd, surfacePaths, resolvedConfig, routeDiscovery)) {
378
+ return null;
379
+ }
380
+ const fs = await import("node:fs/promises");
381
+ const entryDir = resolve2(cwd, ".devflare", "worker-entrypoints");
382
+ const entryPath = resolve2(entryDir, "main.ts");
383
+ await fs.mkdir(entryDir, { recursive: true });
384
+ const surfaceImportPaths = {
385
+ fetch: surfacePaths.fetch ? toImportSpecifier(entryPath, surfacePaths.fetch) : null,
386
+ queue: surfacePaths.queue ? toImportSpecifier(entryPath, surfacePaths.queue) : null,
387
+ scheduled: surfacePaths.scheduled ? toImportSpecifier(entryPath, surfacePaths.scheduled) : null,
388
+ email: surfacePaths.email ? toImportSpecifier(entryPath, surfacePaths.email) : null
389
+ };
390
+ const durableObjectExports = await createGeneratedDurableObjectExports(entryPath, cwd, resolvedConfig);
391
+ const routeImports = createGeneratedRouteModuleImports(entryPath, routeDiscovery);
392
+ await fs.writeFile(entryPath, getComposedWorkerEntrypointSource(surfaceImportPaths, resolvedConfig.bindings?.sendEmail ?? {}, durableObjectExports, routeImports, options));
393
+ return ".devflare/worker-entrypoints/main.ts";
394
+ }
395
+
396
+ // src/vite/plugin.ts
397
+ var CONFIG_DIR = ".devflare";
398
+ var VIRTUAL_DO_ENTRY = "virtual:devflare-do-entry";
399
+ var RESOLVED_VIRTUAL_DO_ENTRY = "\x00" + VIRTUAL_DO_ENTRY;
400
+ var pluginContext = {
401
+ wranglerConfig: null,
402
+ cloudflareConfig: null,
403
+ projectRoot: process.cwd(),
404
+ auxiliaryWorkerConfig: null,
405
+ durableObjects: null
406
+ };
407
+ function getPluginContext() {
408
+ return pluginContext;
409
+ }
410
+ async function discoverDurableObjects(projectRoot, pattern, workerName) {
411
+ const files = new Map;
412
+ const matchedFiles = await findFiles(pattern, { cwd: projectRoot });
413
+ const fs = await import("node:fs/promises");
414
+ for (const filePath of matchedFiles) {
415
+ try {
416
+ const code = await fs.readFile(filePath, "utf-8");
417
+ const classNames = findDurableObjectClasses(code);
418
+ if (classNames.length > 0) {
419
+ files.set(filePath, classNames);
420
+ }
421
+ } catch (error) {
422
+ console.warn(`[devflare] Failed to read DO file: ${filePath}`, error);
423
+ }
424
+ }
425
+ return { files, workerName };
426
+ }
427
+ function generateVirtualDOEntry(discovery) {
428
+ const lines = [
429
+ "// Auto-generated by devflare — DO entry module",
430
+ "// Re-exports all Durable Object classes discovered from files.durableObjects pattern",
431
+ ""
432
+ ];
433
+ for (const [filePath, classNames] of discovery.files) {
434
+ const normalizedPath = filePath.replace(/\\/g, "/");
435
+ lines.push(`export { ${classNames.join(", ")} } from '${normalizedPath}'`);
436
+ }
437
+ lines.push("");
438
+ lines.push("// Default fetch handler for DO worker");
439
+ lines.push("export default {");
440
+ lines.push("\tasync fetch(request: Request): Promise<Response> {");
441
+ lines.push('\t\treturn new Response("Devflare DO Worker", { status: 200 })');
442
+ lines.push("\t}");
443
+ lines.push("}");
444
+ return lines.join(`
445
+ `);
446
+ }
447
+ function createAuxiliaryWorkerConfig(wranglerConfig, discovery) {
448
+ const doBindings = wranglerConfig.durable_objects?.bindings?.map((binding) => ({
449
+ name: binding.name,
450
+ class_name: binding.class_name
451
+ })) ?? [];
452
+ return {
453
+ config: {
454
+ name: discovery.workerName,
455
+ main: VIRTUAL_DO_ENTRY,
456
+ compatibility_date: wranglerConfig.compatibility_date,
457
+ compatibility_flags: wranglerConfig.compatibility_flags,
458
+ durable_objects: { bindings: doBindings },
459
+ migrations: wranglerConfig.migrations,
460
+ kv_namespaces: wranglerConfig.kv_namespaces,
461
+ d1_databases: wranglerConfig.d1_databases,
462
+ r2_buckets: wranglerConfig.r2_buckets,
463
+ browser: wranglerConfig.browser
464
+ }
465
+ };
466
+ }
467
+ function logDiscoveredDurableObjects(projectRoot, discovery) {
468
+ if (!discovery || discovery.files.size === 0) {
469
+ return;
470
+ }
471
+ console.log(`[devflare] Discovered ${discovery.files.size} DO file(s):`);
472
+ for (const [filePath, classes] of discovery.files) {
473
+ console.log(` • ${filePath.replace(projectRoot, ".")} → ${classes.join(", ")}`);
474
+ }
475
+ }
476
+ async function buildPluginContextState(projectRoot, devflareConfig, environment, mode = "serve") {
477
+ const effectiveConfig = mode === "build" ? await resolveConfigResources(devflareConfig, { environment }) : resolveConfigForLocalRuntime(devflareConfig, environment);
478
+ const compiledWranglerConfig = compileConfig(effectiveConfig);
479
+ const wranglerConfig = mode === "build" ? isolateViteBuildOutputPaths(projectRoot, compiledWranglerConfig) : compiledWranglerConfig;
480
+ const cloudflareConfig = {
481
+ ...mode === "build" ? isolateViteBuildOutputPaths(projectRoot, compileToProgrammaticConfig(effectiveConfig)) : compileToProgrammaticConfig(effectiveConfig)
482
+ };
483
+ const composedMainEntry = mode === "build" ? null : await prepareComposedWorkerEntrypoint(projectRoot, effectiveConfig, environment);
484
+ if (composedMainEntry) {
485
+ wranglerConfig.main = composedMainEntry;
486
+ cloudflareConfig.main = composedMainEntry;
487
+ }
488
+ let durableObjects = null;
489
+ let auxiliaryWorkerConfig = null;
490
+ const doPatternConfig = effectiveConfig.files?.durableObjects;
491
+ const doPattern = typeof doPatternConfig === "string" ? doPatternConfig : DEFAULT_DO_PATTERN;
492
+ if (doPatternConfig !== false) {
493
+ const doWorkerName = `${wranglerConfig.name}-do`;
494
+ const discovery = await discoverDurableObjects(projectRoot, doPattern, doWorkerName);
495
+ if (discovery.files.size > 0) {
496
+ durableObjects = discovery;
497
+ if (wranglerConfig.durable_objects?.bindings) {
498
+ for (const binding of wranglerConfig.durable_objects.bindings) {
499
+ binding.script_name = doWorkerName;
500
+ }
501
+ }
502
+ if (cloudflareConfig.durable_objects) {
503
+ const doConfig = cloudflareConfig.durable_objects;
504
+ for (const binding of doConfig.bindings) {
505
+ binding.script_name = doWorkerName;
506
+ }
507
+ }
508
+ auxiliaryWorkerConfig = createAuxiliaryWorkerConfig(wranglerConfig, discovery);
509
+ }
510
+ }
511
+ return {
512
+ wranglerConfig,
513
+ cloudflareConfig,
514
+ durableObjects,
515
+ auxiliaryWorkerConfig
516
+ };
517
+ }
518
+ async function ensureGeneratedConfigDir(projectRoot) {
519
+ const configDir = resolve3(projectRoot, CONFIG_DIR);
520
+ const fs = await import("node:fs/promises");
521
+ await fs.mkdir(configDir, { recursive: true });
522
+ const gitignorePath = resolve3(configDir, ".gitignore");
523
+ try {
524
+ await fs.access(gitignorePath);
525
+ } catch {
526
+ await fs.writeFile(gitignorePath, `*
527
+ `, "utf-8");
528
+ }
529
+ return configDir;
530
+ }
531
+ async function writeGeneratedWranglerConfig(projectRoot, wranglerConfig) {
532
+ const configDir = await ensureGeneratedConfigDir(projectRoot);
533
+ const wranglerFileConfig = rebaseWranglerConfigPaths(projectRoot, configDir, wranglerConfig);
534
+ await writeWranglerConfig(configDir, wranglerFileConfig, "wrangler.jsonc");
535
+ }
536
+ async function resolvePluginConfigPath(projectRoot, configPath) {
537
+ if (configPath) {
538
+ return isAbsolute(configPath) ? configPath : resolve3(projectRoot, configPath);
539
+ }
540
+ return await resolveConfigPath(projectRoot) ?? null;
541
+ }
542
+ function devflarePlugin(options = {}) {
543
+ const {
544
+ configPath,
545
+ environment,
546
+ doTransforms = true,
547
+ watchConfig = true,
548
+ bridgePort = process.env.DEVFLARE_BRIDGE_PORT ? parseInt(process.env.DEVFLARE_BRIDGE_PORT, 10) : undefined,
549
+ wsProxyPatterns = []
550
+ } = options;
551
+ let projectRoot;
552
+ let devflareConfig;
553
+ let resolvedPluginConfigPath = null;
554
+ return {
555
+ name: "devflare",
556
+ enforce: "pre",
557
+ async config(config, { command }) {
558
+ const cwd = config.root ?? process.cwd();
559
+ const returnConfig = {};
560
+ let lfConfig = null;
561
+ try {
562
+ lfConfig = await loadConfig({
563
+ cwd,
564
+ configFile: configPath
565
+ });
566
+ } catch (error) {
567
+ if (command === "build") {
568
+ console.warn("[devflare] Could not load config:", error);
569
+ }
570
+ }
571
+ if (lfConfig) {
572
+ const workerNameValue = lfConfig.name ?? "unknown";
573
+ returnConfig.define = {
574
+ ...config.define ?? {},
575
+ __DEVFLARE_WORKER_NAME__: JSON.stringify(workerNameValue)
576
+ };
577
+ }
578
+ if (command === "serve" && process.env.DEVFLARE_DEV && lfConfig) {
579
+ const port = bridgePort ?? 8787;
580
+ const patterns = [...wsProxyPatterns];
581
+ if (lfConfig.wsRoutes && lfConfig.wsRoutes.length > 0) {
582
+ for (const route of lfConfig.wsRoutes) {
583
+ if (!patterns.includes(route.pattern)) {
584
+ patterns.push(route.pattern);
585
+ }
586
+ }
587
+ }
588
+ const proxyConfig = {};
589
+ for (const pattern of patterns) {
590
+ proxyConfig[pattern] = {
591
+ target: `http://127.0.0.1:${port}`,
592
+ changeOrigin: true,
593
+ ws: true,
594
+ configure: (proxy) => {
595
+ proxy.on("error", (err) => {
596
+ console.error(`[devflare] Proxy error: ${err.message}`);
597
+ });
598
+ }
599
+ };
600
+ }
601
+ if (Object.keys(proxyConfig).length > 0) {
602
+ console.log(`[devflare] WebSocket proxy configured for: ${patterns.join(", ")}`);
603
+ returnConfig.server = {
604
+ proxy: proxyConfig
605
+ };
606
+ }
607
+ }
608
+ return Object.keys(returnConfig).length > 0 ? returnConfig : undefined;
609
+ },
610
+ resolveId(id) {
611
+ if (id === VIRTUAL_DO_ENTRY) {
612
+ return RESOLVED_VIRTUAL_DO_ENTRY;
613
+ }
614
+ return null;
615
+ },
616
+ async load(id) {
617
+ if (id === RESOLVED_VIRTUAL_DO_ENTRY) {
618
+ if (!pluginContext.durableObjects) {
619
+ return `// No Durable Objects configured
620
+ export default { fetch: () => new Response("No DOs") }`;
621
+ }
622
+ return generateVirtualDOEntry(pluginContext.durableObjects);
623
+ }
624
+ return null;
625
+ },
626
+ async configResolved(config) {
627
+ projectRoot = config.root;
628
+ pluginContext.projectRoot = projectRoot;
629
+ resolvedPluginConfigPath = await resolvePluginConfigPath(projectRoot, configPath);
630
+ try {
631
+ devflareConfig = await loadConfig({
632
+ cwd: projectRoot,
633
+ configFile: configPath
634
+ });
635
+ const pluginState = await buildPluginContextState(projectRoot, devflareConfig, environment, config.command === "build" ? "build" : "serve");
636
+ Object.assign(pluginContext, {
637
+ projectRoot,
638
+ ...pluginState
639
+ });
640
+ logDiscoveredDurableObjects(projectRoot, pluginState.durableObjects);
641
+ await writeGeneratedWranglerConfig(projectRoot, pluginState.wranglerConfig);
642
+ if (config.command === "serve") {
643
+ console.log("[devflare] Config generated to .devflare/wrangler.jsonc");
644
+ if (pluginState.auxiliaryWorkerConfig) {
645
+ console.log("[devflare] ✓ Auxiliary DO worker configured");
646
+ }
647
+ }
648
+ if (config.command === "build") {
649
+ console.log(`[devflare] Generated ${CONFIG_DIR}/wrangler.jsonc`);
650
+ }
651
+ } catch (error) {
652
+ if (error instanceof Error) {
653
+ console.error("[devflare] Config error:", error.message);
654
+ }
655
+ throw error;
656
+ }
657
+ },
658
+ configureServer(server) {
659
+ if (!watchConfig)
660
+ return;
661
+ const fullConfigPath = resolvedPluginConfigPath ?? resolve3(projectRoot, configPath || "devflare.config.ts");
662
+ server.watcher.add(fullConfigPath);
663
+ server.watcher.on("change", async (changedPath) => {
664
+ if (changedPath === fullConfigPath) {
665
+ console.log("[devflare] Config changed, reloading...");
666
+ try {
667
+ devflareConfig = await loadConfig({
668
+ cwd: projectRoot,
669
+ configFile: configPath
670
+ });
671
+ const pluginState = await buildPluginContextState(projectRoot, devflareConfig, environment, "serve");
672
+ Object.assign(pluginContext, {
673
+ projectRoot,
674
+ ...pluginState
675
+ });
676
+ logDiscoveredDurableObjects(projectRoot, pluginState.durableObjects);
677
+ await writeGeneratedWranglerConfig(projectRoot, pluginState.wranglerConfig);
678
+ console.log("[devflare] Config reloaded");
679
+ server.ws.send({
680
+ type: "full-reload",
681
+ path: "*"
682
+ });
683
+ } catch (error) {
684
+ console.error("[devflare] Failed to reload config:", error);
685
+ }
686
+ }
687
+ });
688
+ },
689
+ async transform(code, id) {
690
+ if (id.includes("node_modules"))
691
+ return null;
692
+ if (!id.endsWith(".ts") && !id.endsWith(".tsx") && !id.endsWith(".js")) {
693
+ return null;
694
+ }
695
+ if (id.endsWith("worker.ts") || id.endsWith("worker.js")) {
696
+ const {
697
+ shouldTransformWorker,
698
+ transformWorkerEntrypoint
699
+ } = await import("./worker-entrypoint-c259fmfs.js");
700
+ if (shouldTransformWorker(code, id)) {
701
+ const result = transformWorkerEntrypoint(code, id);
702
+ if (result) {
703
+ return {
704
+ code: result.code,
705
+ map: result.map
706
+ };
707
+ }
708
+ }
709
+ }
710
+ if (doTransforms) {
711
+ if (code.includes("DurableObject") || code.includes("@durableObject")) {
712
+ const { transformDurableObject } = await import("./durable-object-yt8v1dyn.js");
713
+ return transformDurableObject(code, id);
714
+ }
715
+ }
716
+ return null;
717
+ }
718
+ };
719
+ }
720
+ async function getCloudflareConfig(options = {}) {
721
+ const cwd = options.cwd ?? process.cwd();
722
+ const devflareConfig = await loadResolvedConfig({
723
+ cwd,
724
+ configFile: options.configPath,
725
+ environment: options.environment
726
+ });
727
+ const composedMainEntry = await prepareComposedWorkerEntrypoint(cwd, devflareConfig);
728
+ const cloudflareConfig = compileToProgrammaticConfig(devflareConfig);
729
+ if (composedMainEntry) {
730
+ cloudflareConfig.main = composedMainEntry;
731
+ }
732
+ return cloudflareConfig;
733
+ }
734
+ async function getDevflareConfigs(options = {}) {
735
+ const cwd = options.cwd ?? process.cwd();
736
+ const devflareConfig = await loadResolvedConfig({
737
+ cwd,
738
+ configFile: options.configPath,
739
+ environment: options.environment
740
+ });
741
+ const composedMainEntry = await prepareComposedWorkerEntrypoint(cwd, devflareConfig);
742
+ const wranglerConfig = compileConfig(devflareConfig);
743
+ const cloudflareConfig = { ...wranglerConfig };
744
+ if (composedMainEntry) {
745
+ wranglerConfig.main = composedMainEntry;
746
+ cloudflareConfig.main = composedMainEntry;
747
+ }
748
+ const auxiliaryWorkers = [];
749
+ const doPatternConfig = devflareConfig.files?.durableObjects;
750
+ const doPattern = typeof doPatternConfig === "string" ? doPatternConfig : DEFAULT_DO_PATTERN;
751
+ if (doPatternConfig !== false) {
752
+ const doWorkerName = `${wranglerConfig.name}-do`;
753
+ const discovery = await discoverDurableObjects(cwd, doPattern, doWorkerName);
754
+ if (discovery.files.size > 0) {
755
+ if (cloudflareConfig.durable_objects) {
756
+ const doConfig = cloudflareConfig.durable_objects;
757
+ for (const binding of doConfig.bindings) {
758
+ binding.script_name = doWorkerName;
759
+ }
760
+ }
761
+ auxiliaryWorkers.push(createAuxiliaryWorkerConfig(wranglerConfig, discovery));
762
+ }
763
+ }
764
+ return { cloudflareConfig, auxiliaryWorkers };
765
+ }
766
+ // src/vite/config-file.ts
767
+ var CONFIG_DIR2 = ".devflare";
768
+ var GENERATED_VITE_CONFIG_FILENAME = "vite.config.mjs";
769
+ function hasInlineViteConfig(viteConfig) {
770
+ return Boolean(viteConfig && Object.keys(viteConfig).length > 0);
771
+ }
772
+ function resolveEffectiveViteProject(detection, config, environment) {
773
+ const resolvedConfig = resolveConfigForEnvironment(config, environment);
774
+ const hasDevflareConfig = hasInlineViteConfig(resolvedConfig.vite);
775
+ return {
776
+ ...detection,
777
+ hasDevflareViteConfig: hasDevflareConfig,
778
+ shouldStartVite: detection.shouldStartVite || hasDevflareConfig,
779
+ wantsViteIntegration: detection.wantsViteIntegration || hasDevflareConfig
780
+ };
781
+ }
782
+ function isPromiseLike(value) {
783
+ return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
784
+ }
785
+ function normalizePluginOptions(pluginOption) {
786
+ if (typeof pluginOption === "undefined") {
787
+ return [];
788
+ }
789
+ return Array.isArray(pluginOption) ? pluginOption : [pluginOption];
790
+ }
791
+ function removePluginByName(pluginOption, pluginName) {
792
+ if (Array.isArray(pluginOption)) {
793
+ const filteredPlugins = pluginOption.map((nestedPlugin) => removePluginByName(nestedPlugin, pluginName)).filter((nestedPlugin) => typeof nestedPlugin !== "undefined");
794
+ return filteredPlugins.length > 0 ? filteredPlugins : undefined;
795
+ }
796
+ if (!pluginOption || typeof pluginOption === "boolean" || isPromiseLike(pluginOption)) {
797
+ return pluginOption;
798
+ }
799
+ return pluginOption.name === pluginName ? undefined : pluginOption;
800
+ }
801
+ function withInjectedDevflarePlugin(config, pluginOptions) {
802
+ const existingPlugins = normalizePluginOptions(config.plugins).map((pluginOption) => removePluginByName(pluginOption, "devflare")).filter((pluginOption) => typeof pluginOption !== "undefined");
803
+ return {
804
+ ...config,
805
+ plugins: [devflarePlugin(pluginOptions), ...existingPlugins]
806
+ };
807
+ }
808
+ async function resolveViteUserConfig(configEnv, options = {}) {
809
+ const { loadConfigFromFile, mergeConfig } = await import("vite");
810
+ const cwd = options.cwd ?? process.cwd();
811
+ const devflareConfig = await loadConfig({
812
+ cwd,
813
+ configFile: options.configPath
814
+ });
815
+ const resolvedDevflareConfig = resolveConfigForEnvironment(devflareConfig, options.environment);
816
+ const inlineViteConfig = resolvedDevflareConfig.vite ?? {};
817
+ const localConfig = options.localConfigPath ? (await loadConfigFromFile(configEnv, options.localConfigPath, cwd))?.config ?? {} : {};
818
+ const mergedConfig = mergeConfig(localConfig, inlineViteConfig);
819
+ const normalizedConfig = mergedConfig.root ? mergedConfig : {
820
+ ...mergedConfig,
821
+ root: cwd
822
+ };
823
+ return withInjectedDevflarePlugin(normalizedConfig, {
824
+ configPath: options.configPath,
825
+ environment: options.environment,
826
+ bridgePort: options.bridgePort
827
+ });
828
+ }
829
+ async function ensureGeneratedConfigDir2(cwd) {
830
+ const fs = await import("node:fs/promises");
831
+ const { resolve: resolve4 } = await import("pathe");
832
+ const configDir = resolve4(cwd, CONFIG_DIR2);
833
+ await fs.mkdir(configDir, { recursive: true });
834
+ const gitignorePath = resolve4(configDir, ".gitignore");
835
+ try {
836
+ await fs.access(gitignorePath);
837
+ } catch {
838
+ await fs.writeFile(gitignorePath, `*
839
+ `, "utf-8");
840
+ }
841
+ return configDir;
842
+ }
843
+ async function resolveDevflarePackageRoot(currentFilePath) {
844
+ const fs = await import("node:fs/promises");
845
+ const { dirname: dirname2 } = await import("node:path");
846
+ const { resolve: resolve4 } = await import("pathe");
847
+ let currentDir = dirname2(currentFilePath);
848
+ while (true) {
849
+ const packageJsonPath = resolve4(currentDir, "package.json");
850
+ try {
851
+ const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
852
+ if (packageJson.name === "devflare") {
853
+ return currentDir;
854
+ }
855
+ } catch {}
856
+ const parentDir = dirname2(currentDir);
857
+ if (parentDir === currentDir) {
858
+ break;
859
+ }
860
+ currentDir = parentDir;
861
+ }
862
+ throw new Error("Could not resolve the devflare package root for generated Vite config imports.");
863
+ }
864
+ async function resolveGeneratedViteImportPath(configDir) {
865
+ const { extname, sep } = await import("node:path");
866
+ const { fileURLToPath } = await import("node:url");
867
+ const { relative: relative3, resolve: resolve4 } = await import("pathe");
868
+ const currentFilePath = fileURLToPath(import.meta.url);
869
+ const currentExtension = extname(currentFilePath);
870
+ const packageRoot = await resolveDevflarePackageRoot(currentFilePath);
871
+ const viteEntryPath = currentFilePath.includes(`${sep}dist${sep}`) ? resolve4(packageRoot, "dist/src/vite/index.js") : resolve4(packageRoot, `src/vite/index${currentExtension}`);
872
+ const relativeImportPath = relative3(configDir, viteEntryPath);
873
+ return relativeImportPath.startsWith(".") ? relativeImportPath : `./${relativeImportPath}`;
874
+ }
875
+ async function writeGeneratedViteConfig(options) {
876
+ const fs = await import("node:fs/promises");
877
+ const { resolve: resolve4 } = await import("pathe");
878
+ const configDir = await ensureGeneratedConfigDir2(options.cwd);
879
+ const generatedConfigPath = resolve4(configDir, GENERATED_VITE_CONFIG_FILENAME);
880
+ const viteImportPath = await resolveGeneratedViteImportPath(configDir);
881
+ const content = `import { defineConfig } from 'vite'
882
+ import { resolveViteUserConfig } from ${JSON.stringify(viteImportPath)}
883
+
884
+ export default defineConfig(async (env) => {
885
+ return await resolveViteUserConfig(env, {
886
+ cwd: ${JSON.stringify(options.cwd)},
887
+ configPath: ${JSON.stringify(options.configPath)},
888
+ environment: ${JSON.stringify(options.environment)},
889
+ localConfigPath: ${JSON.stringify(options.localConfigPath)},
890
+ bridgePort: ${JSON.stringify(options.bridgePort)}
891
+ })
892
+ })
893
+ `;
894
+ await fs.writeFile(generatedConfigPath, content, "utf-8");
895
+ return generatedConfigPath;
896
+ }
897
+ export { DEFAULT_FETCH_ENTRY_FILES, DEFAULT_QUEUE_ENTRY_FILES, DEFAULT_SCHEDULED_ENTRY_FILES, DEFAULT_EMAIL_ENTRY_FILES, resolveWorkerSurfacePaths, hasWorkerSurfacePaths, prepareComposedWorkerEntrypoint, getPluginContext, devflarePlugin, getCloudflareConfig, getDevflareConfigs, hasInlineViteConfig, resolveEffectiveViteProject, resolveViteUserConfig, writeGeneratedViteConfig };