wrangler 0.0.0-e33bea9b → 0.0.0-e3990bbf

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 (298) hide show
  1. package/README.md +10 -12
  2. package/bin/wrangler.js +9 -75
  3. package/package.json +199 -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/middleware/common.ts +9 -4
  8. package/templates/middleware/loader-modules.ts +64 -11
  9. package/templates/middleware/loader-sw.ts +2 -7
  10. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  11. package/templates/middleware/middleware-miniflare3-json-error.ts +1 -0
  12. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  13. package/templates/middleware/middleware-multiworker-dev.ts +59 -0
  14. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  15. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  16. package/templates/new-worker-scheduled.ts +1 -1
  17. package/templates/new-worker.ts +1 -1
  18. package/templates/pages-dev-util.ts +4 -1
  19. package/templates/pages-shim.ts +0 -3
  20. package/templates/pages-template-plugin.ts +12 -2
  21. package/templates/pages-template-worker.ts +11 -2
  22. package/templates/tsconfig.json +1 -1
  23. package/wrangler-dist/cli.d.ts +245 -128
  24. package/wrangler-dist/cli.js +107991 -109502
  25. package/wrangler-dist/wasm-sync.wasm +0 -0
  26. package/import_meta_url.js +0 -3
  27. package/miniflare-config-stubs/.env.empty +0 -0
  28. package/miniflare-config-stubs/package.empty.json +0 -1
  29. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  30. package/miniflare-dist/index.mjs +0 -6368
  31. package/src/__tests__/access.test.ts +0 -25
  32. package/src/__tests__/api-dev.test.ts +0 -238
  33. package/src/__tests__/api-devregistry.test.js +0 -64
  34. package/src/__tests__/api.test.ts +0 -80
  35. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  36. package/src/__tests__/config-cache.test.ts +0 -42
  37. package/src/__tests__/configuration.test.ts +0 -4462
  38. package/src/__tests__/d1/d1.test.ts +0 -82
  39. package/src/__tests__/d1/execute.test.ts +0 -64
  40. package/src/__tests__/d1/migrate.test.ts +0 -155
  41. package/src/__tests__/d1/splitter.test.ts +0 -255
  42. package/src/__tests__/delete.test.ts +0 -266
  43. package/src/__tests__/deployments.test.ts +0 -129
  44. package/src/__tests__/dev.test.tsx +0 -1602
  45. package/src/__tests__/generate.test.ts +0 -238
  46. package/src/__tests__/get-host-from-url.test.ts +0 -16
  47. package/src/__tests__/guess-worker-format.test.ts +0 -120
  48. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  49. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  50. package/src/__tests__/helpers/end-event-loop.ts +0 -6
  51. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  52. package/src/__tests__/helpers/mock-auth-domain.ts +0 -20
  53. package/src/__tests__/helpers/mock-bin.ts +0 -36
  54. package/src/__tests__/helpers/mock-console.ts +0 -106
  55. package/src/__tests__/helpers/mock-dialogs.ts +0 -139
  56. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +0 -25
  57. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -11
  58. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  59. package/src/__tests__/helpers/mock-istty.ts +0 -74
  60. package/src/__tests__/helpers/mock-known-routes.ts +0 -12
  61. package/src/__tests__/helpers/mock-kv.ts +0 -46
  62. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -263
  63. package/src/__tests__/helpers/mock-process.ts +0 -34
  64. package/src/__tests__/helpers/mock-set-timeout.ts +0 -16
  65. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  66. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  67. package/src/__tests__/helpers/msw/blob-worker.cjs +0 -19
  68. package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
  69. package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -93
  70. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -81
  71. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -31
  72. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -60
  73. package/src/__tests__/helpers/msw/handlers/script.ts +0 -56
  74. package/src/__tests__/helpers/msw/handlers/user.ts +0 -52
  75. package/src/__tests__/helpers/msw/handlers/zones.ts +0 -20
  76. package/src/__tests__/helpers/msw/index.ts +0 -50
  77. package/src/__tests__/helpers/msw/read-file-sync.js +0 -61
  78. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  79. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  80. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +0 -28
  81. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  82. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  83. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  84. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
  85. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  86. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  87. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  88. package/src/__tests__/https-options.test.ts +0 -163
  89. package/src/__tests__/index.test.ts +0 -274
  90. package/src/__tests__/init.test.ts +0 -3165
  91. package/src/__tests__/jest.setup.ts +0 -175
  92. package/src/__tests__/kv.test.ts +0 -1799
  93. package/src/__tests__/logger.test.ts +0 -141
  94. package/src/__tests__/logout.test.ts +0 -47
  95. package/src/__tests__/metrics.test.ts +0 -493
  96. package/src/__tests__/middleware.scheduled.test.ts +0 -145
  97. package/src/__tests__/middleware.test.ts +0 -816
  98. package/src/__tests__/mtls-certificates.test.ts +0 -585
  99. package/src/__tests__/package-manager.test.ts +0 -353
  100. package/src/__tests__/pages/deployment-list.test.ts +0 -78
  101. package/src/__tests__/pages/functions-build.test.ts +0 -452
  102. package/src/__tests__/pages/pages.test.ts +0 -81
  103. package/src/__tests__/pages/project-create.test.ts +0 -63
  104. package/src/__tests__/pages/project-list.test.ts +0 -108
  105. package/src/__tests__/pages/project-upload.test.ts +0 -481
  106. package/src/__tests__/pages/publish.test.ts +0 -2820
  107. package/src/__tests__/pages-deployment-tail.test.ts +0 -955
  108. package/src/__tests__/parse.test.ts +0 -436
  109. package/src/__tests__/paths.test.ts +0 -39
  110. package/src/__tests__/publish.test.ts +0 -8303
  111. package/src/__tests__/pubsub.test.ts +0 -493
  112. package/src/__tests__/queues.test.ts +0 -529
  113. package/src/__tests__/r2.test.ts +0 -374
  114. package/src/__tests__/route.test.ts +0 -45
  115. package/src/__tests__/secret.test.ts +0 -693
  116. package/src/__tests__/tail.test.ts +0 -958
  117. package/src/__tests__/test-old-node-version.js +0 -31
  118. package/src/__tests__/tsconfig-sanity.ts +0 -12
  119. package/src/__tests__/tsconfig.json +0 -8
  120. package/src/__tests__/tsconfig.tsbuildinfo +0 -1
  121. package/src/__tests__/type-generation.test.ts +0 -234
  122. package/src/__tests__/user.test.ts +0 -118
  123. package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
  124. package/src/__tests__/validate-dev-props.test.ts +0 -56
  125. package/src/__tests__/version.test.ts +0 -35
  126. package/src/__tests__/whoami.test.tsx +0 -172
  127. package/src/__tests__/worker-namespace.test.ts +0 -339
  128. package/src/abort.d.ts +0 -3
  129. package/src/api/dev.ts +0 -327
  130. package/src/api/index.ts +0 -11
  131. package/src/api/mtls-certificate.ts +0 -148
  132. package/src/api/pages/create-worker-bundle-contents.ts +0 -75
  133. package/src/api/pages/index.ts +0 -5
  134. package/src/api/pages/publish.tsx +0 -355
  135. package/src/bundle-reporter.ts +0 -68
  136. package/src/bundle.ts +0 -894
  137. package/src/cfetch/index.ts +0 -158
  138. package/src/cfetch/internal.ts +0 -258
  139. package/src/cli.ts +0 -28
  140. package/src/config/README.md +0 -107
  141. package/src/config/config.ts +0 -282
  142. package/src/config/diagnostics.ts +0 -80
  143. package/src/config/environment.ts +0 -591
  144. package/src/config/index.ts +0 -385
  145. package/src/config/validation-helpers.ts +0 -597
  146. package/src/config/validation.ts +0 -2252
  147. package/src/config-cache.ts +0 -85
  148. package/src/create-worker-preview.ts +0 -293
  149. package/src/create-worker-upload-form.ts +0 -342
  150. package/src/d1/backups.tsx +0 -215
  151. package/src/d1/constants.ts +0 -2
  152. package/src/d1/create.tsx +0 -64
  153. package/src/d1/delete.ts +0 -53
  154. package/src/d1/execute.tsx +0 -354
  155. package/src/d1/formatTimeAgo.ts +0 -14
  156. package/src/d1/index.ts +0 -100
  157. package/src/d1/list.tsx +0 -60
  158. package/src/d1/migrations/apply.tsx +0 -206
  159. package/src/d1/migrations/create.tsx +0 -76
  160. package/src/d1/migrations/helpers.ts +0 -172
  161. package/src/d1/migrations/index.ts +0 -3
  162. package/src/d1/migrations/list.tsx +0 -92
  163. package/src/d1/migrations/options.ts +0 -23
  164. package/src/d1/options.ts +0 -22
  165. package/src/d1/splitter.ts +0 -161
  166. package/src/d1/types.ts +0 -25
  167. package/src/d1/utils.ts +0 -49
  168. package/src/delete.ts +0 -100
  169. package/src/deployments.ts +0 -116
  170. package/src/deprecated/index.ts +0 -144
  171. package/src/dev/dev-vars.ts +0 -39
  172. package/src/dev/dev.tsx +0 -600
  173. package/src/dev/get-local-persistence-path.ts +0 -31
  174. package/src/dev/local.tsx +0 -920
  175. package/src/dev/remote.tsx +0 -632
  176. package/src/dev/start-server.ts +0 -540
  177. package/src/dev/use-esbuild.ts +0 -209
  178. package/src/dev/validate-dev-props.ts +0 -40
  179. package/src/dev-registry.ts +0 -201
  180. package/src/dev.tsx +0 -928
  181. package/src/dialogs.ts +0 -136
  182. package/src/dispatch-namespace.ts +0 -211
  183. package/src/docs/index.ts +0 -97
  184. package/src/durable.ts +0 -102
  185. package/src/entry.ts +0 -327
  186. package/src/environment-variables/factory.ts +0 -88
  187. package/src/environment-variables/misc-variables.ts +0 -30
  188. package/src/errors.ts +0 -11
  189. package/src/generate/index.ts +0 -298
  190. package/src/git-client.ts +0 -135
  191. package/src/global-wrangler-config-path.ts +0 -26
  192. package/src/https-options.ts +0 -127
  193. package/src/index.ts +0 -705
  194. package/src/init.ts +0 -1023
  195. package/src/inspect.ts +0 -782
  196. package/src/intl-polyfill.d.ts +0 -139
  197. package/src/is-ci.ts +0 -14
  198. package/src/is-interactive.ts +0 -16
  199. package/src/jest.d.ts +0 -4
  200. package/src/kv/helpers.ts +0 -430
  201. package/src/kv/index.ts +0 -594
  202. package/src/logger.ts +0 -104
  203. package/src/metrics/index.ts +0 -5
  204. package/src/metrics/metrics-config.ts +0 -239
  205. package/src/metrics/metrics-dispatcher.ts +0 -96
  206. package/src/metrics/metrics-usage-headers.ts +0 -24
  207. package/src/metrics/send-event.ts +0 -98
  208. package/src/miniflare-cli/README.md +0 -30
  209. package/src/miniflare-cli/assets.ts +0 -251
  210. package/src/miniflare-cli/index.ts +0 -210
  211. package/src/miniflare-cli/request-context.ts +0 -40
  212. package/src/miniflare-cli/tsconfig.json +0 -9
  213. package/src/miniflare-cli/tsconfig.tsbuildinfo +0 -1
  214. package/src/miniflare-cli/types.ts +0 -11
  215. package/src/module-collection.ts +0 -267
  216. package/src/mtls-certificate/cli.ts +0 -155
  217. package/src/open-in-browser.ts +0 -17
  218. package/src/package-manager.ts +0 -219
  219. package/src/pages/build.ts +0 -410
  220. package/src/pages/buildFunctions.ts +0 -140
  221. package/src/pages/constants.ts +0 -18
  222. package/src/pages/deployment-tails.ts +0 -281
  223. package/src/pages/deployments.tsx +0 -86
  224. package/src/pages/dev.ts +0 -716
  225. package/src/pages/errors.ts +0 -67
  226. package/src/pages/functions/buildPlugin.ts +0 -112
  227. package/src/pages/functions/buildWorker.ts +0 -297
  228. package/src/pages/functions/filepath-routing.test.ts +0 -234
  229. package/src/pages/functions/filepath-routing.ts +0 -189
  230. package/src/pages/functions/identifiers.ts +0 -78
  231. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  232. package/src/pages/functions/routes-consolidation.ts +0 -73
  233. package/src/pages/functions/routes-transformation.test.ts +0 -282
  234. package/src/pages/functions/routes-transformation.ts +0 -115
  235. package/src/pages/functions/routes-validation.test.ts +0 -403
  236. package/src/pages/functions/routes-validation.ts +0 -202
  237. package/src/pages/functions/routes.ts +0 -151
  238. package/src/pages/functions/tsconfig.json +0 -8
  239. package/src/pages/functions/tsconfig.tsbuildinfo +0 -1
  240. package/src/pages/functions.ts +0 -86
  241. package/src/pages/hash.ts +0 -13
  242. package/src/pages/index.ts +0 -102
  243. package/src/pages/projects.tsx +0 -162
  244. package/src/pages/prompt-select-project.tsx +0 -31
  245. package/src/pages/publish.tsx +0 -267
  246. package/src/pages/types.ts +0 -46
  247. package/src/pages/upload.tsx +0 -449
  248. package/src/pages/utils.ts +0 -23
  249. package/src/parse.ts +0 -308
  250. package/src/paths.ts +0 -71
  251. package/src/proxy.ts +0 -694
  252. package/src/publish/index.ts +0 -274
  253. package/src/publish/publish.ts +0 -1076
  254. package/src/pubsub/index.ts +0 -286
  255. package/src/pubsub/pubsub-commands.ts +0 -623
  256. package/src/queues/cli/commands/consumer/add.ts +0 -65
  257. package/src/queues/cli/commands/consumer/index.ts +0 -19
  258. package/src/queues/cli/commands/consumer/remove.ts +0 -31
  259. package/src/queues/cli/commands/create.ts +0 -25
  260. package/src/queues/cli/commands/delete.ts +0 -26
  261. package/src/queues/cli/commands/index.ts +0 -35
  262. package/src/queues/cli/commands/list.ts +0 -25
  263. package/src/queues/client.ts +0 -135
  264. package/src/queues/utils.ts +0 -18
  265. package/src/r2/constants.ts +0 -4
  266. package/src/r2/helpers.ts +0 -132
  267. package/src/r2/index.ts +0 -289
  268. package/src/routes.ts +0 -140
  269. package/src/secret/index.ts +0 -375
  270. package/src/selfsigned.d.ts +0 -29
  271. package/src/sites.ts +0 -372
  272. package/src/tail/createTail.ts +0 -406
  273. package/src/tail/filters.ts +0 -277
  274. package/src/tail/index.ts +0 -211
  275. package/src/tail/printing.ts +0 -122
  276. package/src/tsconfig-sanity.ts +0 -16
  277. package/src/type-generation.ts +0 -181
  278. package/src/update-check.ts +0 -19
  279. package/src/user/access.ts +0 -68
  280. package/src/user/auth-variables.ts +0 -113
  281. package/src/user/choose-account.tsx +0 -39
  282. package/src/user/generate-auth-url.ts +0 -33
  283. package/src/user/generate-random-state.ts +0 -16
  284. package/src/user/index.ts +0 -2
  285. package/src/user/user.ts +0 -1233
  286. package/src/utils/collectKeyValues.ts +0 -14
  287. package/src/whoami.ts +0 -135
  288. package/src/worker.ts +0 -264
  289. package/src/yargs-types.ts +0 -37
  290. package/src/zones.ts +0 -191
  291. package/templates/__tests__/tsconfig.tsbuildinfo +0 -1
  292. package/templates/d1-beta-facade.js +0 -244
  293. package/templates/first-party-worker-module-facade.ts +0 -19
  294. package/templates/format-dev-errors.ts +0 -34
  295. package/templates/serve-static-assets.ts +0 -66
  296. package/templates/service-bindings-module-facade.js +0 -55
  297. package/templates/service-bindings-sw-facade.js +0 -42
  298. package/templates/tsconfig.tsbuildinfo +0 -1
package/src/dev.tsx DELETED
@@ -1,928 +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
- showInteractiveDevSession?: boolean;
348
- };
349
-
350
- export async function startDev(args: StartDevOptions) {
351
- let watcher: ReturnType<typeof watch> | undefined;
352
- let rerender: (node: React.ReactNode) => void | undefined;
353
- try {
354
- if (args.logLevel) {
355
- logger.loggerLevel = args.logLevel;
356
- }
357
- await printWranglerBanner();
358
-
359
- if (args.local && process.platform !== "win32") {
360
- logger.info(
361
- chalk.magenta(
362
- `Want to try out the next version of local mode using the open-source Workers runtime?\nSwitch out --local for ${chalk.bold(
363
- "--experimental-local"
364
- )} and let us know what you think at https://discord.gg/cloudflaredev !`
365
- )
366
- );
367
- }
368
-
369
- const configPath =
370
- args.config ||
371
- (args.script && findWranglerToml(path.dirname(args.script)));
372
- let config = readConfig(configPath, args);
373
-
374
- if (config.configPath) {
375
- watcher = watch(config.configPath, {
376
- persistent: true,
377
- }).on("change", async (_event) => {
378
- // TODO: Do we need to handle different `_event` types differently?
379
- // e.g. what if the file is deleted, or added?
380
- config = readConfig(configPath, args);
381
- if (config.configPath) {
382
- logger.log(`${path.basename(config.configPath)} changed...`);
383
- rerender(await getDevReactElement(config));
384
- }
385
- });
386
- }
387
-
388
- const {
389
- entry,
390
- legacyNodeCompat,
391
- nodejsCompat,
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
- legacyNodeCompat={legacyNodeCompat}
431
- nodejsCompat={nodejsCompat}
432
- build={configParam.build || {}}
433
- define={{ ...configParam.define, ...cliDefines }}
434
- initialMode={
435
- args.local || args.experimentalLocal ? "local" : "remote"
436
- }
437
- jsxFactory={args.jsxFactory || configParam.jsx_factory}
438
- jsxFragment={args.jsxFragment || configParam.jsx_fragment}
439
- tsconfig={args.tsconfig ?? configParam.tsconfig}
440
- upstreamProtocol={upstreamProtocol}
441
- localProtocol={args.localProtocol || configParam.dev.local_protocol}
442
- localUpstream={args.localUpstream ?? host}
443
- localPersistencePath={localPersistencePath}
444
- liveReload={args.liveReload || false}
445
- accountId={configParam.account_id || getAccountFromCache()?.id}
446
- assetPaths={assetPaths}
447
- assetsConfig={configParam.assets}
448
- initialPort={
449
- args.port ?? configParam.dev.port ?? (await getLocalPort())
450
- }
451
- initialIp={args.ip || configParam.dev.ip}
452
- inspectorPort={
453
- args.inspectorPort ??
454
- configParam.dev.inspector_port ??
455
- (await getInspectorPort())
456
- }
457
- isWorkersSite={Boolean(args.site || configParam.site)}
458
- compatibilityDate={getDevCompatibilityDate(
459
- configParam,
460
- args.compatibilityDate
461
- )}
462
- compatibilityFlags={
463
- args.compatibilityFlags || configParam.compatibility_flags
464
- }
465
- usageModel={configParam.usage_model}
466
- bindings={bindings}
467
- crons={configParam.triggers.crons}
468
- queueConsumers={configParam.queues.consumers}
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
- legacyNodeCompat,
527
- nodejsCompat,
528
- upstreamProtocol,
529
- zoneId,
530
- host,
531
- routes,
532
- getLocalPort,
533
- getInspectorPort,
534
- cliDefines,
535
- localPersistencePath,
536
- } = await validateDevServerSettings(args, config);
537
-
538
- await metrics.sendMetricsEvent(
539
- "run dev (api)",
540
- { local: args.local },
541
- { sendMetrics: config.send_metrics, offline: args.local }
542
- );
543
-
544
- // eslint-disable-next-line no-inner-declarations
545
- async function getDevServer(configParam: Config) {
546
- const { assetPaths, bindings } = getBindingsAndAssetPaths(
547
- args,
548
- configParam
549
- );
550
-
551
- //if args.bundle is on, don't disable bundling
552
- //if there's no args.bundle, and configParam.no_bundle is on, disable bundling
553
- //otherwise, enable bundling
554
- const enableBundling = args.bundle ?? !configParam.no_bundle;
555
- return await startDevServer({
556
- name: getScriptName({ name: args.name, env: args.env }, configParam),
557
- noBundle: !enableBundling,
558
- entry: entry,
559
- env: args.env,
560
- zone: zoneId,
561
- host: host,
562
- routes: routes,
563
- rules: getRules(configParam),
564
- legacyEnv: isLegacyEnv(configParam),
565
- minify: args.minify ?? configParam.minify,
566
- legacyNodeCompat,
567
- nodejsCompat,
568
- build: configParam.build || {},
569
- define: { ...config.define, ...cliDefines },
570
- initialMode: args.local ? "local" : "remote",
571
- jsxFactory: args.jsxFactory ?? configParam.jsx_factory,
572
- jsxFragment: args.jsxFragment ?? configParam.jsx_fragment,
573
- tsconfig: args.tsconfig ?? configParam.tsconfig,
574
- upstreamProtocol: upstreamProtocol,
575
- localProtocol: args.localProtocol ?? configParam.dev.local_protocol,
576
- localUpstream: args.localUpstream ?? host,
577
- localPersistencePath,
578
- liveReload: args.liveReload ?? false,
579
- accountId: configParam.account_id ?? getAccountFromCache()?.id,
580
- assetPaths: assetPaths,
581
- assetsConfig: configParam.assets,
582
- //port can be 0, which means to use a random port
583
- initialPort: args.port ?? configParam.dev.port ?? (await getLocalPort()),
584
- initialIp: args.ip ?? configParam.dev.ip,
585
- inspectorPort:
586
- args.inspectorPort ??
587
- configParam.dev.inspector_port ??
588
- (await getInspectorPort()),
589
- isWorkersSite: Boolean(args.site || configParam.site),
590
- compatibilityDate: getDevCompatibilityDate(
591
- config,
592
- // Only `compatibilityDate` will be set when using `unstable_dev`
593
- args.compatibilityDate
594
- ),
595
- compatibilityFlags:
596
- args.compatibilityFlags ?? configParam.compatibility_flags,
597
- usageModel: configParam.usage_model,
598
- bindings: bindings,
599
- crons: configParam.triggers.crons,
600
- queueConsumers: configParam.queues.consumers,
601
- onReady: args.onReady,
602
- inspect: args.inspect ?? true,
603
- showInteractiveDevSession: args.showInteractiveDevSession,
604
- forceLocal: args.forceLocal,
605
- enablePagesAssetsServiceBinding: args.enablePagesAssetsServiceBinding,
606
- local: args.local ?? true,
607
- firstPartyWorker: configParam.first_party_worker,
608
- sendMetrics: configParam.send_metrics,
609
- testScheduled: args.testScheduled,
610
- experimentalLocal: args.experimentalLocal,
611
- experimentalLocalRemoteKv: args.experimentalLocalRemoteKv,
612
- disableDevRegistry: args.disableDevRegistry ?? false,
613
- });
614
- }
615
-
616
- const devServer = await getDevServer(config);
617
- if (!devServer) {
618
- throw logger.error("Failed to start dev server.");
619
- }
620
-
621
- return {
622
- stop: async () => {
623
- await devServer.stop();
624
- },
625
- };
626
- }
627
- /**
628
- * Avoiding calling `getPort()` multiple times by memoizing the first result.
629
- */
630
- function memoizeGetPort(defaultPort: number) {
631
- let portValue: number;
632
- return async () => {
633
- return portValue || (portValue = await getPort({ port: defaultPort }));
634
- };
635
- }
636
- /**
637
- * mask anything that was overridden in .dev.vars
638
- * so that we don't log potential secrets into the terminal
639
- */
640
- function maskVars(bindings: CfWorkerInit["bindings"], configParam: Config) {
641
- const maskedVars = { ...bindings.vars };
642
- for (const key of Object.keys(maskedVars)) {
643
- if (maskedVars[key] !== configParam.vars[key]) {
644
- // This means it was overridden in .dev.vars
645
- // so let's mask it
646
- maskedVars[key] = "(hidden)";
647
- }
648
- }
649
- return maskedVars;
650
- }
651
-
652
- async function getZoneIdHostAndRoutes(args: StartDevOptions, config: Config) {
653
- // TODO: if worker_dev = false and no routes, then error (only for dev)
654
- // Compute zone info from the `host` and `route` args and config;
655
- let host = args.host || config.dev.host;
656
- let zoneId: string | undefined;
657
- const routes: Route[] | undefined =
658
- args.routes || (config.route && [config.route]) || config.routes;
659
-
660
- if (args.forceLocal) {
661
- args.local = true;
662
- }
663
-
664
- if (!args.local) {
665
- if (host) {
666
- zoneId = await getZoneIdFromHost(host);
667
- }
668
- if (!zoneId && routes) {
669
- const firstRoute = routes[0];
670
- const zone = await getZoneForRoute(firstRoute);
671
- if (zone) {
672
- zoneId = zone.id;
673
- host = zone.host;
674
- }
675
- }
676
- } else if (!host) {
677
- if (routes) {
678
- const firstRoute = routes[0];
679
- host = getHostFromRoute(firstRoute);
680
- }
681
- }
682
- return { host, routes, zoneId };
683
- }
684
-
685
- async function validateDevServerSettings(
686
- args: StartDevOptions,
687
- config: Config
688
- ) {
689
- const entry = await getEntry(
690
- { assets: args.assets, script: args.script },
691
- config,
692
- "dev"
693
- );
694
-
695
- const { zoneId, host, routes } = await getZoneIdHostAndRoutes(args, config);
696
- const getLocalPort = memoizeGetPort(DEFAULT_LOCAL_PORT);
697
- const getInspectorPort = memoizeGetPort(DEFAULT_INSPECTOR_PORT);
698
-
699
- if (config.services && config.services.length > 0) {
700
- logger.warn(
701
- `This worker is bound to live services: ${config.services
702
- .map(
703
- (service) =>
704
- `${service.binding} (${service.service}${
705
- service.environment ? `@${service.environment}` : ""
706
- })`
707
- )
708
- .join(", ")}`
709
- );
710
- }
711
-
712
- if (args.inspect) {
713
- //devtools are enabled by default, but we still need to disable them if the caller doesn't want them
714
- logger.warn(
715
- "Passing --inspect is unnecessary, now you can always connect to devtools."
716
- );
717
- }
718
- if (args.experimentalPublic) {
719
- throw new Error(
720
- "The --experimental-public field has been renamed to --assets"
721
- );
722
- }
723
-
724
- if (args.public) {
725
- throw new Error("The --public field has been renamed to --assets");
726
- }
727
-
728
- if ((args.assets ?? config.assets) && (args.site ?? config.site)) {
729
- throw new Error("Cannot use Assets and Workers Sites in the same Worker.");
730
- }
731
-
732
- if (args.assets) {
733
- logger.warn(
734
- "The --assets argument is experimental and may change or break at any time"
735
- );
736
- }
737
- const upstreamProtocol =
738
- args.upstreamProtocol ?? config.dev.upstream_protocol;
739
- if (upstreamProtocol === "http") {
740
- logger.warn(
741
- "Setting upstream-protocol to http is not currently implemented.\n" +
742
- "If this is required in your project, please add your use case to the following issue:\n" +
743
- "https://github.com/cloudflare/workers-sdk/issues/583."
744
- );
745
- }
746
- const legacyNodeCompat = args.nodeCompat ?? config.node_compat;
747
- if (legacyNodeCompat) {
748
- logger.warn(
749
- "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."
750
- );
751
- }
752
-
753
- const compatibilityFlags =
754
- args.compatibilityFlags ?? config.compatibility_flags;
755
- const nodejsCompat = compatibilityFlags?.includes("nodejs_compat");
756
- if (legacyNodeCompat && nodejsCompat) {
757
- throw new Error(
758
- "The `nodejs_compat` compatibility flag cannot be used in conjunction with the legacy `--node-compat` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the `--node-compat` argument from your CLI command or `node_compat = true` from your config file."
759
- );
760
- }
761
-
762
- if (args.experimentalEnableLocalPersistence) {
763
- logger.warn(
764
- `--experimental-enable-local-persistence is deprecated.\n` +
765
- `Move any existing data to .wrangler/state and use --persist, or\n` +
766
- `use --persist-to=./wrangler-local-state to keep using the old path.`
767
- );
768
- }
769
-
770
- const localPersistencePath = getLocalPersistencePath(
771
- args.persistTo,
772
- Boolean(args.persist),
773
- config.configPath
774
- );
775
-
776
- const cliDefines = collectKeyValues(args.define);
777
-
778
- return {
779
- entry,
780
- upstreamProtocol,
781
- legacyNodeCompat,
782
- nodejsCompat,
783
- getLocalPort,
784
- getInspectorPort,
785
- zoneId,
786
- host,
787
- routes,
788
- cliDefines,
789
- localPersistencePath,
790
- };
791
- }
792
-
793
- function getBindingsAndAssetPaths(args: StartDevOptions, configParam: Config) {
794
- const cliVars = collectKeyValues(args.var);
795
-
796
- // now log all available bindings into the terminal
797
- const bindings = getBindings(configParam, args.env, args.local ?? false, {
798
- kv: args.kv,
799
- vars: { ...args.vars, ...cliVars },
800
- durableObjects: args.durableObjects,
801
- r2: args.r2,
802
- d1Databases: args.d1Databases,
803
- });
804
-
805
- const maskedVars = maskVars(bindings, configParam);
806
-
807
- printBindings({
808
- ...bindings,
809
- vars: maskedVars,
810
- });
811
-
812
- const assetPaths =
813
- args.assets || configParam.assets
814
- ? getAssetPaths(configParam, args.assets)
815
- : getSiteAssetPaths(
816
- configParam,
817
- args.site,
818
- args.siteInclude,
819
- args.siteExclude
820
- );
821
- return { assetPaths, bindings };
822
- }
823
-
824
- function getBindings(
825
- configParam: Config,
826
- env: string | undefined,
827
- local: boolean,
828
- args: AdditionalDevProps
829
- ): CfWorkerInit["bindings"] {
830
- const bindings = {
831
- kv_namespaces: [
832
- ...(configParam.kv_namespaces || []).map(
833
- ({ binding, preview_id, id: _id }) => {
834
- // In `dev`, we make folks use a separate kv namespace called
835
- // `preview_id` instead of `id` so that they don't
836
- // break production data. So here we check that a `preview_id`
837
- // has actually been configured.
838
- // This whole block of code will be obsoleted in the future
839
- // when we have copy-on-write for previews on edge workers.
840
- if (!preview_id) {
841
- // TODO: This error has to be a _lot_ better, ideally just asking
842
- // to create a preview namespace for the user automatically
843
- throw new Error(
844
- `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`
845
- ); // Ugh, I really don't like this message very much
846
- }
847
- return {
848
- binding,
849
- id: preview_id,
850
- };
851
- }
852
- ),
853
- ...(args.kv || []),
854
- ],
855
- // Use a copy of combinedVars since we're modifying it later
856
- vars: {
857
- ...getVarsForDev(configParam, env),
858
- ...args.vars,
859
- },
860
- wasm_modules: configParam.wasm_modules,
861
- text_blobs: configParam.text_blobs,
862
- data_blobs: configParam.data_blobs,
863
- durable_objects: {
864
- bindings: [
865
- ...(configParam.durable_objects || { bindings: [] }).bindings,
866
- ...(args.durableObjects || []),
867
- ],
868
- },
869
- queues: [
870
- ...(configParam.queues.producers || []).map((queue) => {
871
- return { binding: queue.binding, queue_name: queue.queue };
872
- }),
873
- ],
874
- r2_buckets: [
875
- ...(configParam.r2_buckets?.map(
876
- ({ binding, preview_bucket_name, bucket_name: _bucket_name }) => {
877
- // same idea as kv namespace preview id,
878
- // same copy-on-write TODO
879
- if (!preview_bucket_name) {
880
- throw new Error(
881
- `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`
882
- );
883
- }
884
- return {
885
- binding,
886
- bucket_name: preview_bucket_name,
887
- };
888
- }
889
- ) || []),
890
- ...(args.r2 || []),
891
- ],
892
- dispatch_namespaces: configParam.dispatch_namespaces,
893
- mtls_certificates: configParam.mtls_certificates,
894
- services: configParam.services,
895
- analytics_engine_datasets: configParam.analytics_engine_datasets,
896
- unsafe: {
897
- bindings: configParam.unsafe.bindings,
898
- metadata: configParam.unsafe.metadata,
899
- },
900
- logfwdr: configParam.logfwdr,
901
- d1_databases: identifyD1BindingsAsBeta([
902
- ...(configParam.d1_databases ?? []).map((d1Db) => {
903
- //in local dev, bindings don't matter
904
- if (local) {
905
- return {
906
- ...d1Db,
907
- database_id: "local",
908
- };
909
- }
910
- // if you have a preview_database_id, we'll use it, but we shouldn't force people to use it.
911
- if (!d1Db.preview_database_id && !process.env.NO_D1_WARNING) {
912
- logger.log(
913
- `--------------------\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`
914
- );
915
- }
916
- return {
917
- ...d1Db,
918
- database_id: d1Db.preview_database_id
919
- ? d1Db.preview_database_id
920
- : d1Db.database_id,
921
- };
922
- }),
923
- ...(args.d1Databases || []),
924
- ]),
925
- };
926
-
927
- return bindings;
928
- }