wrangler 0.0.0-e6e1daba → 0.0.0-e739b7fe

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 (311) hide show
  1. package/README.md +10 -12
  2. package/bin/wrangler.js +14 -75
  3. package/package.json +226 -194
  4. package/templates/__tests__/tsconfig.json +1 -1
  5. package/templates/checked-fetch.js +10 -3
  6. package/templates/facade.d.ts +4 -1
  7. package/templates/gitignore +0 -4
  8. package/templates/init-tests/test-vitest-new-worker.js +1 -1
  9. package/templates/init-tests/test-vitest-new-worker.ts +1 -1
  10. package/templates/middleware/common.ts +9 -4
  11. package/templates/middleware/loader-modules.ts +67 -15
  12. package/templates/middleware/loader-sw.ts +6 -10
  13. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  14. package/templates/middleware/middleware-ensure-req-body-drained.ts +19 -0
  15. package/templates/middleware/middleware-miniflare3-json-error.ts +18 -5
  16. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  17. package/templates/middleware/middleware-multiworker-dev.ts +68 -0
  18. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  19. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  20. package/templates/modules-watch-stub.js +4 -0
  21. package/templates/new-worker-scheduled.ts +1 -1
  22. package/templates/new-worker.ts +1 -1
  23. package/templates/pages-dev-pipeline.ts +2 -1
  24. package/templates/pages-dev-util.ts +4 -1
  25. package/templates/pages-shim.ts +0 -3
  26. package/templates/pages-template-plugin.ts +12 -2
  27. package/templates/pages-template-worker.ts +11 -2
  28. package/templates/startDevWorker/InspectorProxyWorker.ts +661 -0
  29. package/templates/startDevWorker/ProxyWorker.ts +326 -0
  30. package/templates/tsconfig.init.json +1 -2
  31. package/templates/tsconfig.json +1 -1
  32. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  33. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  34. package/wrangler-dist/ProxyWorker.js +237 -0
  35. package/wrangler-dist/ProxyWorker.js.map +6 -0
  36. package/wrangler-dist/cli.d.ts +22647 -337
  37. package/wrangler-dist/cli.js +137196 -118219
  38. package/wrangler-dist/wasm-sync.wasm +0 -0
  39. package/import_meta_url.js +0 -3
  40. package/miniflare-config-stubs/.env.empty +0 -0
  41. package/miniflare-config-stubs/package.empty.json +0 -1
  42. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  43. package/miniflare-dist/index.mjs +0 -6368
  44. package/src/__tests__/access.test.ts +0 -25
  45. package/src/__tests__/api-dev.test.ts +0 -238
  46. package/src/__tests__/api-devregistry.test.js +0 -64
  47. package/src/__tests__/api.test.ts +0 -80
  48. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  49. package/src/__tests__/config-cache.test.ts +0 -42
  50. package/src/__tests__/configuration.test.ts +0 -4233
  51. package/src/__tests__/d1/d1.test.ts +0 -82
  52. package/src/__tests__/d1/execute.test.ts +0 -64
  53. package/src/__tests__/d1/migrate.test.ts +0 -155
  54. package/src/__tests__/d1/splitter.test.ts +0 -255
  55. package/src/__tests__/delete.test.ts +0 -266
  56. package/src/__tests__/deployments.test.ts +0 -129
  57. package/src/__tests__/dev.test.tsx +0 -1587
  58. package/src/__tests__/generate.test.ts +0 -238
  59. package/src/__tests__/get-host-from-url.test.ts +0 -16
  60. package/src/__tests__/guess-worker-format.test.ts +0 -120
  61. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  62. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  63. package/src/__tests__/helpers/end-event-loop.ts +0 -6
  64. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  65. package/src/__tests__/helpers/mock-auth-domain.ts +0 -20
  66. package/src/__tests__/helpers/mock-bin.ts +0 -36
  67. package/src/__tests__/helpers/mock-console.ts +0 -106
  68. package/src/__tests__/helpers/mock-dialogs.ts +0 -139
  69. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +0 -25
  70. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -11
  71. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  72. package/src/__tests__/helpers/mock-istty.ts +0 -74
  73. package/src/__tests__/helpers/mock-known-routes.ts +0 -12
  74. package/src/__tests__/helpers/mock-kv.ts +0 -46
  75. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -263
  76. package/src/__tests__/helpers/mock-process.ts +0 -34
  77. package/src/__tests__/helpers/mock-set-timeout.ts +0 -16
  78. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  79. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  80. package/src/__tests__/helpers/msw/blob-worker.cjs +0 -19
  81. package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
  82. package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -93
  83. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -81
  84. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -31
  85. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -60
  86. package/src/__tests__/helpers/msw/handlers/script.ts +0 -56
  87. package/src/__tests__/helpers/msw/handlers/user.ts +0 -52
  88. package/src/__tests__/helpers/msw/handlers/zones.ts +0 -20
  89. package/src/__tests__/helpers/msw/index.ts +0 -50
  90. package/src/__tests__/helpers/msw/read-file-sync.js +0 -61
  91. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  92. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  93. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +0 -28
  94. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  95. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  96. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  97. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
  98. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  99. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  100. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  101. package/src/__tests__/https-options.test.ts +0 -163
  102. package/src/__tests__/index.test.ts +0 -274
  103. package/src/__tests__/init.test.ts +0 -3164
  104. package/src/__tests__/jest.setup.ts +0 -175
  105. package/src/__tests__/kv.test.ts +0 -1799
  106. package/src/__tests__/logger.test.ts +0 -141
  107. package/src/__tests__/logout.test.ts +0 -47
  108. package/src/__tests__/metrics.test.ts +0 -493
  109. package/src/__tests__/middleware.scheduled.test.ts +0 -145
  110. package/src/__tests__/middleware.test.ts +0 -815
  111. package/src/__tests__/mtls-certificates.test.ts +0 -585
  112. package/src/__tests__/package-manager.test.ts +0 -353
  113. package/src/__tests__/pages/deployment-list.test.ts +0 -78
  114. package/src/__tests__/pages/functions-build.test.ts +0 -402
  115. package/src/__tests__/pages/pages.test.ts +0 -81
  116. package/src/__tests__/pages/project-create.test.ts +0 -63
  117. package/src/__tests__/pages/project-list.test.ts +0 -108
  118. package/src/__tests__/pages/project-upload.test.ts +0 -481
  119. package/src/__tests__/pages/publish.test.ts +0 -2745
  120. package/src/__tests__/pages-deployment-tail.test.ts +0 -955
  121. package/src/__tests__/parse.test.ts +0 -436
  122. package/src/__tests__/paths.test.ts +0 -39
  123. package/src/__tests__/publish.test.ts +0 -8167
  124. package/src/__tests__/pubsub.test.ts +0 -493
  125. package/src/__tests__/queues.test.ts +0 -529
  126. package/src/__tests__/r2.test.ts +0 -374
  127. package/src/__tests__/route.test.ts +0 -45
  128. package/src/__tests__/secret.test.ts +0 -693
  129. package/src/__tests__/tail.test.ts +0 -958
  130. package/src/__tests__/test-old-node-version.js +0 -31
  131. package/src/__tests__/tsconfig-sanity.ts +0 -12
  132. package/src/__tests__/tsconfig.json +0 -8
  133. package/src/__tests__/tsconfig.tsbuildinfo +0 -1
  134. package/src/__tests__/type-generation.test.ts +0 -233
  135. package/src/__tests__/user.test.ts +0 -118
  136. package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
  137. package/src/__tests__/validate-dev-props.test.ts +0 -56
  138. package/src/__tests__/version.test.ts +0 -35
  139. package/src/__tests__/whoami.test.tsx +0 -172
  140. package/src/__tests__/worker-namespace.test.ts +0 -339
  141. package/src/abort.d.ts +0 -3
  142. package/src/api/dev.ts +0 -328
  143. package/src/api/index.ts +0 -11
  144. package/src/api/mtls-certificate.ts +0 -148
  145. package/src/api/pages/create-worker-bundle-contents.ts +0 -75
  146. package/src/api/pages/index.ts +0 -5
  147. package/src/api/pages/publish.tsx +0 -368
  148. package/src/bundle-reporter.ts +0 -68
  149. package/src/bundle.ts +0 -877
  150. package/src/cfetch/index.ts +0 -158
  151. package/src/cfetch/internal.ts +0 -258
  152. package/src/cli.ts +0 -28
  153. package/src/config/README.md +0 -107
  154. package/src/config/config.ts +0 -282
  155. package/src/config/diagnostics.ts +0 -80
  156. package/src/config/environment.ts +0 -586
  157. package/src/config/index.ts +0 -375
  158. package/src/config/validation-helpers.ts +0 -597
  159. package/src/config/validation.ts +0 -2198
  160. package/src/config-cache.ts +0 -85
  161. package/src/create-worker-preview.ts +0 -293
  162. package/src/create-worker-upload-form.ts +0 -334
  163. package/src/d1/backups.tsx +0 -215
  164. package/src/d1/constants.ts +0 -2
  165. package/src/d1/create.tsx +0 -64
  166. package/src/d1/delete.ts +0 -53
  167. package/src/d1/execute.tsx +0 -354
  168. package/src/d1/formatTimeAgo.ts +0 -14
  169. package/src/d1/index.ts +0 -100
  170. package/src/d1/list.tsx +0 -60
  171. package/src/d1/migrations/apply.tsx +0 -206
  172. package/src/d1/migrations/create.tsx +0 -76
  173. package/src/d1/migrations/helpers.ts +0 -172
  174. package/src/d1/migrations/index.ts +0 -3
  175. package/src/d1/migrations/list.tsx +0 -92
  176. package/src/d1/migrations/options.ts +0 -23
  177. package/src/d1/options.ts +0 -22
  178. package/src/d1/splitter.ts +0 -161
  179. package/src/d1/types.ts +0 -25
  180. package/src/d1/utils.ts +0 -49
  181. package/src/delete.ts +0 -100
  182. package/src/deployments.ts +0 -116
  183. package/src/deprecated/index.ts +0 -144
  184. package/src/dev/dev-vars.ts +0 -39
  185. package/src/dev/dev.tsx +0 -600
  186. package/src/dev/get-local-persistence-path.ts +0 -31
  187. package/src/dev/local.tsx +0 -922
  188. package/src/dev/remote.tsx +0 -632
  189. package/src/dev/start-server.ts +0 -538
  190. package/src/dev/use-esbuild.ts +0 -205
  191. package/src/dev/validate-dev-props.ts +0 -31
  192. package/src/dev-registry.ts +0 -201
  193. package/src/dev.tsx +0 -914
  194. package/src/dialogs.ts +0 -136
  195. package/src/dispatch-namespace.ts +0 -211
  196. package/src/docs/index.ts +0 -97
  197. package/src/durable.ts +0 -102
  198. package/src/entry.ts +0 -327
  199. package/src/environment-variables/factory.ts +0 -88
  200. package/src/environment-variables/misc-variables.ts +0 -30
  201. package/src/errors.ts +0 -11
  202. package/src/generate/index.ts +0 -298
  203. package/src/git-client.ts +0 -135
  204. package/src/global-wrangler-config-path.ts +0 -26
  205. package/src/https-options.ts +0 -127
  206. package/src/index.ts +0 -705
  207. package/src/init.ts +0 -1022
  208. package/src/inspect.ts +0 -782
  209. package/src/intl-polyfill.d.ts +0 -139
  210. package/src/is-ci.ts +0 -14
  211. package/src/is-interactive.ts +0 -16
  212. package/src/jest.d.ts +0 -4
  213. package/src/kv/helpers.ts +0 -430
  214. package/src/kv/index.ts +0 -594
  215. package/src/logger.ts +0 -104
  216. package/src/metrics/index.ts +0 -5
  217. package/src/metrics/metrics-config.ts +0 -239
  218. package/src/metrics/metrics-dispatcher.ts +0 -96
  219. package/src/metrics/metrics-usage-headers.ts +0 -24
  220. package/src/metrics/send-event.ts +0 -98
  221. package/src/miniflare-cli/README.md +0 -30
  222. package/src/miniflare-cli/assets.ts +0 -251
  223. package/src/miniflare-cli/index.ts +0 -210
  224. package/src/miniflare-cli/request-context.ts +0 -40
  225. package/src/miniflare-cli/tsconfig.json +0 -9
  226. package/src/miniflare-cli/tsconfig.tsbuildinfo +0 -1
  227. package/src/miniflare-cli/types.ts +0 -11
  228. package/src/module-collection.ts +0 -267
  229. package/src/mtls-certificate/cli.ts +0 -155
  230. package/src/open-in-browser.ts +0 -17
  231. package/src/package-manager.ts +0 -219
  232. package/src/pages/build.ts +0 -232
  233. package/src/pages/buildFunctions.ts +0 -130
  234. package/src/pages/constants.ts +0 -18
  235. package/src/pages/deployment-tails.ts +0 -281
  236. package/src/pages/deployments.tsx +0 -86
  237. package/src/pages/dev.ts +0 -716
  238. package/src/pages/errors.ts +0 -66
  239. package/src/pages/functions/buildPlugin.ts +0 -90
  240. package/src/pages/functions/buildWorker.ts +0 -288
  241. package/src/pages/functions/filepath-routing.test.ts +0 -234
  242. package/src/pages/functions/filepath-routing.ts +0 -189
  243. package/src/pages/functions/identifiers.ts +0 -78
  244. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  245. package/src/pages/functions/routes-consolidation.ts +0 -73
  246. package/src/pages/functions/routes-transformation.test.ts +0 -282
  247. package/src/pages/functions/routes-transformation.ts +0 -115
  248. package/src/pages/functions/routes-validation.test.ts +0 -403
  249. package/src/pages/functions/routes-validation.ts +0 -202
  250. package/src/pages/functions/routes.ts +0 -151
  251. package/src/pages/functions/tsconfig.json +0 -8
  252. package/src/pages/functions/tsconfig.tsbuildinfo +0 -1
  253. package/src/pages/functions.ts +0 -86
  254. package/src/pages/hash.ts +0 -13
  255. package/src/pages/index.ts +0 -102
  256. package/src/pages/projects.tsx +0 -162
  257. package/src/pages/prompt-select-project.tsx +0 -31
  258. package/src/pages/publish.tsx +0 -276
  259. package/src/pages/types.ts +0 -46
  260. package/src/pages/upload.tsx +0 -449
  261. package/src/pages/utils.ts +0 -23
  262. package/src/parse.ts +0 -308
  263. package/src/paths.ts +0 -71
  264. package/src/proxy.ts +0 -694
  265. package/src/publish/index.ts +0 -274
  266. package/src/publish/publish.ts +0 -1065
  267. package/src/pubsub/index.ts +0 -286
  268. package/src/pubsub/pubsub-commands.ts +0 -623
  269. package/src/queues/cli/commands/consumer/add.ts +0 -65
  270. package/src/queues/cli/commands/consumer/index.ts +0 -19
  271. package/src/queues/cli/commands/consumer/remove.ts +0 -31
  272. package/src/queues/cli/commands/create.ts +0 -25
  273. package/src/queues/cli/commands/delete.ts +0 -26
  274. package/src/queues/cli/commands/index.ts +0 -35
  275. package/src/queues/cli/commands/list.ts +0 -25
  276. package/src/queues/client.ts +0 -135
  277. package/src/queues/utils.ts +0 -18
  278. package/src/r2/constants.ts +0 -4
  279. package/src/r2/helpers.ts +0 -132
  280. package/src/r2/index.ts +0 -289
  281. package/src/routes.ts +0 -140
  282. package/src/secret/index.ts +0 -375
  283. package/src/selfsigned.d.ts +0 -29
  284. package/src/sites.ts +0 -372
  285. package/src/tail/createTail.ts +0 -406
  286. package/src/tail/filters.ts +0 -277
  287. package/src/tail/index.ts +0 -211
  288. package/src/tail/printing.ts +0 -122
  289. package/src/tsconfig-sanity.ts +0 -16
  290. package/src/type-generation.ts +0 -181
  291. package/src/update-check.ts +0 -19
  292. package/src/user/access.ts +0 -68
  293. package/src/user/auth-variables.ts +0 -113
  294. package/src/user/choose-account.tsx +0 -39
  295. package/src/user/generate-auth-url.ts +0 -33
  296. package/src/user/generate-random-state.ts +0 -16
  297. package/src/user/index.ts +0 -2
  298. package/src/user/user.ts +0 -1233
  299. package/src/utils/collectKeyValues.ts +0 -14
  300. package/src/whoami.ts +0 -135
  301. package/src/worker.ts +0 -257
  302. package/src/yargs-types.ts +0 -37
  303. package/src/zones.ts +0 -191
  304. package/templates/__tests__/tsconfig.tsbuildinfo +0 -1
  305. package/templates/d1-beta-facade.js +0 -241
  306. package/templates/first-party-worker-module-facade.ts +0 -19
  307. package/templates/format-dev-errors.ts +0 -34
  308. package/templates/serve-static-assets.ts +0 -66
  309. package/templates/service-bindings-module-facade.js +0 -55
  310. package/templates/service-bindings-sw-facade.js +0 -42
  311. package/templates/tsconfig.tsbuildinfo +0 -1
package/src/dev.tsx DELETED
@@ -1,914 +0,0 @@
1
- import path from "node:path";
2
- import chalk from "chalk";
3
- import { watch } from "chokidar";
4
- import getPort from "get-port";
5
- import { render } from "ink";
6
- import React from "react";
7
- import { findWranglerToml, printBindings, readConfig } from "./config";
8
- import Dev from "./dev/dev";
9
- import { getVarsForDev } from "./dev/dev-vars";
10
- import { getLocalPersistencePath } from "./dev/get-local-persistence-path";
11
-
12
- import { startDevServer } from "./dev/start-server";
13
- import { getEntry } from "./entry";
14
- import { logger } from "./logger";
15
- import * as metrics from "./metrics";
16
- import { getAssetPaths, getSiteAssetPaths } from "./sites";
17
- import { getAccountFromCache, loginOrRefreshIfRequired } from "./user";
18
- import { collectKeyValues } from "./utils/collectKeyValues";
19
- import { identifyD1BindingsAsBeta } from "./worker";
20
- import { getHostFromRoute, getZoneForRoute, getZoneIdFromHost } from "./zones";
21
- import {
22
- DEFAULT_INSPECTOR_PORT,
23
- DEFAULT_LOCAL_PORT,
24
- getDevCompatibilityDate,
25
- getRules,
26
- getScriptName,
27
- isLegacyEnv,
28
- printWranglerBanner,
29
- } from "./index";
30
- import type { Config, Environment } from "./config";
31
- import type { Route } from "./config/environment";
32
- import type { LoggerLevel } from "./logger";
33
- import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types";
34
- import type { CfWorkerInit } from "./worker";
35
- import type {
36
- CommonYargsArgv,
37
- StrictYargsOptionsToInterface,
38
- } from "./yargs-types";
39
-
40
- export function devOptions(yargs: CommonYargsArgv) {
41
- return (
42
- yargs
43
- .positional("script", {
44
- describe: "The path to an entry point for your worker",
45
- type: "string",
46
- })
47
- .option("name", {
48
- describe: "Name of the worker",
49
- type: "string",
50
- requiresArg: true,
51
- })
52
- // We want to have a --no-bundle flag, but yargs requires that
53
- // we also have a --bundle flag (that it adds the --no to by itself)
54
- // So we make a --bundle flag, but hide it, and then add a --no-bundle flag
55
- // that's visible to the user but doesn't "do" anything.
56
- .option("bundle", {
57
- describe: "Run wrangler's compilation step before publishing",
58
- type: "boolean",
59
- hidden: true,
60
- })
61
- .option("no-bundle", {
62
- describe: "Skip internal build steps and directly publish script",
63
- type: "boolean",
64
- default: false,
65
- })
66
- .option("format", {
67
- choices: ["modules", "service-worker"] as const,
68
- describe: "Choose an entry type",
69
- hidden: true,
70
- deprecated: true,
71
- })
72
- .option("compatibility-date", {
73
- describe: "Date to use for compatibility checks",
74
- type: "string",
75
- requiresArg: true,
76
- })
77
- .option("compatibility-flags", {
78
- describe: "Flags to use for compatibility checks",
79
- alias: "compatibility-flag",
80
- type: "string",
81
- requiresArg: true,
82
- array: true,
83
- })
84
- .option("latest", {
85
- describe: "Use the latest version of the worker runtime",
86
- type: "boolean",
87
- default: true,
88
- })
89
- .option("ip", {
90
- describe: "IP address to listen on",
91
- type: "string",
92
- })
93
- .option("port", {
94
- describe: "Port to listen on",
95
- type: "number",
96
- })
97
- .option("inspector-port", {
98
- describe: "Port for devtools to connect to",
99
- type: "number",
100
- })
101
- .option("routes", {
102
- describe: "Routes to upload",
103
- alias: "route",
104
- type: "string",
105
- requiresArg: true,
106
- array: true,
107
- })
108
- .option("host", {
109
- type: "string",
110
- requiresArg: true,
111
- describe:
112
- "Host to forward requests to, defaults to the zone of project",
113
- })
114
- .option("local-protocol", {
115
- describe: "Protocol to listen to requests on, defaults to http.",
116
- choices: ["http", "https"] as const,
117
- })
118
- .options("local-upstream", {
119
- type: "string",
120
- describe:
121
- "Host to act as origin in local mode, defaults to dev.host or route",
122
- })
123
- .option("experimental-public", {
124
- describe: "Static assets to be served",
125
- type: "string",
126
- requiresArg: true,
127
- deprecated: true,
128
- hidden: true,
129
- })
130
- .option("assets", {
131
- describe: "Static assets to be served",
132
- type: "string",
133
- requiresArg: true,
134
- })
135
- .option("public", {
136
- describe: "(Deprecated) Static assets to be served",
137
- type: "string",
138
- requiresArg: true,
139
- deprecated: true,
140
- hidden: true,
141
- })
142
- .option("site", {
143
- describe: "Root folder of static assets for Workers Sites",
144
- type: "string",
145
- requiresArg: true,
146
- })
147
- .option("site-include", {
148
- describe:
149
- "Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded.",
150
- type: "string",
151
- requiresArg: true,
152
- array: true,
153
- })
154
- .option("site-exclude", {
155
- describe:
156
- "Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded.",
157
- type: "string",
158
- requiresArg: true,
159
- array: true,
160
- })
161
- .option("upstream-protocol", {
162
- describe: "Protocol to forward requests to host on, defaults to https.",
163
- choices: ["http", "https"] as const,
164
- })
165
- .option("var", {
166
- describe:
167
- "A key-value pair to be injected into the script as a variable",
168
- type: "string",
169
- requiresArg: true,
170
- array: true,
171
- })
172
- .option("define", {
173
- describe: "A key-value pair to be substituted in the script",
174
- type: "string",
175
- requiresArg: true,
176
- array: true,
177
- })
178
- .option("jsx-factory", {
179
- describe: "The function that is called for each JSX element",
180
- type: "string",
181
- requiresArg: true,
182
- })
183
- .option("jsx-fragment", {
184
- describe: "The function that is called for each JSX fragment",
185
- type: "string",
186
- requiresArg: true,
187
- })
188
- .option("tsconfig", {
189
- describe: "Path to a custom tsconfig.json file",
190
- type: "string",
191
- requiresArg: true,
192
- })
193
- .option("local", {
194
- alias: "l",
195
- describe: "Run on my machine",
196
- type: "boolean",
197
- default: false, // I bet this will a point of contention. We'll revisit it.
198
- })
199
- .option("experimental-local", {
200
- describe: "Run on my machine using the Cloudflare Workers runtime",
201
- type: "boolean",
202
- default: false,
203
- })
204
- .option("experimental-local-remote-kv", {
205
- describe:
206
- "Read/write KV data from/to real namespaces on the Cloudflare network",
207
- type: "boolean",
208
- default: false,
209
- })
210
- .check((argv) => {
211
- if (argv.local && argv["experimental-local"]) {
212
- throw new Error(
213
- "--local and --experimental-local are mutually exclusive. " +
214
- "Please enable one or the other."
215
- );
216
- }
217
- if (
218
- argv["experimental-local-remote-kv"] &&
219
- !argv["experimental-local"]
220
- ) {
221
- throw new Error(
222
- "--experimental-local-remote-kv requires --experimental-local to be enabled."
223
- );
224
- }
225
- return true;
226
- })
227
- .option("minify", {
228
- describe: "Minify the script",
229
- type: "boolean",
230
- })
231
- .option("node-compat", {
232
- describe: "Enable node.js compatibility",
233
- type: "boolean",
234
- })
235
- .option("experimental-enable-local-persistence", {
236
- describe:
237
- "Enable persistence for local mode (deprecated, use --persist)",
238
- type: "boolean",
239
- deprecated: true,
240
- hidden: true,
241
- })
242
- .option("persist", {
243
- describe:
244
- "Enable persistence for local mode, using default path: .wrangler/state",
245
- type: "boolean",
246
- })
247
- .option("persist-to", {
248
- describe:
249
- "Specify directory to use for local persistence (implies --persist)",
250
- type: "string",
251
- requiresArg: true,
252
- })
253
- .option("live-reload", {
254
- describe:
255
- "Auto reload HTML pages when change is detected in local mode",
256
- type: "boolean",
257
- })
258
- .check((argv) => {
259
- const local = argv["local"] || argv["experimental-local"];
260
- if (argv["live-reload"] && !local) {
261
- throw new Error(
262
- "--live-reload is only supported in local mode. " +
263
- "Please enable either --local or --experimental-local."
264
- );
265
- }
266
- return true;
267
- })
268
- .option("inspect", {
269
- describe: "Enable dev tools",
270
- type: "boolean",
271
- deprecated: true,
272
- hidden: true,
273
- })
274
- .option("legacy-env", {
275
- type: "boolean",
276
- describe: "Use legacy environments",
277
- hidden: true,
278
- })
279
- .option("test-scheduled", {
280
- describe: "Test scheduled events by visiting /__scheduled in browser",
281
- type: "boolean",
282
- default: false,
283
- })
284
- .option("log-level", {
285
- choices: ["debug", "info", "log", "warn", "error", "none"] as const,
286
- describe: "Specify logging level",
287
- // Yargs requires this to type log-level properly
288
- default: "log" as LoggerLevel,
289
- })
290
- );
291
- }
292
-
293
- type DevArguments = StrictYargsOptionsToInterface<typeof devOptions>;
294
-
295
- export async function devHandler(args: DevArguments) {
296
- if (!(args.local || args.experimentalLocal)) {
297
- const isLoggedIn = await loginOrRefreshIfRequired();
298
- if (!isLoggedIn) {
299
- throw new Error(
300
- "You must be logged in to use wrangler dev in remote mode. Try logging in, or run wrangler dev --local."
301
- );
302
- }
303
- }
304
-
305
- let watcher;
306
- try {
307
- const devInstance = await startDev(args);
308
- watcher = devInstance.watcher;
309
- const { waitUntilExit } = devInstance.devReactElement;
310
- await waitUntilExit();
311
- } finally {
312
- await watcher?.close();
313
- }
314
- }
315
-
316
- export type AdditionalDevProps = {
317
- vars?: {
318
- [key: string]: unknown;
319
- };
320
- kv?: {
321
- binding: string;
322
- id: string;
323
- preview_id?: string;
324
- }[];
325
- durableObjects?: {
326
- name: string;
327
- class_name: string;
328
- script_name?: string | undefined;
329
- environment?: string | undefined;
330
- }[];
331
- r2?: {
332
- binding: string;
333
- bucket_name: string;
334
- preview_bucket_name?: string;
335
- }[];
336
- d1Databases?: Environment["d1_databases"];
337
- };
338
-
339
- type StartDevOptions = DevArguments &
340
- // These options can be passed in directly when called with the `wrangler.dev()` API.
341
- // They aren't exposed as CLI arguments.
342
- AdditionalDevProps & {
343
- forceLocal?: boolean;
344
- disableDevRegistry?: boolean;
345
- enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
346
- onReady?: (ip: string, port: number) => void;
347
- logPrefix?: string;
348
- showInteractiveDevSession?: boolean;
349
- };
350
-
351
- export async function startDev(args: StartDevOptions) {
352
- let watcher: ReturnType<typeof watch> | undefined;
353
- let rerender: (node: React.ReactNode) => void | undefined;
354
- try {
355
- if (args.logLevel) {
356
- logger.loggerLevel = args.logLevel;
357
- }
358
- await printWranglerBanner();
359
-
360
- if (args.local && process.platform !== "win32") {
361
- logger.info(
362
- chalk.magenta(
363
- `Want to try out the next version of local mode using the open-source Workers runtime?\nSwitch out --local for ${chalk.bold(
364
- "--experimental-local"
365
- )} and let us know what you think at https://discord.gg/cloudflaredev !`
366
- )
367
- );
368
- }
369
-
370
- const configPath =
371
- args.config ||
372
- (args.script && findWranglerToml(path.dirname(args.script)));
373
- let config = readConfig(configPath, args);
374
-
375
- if (config.configPath) {
376
- watcher = watch(config.configPath, {
377
- persistent: true,
378
- }).on("change", async (_event) => {
379
- // TODO: Do we need to handle different `_event` types differently?
380
- // e.g. what if the file is deleted, or added?
381
- config = readConfig(configPath, args);
382
- if (config.configPath) {
383
- logger.log(`${path.basename(config.configPath)} changed...`);
384
- rerender(await getDevReactElement(config));
385
- }
386
- });
387
- }
388
-
389
- const {
390
- entry,
391
- nodeCompat,
392
- upstreamProtocol,
393
- zoneId,
394
- host,
395
- routes,
396
- getLocalPort,
397
- getInspectorPort,
398
- cliDefines,
399
- localPersistencePath,
400
- } = await validateDevServerSettings(args, config);
401
-
402
- await metrics.sendMetricsEvent(
403
- "run dev",
404
- {
405
- local: args.local,
406
- usesTypeScript: /\.tsx?$/.test(entry.file),
407
- },
408
- { sendMetrics: config.send_metrics, offline: args.local }
409
- );
410
-
411
- // eslint-disable-next-line no-inner-declarations
412
- async function getDevReactElement(configParam: Config) {
413
- const { assetPaths, bindings } = getBindingsAndAssetPaths(
414
- args,
415
- configParam
416
- );
417
-
418
- return (
419
- <Dev
420
- name={getScriptName({ name: args.name, env: args.env }, configParam)}
421
- noBundle={!(args.bundle ?? !configParam.no_bundle)}
422
- entry={entry}
423
- env={args.env}
424
- zone={zoneId}
425
- host={host}
426
- routes={routes}
427
- rules={getRules(configParam)}
428
- legacyEnv={isLegacyEnv(configParam)}
429
- minify={args.minify ?? configParam.minify}
430
- nodeCompat={nodeCompat}
431
- build={configParam.build || {}}
432
- define={{ ...configParam.define, ...cliDefines }}
433
- initialMode={
434
- args.local || args.experimentalLocal ? "local" : "remote"
435
- }
436
- jsxFactory={args.jsxFactory || configParam.jsx_factory}
437
- jsxFragment={args.jsxFragment || configParam.jsx_fragment}
438
- tsconfig={args.tsconfig ?? configParam.tsconfig}
439
- upstreamProtocol={upstreamProtocol}
440
- localProtocol={args.localProtocol || configParam.dev.local_protocol}
441
- localUpstream={args.localUpstream ?? host}
442
- localPersistencePath={localPersistencePath}
443
- liveReload={args.liveReload || false}
444
- accountId={configParam.account_id || getAccountFromCache()?.id}
445
- assetPaths={assetPaths}
446
- assetsConfig={configParam.assets}
447
- initialPort={
448
- args.port ?? configParam.dev.port ?? (await getLocalPort())
449
- }
450
- initialIp={args.ip || configParam.dev.ip}
451
- inspectorPort={
452
- args.inspectorPort ??
453
- configParam.dev.inspector_port ??
454
- (await getInspectorPort())
455
- }
456
- isWorkersSite={Boolean(args.site || configParam.site)}
457
- compatibilityDate={getDevCompatibilityDate(
458
- configParam,
459
- args.compatibilityDate
460
- )}
461
- compatibilityFlags={
462
- args.compatibilityFlags || configParam.compatibility_flags
463
- }
464
- usageModel={configParam.usage_model}
465
- bindings={bindings}
466
- crons={configParam.triggers.crons}
467
- queueConsumers={configParam.queues.consumers}
468
- logPrefix={args.logPrefix}
469
- onReady={args.onReady}
470
- inspect={args.inspect ?? true}
471
- showInteractiveDevSession={args.showInteractiveDevSession}
472
- forceLocal={args.forceLocal}
473
- enablePagesAssetsServiceBinding={args.enablePagesAssetsServiceBinding}
474
- firstPartyWorker={configParam.first_party_worker}
475
- sendMetrics={configParam.send_metrics}
476
- testScheduled={args.testScheduled}
477
- experimentalLocal={args.experimentalLocal}
478
- experimentalLocalRemoteKv={args.experimentalLocalRemoteKv}
479
- />
480
- );
481
- }
482
- const devReactElement = render(await getDevReactElement(config));
483
-
484
- // In the bootstrapper script `bin/wrangler.js`, we open an IPC channel, so
485
- // IPC messages from this process are propagated through the bootstrapper.
486
- // Normally, Node's SIGINT handler would close this for us, but interactive
487
- // mode enables raw mode on stdin which disables the built-in handler. The
488
- // following line disconnects from the IPC channel when we press `x` or
489
- // CTRL-C in interactive mode, ensuring no open handles, and allowing for a
490
- // clean exit. Note, if we called `stop()` using the dev API, we don't want
491
- // to disconnect here, as the user may still need IPC. We also don't want
492
- // to disconnect if this file was imported in Jest (not the case with E2E
493
- // tests), as that would stop communication with the test runner.
494
- let apiStopped = false;
495
- void devReactElement.waitUntilExit().then(() => {
496
- if (!apiStopped && typeof jest === "undefined") process.disconnect?.();
497
- });
498
-
499
- rerender = devReactElement.rerender;
500
- return {
501
- devReactElement,
502
- watcher,
503
- stop: async () => {
504
- apiStopped = true;
505
- devReactElement.unmount();
506
- await watcher?.close();
507
- },
508
- };
509
- } finally {
510
- await watcher?.close();
511
- }
512
- }
513
-
514
- export async function startApiDev(args: StartDevOptions) {
515
- if (args.logLevel) {
516
- logger.loggerLevel = args.logLevel;
517
- }
518
- await printWranglerBanner();
519
-
520
- const configPath =
521
- args.config || (args.script && findWranglerToml(path.dirname(args.script)));
522
- const config = readConfig(configPath, args);
523
-
524
- const {
525
- entry,
526
- nodeCompat,
527
- upstreamProtocol,
528
- zoneId,
529
- host,
530
- routes,
531
- getLocalPort,
532
- getInspectorPort,
533
- cliDefines,
534
- localPersistencePath,
535
- } = await validateDevServerSettings(args, config);
536
-
537
- await metrics.sendMetricsEvent(
538
- "run dev (api)",
539
- { local: args.local },
540
- { sendMetrics: config.send_metrics, offline: args.local }
541
- );
542
-
543
- // eslint-disable-next-line no-inner-declarations
544
- async function getDevServer(configParam: Config) {
545
- const { assetPaths, bindings } = getBindingsAndAssetPaths(
546
- args,
547
- configParam
548
- );
549
-
550
- //if args.bundle is on, don't disable bundling
551
- //if there's no args.bundle, and configParam.no_bundle is on, disable bundling
552
- //otherwise, enable bundling
553
- const enableBundling = args.bundle ?? !configParam.no_bundle;
554
- return await startDevServer({
555
- name: getScriptName({ name: args.name, env: args.env }, configParam),
556
- noBundle: !enableBundling,
557
- entry: entry,
558
- env: args.env,
559
- zone: zoneId,
560
- host: host,
561
- routes: routes,
562
- rules: getRules(configParam),
563
- legacyEnv: isLegacyEnv(configParam),
564
- minify: args.minify ?? configParam.minify,
565
- nodeCompat: nodeCompat,
566
- build: configParam.build || {},
567
- define: { ...config.define, ...cliDefines },
568
- initialMode: args.local ? "local" : "remote",
569
- jsxFactory: args.jsxFactory ?? configParam.jsx_factory,
570
- jsxFragment: args.jsxFragment ?? configParam.jsx_fragment,
571
- tsconfig: args.tsconfig ?? configParam.tsconfig,
572
- upstreamProtocol: upstreamProtocol,
573
- localProtocol: args.localProtocol ?? configParam.dev.local_protocol,
574
- localUpstream: args.localUpstream ?? host,
575
- localPersistencePath,
576
- liveReload: args.liveReload ?? false,
577
- accountId: configParam.account_id ?? getAccountFromCache()?.id,
578
- assetPaths: assetPaths,
579
- assetsConfig: configParam.assets,
580
- //port can be 0, which means to use a random port
581
- initialPort: args.port ?? configParam.dev.port ?? (await getLocalPort()),
582
- initialIp: args.ip ?? configParam.dev.ip,
583
- inspectorPort:
584
- args.inspectorPort ??
585
- configParam.dev.inspector_port ??
586
- (await getInspectorPort()),
587
- isWorkersSite: Boolean(args.site || configParam.site),
588
- compatibilityDate: getDevCompatibilityDate(
589
- config,
590
- // Only `compatibilityDate` will be set when using `unstable_dev`
591
- args.compatibilityDate
592
- ),
593
- compatibilityFlags:
594
- args.compatibilityFlags ?? configParam.compatibility_flags,
595
- usageModel: configParam.usage_model,
596
- bindings: bindings,
597
- crons: configParam.triggers.crons,
598
- queueConsumers: configParam.queues.consumers,
599
- logPrefix: args.logPrefix,
600
- onReady: args.onReady,
601
- inspect: args.inspect ?? true,
602
- showInteractiveDevSession: args.showInteractiveDevSession,
603
- forceLocal: args.forceLocal,
604
- enablePagesAssetsServiceBinding: args.enablePagesAssetsServiceBinding,
605
- local: args.local ?? true,
606
- firstPartyWorker: configParam.first_party_worker,
607
- sendMetrics: configParam.send_metrics,
608
- testScheduled: args.testScheduled,
609
- experimentalLocal: args.experimentalLocal,
610
- experimentalLocalRemoteKv: args.experimentalLocalRemoteKv,
611
- disableDevRegistry: args.disableDevRegistry ?? false,
612
- });
613
- }
614
-
615
- const devServer = await getDevServer(config);
616
- if (!devServer) {
617
- throw logger.error("Failed to start dev server.");
618
- }
619
-
620
- return {
621
- stop: async () => {
622
- await devServer.stop();
623
- },
624
- };
625
- }
626
- /**
627
- * Avoiding calling `getPort()` multiple times by memoizing the first result.
628
- */
629
- function memoizeGetPort(defaultPort: number) {
630
- let portValue: number;
631
- return async () => {
632
- return portValue || (portValue = await getPort({ port: defaultPort }));
633
- };
634
- }
635
- /**
636
- * mask anything that was overridden in .dev.vars
637
- * so that we don't log potential secrets into the terminal
638
- */
639
- function maskVars(bindings: CfWorkerInit["bindings"], configParam: Config) {
640
- const maskedVars = { ...bindings.vars };
641
- for (const key of Object.keys(maskedVars)) {
642
- if (maskedVars[key] !== configParam.vars[key]) {
643
- // This means it was overridden in .dev.vars
644
- // so let's mask it
645
- maskedVars[key] = "(hidden)";
646
- }
647
- }
648
- return maskedVars;
649
- }
650
-
651
- async function getZoneIdHostAndRoutes(args: StartDevOptions, config: Config) {
652
- // TODO: if worker_dev = false and no routes, then error (only for dev)
653
- // Compute zone info from the `host` and `route` args and config;
654
- let host = args.host || config.dev.host;
655
- let zoneId: string | undefined;
656
- const routes: Route[] | undefined =
657
- args.routes || (config.route && [config.route]) || config.routes;
658
-
659
- if (args.forceLocal) {
660
- args.local = true;
661
- }
662
-
663
- if (!args.local) {
664
- if (host) {
665
- zoneId = await getZoneIdFromHost(host);
666
- }
667
- if (!zoneId && routes) {
668
- const firstRoute = routes[0];
669
- const zone = await getZoneForRoute(firstRoute);
670
- if (zone) {
671
- zoneId = zone.id;
672
- host = zone.host;
673
- }
674
- }
675
- } else if (!host) {
676
- if (routes) {
677
- const firstRoute = routes[0];
678
- host = getHostFromRoute(firstRoute);
679
- }
680
- }
681
- return { host, routes, zoneId };
682
- }
683
-
684
- async function validateDevServerSettings(
685
- args: StartDevOptions,
686
- config: Config
687
- ) {
688
- const entry = await getEntry(
689
- { assets: args.assets, script: args.script },
690
- config,
691
- "dev"
692
- );
693
-
694
- const { zoneId, host, routes } = await getZoneIdHostAndRoutes(args, config);
695
- const getLocalPort = memoizeGetPort(DEFAULT_LOCAL_PORT);
696
- const getInspectorPort = memoizeGetPort(DEFAULT_INSPECTOR_PORT);
697
-
698
- if (config.services && config.services.length > 0) {
699
- logger.warn(
700
- `This worker is bound to live services: ${config.services
701
- .map(
702
- (service) =>
703
- `${service.binding} (${service.service}${
704
- service.environment ? `@${service.environment}` : ""
705
- })`
706
- )
707
- .join(", ")}`
708
- );
709
- }
710
-
711
- if (args.inspect) {
712
- //devtools are enabled by default, but we still need to disable them if the caller doesn't want them
713
- logger.warn(
714
- "Passing --inspect is unnecessary, now you can always connect to devtools."
715
- );
716
- }
717
- if (args.experimentalPublic) {
718
- throw new Error(
719
- "The --experimental-public field has been renamed to --assets"
720
- );
721
- }
722
-
723
- if (args.public) {
724
- throw new Error("The --public field has been renamed to --assets");
725
- }
726
-
727
- if ((args.assets ?? config.assets) && (args.site ?? config.site)) {
728
- throw new Error("Cannot use Assets and Workers Sites in the same Worker.");
729
- }
730
-
731
- if (args.assets) {
732
- logger.warn(
733
- "The --assets argument is experimental and may change or break at any time"
734
- );
735
- }
736
- const upstreamProtocol =
737
- args.upstreamProtocol ?? config.dev.upstream_protocol;
738
- if (upstreamProtocol === "http") {
739
- logger.warn(
740
- "Setting upstream-protocol to http is not currently implemented.\n" +
741
- "If this is required in your project, please add your use case to the following issue:\n" +
742
- "https://github.com/cloudflare/workers-sdk/issues/583."
743
- );
744
- }
745
- const nodeCompat = args.nodeCompat ?? config.node_compat;
746
- if (nodeCompat) {
747
- logger.warn(
748
- "Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
749
- );
750
- }
751
-
752
- if (args.experimentalEnableLocalPersistence) {
753
- logger.warn(
754
- `--experimental-enable-local-persistence is deprecated.\n` +
755
- `Move any existing data to .wrangler/state and use --persist, or\n` +
756
- `use --persist-to=./wrangler-local-state to keep using the old path.`
757
- );
758
- }
759
-
760
- const localPersistencePath = getLocalPersistencePath(
761
- args.persistTo,
762
- Boolean(args.persist),
763
- config.configPath
764
- );
765
-
766
- const cliDefines = collectKeyValues(args.define);
767
-
768
- return {
769
- entry,
770
- upstreamProtocol,
771
- nodeCompat,
772
- getLocalPort,
773
- getInspectorPort,
774
- zoneId,
775
- host,
776
- routes,
777
- cliDefines,
778
- localPersistencePath,
779
- };
780
- }
781
-
782
- function getBindingsAndAssetPaths(args: StartDevOptions, configParam: Config) {
783
- const cliVars = collectKeyValues(args.var);
784
-
785
- // now log all available bindings into the terminal
786
- const bindings = getBindings(configParam, args.env, args.local ?? false, {
787
- kv: args.kv,
788
- vars: { ...args.vars, ...cliVars },
789
- durableObjects: args.durableObjects,
790
- r2: args.r2,
791
- d1Databases: args.d1Databases,
792
- });
793
-
794
- const maskedVars = maskVars(bindings, configParam);
795
-
796
- printBindings({
797
- ...bindings,
798
- vars: maskedVars,
799
- });
800
-
801
- const assetPaths =
802
- args.assets || configParam.assets
803
- ? getAssetPaths(configParam, args.assets)
804
- : getSiteAssetPaths(
805
- configParam,
806
- args.site,
807
- args.siteInclude,
808
- args.siteExclude
809
- );
810
- return { assetPaths, bindings };
811
- }
812
-
813
- function getBindings(
814
- configParam: Config,
815
- env: string | undefined,
816
- local: boolean,
817
- args: AdditionalDevProps
818
- ): CfWorkerInit["bindings"] {
819
- const bindings = {
820
- kv_namespaces: [
821
- ...(configParam.kv_namespaces || []).map(
822
- ({ binding, preview_id, id: _id }) => {
823
- // In `dev`, we make folks use a separate kv namespace called
824
- // `preview_id` instead of `id` so that they don't
825
- // break production data. So here we check that a `preview_id`
826
- // has actually been configured.
827
- // This whole block of code will be obsoleted in the future
828
- // when we have copy-on-write for previews on edge workers.
829
- if (!preview_id) {
830
- // TODO: This error has to be a _lot_ better, ideally just asking
831
- // to create a preview namespace for the user automatically
832
- throw new Error(
833
- `In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv:namespace create <name> --preview" and add its id as preview_id to the kv_namespace "${binding}" in your wrangler.toml`
834
- ); // Ugh, I really don't like this message very much
835
- }
836
- return {
837
- binding,
838
- id: preview_id,
839
- };
840
- }
841
- ),
842
- ...(args.kv || []),
843
- ],
844
- // Use a copy of combinedVars since we're modifying it later
845
- vars: {
846
- ...getVarsForDev(configParam, env),
847
- ...args.vars,
848
- },
849
- wasm_modules: configParam.wasm_modules,
850
- text_blobs: configParam.text_blobs,
851
- data_blobs: configParam.data_blobs,
852
- durable_objects: {
853
- bindings: [
854
- ...(configParam.durable_objects || { bindings: [] }).bindings,
855
- ...(args.durableObjects || []),
856
- ],
857
- },
858
- queues: [
859
- ...(configParam.queues.producers || []).map((queue) => {
860
- return { binding: queue.binding, queue_name: queue.queue };
861
- }),
862
- ],
863
- r2_buckets: [
864
- ...(configParam.r2_buckets?.map(
865
- ({ binding, preview_bucket_name, bucket_name: _bucket_name }) => {
866
- // same idea as kv namespace preview id,
867
- // same copy-on-write TODO
868
- if (!preview_bucket_name) {
869
- throw new Error(
870
- `In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create <name>" and add its name as preview_bucket_name to the r2_buckets "${binding}" in your wrangler.toml`
871
- );
872
- }
873
- return {
874
- binding,
875
- bucket_name: preview_bucket_name,
876
- };
877
- }
878
- ) || []),
879
- ...(args.r2 || []),
880
- ],
881
- dispatch_namespaces: configParam.dispatch_namespaces,
882
- mtls_certificates: configParam.mtls_certificates,
883
- services: configParam.services,
884
- analytics_engine_datasets: configParam.analytics_engine_datasets,
885
- unsafe: configParam.unsafe?.bindings,
886
- logfwdr: configParam.logfwdr,
887
- d1_databases: identifyD1BindingsAsBeta([
888
- ...(configParam.d1_databases ?? []).map((d1Db) => {
889
- //in local dev, bindings don't matter
890
- if (local) {
891
- return {
892
- ...d1Db,
893
- database_id: "local",
894
- };
895
- }
896
- // if you have a preview_database_id, we'll use it, but we shouldn't force people to use it.
897
- if (!d1Db.preview_database_id && !process.env.NO_D1_WARNING) {
898
- logger.log(
899
- `--------------------\nšŸ’” Recommendation: for development, use a preview D1 database rather than the one you'd use in production.\nšŸ’” Create a new D1 database with "wrangler d1 create <name>" and add its id as preview_database_id to the d1_database "${d1Db.binding}" in your wrangler.toml\n--------------------\n`
900
- );
901
- }
902
- return {
903
- ...d1Db,
904
- database_id: d1Db.preview_database_id
905
- ? d1Db.preview_database_id
906
- : d1Db.database_id,
907
- };
908
- }),
909
- ...(args.d1Databases || []),
910
- ]),
911
- };
912
-
913
- return bindings;
914
- }