wrangler 0.0.0-e452a35 → 0.0.0-e4ca780f

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 (359) hide show
  1. package/README.md +24 -4
  2. package/bin/wrangler.js +170 -62
  3. package/kv-asset-handler.js +1 -0
  4. package/miniflare-dist/index.mjs +1590 -81
  5. package/package.json +198 -152
  6. package/src/__tests__/access.test.ts +25 -0
  7. package/src/__tests__/api-dev.test.ts +238 -0
  8. package/src/__tests__/api-devregistry.test.ts +121 -0
  9. package/src/__tests__/api.test.ts +102 -0
  10. package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
  11. package/src/__tests__/config-cache.test.ts +30 -24
  12. package/src/__tests__/configuration.test.ts +4498 -3321
  13. package/src/__tests__/d1/d1.test.ts +82 -0
  14. package/src/__tests__/d1/execute.test.ts +66 -0
  15. package/src/__tests__/d1/migrate.test.ts +157 -0
  16. package/src/__tests__/d1/splitter.test.ts +255 -0
  17. package/src/__tests__/delete.test.ts +272 -0
  18. package/src/__tests__/deployments.test.ts +369 -0
  19. package/src/__tests__/dev.test.tsx +1592 -874
  20. package/src/__tests__/generate.test.ts +237 -0
  21. package/src/__tests__/get-host-from-url.test.ts +16 -0
  22. package/src/__tests__/guess-worker-format.test.ts +103 -68
  23. package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
  24. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  25. package/src/__tests__/helpers/mock-account-id.ts +24 -24
  26. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  27. package/src/__tests__/helpers/mock-bin.ts +20 -20
  28. package/src/__tests__/helpers/mock-console.ts +64 -39
  29. package/src/__tests__/helpers/mock-dialogs.ts +104 -55
  30. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  31. package/src/__tests__/helpers/mock-get-zone-from-host.ts +11 -0
  32. package/src/__tests__/helpers/mock-http-server.ts +30 -30
  33. package/src/__tests__/helpers/mock-istty.ts +65 -18
  34. package/src/__tests__/helpers/mock-known-routes.ts +12 -0
  35. package/src/__tests__/helpers/mock-kv.ts +41 -28
  36. package/src/__tests__/helpers/mock-oauth-flow.ts +241 -233
  37. package/src/__tests__/helpers/mock-process.ts +34 -0
  38. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  39. package/src/__tests__/helpers/mock-stdin.ts +82 -77
  40. package/src/__tests__/helpers/mock-web-socket.ts +21 -21
  41. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  42. package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
  43. package/src/__tests__/helpers/msw/handlers/deployments.ts +160 -0
  44. package/src/__tests__/helpers/msw/handlers/namespaces.ts +81 -0
  45. package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
  46. package/src/__tests__/helpers/msw/handlers/r2.ts +60 -0
  47. package/src/__tests__/helpers/msw/handlers/script.ts +56 -0
  48. package/src/__tests__/helpers/msw/handlers/user.ts +52 -0
  49. package/src/__tests__/helpers/msw/handlers/zones.ts +20 -0
  50. package/src/__tests__/helpers/msw/index.ts +52 -0
  51. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  52. package/src/__tests__/helpers/run-in-tmp.ts +27 -28
  53. package/src/__tests__/helpers/run-wrangler.ts +8 -8
  54. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  55. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
  56. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
  57. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
  58. package/src/__tests__/helpers/worker-scripts/parent-worker.js +11 -0
  59. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
  60. package/src/__tests__/helpers/write-worker-source.ts +16 -16
  61. package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
  62. package/src/__tests__/https-options.test.ts +142 -109
  63. package/src/__tests__/index.test.ts +260 -236
  64. package/src/__tests__/init.test.ts +3167 -1528
  65. package/src/__tests__/jest.setup.ts +152 -50
  66. package/src/__tests__/kv.test.ts +1789 -1471
  67. package/src/__tests__/logger.test.ts +167 -75
  68. package/src/__tests__/logout.test.ts +47 -0
  69. package/src/__tests__/metrics.test.ts +493 -0
  70. package/src/__tests__/middleware.scheduled.test.ts +145 -0
  71. package/src/__tests__/middleware.test.ts +816 -0
  72. package/src/__tests__/mtls-certificates.test.ts +588 -0
  73. package/src/__tests__/package-manager.test.ts +312 -165
  74. package/src/__tests__/pages/deployment-list.test.ts +80 -0
  75. package/src/__tests__/pages/functions-build.test.ts +452 -0
  76. package/src/__tests__/pages/pages.test.ts +81 -0
  77. package/src/__tests__/pages/project-create.test.ts +63 -0
  78. package/src/__tests__/pages/project-list.test.ts +110 -0
  79. package/src/__tests__/pages/project-upload.test.ts +500 -0
  80. package/src/__tests__/pages/publish.test.ts +2864 -0
  81. package/src/__tests__/pages-deployment-tail.test.ts +955 -0
  82. package/src/__tests__/parse.test.ts +358 -252
  83. package/src/__tests__/paths.test.ts +39 -0
  84. package/src/__tests__/publish.test.ts +8310 -5355
  85. package/src/__tests__/pubsub.test.ts +496 -0
  86. package/src/__tests__/queues.test.ts +532 -0
  87. package/src/__tests__/r2.test.ts +369 -228
  88. package/src/__tests__/route.test.ts +18 -18
  89. package/src/__tests__/secret.test.ts +681 -469
  90. package/src/__tests__/tail.test.ts +835 -567
  91. package/src/__tests__/test-old-node-version.js +31 -0
  92. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  93. package/src/__tests__/tsconfig-sanity.ts +12 -0
  94. package/src/__tests__/tsconfig.json +8 -0
  95. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  96. package/src/__tests__/type-generation.test.ts +234 -0
  97. package/src/__tests__/user.test.ts +107 -120
  98. package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
  99. package/src/__tests__/validate-dev-props.test.ts +56 -0
  100. package/src/__tests__/version.test.ts +35 -0
  101. package/src/__tests__/whoami.test.tsx +165 -98
  102. package/src/__tests__/worker-namespace.test.ts +340 -0
  103. package/src/abort.d.ts +1 -1
  104. package/src/api/dev.ts +316 -0
  105. package/src/api/index.ts +11 -0
  106. package/src/api/mtls-certificate.ts +148 -0
  107. package/src/api/pages/create-worker-bundle-contents.ts +76 -0
  108. package/src/api/pages/index.ts +5 -0
  109. package/src/api/pages/publish.tsx +355 -0
  110. package/src/bundle-reporter.ts +68 -0
  111. package/src/bundle.ts +869 -161
  112. package/src/cfetch/index.ts +120 -83
  113. package/src/cfetch/internal.ts +214 -95
  114. package/src/cli.ts +23 -8
  115. package/src/config/config.ts +244 -196
  116. package/src/config/diagnostics.ts +61 -61
  117. package/src/config/environment.ts +555 -357
  118. package/src/config/index.ts +374 -196
  119. package/src/config/validation-helpers.ts +379 -357
  120. package/src/config/validation.ts +2170 -1358
  121. package/src/config-cache.ts +81 -41
  122. package/src/create-worker-preview.ts +250 -142
  123. package/src/create-worker-upload-form.ts +343 -238
  124. package/src/d1/backups.tsx +219 -0
  125. package/src/d1/constants.ts +2 -0
  126. package/src/d1/create.tsx +68 -0
  127. package/src/d1/delete.ts +53 -0
  128. package/src/d1/execute.tsx +357 -0
  129. package/src/d1/formatTimeAgo.ts +14 -0
  130. package/src/d1/index.ts +100 -0
  131. package/src/d1/list.tsx +60 -0
  132. package/src/d1/migrations/apply.tsx +212 -0
  133. package/src/d1/migrations/create.tsx +79 -0
  134. package/src/d1/migrations/helpers.ts +172 -0
  135. package/src/d1/migrations/index.ts +3 -0
  136. package/src/d1/migrations/list.tsx +95 -0
  137. package/src/d1/migrations/options.ts +23 -0
  138. package/src/d1/options.ts +22 -0
  139. package/src/d1/splitter.ts +161 -0
  140. package/src/d1/types.ts +25 -0
  141. package/src/d1/utils.ts +49 -0
  142. package/src/delete.ts +100 -0
  143. package/src/deployments.ts +368 -0
  144. package/src/deprecated/index.ts +144 -0
  145. package/src/dev/dev-vars.ts +20 -17
  146. package/src/dev/dev.tsx +533 -355
  147. package/src/dev/get-local-persistence-path.ts +31 -0
  148. package/src/dev/local.tsx +900 -298
  149. package/src/dev/remote.tsx +620 -215
  150. package/src/dev/start-server.ts +534 -0
  151. package/src/dev/use-esbuild.ts +182 -97
  152. package/src/dev/validate-dev-props.ts +40 -0
  153. package/src/dev-registry.ts +202 -0
  154. package/src/dev.tsx +929 -0
  155. package/src/dialogs.ts +136 -0
  156. package/src/dispatch-namespace.ts +211 -0
  157. package/src/docs/index.ts +97 -0
  158. package/src/durable.ts +87 -87
  159. package/src/entry.ts +246 -231
  160. package/src/environment-variables/factory.ts +88 -0
  161. package/src/environment-variables/misc-variables.ts +30 -0
  162. package/src/errors.ts +6 -6
  163. package/src/generate/index.ts +298 -0
  164. package/src/git-client.ts +135 -0
  165. package/src/global-wrangler-config-path.ts +26 -0
  166. package/src/https-options.ts +84 -80
  167. package/src/index.ts +758 -0
  168. package/src/init.ts +1032 -0
  169. package/src/inspect.ts +713 -593
  170. package/src/intl-polyfill.d.ts +123 -123
  171. package/src/is-ci.ts +14 -0
  172. package/src/is-interactive.ts +16 -0
  173. package/src/jest.d.ts +4 -0
  174. package/src/kv/helpers.ts +430 -0
  175. package/src/kv/index.ts +594 -0
  176. package/src/logger.ts +96 -43
  177. package/src/metrics/index.ts +5 -0
  178. package/src/metrics/metrics-config.ts +239 -0
  179. package/src/metrics/metrics-dispatcher.ts +96 -0
  180. package/src/metrics/metrics-usage-headers.ts +24 -0
  181. package/src/metrics/send-event.ts +99 -0
  182. package/src/miniflare-cli/assets.ts +251 -0
  183. package/src/miniflare-cli/index.ts +202 -33
  184. package/src/miniflare-cli/request-context.ts +18 -18
  185. package/src/miniflare-cli/tsconfig.json +9 -0
  186. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  187. package/src/miniflare-cli/types.ts +11 -0
  188. package/src/module-collection.ts +290 -215
  189. package/src/mtls-certificate/cli.ts +155 -0
  190. package/src/open-in-browser.ts +4 -6
  191. package/src/package-manager.ts +182 -90
  192. package/src/pages/build.ts +410 -0
  193. package/src/pages/buildFunctions.ts +140 -0
  194. package/src/pages/constants.ts +18 -0
  195. package/src/pages/deployment-tails.ts +281 -0
  196. package/src/pages/deployments.tsx +84 -0
  197. package/src/pages/dev.ts +716 -0
  198. package/src/pages/errors.ts +67 -0
  199. package/src/pages/functions/buildPlugin.ts +113 -0
  200. package/src/pages/functions/buildWorker.ts +291 -0
  201. package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
  202. package/src/pages/functions/filepath-routing.ts +189 -0
  203. package/src/pages/functions/identifiers.ts +78 -0
  204. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  205. package/src/pages/functions/routes-consolidation.ts +73 -0
  206. package/src/pages/functions/routes-transformation.test.ts +282 -0
  207. package/src/pages/functions/routes-transformation.ts +115 -0
  208. package/src/pages/functions/routes-validation.test.ts +403 -0
  209. package/src/pages/functions/routes-validation.ts +202 -0
  210. package/src/pages/functions/routes.ts +151 -0
  211. package/src/pages/functions/tsconfig.json +8 -0
  212. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  213. package/src/pages/functions.ts +86 -0
  214. package/src/pages/hash.ts +13 -0
  215. package/src/pages/index.ts +102 -0
  216. package/src/pages/projects.tsx +159 -0
  217. package/src/pages/prompt-select-project.tsx +31 -0
  218. package/src/pages/publish.tsx +267 -0
  219. package/src/pages/types.ts +46 -0
  220. package/src/pages/upload.tsx +469 -0
  221. package/src/pages/utils.ts +23 -0
  222. package/src/parse.ts +232 -126
  223. package/src/paths.ts +53 -8
  224. package/src/proxy.ts +623 -394
  225. package/src/publish/index.ts +274 -0
  226. package/src/publish/publish.ts +1060 -0
  227. package/src/pubsub/index.ts +286 -0
  228. package/src/pubsub/pubsub-commands.ts +623 -0
  229. package/src/queues/cli/commands/consumer/add.ts +71 -0
  230. package/src/queues/cli/commands/consumer/index.ts +19 -0
  231. package/src/queues/cli/commands/consumer/remove.ts +31 -0
  232. package/src/queues/cli/commands/create.ts +25 -0
  233. package/src/queues/cli/commands/delete.ts +26 -0
  234. package/src/queues/cli/commands/index.ts +35 -0
  235. package/src/queues/cli/commands/list.ts +25 -0
  236. package/src/queues/client.ts +136 -0
  237. package/src/queues/utils.ts +18 -0
  238. package/src/r2/constants.ts +4 -0
  239. package/src/r2/helpers.ts +132 -0
  240. package/src/r2/index.ts +289 -0
  241. package/src/routes.ts +140 -0
  242. package/src/secret/index.ts +376 -0
  243. package/src/selfsigned.d.ts +23 -23
  244. package/src/sites.ts +372 -0
  245. package/src/tail/createTail.ts +406 -0
  246. package/src/tail/filters.ts +109 -111
  247. package/src/tail/index.ts +208 -296
  248. package/src/tail/printing.ts +101 -46
  249. package/src/traverse-module-graph.ts +53 -0
  250. package/src/tsconfig-sanity.ts +16 -0
  251. package/src/type-generation.ts +181 -0
  252. package/src/update-check.ts +11 -11
  253. package/src/user/access.ts +68 -0
  254. package/src/user/auth-variables.ts +113 -0
  255. package/src/user/choose-account.tsx +39 -0
  256. package/src/user/generate-auth-url.ts +33 -0
  257. package/src/user/generate-random-state.ts +16 -0
  258. package/src/user/index.ts +2 -0
  259. package/src/user/user.ts +1233 -0
  260. package/src/utils/collectKeyValues.ts +14 -0
  261. package/src/utils/render.ts +93 -0
  262. package/src/whoami.ts +135 -0
  263. package/src/worker.ts +200 -106
  264. package/src/yargs-types.ts +37 -0
  265. package/src/zones.ts +191 -0
  266. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  267. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  268. package/templates/__tests__/tsconfig.json +8 -0
  269. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  270. package/templates/checked-fetch.js +23 -0
  271. package/templates/d1-beta-facade.js +244 -0
  272. package/templates/facade.d.ts +14 -0
  273. package/templates/first-party-worker-module-facade.ts +19 -0
  274. package/templates/format-dev-errors.ts +34 -0
  275. package/templates/gitignore +1 -0
  276. package/templates/init-tests/test-jest-new-worker.js +23 -0
  277. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  278. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  279. package/templates/middleware/common.ts +62 -0
  280. package/templates/middleware/loader-modules.ts +84 -0
  281. package/templates/middleware/loader-sw.ts +233 -0
  282. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  283. package/templates/middleware/middleware-pretty-error.ts +40 -0
  284. package/templates/middleware/middleware-scheduled.ts +15 -0
  285. package/templates/new-worker-scheduled.js +17 -0
  286. package/templates/new-worker-scheduled.ts +32 -0
  287. package/templates/new-worker.js +3 -3
  288. package/templates/new-worker.ts +18 -15
  289. package/templates/no-op-worker.js +10 -0
  290. package/templates/pages-dev-pipeline.ts +31 -0
  291. package/templates/pages-dev-util.ts +52 -0
  292. package/templates/pages-shim.ts +12 -0
  293. package/templates/pages-template-plugin.ts +180 -0
  294. package/templates/pages-template-worker.ts +189 -0
  295. package/templates/serve-static-assets.ts +66 -0
  296. package/templates/service-bindings-module-facade.js +55 -0
  297. package/templates/service-bindings-sw-facade.js +42 -0
  298. package/templates/tsconfig-sanity.ts +11 -0
  299. package/templates/tsconfig.init.json +105 -0
  300. package/templates/tsconfig.json +6 -103
  301. package/templates/tsconfig.tsbuildinfo +1 -0
  302. package/wrangler-dist/cli.d.ts +1641 -0
  303. package/wrangler-dist/cli.js +138434 -111674
  304. package/wrangler-dist/wasm-sync.wasm +0 -0
  305. package/pages/functions/buildPlugin.ts +0 -105
  306. package/pages/functions/buildWorker.ts +0 -151
  307. package/pages/functions/filepath-routing.ts +0 -189
  308. package/pages/functions/identifiers.ts +0 -78
  309. package/pages/functions/routes.ts +0 -156
  310. package/pages/functions/template-plugin.ts +0 -147
  311. package/pages/functions/template-worker.ts +0 -143
  312. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  313. package/src/__tests__/helpers/mock-cfetch.ts +0 -211
  314. package/src/__tests__/pages.test.ts +0 -657
  315. package/src/dialogs.tsx +0 -87
  316. package/src/environment-variables.ts +0 -35
  317. package/src/index.tsx +0 -2789
  318. package/src/kv.ts +0 -408
  319. package/src/miniflare-cli/enum-keys.ts +0 -17
  320. package/src/pages.tsx +0 -2027
  321. package/src/publish.ts +0 -583
  322. package/src/r2.ts +0 -50
  323. package/src/sites.tsx +0 -295
  324. package/src/user.tsx +0 -1203
  325. package/src/whoami.tsx +0 -70
  326. package/templates/static-asset-facade.js +0 -47
  327. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  328. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  329. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  330. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  331. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  332. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  333. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  334. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  335. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  336. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  337. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  338. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  339. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  340. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  341. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  342. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  343. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  344. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  345. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  346. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  347. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  348. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  349. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  350. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  351. package/vendor/wrangler-mime/LICENSE +0 -21
  352. package/vendor/wrangler-mime/Mime.js +0 -97
  353. package/vendor/wrangler-mime/README.md +0 -187
  354. package/vendor/wrangler-mime/cli.js +0 -46
  355. package/vendor/wrangler-mime/index.js +0 -4
  356. package/vendor/wrangler-mime/lite.js +0 -4
  357. package/vendor/wrangler-mime/package.json +0 -52
  358. package/vendor/wrangler-mime/types/other.js +0 -1
  359. package/vendor/wrangler-mime/types/standard.js +0 -1
package/src/index.ts ADDED
@@ -0,0 +1,758 @@
1
+ import os from "node:os";
2
+ import TOML from "@iarna/toml";
3
+ import chalk from "chalk";
4
+ import supportsColor from "supports-color";
5
+ import { ProxyAgent, setGlobalDispatcher } from "undici";
6
+ import makeCLI from "yargs";
7
+ import { version as wranglerVersion } from "../package.json";
8
+ import { isBuildFailure } from "./bundle";
9
+ import { loadDotEnv, readConfig } from "./config";
10
+ import { d1 } from "./d1";
11
+ import { deleteHandler, deleteOptions } from "./delete";
12
+ import {
13
+ deployments,
14
+ commonDeploymentCMDSetup,
15
+ rollbackDeployment,
16
+ viewDeployment,
17
+ } from "./deployments";
18
+ import {
19
+ buildHandler,
20
+ buildOptions,
21
+ configHandler,
22
+ noOpOptions,
23
+ previewHandler,
24
+ previewOptions,
25
+ route,
26
+ routeHandler,
27
+ subdomainHandler,
28
+ subdomainOptions,
29
+ } from "./deprecated";
30
+ import { devHandler, devOptions } from "./dev";
31
+ import { workerNamespaceCommands } from "./dispatch-namespace";
32
+ import { docsHandler, docsOptions } from "./docs";
33
+ import { generateHandler, generateOptions } from "./generate";
34
+ import { initHandler, initOptions } from "./init";
35
+ import { kvNamespace, kvKey, kvBulk } from "./kv";
36
+ import { logBuildFailure, logger } from "./logger";
37
+ import * as metrics from "./metrics";
38
+ import { mTlsCertificateCommands } from "./mtls-certificate/cli";
39
+ import { pages } from "./pages";
40
+ import { formatMessage, ParseError } from "./parse";
41
+ import { publishOptions, publishHandler } from "./publish";
42
+ import { pubSubCommands } from "./pubsub/pubsub-commands";
43
+ import { queues } from "./queues/cli/commands";
44
+ import { r2 } from "./r2";
45
+ import { secret, secretBulkHandler, secretBulkOptions } from "./secret";
46
+ import { tailOptions, tailHandler } from "./tail";
47
+ import { generateTypes } from "./type-generation";
48
+ import { updateCheck } from "./update-check";
49
+ import { listScopes, login, logout, validateScopeKeys } from "./user";
50
+ import { whoami } from "./whoami";
51
+
52
+ import type { Config } from "./config";
53
+ import type { CommonYargsArgv, CommonYargsOptions } from "./yargs-types";
54
+ import type Yargs from "yargs";
55
+
56
+ const resetColor = "\x1b[0m";
57
+ const fgGreenColor = "\x1b[32m";
58
+ export const DEFAULT_LOCAL_PORT = 8787;
59
+ export const DEFAULT_INSPECTOR_PORT = 9229;
60
+
61
+ const proxy =
62
+ process.env.https_proxy ||
63
+ process.env.HTTPS_PROXY ||
64
+ process.env.http_proxy ||
65
+ process.env.HTTP_PROXY ||
66
+ undefined;
67
+
68
+ if (proxy) {
69
+ setGlobalDispatcher(new ProxyAgent(proxy));
70
+ logger.log(
71
+ `Proxy environment variables detected. We'll use your proxy for fetch requests.`
72
+ );
73
+ }
74
+
75
+ export function getRules(config: Config): Config["rules"] {
76
+ const rules = config.rules ?? config.build?.upload?.rules ?? [];
77
+
78
+ if (config.rules && config.build?.upload?.rules) {
79
+ throw new Error(
80
+ `You cannot configure both [rules] and [build.upload.rules] in your wrangler.toml. Delete the \`build.upload\` section.`
81
+ );
82
+ }
83
+
84
+ if (config.build?.upload?.rules) {
85
+ logger.warn(
86
+ `Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration file, and add this:
87
+
88
+ ${TOML.stringify({ rules: config.build.upload.rules })}`
89
+ );
90
+ }
91
+ return rules;
92
+ }
93
+
94
+ export async function printWranglerBanner() {
95
+ // Let's not print this in tests
96
+ if (typeof jest !== "undefined") {
97
+ return;
98
+ }
99
+
100
+ const text = ` ⛅️ wrangler ${wranglerVersion} ${await updateCheck()}`;
101
+
102
+ logger.log(
103
+ text +
104
+ "\n" +
105
+ (supportsColor.stdout
106
+ ? chalk.hex("#FF8800")("-".repeat(text.length))
107
+ : "-".repeat(text.length))
108
+ );
109
+ }
110
+
111
+ export function isLegacyEnv(config: Config): boolean {
112
+ // We only read from config here, because we've already accounted for
113
+ // args["legacy-env"] in https://github.com/cloudflare/workers-sdk/blob/b24aeb5722370c2e04bce97a84a1fa1e55725d79/packages/wrangler/src/config/validation.ts#L94-L98
114
+ return config.legacy_env;
115
+ }
116
+
117
+ export function getScriptName(
118
+ args: { name: string | undefined; env: string | undefined },
119
+ config: Config
120
+ ): string | undefined {
121
+ if (args.name && isLegacyEnv(config) && args.env) {
122
+ throw new CommandLineArgsError(
123
+ "In legacy environment mode you cannot use --name and --env together. If you want to specify a Worker name for a specific environment you can add the following to your wrangler.toml config:" +
124
+ `
125
+ [env.${args.env}]
126
+ name = "${args.name}"
127
+ `
128
+ );
129
+ }
130
+
131
+ return args.name ?? config.name;
132
+ }
133
+
134
+ /**
135
+ * Alternative to the getScriptName() because special Legacy cases allowed "name", and "env" together in Wrangler v1
136
+ */
137
+ export function getLegacyScriptName(
138
+ args: { name: string | undefined; env: string | undefined },
139
+ config: Config
140
+ ) {
141
+ return args.name && args.env && isLegacyEnv(config)
142
+ ? `${args.name}-${args.env}`
143
+ : args.name ?? config.name;
144
+ }
145
+
146
+ // a helper to demand one of a set of options
147
+ // via https://github.com/yargs/yargs/issues/1093#issuecomment-491299261
148
+ export function demandOneOfOption(...options: string[]) {
149
+ return function (argv: Yargs.Arguments) {
150
+ const count = options.filter((option) => argv[option]).length;
151
+ const lastOption = options.pop();
152
+
153
+ if (count === 0) {
154
+ throw new CommandLineArgsError(
155
+ `Exactly one of the arguments ${options.join(
156
+ ", "
157
+ )} and ${lastOption} is required`
158
+ );
159
+ } else if (count > 1) {
160
+ throw new CommandLineArgsError(
161
+ `Arguments ${options.join(
162
+ ", "
163
+ )} and ${lastOption} are mutually exclusive`
164
+ );
165
+ }
166
+
167
+ return true;
168
+ };
169
+ }
170
+
171
+ export class CommandLineArgsError extends Error {}
172
+
173
+ export function createCLIParser(argv: string[]) {
174
+ // Type check result against CommonYargsOptions to make sure we've included
175
+ // all common options
176
+ const wrangler: CommonYargsArgv = makeCLI(argv)
177
+ .strict()
178
+ // We handle errors ourselves in a try-catch around `yargs.parse`.
179
+ // If you want the "help info" to be displayed then throw an instance of `CommandLineArgsError`.
180
+ // Otherwise we just log the error that was thrown without any "help info".
181
+ .showHelpOnFail(false)
182
+ .fail((msg, error) => {
183
+ if (!error || error.name === "YError") {
184
+ // If there is no error or the error is a "YError", then this came from yargs own validation
185
+ // Wrap it in a `CommandLineArgsError` so that we can handle it appropriately further up.
186
+ error = new CommandLineArgsError(msg);
187
+ }
188
+ throw error;
189
+ })
190
+ .scriptName("wrangler")
191
+ .wrap(null)
192
+ // Define global options here, so they get included in the `Argv` type of
193
+ // the `wrangler` variable
194
+ .version(false)
195
+ .option("v", {
196
+ describe: "Show version number",
197
+ alias: "version",
198
+ type: "boolean",
199
+ })
200
+ .option("config", {
201
+ alias: "c",
202
+ describe: "Path to .toml configuration file",
203
+ type: "string",
204
+ requiresArg: true,
205
+ })
206
+ .option("env", {
207
+ alias: "e",
208
+ describe: "Environment to use for operations and .env files",
209
+ type: "string",
210
+ requiresArg: true,
211
+ })
212
+ .option("experimental-json-config", {
213
+ alias: "j",
214
+ describe: `Experimental: Support wrangler.json`,
215
+ type: "boolean",
216
+ })
217
+ .check((args) => {
218
+ // Grab locally specified env params from `.env` file
219
+ const loaded = loadDotEnv(".env", args.env);
220
+ for (const [key, value] of Object.entries(loaded?.parsed ?? {})) {
221
+ if (!(key in process.env)) process.env[key] = value;
222
+ }
223
+ return true;
224
+ });
225
+
226
+ wrangler.group(
227
+ ["experimental-json-config", "config", "env", "help", "version"],
228
+ "Flags:"
229
+ );
230
+ wrangler.help().alias("h", "help");
231
+
232
+ // Default help command that supports the subcommands
233
+ const subHelp: Yargs.CommandModule<CommonYargsOptions, CommonYargsOptions> = {
234
+ command: ["*"],
235
+ handler: async (args) => {
236
+ setImmediate(() =>
237
+ wrangler.parse([...args._.map((a) => `${a}`), "--help"])
238
+ );
239
+ },
240
+ };
241
+ wrangler.command(
242
+ ["*"],
243
+ false,
244
+ () => {},
245
+ async (args) => {
246
+ if (args._.length > 0) {
247
+ throw new CommandLineArgsError(`Unknown command: ${args._}.`);
248
+ } else {
249
+ // args.v will exist and be true in the case that no command is called, and the -v
250
+ // option is present. This is to allow for running asynchronous printWranglerBanner
251
+ // in the version command.
252
+ if (args.v) {
253
+ if (process.stdout.isTTY) {
254
+ await printWranglerBanner();
255
+ } else {
256
+ logger.log(wranglerVersion);
257
+ }
258
+ } else {
259
+ wrangler.showHelp("log");
260
+ }
261
+ }
262
+ }
263
+ );
264
+
265
+ // You will note that we use the form for all commands where we use the builder function
266
+ // to define options and subcommands.
267
+ // Further we return the result of this builder even though it's not completely necessary.
268
+ // The reason is that it's required for type inference of the args in the handle function.
269
+ // I wish we could enforce this pattern, but this comment will have to do for now.
270
+ // (It's also annoying that choices[] doesn't get inferred as an enum. 🤷‍♂.)
271
+
272
+ // docs
273
+ wrangler.command(
274
+ "docs [command]",
275
+ "📚 Open wrangler's docs in your browser",
276
+ docsOptions,
277
+ docsHandler
278
+ );
279
+
280
+ // init
281
+ wrangler.command(
282
+ "init [name]",
283
+ "📥 Initialize a basic Worker project, including a wrangler.toml file",
284
+ initOptions,
285
+ initHandler
286
+ );
287
+
288
+ // generate
289
+ wrangler.command(
290
+ "generate [name] [template]",
291
+ "✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/templates",
292
+ generateOptions,
293
+ generateHandler
294
+ );
295
+
296
+ // [DEPRECATED] build
297
+ wrangler.command("build", false, buildOptions, buildHandler);
298
+
299
+ // [DEPRECATED] config
300
+ wrangler.command("config", false, noOpOptions, configHandler);
301
+
302
+ // dev
303
+ wrangler.command(
304
+ "dev [script]",
305
+ "👂 Start a local server for developing your worker",
306
+ devOptions,
307
+ devHandler
308
+ );
309
+
310
+ // publish
311
+ wrangler.command(
312
+ "publish [script]",
313
+ "🆙 Publish your Worker to Cloudflare.",
314
+ publishOptions,
315
+ publishHandler
316
+ );
317
+
318
+ // delete
319
+ wrangler.command(
320
+ "delete [script]",
321
+ "🗑 Delete your Worker from Cloudflare.",
322
+ deleteOptions,
323
+ deleteHandler
324
+ );
325
+
326
+ // tail
327
+ wrangler.command(
328
+ "tail [worker]",
329
+ "🦚 Starts a log tailing session for a published Worker.",
330
+ tailOptions,
331
+ tailHandler
332
+ );
333
+
334
+ // [DEPRECATED] preview
335
+ wrangler.command(
336
+ "preview [method] [body]",
337
+ false,
338
+ previewOptions,
339
+ previewHandler
340
+ );
341
+
342
+ // [DEPRECATED] route
343
+ wrangler.command(
344
+ "route",
345
+ false, // I think we want to hide this command
346
+ // "➡️ List or delete worker routes",
347
+ (routeYargs) => {
348
+ return route(routeYargs);
349
+ },
350
+ routeHandler
351
+ );
352
+
353
+ // [DEPRECATED] subdomain
354
+ wrangler.command(
355
+ "subdomain [name]",
356
+ false,
357
+ // "👷 Create or change your workers.dev subdomain.",
358
+ subdomainOptions,
359
+ subdomainHandler
360
+ );
361
+
362
+ // secret
363
+ wrangler.command(
364
+ "secret",
365
+ "🤫 Generate a secret that can be referenced in a Worker",
366
+ (secretYargs) => {
367
+ return secret(secretYargs.command(subHelp));
368
+ }
369
+ );
370
+
371
+ wrangler.command(
372
+ "secret:bulk <json>",
373
+ "🗄️ Bulk upload secrets for a Worker",
374
+ secretBulkOptions,
375
+ secretBulkHandler
376
+ );
377
+
378
+ // kv namespace
379
+ wrangler.command(
380
+ "kv:namespace",
381
+ "🗂️ Interact with your Workers KV Namespaces",
382
+ (namespaceYargs) => {
383
+ return kvNamespace(namespaceYargs.command(subHelp));
384
+ }
385
+ );
386
+
387
+ // kv key
388
+ wrangler.command(
389
+ "kv:key",
390
+ "🔑 Individually manage Workers KV key-value pairs",
391
+ (keyYargs) => {
392
+ return kvKey(keyYargs.command(subHelp));
393
+ }
394
+ );
395
+
396
+ // kv bulk
397
+ wrangler.command(
398
+ "kv:bulk",
399
+ "💪 Interact with multiple Workers KV key-value pairs at once",
400
+ (bulkYargs) => {
401
+ return kvBulk(bulkYargs.command(subHelp));
402
+ }
403
+ );
404
+
405
+ // pages
406
+ wrangler.command("pages", "⚡️ Configure Cloudflare Pages", (pagesYargs) => {
407
+ return pages(pagesYargs.command(subHelp));
408
+ });
409
+
410
+ // queues
411
+ wrangler.command("queues", "🇶 Configure Workers Queues", (queuesYargs) => {
412
+ return queues(queuesYargs.command(subHelp));
413
+ });
414
+
415
+ // r2
416
+ wrangler.command("r2", "📦 Interact with an R2 store", (r2Yargs) => {
417
+ return r2(r2Yargs.command(subHelp));
418
+ });
419
+
420
+ // dispatch-namespace
421
+ wrangler.command(
422
+ "dispatch-namespace",
423
+ "📦 Interact with a dispatch namespace",
424
+ (workerNamespaceYargs) => {
425
+ return workerNamespaceCommands(workerNamespaceYargs, subHelp);
426
+ }
427
+ );
428
+
429
+ // d1
430
+ wrangler.command("d1", "🗄 Interact with a D1 database", (d1Yargs) => {
431
+ return d1(d1Yargs.command(subHelp));
432
+ });
433
+
434
+ // pubsub
435
+ wrangler.command(
436
+ "pubsub",
437
+ "📮 Interact and manage Pub/Sub Brokers",
438
+ (pubsubYargs) => {
439
+ return pubSubCommands(pubsubYargs, subHelp);
440
+ }
441
+ );
442
+
443
+ // mtls-certificate
444
+ wrangler.command(
445
+ "mtls-certificate",
446
+ "🪪 Manage certificates used for mTLS connections",
447
+ (mtlsYargs) => {
448
+ return mTlsCertificateCommands(mtlsYargs.command(subHelp));
449
+ }
450
+ );
451
+
452
+ /**
453
+ * User Group: login, logout, and whoami
454
+ * TODO: group commands into User group similar to .group() for flags in yargs
455
+ */
456
+ // login
457
+ wrangler.command(
458
+ // this needs scopes as an option?
459
+ "login",
460
+ "🔓 Login to Cloudflare",
461
+ (yargs) => {
462
+ // TODO: This needs some copy editing
463
+ // I mean, this entire app does, but this too.
464
+ return yargs
465
+ .option("scopes-list", {
466
+ describe: "List all the available OAuth scopes with descriptions",
467
+ })
468
+ .option("browser", {
469
+ default: true,
470
+ type: "boolean",
471
+ describe: "Automatically open the OAuth link in a browser",
472
+ })
473
+ .option("scopes", {
474
+ describe: "Pick the set of applicable OAuth scopes when logging in",
475
+ array: true,
476
+ type: "string",
477
+ requiresArg: true,
478
+ });
479
+
480
+ // TODO: scopes
481
+ },
482
+ async (args) => {
483
+ await printWranglerBanner();
484
+ if (args["scopes-list"]) {
485
+ listScopes();
486
+ return;
487
+ }
488
+ if (args.scopes) {
489
+ if (args.scopes.length === 0) {
490
+ // don't allow no scopes to be passed, that would be weird
491
+ listScopes();
492
+ return;
493
+ }
494
+ if (!validateScopeKeys(args.scopes)) {
495
+ throw new CommandLineArgsError(
496
+ `One of ${args.scopes} is not a valid authentication scope. Run "wrangler login --list-scopes" to see the valid scopes.`
497
+ );
498
+ }
499
+ await login({ scopes: args.scopes, browser: args.browser });
500
+ return;
501
+ }
502
+ await login({ browser: args.browser });
503
+ const config = readConfig(args.config, args);
504
+ await metrics.sendMetricsEvent("login user", {
505
+ sendMetrics: config.send_metrics,
506
+ });
507
+
508
+ // TODO: would be nice if it optionally saved login
509
+ // credentials inside node_modules/.cache or something
510
+ // this way you could have multiple users on a single machine
511
+ }
512
+ );
513
+
514
+ // logout
515
+ wrangler.command(
516
+ // this needs scopes as an option?
517
+ "logout",
518
+ "🚪 Logout from Cloudflare",
519
+ () => {},
520
+ async (args) => {
521
+ await printWranglerBanner();
522
+ await logout();
523
+ const config = readConfig(undefined, args);
524
+ await metrics.sendMetricsEvent("logout user", {
525
+ sendMetrics: config.send_metrics,
526
+ });
527
+ }
528
+ );
529
+
530
+ // whoami
531
+ wrangler.command(
532
+ "whoami",
533
+ "🕵️ Retrieve your user info and test your auth config",
534
+ () => {},
535
+ async (args) => {
536
+ await printWranglerBanner();
537
+ await whoami();
538
+ const config = readConfig(undefined, args);
539
+ await metrics.sendMetricsEvent("view accounts", {
540
+ sendMetrics: config.send_metrics,
541
+ });
542
+ }
543
+ );
544
+
545
+ // type generation
546
+ wrangler.command(
547
+ "types",
548
+ "📝 Generate types from bindings & module rules in config",
549
+ () => {},
550
+ async (args) => {
551
+ await printWranglerBanner();
552
+ const config = readConfig(undefined, args);
553
+
554
+ const configBindings: Partial<Config> = {
555
+ kv_namespaces: config.kv_namespaces ?? [],
556
+ vars: { ...config.vars },
557
+ wasm_modules: config.wasm_modules,
558
+ text_blobs: {
559
+ ...config.text_blobs,
560
+ },
561
+ data_blobs: config.data_blobs,
562
+ durable_objects: config.durable_objects,
563
+ r2_buckets: config.r2_buckets,
564
+ d1_databases: config.d1_databases,
565
+ services: config.services,
566
+ analytics_engine_datasets: config.analytics_engine_datasets,
567
+ dispatch_namespaces: config.dispatch_namespaces,
568
+ logfwdr: config.logfwdr,
569
+ unsafe: config.unsafe,
570
+ rules: config.rules,
571
+ queues: config.queues,
572
+ };
573
+
574
+ await generateTypes(configBindings, config);
575
+ }
576
+ );
577
+
578
+ //deployments
579
+ const deploymentsWarning =
580
+ "🚧`wrangler deployments` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose";
581
+ wrangler.command(
582
+ "deployments",
583
+ "🚢 List and view details for deployments",
584
+ (yargs) =>
585
+ yargs
586
+ .option("name", {
587
+ describe: "The name of your worker",
588
+ type: "string",
589
+ })
590
+ .command(
591
+ "list",
592
+ "🚢 Displays the 10 most recent deployments for a worker",
593
+ async (listYargs) => listYargs,
594
+ async (listYargs) => {
595
+ const { accountId, scriptName, config } =
596
+ await commonDeploymentCMDSetup(listYargs, deploymentsWarning);
597
+ await deployments(accountId, scriptName, config);
598
+ }
599
+ )
600
+ .command(
601
+ "view [deployment-id]",
602
+ "🔍 View a deployment",
603
+ async (viewYargs) =>
604
+ viewYargs.positional("deployment-id", {
605
+ describe: "The ID of the deployment you want to inspect",
606
+ type: "string",
607
+ demandOption: false,
608
+ }),
609
+ async (viewYargs) => {
610
+ const { accountId, scriptName, config } =
611
+ await commonDeploymentCMDSetup(viewYargs, deploymentsWarning);
612
+
613
+ await viewDeployment(
614
+ accountId,
615
+ scriptName,
616
+ config,
617
+ viewYargs.deploymentId
618
+ );
619
+ }
620
+ )
621
+ .command(subHelp)
622
+ .epilogue(deploymentsWarning)
623
+ );
624
+ const rollbackWarning =
625
+ "🚧`wrangler rollback` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose";
626
+ wrangler
627
+ .command(
628
+ "rollback [deployment-id]",
629
+ "🔙 Rollback a deployment",
630
+ (rollbackYargs) =>
631
+ rollbackYargs
632
+ .positional("deployment-id", {
633
+ describe: "The ID of the deployment to rollback to",
634
+ type: "string",
635
+ demandOption: false,
636
+ })
637
+ .option("message", {
638
+ alias: "m",
639
+ describe:
640
+ "Skip confirmation and message prompts, uses provided argument as message",
641
+ type: "string",
642
+ default: undefined,
643
+ }),
644
+ async (rollbackYargs) => {
645
+ const { accountId, scriptName, config } =
646
+ await commonDeploymentCMDSetup(rollbackYargs, rollbackWarning);
647
+
648
+ await rollbackDeployment(
649
+ accountId,
650
+ scriptName,
651
+ config,
652
+ rollbackYargs.deploymentId,
653
+ rollbackYargs.message
654
+ );
655
+ }
656
+ )
657
+ .epilogue(rollbackWarning);
658
+
659
+ // This set to false to allow overwrite of default behaviour
660
+ wrangler.version(false);
661
+
662
+ // version
663
+ wrangler.command(
664
+ "version",
665
+ false,
666
+ () => {},
667
+ async () => {
668
+ if (process.stdout.isTTY) {
669
+ await printWranglerBanner();
670
+ } else {
671
+ logger.log(wranglerVersion);
672
+ }
673
+ }
674
+ );
675
+
676
+ wrangler.exitProcess(false);
677
+
678
+ return wrangler;
679
+ }
680
+
681
+ export async function main(argv: string[]): Promise<void> {
682
+ const wrangler = createCLIParser(argv);
683
+ try {
684
+ await wrangler.parse();
685
+ } catch (e) {
686
+ logger.log(""); // Just adds a bit of space
687
+ if (e instanceof CommandLineArgsError) {
688
+ logger.error(e.message);
689
+ // We are not able to ask the `wrangler` CLI parser to show help for a subcommand programmatically.
690
+ // The workaround is to re-run the parsing with an additional `--help` flag, which will result in the correct help message being displayed.
691
+ // The `wrangler` object is "frozen"; we cannot reuse that with different args, so we must create a new CLI parser to generate the help message.
692
+ await createCLIParser([...argv, "--help"]).parse();
693
+ } else if (e instanceof ParseError) {
694
+ e.notes.push({
695
+ text: "\nIf you think this is a bug, please open an issue at: https://github.com/cloudflare/workers-sdk/issues/new/choose",
696
+ });
697
+ logger.log(formatMessage(e));
698
+ } else if (
699
+ e instanceof Error &&
700
+ e.message.includes("Raw mode is not supported on")
701
+ ) {
702
+ // the current terminal doesn't support raw mode, which Ink needs to render
703
+ // Ink doesn't throw a typed error or subclass or anything, so we just check the message content.
704
+ // https://github.com/vadimdemedes/ink/blob/546fe16541fd05ad4e638d6842ca4cbe88b4092b/src/components/App.tsx#L138-L148
705
+
706
+ const currentPlatform = os.platform();
707
+
708
+ const thisTerminalIsUnsupported =
709
+ "This terminal doesn't support raw mode.";
710
+ const soWranglerWontWork =
711
+ "Wrangler uses raw mode to read user input and write output to the terminal, and won't function correctly without it.";
712
+ const tryRunningItIn =
713
+ "Try running your previous command in a terminal that supports raw mode";
714
+ const oneOfThese =
715
+ currentPlatform === "win32"
716
+ ? ", such as Command Prompt or Powershell."
717
+ : currentPlatform === "darwin"
718
+ ? ", such as Terminal.app or iTerm."
719
+ : "."; // linux user detected, hand holding disengaged.
720
+
721
+ logger.error(
722
+ `${thisTerminalIsUnsupported}\n${soWranglerWontWork}\n${tryRunningItIn}${oneOfThese}`
723
+ );
724
+ } else if (isBuildFailure(e)) {
725
+ logBuildFailure(e);
726
+ logger.error(e.message);
727
+ } else {
728
+ logger.error(e instanceof Error ? e.message : e);
729
+ logger.log(
730
+ `${fgGreenColor}%s${resetColor}`,
731
+ "If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
732
+ );
733
+ }
734
+ throw e;
735
+ }
736
+ }
737
+
738
+ export function getDevCompatibilityDate(
739
+ config: Config,
740
+ compatibilityDate = config.compatibility_date
741
+ ) {
742
+ const currentDate = new Date().toISOString().substring(0, 10);
743
+ if (config.configPath !== undefined && compatibilityDate === undefined) {
744
+ logger.warn(
745
+ `No compatibility_date was specified. Using today's date: ${currentDate}.\n` +
746
+ "Add one to your wrangler.toml file:\n" +
747
+ "```\n" +
748
+ `compatibility_date = "${currentDate}"\n` +
749
+ "```\n" +
750
+ "or pass it in your terminal:\n" +
751
+ "```\n" +
752
+ `--compatibility-date=${currentDate}\n` +
753
+ "```\n" +
754
+ "See https://developers.cloudflare.com/workers/platform/compatibility-dates/ for more information."
755
+ );
756
+ }
757
+ return compatibilityDate ?? currentDate;
758
+ }