devflare 1.0.0-next.39 → 1.0.0-next.40

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 (277) hide show
  1. package/dist/_chunks/account-BtWcv3X9.js +462 -0
  2. package/dist/_chunks/account-resources-CsmVowJp.js +159 -0
  3. package/dist/_chunks/ai-CBEuLdoP.js +322 -0
  4. package/dist/_chunks/api-TzdliH-6.js +568 -0
  5. package/dist/_chunks/build-3T6O4uIg.js +24 -0
  6. package/dist/_chunks/build-artifacts-8TqBSQkG.js +483 -0
  7. package/dist/_chunks/cli-BTF1X4SG.js +1128 -0
  8. package/dist/_chunks/cloudflare-BaloqI3H.js +157 -0
  9. package/dist/_chunks/colors-DiK6wPJ5.js +13 -0
  10. package/dist/_chunks/command-utils-BsfkmTqh.js +45 -0
  11. package/dist/_chunks/compiler-uoyAQ8zW.js +424 -0
  12. package/dist/_chunks/config-D5u-bEkn.js +78 -0
  13. package/dist/_chunks/config-path-DCPto4XB.js +42 -0
  14. package/dist/_chunks/context-CX50Y2Kb.js +2250 -0
  15. package/dist/_chunks/decorators-QmV57ixr.js +19 -0
  16. package/dist/_chunks/dependencies-C2oxFjU_.js +57 -0
  17. package/dist/_chunks/deploy-DMTr6JeR.js +915 -0
  18. package/dist/_chunks/dev-CvRHmRFZ.js +3456 -0
  19. package/dist/_chunks/doctor-DIG8DoFU.js +219 -0
  20. package/dist/_chunks/durable-object-DMtH0XYX.js +234 -0
  21. package/dist/_chunks/env-S0_nMVz1.js +125 -0
  22. package/dist/_chunks/family-DXC5SdFK.js +143 -0
  23. package/dist/_chunks/generated-artifacts-dMJY4KAt.js +32 -0
  24. package/dist/_chunks/glob-CmQOvunB.js +56 -0
  25. package/dist/_chunks/init-3moXTgpb.js +165 -0
  26. package/dist/_chunks/loader-DLXO60RO.js +1153 -0
  27. package/dist/_chunks/local-dev-vars-CTSa-wvF.js +81 -0
  28. package/dist/_chunks/local-hyperdrive-CJ90j46O.js +119 -0
  29. package/dist/_chunks/local-media-bindings-DsAW4AMF.js +335 -0
  30. package/dist/_chunks/local-secrets-DMmEOygL.js +123 -0
  31. package/dist/_chunks/local-workflow-entrypoints-Wip3o1u8.js +90 -0
  32. package/dist/_chunks/login-BmnDzDlH.js +51 -0
  33. package/dist/_chunks/package-metadata-DAuCkyvK.js +39 -0
  34. package/dist/_chunks/preferences-BKp_7XJx.js +241 -0
  35. package/dist/_chunks/preview-BhqDmq8I.js +456 -0
  36. package/dist/_chunks/preview-registry-ClAbLTHH.js +1186 -0
  37. package/dist/_chunks/preview-resources-DdXj8LMM.js +358 -0
  38. package/dist/_chunks/previews-Dlr13x5M.js +1134 -0
  39. package/dist/_chunks/productions-D3AnOHac.js +411 -0
  40. package/dist/_chunks/ref-CYJNAAe_.js +178 -0
  41. package/dist/_chunks/remote-CZnP-HLJ.js +79 -0
  42. package/dist/_chunks/remote-config-D39BY9ji.js +132 -0
  43. package/dist/_chunks/resolve-package-Y84HB3Nt.js +133 -0
  44. package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
  45. package/dist/_chunks/routes-C3FqES2W.js +796 -0
  46. package/dist/_chunks/runtime-FvXvfuZ2.js +550 -0
  47. package/dist/_chunks/schema-normalization-DWVleVxo.js +477 -0
  48. package/dist/_chunks/secrets-70eN0Q6C.js +95 -0
  49. package/dist/_chunks/token-kguIDmej.js +333 -0
  50. package/dist/_chunks/tokens-iVcgNXi-.js +221 -0
  51. package/dist/_chunks/types-OrLbzv4I.js +476 -0
  52. package/dist/_chunks/ui-BUoZApvE.js +103 -0
  53. package/dist/_chunks/usage-BBTGzjon.js +272 -0
  54. package/dist/_chunks/vite-CsI0E-uV.js +1235 -0
  55. package/dist/_chunks/vite-utils-OVLMV605.js +183 -0
  56. package/dist/_chunks/worker-CS1jgNFE.js +410 -0
  57. package/dist/_chunks/worker-bundler-dTTnYU3n.js +458 -0
  58. package/dist/_chunks/worker-entrypoint-CQW77lG8.js +247 -0
  59. package/dist/_chunks/workerName-CFJsLZA-.js +23 -0
  60. package/dist/bridge/index.d.ts +6 -6
  61. package/dist/bridge/miniflare.d.ts +2 -2
  62. package/dist/bridge/proxy.d.ts +1 -1
  63. package/dist/bridge/v2/body-streams.d.ts +1 -1
  64. package/dist/bridge/v2/codec.d.ts +4 -4
  65. package/dist/bridge/v2/index.d.ts +10 -10
  66. package/dist/bridge/v2/serialization.d.ts +1 -1
  67. package/dist/bridge/v2/value-codec.d.ts +1 -1
  68. package/dist/bridge/v2/value-serialization.d.ts.map +1 -1
  69. package/dist/bridge/v2/ws-relay.d.ts +3 -3
  70. package/dist/browser-shim/index.d.ts +2 -2
  71. package/dist/browser.d.ts +70 -70
  72. package/dist/browser.js +74 -2462
  73. package/dist/bundler/do-bundler.d.ts +1 -1
  74. package/dist/bundler/index.d.ts +3 -3
  75. package/dist/bundler/rolldown-shared.d.ts +1 -1
  76. package/dist/bundler/worker-bundler.d.ts +1 -1
  77. package/dist/cli/build-manifest.d.ts +1 -1
  78. package/dist/cli/command-utils.d.ts +1 -1
  79. package/dist/cli/commands/account.d.ts +1 -1
  80. package/dist/cli/commands/ai.d.ts +1 -1
  81. package/dist/cli/commands/build-artifacts.d.ts +5 -5
  82. package/dist/cli/commands/build.d.ts +1 -1
  83. package/dist/cli/commands/config.d.ts +1 -1
  84. package/dist/cli/commands/deploy/prepare.d.ts +2 -2
  85. package/dist/cli/commands/deploy/runtime.d.ts +1 -1
  86. package/dist/cli/commands/deploy/verification.d.ts +1 -1
  87. package/dist/cli/commands/deploy.d.ts +1 -1
  88. package/dist/cli/commands/dev.d.ts +1 -1
  89. package/dist/cli/commands/doctor.d.ts +1 -1
  90. package/dist/cli/commands/init.d.ts +1 -1
  91. package/dist/cli/commands/login.d.ts +1 -1
  92. package/dist/cli/commands/previews-support/cleanup.d.ts +1 -1
  93. package/dist/cli/commands/previews-support/family.d.ts +3 -3
  94. package/dist/cli/commands/previews-support/render.d.ts +3 -3
  95. package/dist/cli/commands/previews-support/theme.d.ts +2 -2
  96. package/dist/cli/commands/previews-support/types.d.ts +2 -2
  97. package/dist/cli/commands/previews.d.ts +1 -1
  98. package/dist/cli/commands/productions.d.ts +1 -1
  99. package/dist/cli/commands/remote.d.ts +1 -1
  100. package/dist/cli/commands/secrets.d.ts +1 -1
  101. package/dist/cli/commands/token.d.ts +1 -1
  102. package/dist/cli/commands/type-generation/discovery.d.ts +2 -2
  103. package/dist/cli/commands/type-generation/generator.d.ts +3 -3
  104. package/dist/cli/commands/type-generation/models.d.ts +1 -1
  105. package/dist/cli/commands/types.d.ts +1 -1
  106. package/dist/cli/commands/worker.d.ts +1 -1
  107. package/dist/cli/deploy-strategy.d.ts +1 -1
  108. package/dist/cli/deploy-target.d.ts +1 -1
  109. package/dist/cli/help-pages/pages/account.d.ts +1 -1
  110. package/dist/cli/help-pages/pages/core.d.ts +1 -1
  111. package/dist/cli/help-pages/pages/index.d.ts +1 -1
  112. package/dist/cli/help-pages/pages/misc.d.ts +1 -1
  113. package/dist/cli/help-pages/pages/previews.d.ts +1 -1
  114. package/dist/cli/help-pages/pages/productions.d.ts +1 -1
  115. package/dist/cli/help-pages/render.d.ts +2 -2
  116. package/dist/cli/help-pages/shared.d.ts +1 -1
  117. package/dist/cli/help.d.ts +2 -2
  118. package/dist/cli/index.js +2 -1383
  119. package/dist/cli/preview-bindings.d.ts +3 -3
  120. package/dist/cli/preview.d.ts +1 -1
  121. package/dist/cli/wrangler-auth.d.ts +1 -1
  122. package/dist/cloudflare/account-core.d.ts +2 -2
  123. package/dist/cloudflare/account-resources.d.ts +2 -2
  124. package/dist/cloudflare/account-status.d.ts +1 -1
  125. package/dist/cloudflare/account-workers.d.ts +2 -2
  126. package/dist/cloudflare/account.d.ts +7 -7
  127. package/dist/cloudflare/auth.d.ts +1 -1
  128. package/dist/cloudflare/index.d.ts +13 -13
  129. package/dist/cloudflare/index.js +4 -59
  130. package/dist/cloudflare/kv-namespace.d.ts +1 -1
  131. package/dist/cloudflare/preview-registry-cache.d.ts +1 -1
  132. package/dist/cloudflare/preview-registry-inference.d.ts +2 -2
  133. package/dist/cloudflare/preview-registry-records.d.ts +3 -3
  134. package/dist/cloudflare/preview-registry-shape.d.ts +2 -2
  135. package/dist/cloudflare/preview-registry-store.d.ts +3 -3
  136. package/dist/cloudflare/preview-registry-transport.d.ts +2 -2
  137. package/dist/cloudflare/preview-registry-types.d.ts +2 -2
  138. package/dist/cloudflare/preview-registry.d.ts +5 -5
  139. package/dist/cloudflare/tokens.d.ts +2 -2
  140. package/dist/cloudflare/usage.d.ts +2 -2
  141. package/dist/config/binding-resolution-helpers.d.ts +1 -1
  142. package/dist/config/compiler/bindings.d.ts +2 -2
  143. package/dist/config/compiler/core-helpers.d.ts +2 -2
  144. package/dist/config/compiler/do-workers.d.ts +2 -2
  145. package/dist/config/compiler/paths.d.ts +1 -1
  146. package/dist/config/compiler.d.ts +6 -6
  147. package/dist/config/define.d.ts +2 -2
  148. package/dist/config/deploy-resources.d.ts +5 -5
  149. package/dist/config/env-vars.d.ts +1 -1
  150. package/dist/config/framework-providers.d.ts +1 -1
  151. package/dist/config/index.d.ts +12 -12
  152. package/dist/config/loader.d.ts +2 -2
  153. package/dist/config/local-dev-vars.d.ts +1 -1
  154. package/dist/config/preview-resources.d.ts +4 -4
  155. package/dist/config/preview.d.ts +1 -1
  156. package/dist/config/ref.d.ts +2 -2
  157. package/dist/config/resolve-phased.d.ts +4 -4
  158. package/dist/config/resolve.d.ts +1 -1
  159. package/dist/config/resource-resolution.d.ts +6 -6
  160. package/dist/config/schema-env.d.ts +20 -20
  161. package/dist/config/schema-normalization.d.ts +1 -1
  162. package/dist/config/schema-types-bindings.d.ts +4 -4
  163. package/dist/config/schema-types-build.d.ts +1 -1
  164. package/dist/config/schema-types.d.ts +7 -7
  165. package/dist/config/schema.d.ts +46 -46
  166. package/dist/config/service-bindings-validation.d.ts +1 -1
  167. package/dist/config-entry.d.ts +6 -6
  168. package/dist/config-entry.js +3 -8
  169. package/dist/decorators/index.d.ts +2 -2
  170. package/dist/decorators/index.js +2 -9
  171. package/dist/dev-server/d1-migrations.d.ts +1 -1
  172. package/dist/dev-server/dev-server-state.d.ts +6 -6
  173. package/dist/dev-server/gateway-script.d.ts +1 -1
  174. package/dist/dev-server/index.d.ts +1 -1
  175. package/dist/dev-server/miniflare-bindings.d.ts +1 -1
  176. package/dist/dev-server/miniflare-dev-config.d.ts +5 -5
  177. package/dist/dev-server/miniflare-worker-config.d.ts +3 -3
  178. package/dist/dev-server/server-startup-helpers.d.ts +6 -6
  179. package/dist/dev-server/worker-surface-paths.d.ts +2 -2
  180. package/dist/index.d.ts +8 -8
  181. package/dist/index.js +9 -22
  182. package/dist/runtime/context-events.d.ts +1 -1
  183. package/dist/runtime/context.d.ts +3 -3
  184. package/dist/runtime/exports.d.ts +2 -2
  185. package/dist/runtime/index.d.ts +10 -10
  186. package/dist/runtime/index.js +5 -57
  187. package/dist/runtime/middleware.d.ts +1 -1
  188. package/dist/runtime/router/index.d.ts +3 -3
  189. package/dist/runtime/validation.d.ts +1 -1
  190. package/dist/secrets/local-secrets.d.ts +1 -1
  191. package/dist/shims/local-media-bindings.d.ts +1 -1
  192. package/dist/sveltekit/index.d.ts +1 -1
  193. package/dist/sveltekit/index.js +327 -9
  194. package/dist/sveltekit/local-bindings.d.ts +1 -1
  195. package/dist/sveltekit/platform.d.ts +1 -1
  196. package/dist/test/binding-hints.d.ts +2 -2
  197. package/dist/test/cf.d.ts +19 -19
  198. package/dist/test/index.d.ts +18 -18
  199. package/dist/test/index.js +4495 -46
  200. package/dist/test/offline-bindings.d.ts +3 -3
  201. package/dist/test/resolve-service-bindings.d.ts +1 -1
  202. package/dist/test/simple-context-bindings.d.ts +1 -1
  203. package/dist/test/simple-context-durable-objects.d.ts +1 -1
  204. package/dist/test/simple-context-env.d.ts +2 -2
  205. package/dist/test/simple-context-handlers.d.ts +2 -2
  206. package/dist/test/simple-context-lifecycle.d.ts +2 -2
  207. package/dist/test/simple-context-mfconfig.d.ts +1 -1
  208. package/dist/test/simple-context-multi-worker.d.ts +2 -2
  209. package/dist/test/simple-context-runtime.d.ts +1 -1
  210. package/dist/test/simple-context-startup.d.ts +1 -1
  211. package/dist/test/simple-context.d.ts +1 -1
  212. package/dist/test/utilities/env.d.ts +3 -3
  213. package/dist/test/utilities.d.ts +10 -10
  214. package/dist/test/worker.d.ts +1 -1
  215. package/dist/transform/index.d.ts +2 -2
  216. package/dist/utils/send-email.js +163 -19
  217. package/dist/vite/config-file.d.ts +2 -2
  218. package/dist/vite/index.d.ts +3 -3
  219. package/dist/vite/index.js +2 -31
  220. package/dist/vite/plugin-config-hook.d.ts +1 -1
  221. package/dist/vite/plugin-context.d.ts +3 -3
  222. package/dist/vite/plugin-durable-objects.d.ts +2 -2
  223. package/dist/vite/plugin-programmatic.d.ts +1 -1
  224. package/dist/vite/plugin-service-bindings.d.ts +2 -2
  225. package/dist/vite/plugin.d.ts +3 -3
  226. package/dist/worker-entry/composed-worker.d.ts +1 -1
  227. package/dist/worker-entry/routes.d.ts +2 -2
  228. package/dist/worker-entry/surface-paths.d.ts +1 -1
  229. package/dist/workflows/local-workflow-entrypoints.d.ts +1 -1
  230. package/package.json +5 -3
  231. package/dist/account-4tgh03a8.js +0 -484
  232. package/dist/ai-r3zqmxan.js +0 -261
  233. package/dist/api-6z01z734.js +0 -33
  234. package/dist/build-kw625v84.js +0 -51
  235. package/dist/config-ghk2bxj3.js +0 -102
  236. package/dist/deploy-9kee65n9.js +0 -1062
  237. package/dist/dev-x8zr249a.js +0 -3569
  238. package/dist/doctor-0ng5qrr1.js +0 -258
  239. package/dist/durable-object-0ybmg08a.js +0 -13
  240. package/dist/index-04wh9bxx.js +0 -514
  241. package/dist/index-0cc05hzv.js +0 -74
  242. package/dist/index-2yv7w548.js +0 -185
  243. package/dist/index-37x76zdn.js +0 -4
  244. package/dist/index-3cpzsr47.js +0 -125
  245. package/dist/index-3t6rypgc.js +0 -13
  246. package/dist/index-4mmpccrb.js +0 -309
  247. package/dist/index-5dkjffqz.js +0 -25
  248. package/dist/index-5hy7jmv3.js +0 -890
  249. package/dist/index-627srx16.js +0 -45
  250. package/dist/index-7m557715.js +0 -283
  251. package/dist/index-a8pnvg3r.js +0 -52
  252. package/dist/index-aabgympv.js +0 -39
  253. package/dist/index-atwc3csp.js +0 -256
  254. package/dist/index-cv4cvrxe.js +0 -2046
  255. package/dist/index-h7r11y4a.js +0 -539
  256. package/dist/index-hvtd936d.js +0 -1229
  257. package/dist/index-kcp7y951.js +0 -136
  258. package/dist/index-maw0jjnn.js +0 -147
  259. package/dist/index-mek9msfv.js +0 -705
  260. package/dist/index-n4xkaymm.js +0 -236
  261. package/dist/index-nkk59p3y.js +0 -579
  262. package/dist/index-phcrvs6d.js +0 -342
  263. package/dist/index-se4kw8tm.js +0 -460
  264. package/dist/index-x8s9rwfh.js +0 -2020
  265. package/dist/index-y7w3x9p1.js +0 -18
  266. package/dist/index-z9gy8w6b.js +0 -57
  267. package/dist/index-zdd0d9qa.js +0 -199
  268. package/dist/init-tb8jqgvr.js +0 -180
  269. package/dist/login-4h1sfsed.js +0 -75
  270. package/dist/previews-qr7c5j8h.js +0 -1336
  271. package/dist/productions-xpmd6bw8.js +0 -505
  272. package/dist/remote-kqcvhnfx.js +0 -192
  273. package/dist/secrets-6wbdsdek.js +0 -89
  274. package/dist/token-yp1qa70y.js +0 -419
  275. package/dist/types-15yv4cj3.js +0 -701
  276. package/dist/worker-1yg72jxg.js +0 -510
  277. package/dist/worker-entrypoint-y8s9kdcx.js +0 -15
@@ -0,0 +1,183 @@
1
+ import { resolve } from "pathe";
2
+ import { spawn } from "node:child_process";
3
+ //#region src/dev-server/vite-utils.ts
4
+ const VITE_CONFIG_FILES = [
5
+ "vite.config.ts",
6
+ "vite.config.js",
7
+ "vite.config.mts",
8
+ "vite.config.mjs",
9
+ "vite.config.cts",
10
+ "vite.config.cjs"
11
+ ];
12
+ const ANSI_REGEX = /\x1b\[[0-9;]*m/g;
13
+ const LOCAL_VITE_URL_REGEX = /https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?\/?/i;
14
+ async function getNodeFs() {
15
+ return await import("node:fs/promises");
16
+ }
17
+ function safeParsePackageJson(content) {
18
+ try {
19
+ return JSON.parse(content);
20
+ } catch {
21
+ return {};
22
+ }
23
+ }
24
+ function readDependencyFlag(pkg, name) {
25
+ const dependencies = pkg.dependencies;
26
+ const devDependencies = pkg.devDependencies;
27
+ return Boolean(dependencies?.[name] ?? devDependencies?.[name]);
28
+ }
29
+ async function detectViteProject(cwd, fs) {
30
+ const fileSystem = fs ?? await getNodeFs();
31
+ let viteConfigPath = null;
32
+ for (const configName of VITE_CONFIG_FILES) {
33
+ const absolutePath = resolve(cwd, configName);
34
+ try {
35
+ await fileSystem.access(absolutePath);
36
+ viteConfigPath = absolutePath;
37
+ break;
38
+ } catch {}
39
+ }
40
+ let pkg = {};
41
+ try {
42
+ pkg = safeParsePackageJson(await fileSystem.readFile(resolve(cwd, "package.json"), "utf-8"));
43
+ } catch {
44
+ pkg = {};
45
+ }
46
+ const hasLocalViteDependency = readDependencyFlag(pkg, "vite");
47
+ const hasLocalCloudflareVitePluginDependency = readDependencyFlag(pkg, "@cloudflare/vite-plugin");
48
+ return {
49
+ viteConfigPath,
50
+ hasLocalViteDependency,
51
+ hasLocalCloudflareVitePluginDependency,
52
+ shouldStartVite: Boolean(viteConfigPath),
53
+ wantsViteIntegration: Boolean(viteConfigPath || hasLocalViteDependency || hasLocalCloudflareVitePluginDependency)
54
+ };
55
+ }
56
+ /**
57
+ * Resolve the effective Vite mode for a project. Combines the caller's
58
+ * `requested` preference with the filesystem detection so that callers who ask
59
+ * for Vite but lack a local config are downgraded to worker-only mode rather
60
+ * than silently having the detection result ignored.
61
+ */
62
+ async function resolveViteMode(cwd, options = {}) {
63
+ const detection = await detectViteProject(cwd, options.fs);
64
+ return {
65
+ enableVite: (options.requested ?? true) && detection.shouldStartVite,
66
+ viteConfigPath: detection.viteConfigPath,
67
+ detection
68
+ };
69
+ }
70
+ function stripAnsi(value) {
71
+ return value.replace(ANSI_REGEX, "");
72
+ }
73
+ function extractViteReadyUrl(output) {
74
+ const cleaned = stripAnsi(output);
75
+ const lines = cleaned.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
76
+ for (const line of lines) {
77
+ if (!line.toLowerCase().includes("local:")) continue;
78
+ const match = line.match(LOCAL_VITE_URL_REGEX);
79
+ if (match) return match[0];
80
+ }
81
+ return cleaned.match(LOCAL_VITE_URL_REGEX)?.[0] ?? null;
82
+ }
83
+ async function waitForViteReady(process, options = {}) {
84
+ const { timeoutMs = 15e3, onStdout, onStderr } = options;
85
+ let combinedOutput = "";
86
+ return await new Promise((resolvePromise, rejectPromise) => {
87
+ let settled = false;
88
+ let timeout;
89
+ const settle = (resolver) => {
90
+ if (settled) return;
91
+ settled = true;
92
+ clearTimeout(timeout);
93
+ resolver();
94
+ };
95
+ const inspectChunk = (chunk) => {
96
+ combinedOutput += typeof chunk === "string" ? chunk : chunk.toString("utf-8");
97
+ const readyUrl = extractViteReadyUrl(combinedOutput);
98
+ if (readyUrl) settle(() => resolvePromise(readyUrl));
99
+ };
100
+ process.stdout?.on("data", (chunk) => {
101
+ onStdout?.(chunk);
102
+ inspectChunk(chunk);
103
+ });
104
+ process.stderr?.on("data", (chunk) => {
105
+ onStderr?.(chunk);
106
+ inspectChunk(chunk);
107
+ });
108
+ process.on("error", (error) => {
109
+ settle(() => rejectPromise(error));
110
+ });
111
+ process.on("exit", (code, signal) => {
112
+ settle(() => {
113
+ const reason = signal ? `signal ${signal}` : `exit code ${code ?? "unknown"}`;
114
+ rejectPromise(/* @__PURE__ */ new Error(`Vite exited before reporting a ready URL (${reason})`));
115
+ });
116
+ });
117
+ timeout = setTimeout(() => {
118
+ settle(() => resolvePromise(null));
119
+ }, timeoutMs);
120
+ });
121
+ }
122
+ async function defaultRunCommand(command, args) {
123
+ await new Promise((resolvePromise, rejectPromise) => {
124
+ const child = spawn(command, args, {
125
+ stdio: "ignore",
126
+ windowsHide: true
127
+ });
128
+ child.on("error", rejectPromise);
129
+ child.on("exit", () => resolvePromise());
130
+ });
131
+ }
132
+ function waitForProcessExit(process, timeoutMs) {
133
+ if (process.killed) return Promise.resolve(true);
134
+ return new Promise((resolvePromise) => {
135
+ let settled = false;
136
+ let timeout;
137
+ const settle = (value) => {
138
+ if (settled) return;
139
+ settled = true;
140
+ clearTimeout(timeout);
141
+ resolvePromise(value);
142
+ };
143
+ process.on("exit", () => settle(true));
144
+ timeout = setTimeout(() => {
145
+ settle(false);
146
+ }, timeoutMs);
147
+ });
148
+ }
149
+ async function stopSpawnedProcessTree(process, options = {}) {
150
+ const { platform = globalThis.process?.platform ?? "linux", timeoutMs = 3e3, runCommand = defaultRunCommand } = options;
151
+ if (platform === "win32" && process.pid) {
152
+ try {
153
+ await runCommand("taskkill", [
154
+ "/pid",
155
+ String(process.pid),
156
+ "/t",
157
+ "/f"
158
+ ]);
159
+ } catch {
160
+ try {
161
+ process.kill("SIGTERM");
162
+ } catch {
163
+ return;
164
+ }
165
+ }
166
+ await waitForProcessExit(process, timeoutMs);
167
+ return;
168
+ }
169
+ try {
170
+ process.kill("SIGTERM");
171
+ } catch {
172
+ return;
173
+ }
174
+ if (await waitForProcessExit(process, timeoutMs)) return;
175
+ try {
176
+ process.kill("SIGKILL");
177
+ } catch {
178
+ return;
179
+ }
180
+ await waitForProcessExit(process, timeoutMs);
181
+ }
182
+ //#endregion
183
+ export { waitForViteReady as i, resolveViteMode as n, stopSpawnedProcessTree as r, detectViteProject as t };
@@ -0,0 +1,410 @@
1
+ import { r as loadConfig } from "./loader-DLXO60RO.js";
2
+ import { o as normalizeDOBinding } from "./schema-normalization-DWVleVxo.js";
3
+ import { t as account } from "./cloudflare-BaloqI3H.js";
4
+ import { d as green, f as logLine, g as yellow, h as whiteDim, n as bold, o as dim, r as createCliTheme } from "./ui-BUoZApvE.js";
5
+ import { r as resolveCloudflareAccountId, t as asOptionalString } from "./command-utils-BsfkmTqh.js";
6
+ import { n as formatSupportedConfigFilenames, r as resolveConfigCandidatePath, t as findConfigPathsUnderDirectory } from "./config-path-DCPto4XB.js";
7
+ import { basename, dirname, relative, resolve } from "pathe";
8
+ import MagicString from "magic-string";
9
+ //#region src/cli/commands/worker.ts
10
+ function formatPathForLog(cwd, filePath) {
11
+ const relativePath = relative(cwd, filePath).replace(/\\/g, "/");
12
+ return relativePath && !relativePath.startsWith("..") ? relativePath : filePath;
13
+ }
14
+ async function loadConfigFromPath(configPath) {
15
+ return {
16
+ configPath,
17
+ config: await loadConfig({
18
+ cwd: dirname(configPath),
19
+ configFile: basename(configPath)
20
+ })
21
+ };
22
+ }
23
+ async function loadDiscoveredConfigs(cwd, explicitConfigPath) {
24
+ const candidatePaths = /* @__PURE__ */ new Set();
25
+ const discoveredPaths = await findConfigPathsUnderDirectory(cwd);
26
+ for (const configPath of discoveredPaths) candidatePaths.add(configPath);
27
+ if (explicitConfigPath) candidatePaths.add(explicitConfigPath);
28
+ const loadedConfigs = [];
29
+ for (const configPath of [...candidatePaths].sort((left, right) => left.localeCompare(right))) try {
30
+ loadedConfigs.push(await loadConfigFromPath(configPath));
31
+ } catch (error) {
32
+ if (explicitConfigPath && explicitConfigPath === configPath) throw error;
33
+ }
34
+ return loadedConfigs;
35
+ }
36
+ function formatConfigChoices(matches, cwd) {
37
+ return matches.map((match) => ` - ${formatPathForLog(cwd, match.configPath)} (${match.config.name})`).join("\n");
38
+ }
39
+ function selectTargetConfig(loadedConfigs, cwd, oldName, newName, explicitConfigPath) {
40
+ if (loadedConfigs.length === 0) throw new Error(`Could not find ${formatSupportedConfigFilenames()} under ${cwd}.`);
41
+ if (explicitConfigPath) {
42
+ const target = loadedConfigs.find((candidate) => candidate.configPath === explicitConfigPath);
43
+ if (!target) throw new Error(`Could not load the selected config: ${explicitConfigPath}`);
44
+ if (target.config.name === oldName) return {
45
+ target,
46
+ localConfigAlreadyUpdated: false,
47
+ allConfigs: loadedConfigs
48
+ };
49
+ if (target.config.name === newName) return {
50
+ target,
51
+ localConfigAlreadyUpdated: true,
52
+ allConfigs: loadedConfigs
53
+ };
54
+ throw new Error(`The selected config uses \`${target.config.name}\`, not \`${oldName}\` or \`${newName}\`.`);
55
+ }
56
+ const matchingConfigs = loadedConfigs.filter((candidate) => {
57
+ return candidate.config.name === oldName || candidate.config.name === newName;
58
+ });
59
+ const oldMatches = matchingConfigs.filter((candidate) => candidate.config.name === oldName);
60
+ const newMatches = matchingConfigs.filter((candidate) => candidate.config.name === newName);
61
+ if (oldMatches.length === 1 && matchingConfigs.length === 1) return {
62
+ target: oldMatches[0],
63
+ localConfigAlreadyUpdated: false,
64
+ allConfigs: loadedConfigs
65
+ };
66
+ if (newMatches.length === 1 && matchingConfigs.length === 1) return {
67
+ target: newMatches[0],
68
+ localConfigAlreadyUpdated: true,
69
+ allConfigs: loadedConfigs
70
+ };
71
+ if (matchingConfigs.length === 0) throw new Error(`Could not find a matching devflare config under ${cwd}. Expected a config whose \`name\` is \`${oldName}\` or \`${newName}\`.`);
72
+ throw new Error(`Multiple matching devflare configs were found. Use --config to pick one explicitly.\n${formatConfigChoices(matchingConfigs, cwd)}`);
73
+ }
74
+ async function resolveAccountId(parsed, config) {
75
+ return resolveCloudflareAccountId({
76
+ explicitAccountId: asOptionalString(parsed.options.account),
77
+ configuredAccountId: config.accountId
78
+ });
79
+ }
80
+ function skipWhitespaceAndComments(source, start, end) {
81
+ let index = start;
82
+ while (index < end) {
83
+ const char = source[index];
84
+ if (/\s/.test(char)) {
85
+ index++;
86
+ continue;
87
+ }
88
+ const nextIndex = consumeComment(source, index, end);
89
+ if (nextIndex !== null) {
90
+ index = nextIndex;
91
+ continue;
92
+ }
93
+ break;
94
+ }
95
+ return index;
96
+ }
97
+ function consumeQuotedLiteral(source, start, end) {
98
+ const quote = source[start];
99
+ let index = start + 1;
100
+ while (index < end) {
101
+ const char = source[index];
102
+ if (char === "\\") {
103
+ index += 2;
104
+ continue;
105
+ }
106
+ if (char === quote) return index + 1;
107
+ index++;
108
+ }
109
+ throw new Error("Unterminated string literal in devflare config.");
110
+ }
111
+ function consumeComment(source, start, end) {
112
+ if (source[start] !== "/") return null;
113
+ if (source[start + 1] === "/") {
114
+ let index = start + 2;
115
+ while (index < end && source[index] !== "\n") index++;
116
+ return index;
117
+ }
118
+ if (source[start + 1] === "*") {
119
+ let index = start + 2;
120
+ while (index < end && !(source[index] === "*" && source[index + 1] === "/")) index++;
121
+ return Math.min(index + 2, end);
122
+ }
123
+ return null;
124
+ }
125
+ function findConfigObjectStart(source) {
126
+ const defineConfigIndex = source.indexOf("defineConfig");
127
+ if (defineConfigIndex >= 0) {
128
+ const parenIndex = source.indexOf("(", defineConfigIndex);
129
+ if (parenIndex >= 0) {
130
+ const objectIndex = source.indexOf("{", parenIndex);
131
+ if (objectIndex >= 0) return objectIndex;
132
+ }
133
+ }
134
+ const exportDefaultIndex = source.indexOf("export default");
135
+ if (exportDefaultIndex >= 0) {
136
+ const objectIndex = source.indexOf("{", exportDefaultIndex);
137
+ if (objectIndex >= 0) return objectIndex;
138
+ }
139
+ return -1;
140
+ }
141
+ function getRootPropertySlices(source, objectStart) {
142
+ const slices = [];
143
+ let curlyDepth = 1;
144
+ let squareDepth = 0;
145
+ let parenDepth = 0;
146
+ let propertyStart = objectStart + 1;
147
+ let index = objectStart + 1;
148
+ while (index < source.length) {
149
+ const char = source[index];
150
+ if (char === "'" || char === "\"" || char === "`") {
151
+ index = consumeQuotedLiteral(source, index, source.length);
152
+ continue;
153
+ }
154
+ const nextIndex = consumeComment(source, index, source.length);
155
+ if (nextIndex !== null) {
156
+ index = nextIndex;
157
+ continue;
158
+ }
159
+ if (char === "{") {
160
+ curlyDepth++;
161
+ index++;
162
+ continue;
163
+ }
164
+ if (char === "}") {
165
+ curlyDepth--;
166
+ if (curlyDepth === 0) {
167
+ slices.push({
168
+ start: propertyStart,
169
+ end: index
170
+ });
171
+ return slices;
172
+ }
173
+ index++;
174
+ continue;
175
+ }
176
+ if (char === "[") {
177
+ squareDepth++;
178
+ index++;
179
+ continue;
180
+ }
181
+ if (char === "]") {
182
+ squareDepth--;
183
+ index++;
184
+ continue;
185
+ }
186
+ if (char === "(") {
187
+ parenDepth++;
188
+ index++;
189
+ continue;
190
+ }
191
+ if (char === ")") {
192
+ parenDepth--;
193
+ index++;
194
+ continue;
195
+ }
196
+ if (char === "," && curlyDepth === 1 && squareDepth === 0 && parenDepth === 0) {
197
+ slices.push({
198
+ start: propertyStart,
199
+ end: index
200
+ });
201
+ propertyStart = index + 1;
202
+ }
203
+ index++;
204
+ }
205
+ throw new Error("Could not parse the root object in devflare config.");
206
+ }
207
+ function findTopLevelColon(source, start, end) {
208
+ let curlyDepth = 0;
209
+ let squareDepth = 0;
210
+ let parenDepth = 0;
211
+ let index = start;
212
+ while (index < end) {
213
+ const char = source[index];
214
+ if (char === "'" || char === "\"" || char === "`") {
215
+ index = consumeQuotedLiteral(source, index, end);
216
+ continue;
217
+ }
218
+ const nextIndex = consumeComment(source, index, end);
219
+ if (nextIndex !== null) {
220
+ index = nextIndex;
221
+ continue;
222
+ }
223
+ if (char === "{") {
224
+ curlyDepth++;
225
+ index++;
226
+ continue;
227
+ }
228
+ if (char === "}") {
229
+ curlyDepth--;
230
+ index++;
231
+ continue;
232
+ }
233
+ if (char === "[") {
234
+ squareDepth++;
235
+ index++;
236
+ continue;
237
+ }
238
+ if (char === "]") {
239
+ squareDepth--;
240
+ index++;
241
+ continue;
242
+ }
243
+ if (char === "(") {
244
+ parenDepth++;
245
+ index++;
246
+ continue;
247
+ }
248
+ if (char === ")") {
249
+ parenDepth--;
250
+ index++;
251
+ continue;
252
+ }
253
+ if (char === ":" && curlyDepth === 0 && squareDepth === 0 && parenDepth === 0) return index;
254
+ index++;
255
+ }
256
+ return -1;
257
+ }
258
+ function normalizePropertyKey(rawKey) {
259
+ const trimmed = rawKey.trim();
260
+ if (trimmed.startsWith("'") && trimmed.endsWith("'") || trimmed.startsWith("\"") && trimmed.endsWith("\"")) return trimmed.slice(1, -1);
261
+ return trimmed;
262
+ }
263
+ function findRootNameLiteralRange(source) {
264
+ const objectStart = findConfigObjectStart(source);
265
+ if (objectStart < 0) return null;
266
+ for (const slice of getRootPropertySlices(source, objectStart)) {
267
+ const keyStart = skipWhitespaceAndComments(source, slice.start, slice.end);
268
+ const colonIndex = findTopLevelColon(source, keyStart, slice.end);
269
+ if (colonIndex < 0) continue;
270
+ if (normalizePropertyKey(source.slice(keyStart, colonIndex)) !== "name") continue;
271
+ const valueStart = skipWhitespaceAndComments(source, colonIndex + 1, slice.end);
272
+ const quote = source[valueStart];
273
+ if (quote !== "'" && quote !== "\"") throw new Error("The top-level `name` property must be a string literal to be updated automatically.");
274
+ return {
275
+ start: valueStart,
276
+ end: consumeQuotedLiteral(source, valueStart, slice.end),
277
+ quote
278
+ };
279
+ }
280
+ return null;
281
+ }
282
+ function quoteWorkerName(value, quote) {
283
+ return `${quote}${value.replace(/\\/g, "\\\\").replace(new RegExp(`\\${quote}`, "g"), `\\${quote}`)}${quote}`;
284
+ }
285
+ async function updateConfigName(configPath, newName) {
286
+ const fs = await import("node:fs/promises");
287
+ const source = await fs.readFile(configPath, "utf-8");
288
+ const literalRange = findRootNameLiteralRange(source);
289
+ if (!literalRange) throw new Error("Could not locate a top-level string literal `name` property in the selected devflare config.");
290
+ const magicString = new MagicString(source);
291
+ magicString.overwrite(literalRange.start, literalRange.end, quoteWorkerName(newName, literalRange.quote));
292
+ await fs.writeFile(configPath, magicString.toString(), "utf-8");
293
+ }
294
+ function collectReferenceHitsFromConfig(configPath, configLike, oldName, scope) {
295
+ if (!configLike?.bindings) return [];
296
+ const hits = [];
297
+ for (const [bindingName, bindingConfig] of Object.entries(configLike.bindings.services ?? {})) if (bindingConfig.service === oldName) hits.push({
298
+ configPath,
299
+ scope,
300
+ kind: "service",
301
+ bindingName
302
+ });
303
+ for (const [bindingName, bindingConfig] of Object.entries(configLike.bindings.durableObjects ?? {})) if (normalizeDOBinding(bindingConfig).scriptName === oldName) hits.push({
304
+ configPath,
305
+ scope,
306
+ kind: "durable-object",
307
+ bindingName
308
+ });
309
+ return hits;
310
+ }
311
+ function collectReferenceHits(loadedConfigs, oldName) {
312
+ const hits = [];
313
+ for (const record of loadedConfigs) {
314
+ hits.push(...collectReferenceHitsFromConfig(record.configPath, record.config, oldName, "root"));
315
+ for (const [envName, envConfig] of Object.entries(record.config.env ?? {})) hits.push(...collectReferenceHitsFromConfig(record.configPath, envConfig, oldName, `env.${envName}`));
316
+ }
317
+ return hits;
318
+ }
319
+ async function runWorkerCommand(parsed, logger, options) {
320
+ const cwd = options.cwd ?? process.cwd();
321
+ const theme = createCliTheme(parsed.options);
322
+ const subcommand = parsed.args[0];
323
+ const oldName = parsed.args[1]?.trim();
324
+ const newName = asOptionalString(parsed.options.to);
325
+ const explicitConfigPath = asOptionalString(parsed.options.config);
326
+ if (subcommand !== "rename") {
327
+ logger.error(`Unknown worker subcommand: ${subcommand ?? "<none>"}`);
328
+ logLine(logger, dim("Usage: devflare worker rename <old-name> --to <new-name> [--config <path>]", theme));
329
+ return { exitCode: 1 };
330
+ }
331
+ if (!oldName) {
332
+ logger.error("A current Worker name is required.");
333
+ logLine(logger, dim("Usage: devflare worker rename <old-name> --to <new-name> [--config <path>]", theme));
334
+ return { exitCode: 1 };
335
+ }
336
+ if (!newName) {
337
+ logger.error("The new Worker name must be provided with --to.");
338
+ return { exitCode: 1 };
339
+ }
340
+ if (oldName === newName) {
341
+ logger.error("The new Worker name must be different from the current name.");
342
+ return { exitCode: 1 };
343
+ }
344
+ logLine(logger);
345
+ logLine(logger, `${yellow("worker", theme)} ${dim("Renaming Worker identity", theme)}`);
346
+ logLine(logger, `${dim("from", theme)} ${whiteDim(oldName, theme)}`);
347
+ logLine(logger, `${dim("to", theme)} ${green(newName, theme)}`);
348
+ if (!await account.isAuthenticated()) {
349
+ logger.error("Not authenticated with Cloudflare");
350
+ logLine(logger, dim("Run `devflare login` first.", theme));
351
+ return { exitCode: 1 };
352
+ }
353
+ let remoteRenamed = false;
354
+ try {
355
+ const explicitResolvedConfigPath = explicitConfigPath ? await resolveConfigCandidatePath(resolve(cwd, explicitConfigPath)) : null;
356
+ if (explicitConfigPath && !explicitResolvedConfigPath) throw new Error(`${formatSupportedConfigFilenames()} not found for --config ${explicitConfigPath}.`);
357
+ const { target, localConfigAlreadyUpdated, allConfigs } = selectTargetConfig(await loadDiscoveredConfigs(cwd, explicitResolvedConfigPath ?? void 0), cwd, oldName, newName, explicitResolvedConfigPath ?? void 0);
358
+ const accountId = await resolveAccountId(parsed, target.config);
359
+ if (!accountId) {
360
+ logger.error("No Cloudflare account could be resolved for this config.");
361
+ logLine(logger, dim("Set accountId in devflare.config.ts, pass --account, or configure a default account.", theme));
362
+ return { exitCode: 1 };
363
+ }
364
+ logLine(logger, `${dim("config", theme)} ${whiteDim(formatPathForLog(cwd, target.configPath), theme)}`);
365
+ logLine(logger, `${dim("account", theme)} ${whiteDim(accountId, theme)}`);
366
+ logLine(logger);
367
+ const workers = await account.workers(accountId);
368
+ const hasOldWorker = workers.some((worker) => worker.name === oldName);
369
+ const hasNewWorker = workers.some((worker) => worker.name === newName);
370
+ if (hasOldWorker && hasNewWorker) {
371
+ logger.error(`Both \`${oldName}\` and \`${newName}\` already exist in Cloudflare.`);
372
+ logLine(logger, dim("Refusing to rename because the target Worker name is already taken.", theme));
373
+ return { exitCode: 1 };
374
+ }
375
+ if (!hasOldWorker && !hasNewWorker) {
376
+ logger.error(`Neither \`${oldName}\` nor \`${newName}\` exists in Cloudflare for account ${accountId}.`);
377
+ return { exitCode: 1 };
378
+ }
379
+ if (hasOldWorker && !hasNewWorker) {
380
+ await account.renameWorker(accountId, oldName, newName);
381
+ remoteRenamed = true;
382
+ logger.success(`Renamed remote Worker ${oldName} → ${newName}`);
383
+ } else logLine(logger, `${dim("remote", theme)} ${green(newName, theme)} ${dim("is already the active Worker name in Cloudflare", theme)}`);
384
+ if (!localConfigAlreadyUpdated) {
385
+ await updateConfigName(target.configPath, newName);
386
+ logger.success(`Updated ${formatPathForLog(cwd, target.configPath)}`);
387
+ } else logLine(logger, `${dim("config", theme)} ${green("already updated locally", theme)}`);
388
+ const referenceHits = collectReferenceHits(allConfigs, oldName);
389
+ if (referenceHits.length > 0) {
390
+ logger.warn(`Found ${referenceHits.length} local reference(s) that still use \`${oldName}\`.`);
391
+ for (const hit of referenceHits) logLine(logger, ` ${formatPathForLog(cwd, hit.configPath)} ${dim(`(${hit.scope})`, theme)} ${dim("—", theme)} ${hit.kind === "service" ? "service binding" : "durable object binding"} ${bold(hit.bindingName, theme)}`);
392
+ }
393
+ logLine(logger);
394
+ logLine(logger, `${yellow("preview urls", theme)} ${dim("Existing preview URLs and registry entries may continue using the old Worker name until you upload fresh previews for the renamed Worker.", theme)}`);
395
+ logLine(logger, dim("Future deploys and preview uploads from this config will target the new Worker name.", theme));
396
+ return { exitCode: 0 };
397
+ } catch (error) {
398
+ if (remoteRenamed) {
399
+ logger.warn("The remote Worker rename succeeded, but the local config update did not complete.");
400
+ logLine(logger, dim("Update devflare.config.ts manually so future deploys target the renamed Worker.", theme));
401
+ }
402
+ if (error instanceof Error) {
403
+ logger.error(error.message);
404
+ return { exitCode: 1 };
405
+ }
406
+ throw error;
407
+ }
408
+ }
409
+ //#endregion
410
+ export { runWorkerCommand };