wrangler 0.0.0-e7a0cd5b → 0.0.0-e7cf0caa

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 (237) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +30 -10
  3. package/miniflare-dist/index.mjs +126 -74
  4. package/package.json +27 -19
  5. package/src/__tests__/api-dev.test.ts +65 -36
  6. package/src/__tests__/api-devregistry.test.ts +121 -0
  7. package/src/__tests__/api.test.ts +27 -5
  8. package/src/__tests__/configuration.test.ts +567 -86
  9. package/src/__tests__/d1/d1.test.ts +82 -0
  10. package/src/__tests__/d1/execute.test.ts +66 -0
  11. package/src/__tests__/d1/migrate.test.ts +157 -0
  12. package/src/__tests__/d1/splitter.test.ts +255 -0
  13. package/src/__tests__/delete.test.ts +91 -49
  14. package/src/__tests__/deployments.test.ts +330 -56
  15. package/src/__tests__/dev.test.tsx +198 -90
  16. package/src/__tests__/generate.test.ts +12 -10
  17. package/src/__tests__/guess-worker-format.test.ts +35 -0
  18. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  19. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  20. package/src/__tests__/helpers/mock-console.ts +6 -0
  21. package/src/__tests__/helpers/mock-dialogs.ts +71 -85
  22. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  23. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
  24. package/src/__tests__/helpers/mock-known-routes.ts +7 -2
  25. package/src/__tests__/helpers/mock-kv.ts +29 -16
  26. package/src/__tests__/helpers/mock-oauth-flow.ts +103 -92
  27. package/src/__tests__/helpers/mock-process.ts +8 -13
  28. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  29. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  30. package/src/__tests__/helpers/msw/handlers/deployments.ts +128 -27
  31. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  32. package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
  33. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  34. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  35. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  36. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  37. package/src/__tests__/helpers/msw/index.ts +32 -1
  38. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  39. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  40. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  41. package/src/__tests__/index.test.ts +90 -72
  42. package/src/__tests__/init.test.ts +927 -631
  43. package/src/__tests__/jest.setup.ts +19 -42
  44. package/src/__tests__/kv.test.ts +355 -231
  45. package/src/__tests__/logger.test.ts +68 -2
  46. package/src/__tests__/logout.test.ts +47 -0
  47. package/src/__tests__/metrics.test.ts +94 -51
  48. package/src/__tests__/middleware.scheduled.test.ts +42 -32
  49. package/src/__tests__/middleware.test.ts +212 -122
  50. package/src/__tests__/mtls-certificates.test.ts +588 -0
  51. package/src/__tests__/pages/deployment-list.test.ts +80 -0
  52. package/src/__tests__/pages/functions-build.test.ts +452 -0
  53. package/src/__tests__/pages/pages.test.ts +81 -0
  54. package/src/__tests__/pages/project-create.test.ts +63 -0
  55. package/src/__tests__/pages/project-list.test.ts +110 -0
  56. package/src/__tests__/pages/project-upload.test.ts +500 -0
  57. package/src/__tests__/pages/publish.test.ts +2864 -0
  58. package/src/__tests__/pages-deployment-tail.test.ts +955 -0
  59. package/src/__tests__/parse.test.ts +106 -0
  60. package/src/__tests__/publish.test.ts +1615 -852
  61. package/src/__tests__/pubsub.test.ts +226 -100
  62. package/src/__tests__/queues.test.ts +238 -77
  63. package/src/__tests__/r2.test.ts +55 -57
  64. package/src/__tests__/secret.test.ts +179 -130
  65. package/src/__tests__/tail.test.ts +267 -109
  66. package/src/__tests__/test-old-node-version.js +3 -3
  67. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  68. package/src/__tests__/tsconfig-sanity.ts +12 -0
  69. package/src/__tests__/tsconfig.json +8 -0
  70. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  71. package/src/__tests__/type-generation.test.ts +43 -26
  72. package/src/__tests__/user.test.ts +35 -72
  73. package/src/__tests__/whoami.test.tsx +8 -114
  74. package/src/__tests__/worker-namespace.test.ts +83 -69
  75. package/src/api/dev.ts +168 -60
  76. package/src/api/index.ts +10 -1
  77. package/src/api/mtls-certificate.ts +148 -0
  78. package/src/api/pages/create-worker-bundle-contents.ts +76 -0
  79. package/src/api/pages/index.ts +5 -0
  80. package/src/api/pages/publish.tsx +355 -0
  81. package/src/bundle.ts +263 -140
  82. package/src/cfetch/index.ts +0 -2
  83. package/src/cfetch/internal.ts +16 -21
  84. package/src/cli.ts +4 -4
  85. package/src/config/config.ts +14 -7
  86. package/src/config/environment.ts +79 -24
  87. package/src/config/index.ts +99 -38
  88. package/src/config/validation-helpers.ts +1 -1
  89. package/src/config/validation.ts +248 -19
  90. package/src/create-worker-preview.ts +19 -8
  91. package/src/create-worker-upload-form.ts +60 -22
  92. package/src/d1/backups.tsx +43 -42
  93. package/src/d1/constants.ts +2 -0
  94. package/src/d1/create.tsx +44 -30
  95. package/src/d1/{delete.tsx → delete.ts} +11 -14
  96. package/src/d1/execute.tsx +209 -151
  97. package/src/d1/index.ts +31 -7
  98. package/src/d1/list.tsx +22 -10
  99. package/src/d1/migrations/apply.tsx +212 -0
  100. package/src/d1/migrations/create.tsx +79 -0
  101. package/src/d1/migrations/helpers.ts +172 -0
  102. package/src/d1/migrations/index.ts +3 -0
  103. package/src/d1/migrations/list.tsx +95 -0
  104. package/src/d1/migrations/options.ts +23 -0
  105. package/src/d1/options.ts +12 -2
  106. package/src/d1/splitter.ts +161 -0
  107. package/src/d1/{types.tsx → types.ts} +11 -0
  108. package/src/d1/utils.ts +12 -2
  109. package/src/delete.ts +8 -16
  110. package/src/deployments.ts +340 -46
  111. package/src/deprecated/index.ts +8 -302
  112. package/src/dev/dev.tsx +57 -44
  113. package/src/dev/local.tsx +294 -91
  114. package/src/dev/remote.tsx +32 -3
  115. package/src/dev/start-server.ts +89 -68
  116. package/src/dev/use-esbuild.ts +17 -18
  117. package/src/dev/validate-dev-props.ts +9 -0
  118. package/src/{dev-registry.tsx → dev-registry.ts} +2 -1
  119. package/src/dev.tsx +178 -118
  120. package/src/dialogs.ts +136 -0
  121. package/src/dispatch-namespace.ts +21 -17
  122. package/src/docs/index.ts +97 -0
  123. package/src/entry.ts +19 -11
  124. package/src/environment-variables/factory.ts +88 -0
  125. package/src/environment-variables/misc-variables.ts +30 -0
  126. package/src/generate/index.ts +298 -0
  127. package/src/git-client.ts +15 -4
  128. package/src/{index.tsx → index.ts} +137 -63
  129. package/src/init.ts +249 -187
  130. package/src/inspect.ts +16 -1
  131. package/src/jest.d.ts +4 -0
  132. package/src/kv/index.ts +15 -17
  133. package/src/logger.ts +32 -5
  134. package/src/metrics/metrics-config.ts +3 -3
  135. package/src/metrics/send-event.ts +6 -1
  136. package/src/miniflare-cli/assets.ts +64 -28
  137. package/src/miniflare-cli/index.ts +4 -7
  138. package/src/miniflare-cli/tsconfig.json +9 -0
  139. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  140. package/src/miniflare-cli/types.ts +11 -0
  141. package/src/module-collection.ts +91 -25
  142. package/src/mtls-certificate/cli.ts +155 -0
  143. package/src/pages/build.ts +410 -0
  144. package/src/pages/buildFunctions.ts +140 -0
  145. package/src/pages/deployment-tails.ts +281 -0
  146. package/src/pages/deployments.tsx +11 -33
  147. package/src/pages/{dev.tsx → dev.ts} +147 -124
  148. package/src/pages/errors.ts +1 -0
  149. package/src/pages/functions/buildPlugin.ts +72 -69
  150. package/src/pages/functions/buildWorker.ts +249 -114
  151. package/src/pages/functions/tsconfig.json +8 -0
  152. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  153. package/src/pages/{functions.tsx → functions.ts} +8 -4
  154. package/src/pages/{index.tsx → index.ts} +11 -3
  155. package/src/pages/projects.tsx +12 -22
  156. package/src/pages/prompt-select-project.tsx +31 -0
  157. package/src/pages/publish.tsx +45 -214
  158. package/src/pages/types.ts +6 -9
  159. package/src/pages/upload.tsx +58 -14
  160. package/src/pages/utils.ts +14 -3
  161. package/src/parse.ts +23 -1
  162. package/src/paths.ts +1 -1
  163. package/src/proxy.ts +5 -0
  164. package/src/publish/index.ts +20 -16
  165. package/src/publish/publish.ts +72 -47
  166. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
  167. package/src/queues/cli/commands/consumer/add.ts +24 -24
  168. package/src/queues/cli/commands/consumer/index.ts +3 -6
  169. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  170. package/src/queues/cli/commands/create.ts +8 -8
  171. package/src/queues/cli/commands/delete.ts +8 -8
  172. package/src/queues/cli/commands/index.ts +6 -4
  173. package/src/queues/cli/commands/list.ts +8 -8
  174. package/src/queues/client.ts +1 -0
  175. package/src/queues/utils.ts +18 -0
  176. package/src/r2/constants.ts +4 -0
  177. package/src/r2/helpers.ts +1 -0
  178. package/src/r2/index.ts +40 -28
  179. package/src/secret/index.ts +14 -17
  180. package/src/{sites.tsx → sites.ts} +1 -1
  181. package/src/tail/createTail.ts +94 -3
  182. package/src/tail/filters.ts +1 -1
  183. package/src/tail/index.ts +8 -11
  184. package/src/tail/printing.ts +15 -0
  185. package/src/traverse-module-graph.ts +53 -0
  186. package/src/tsconfig-sanity.ts +16 -0
  187. package/src/type-generation.ts +79 -57
  188. package/src/user/access.ts +0 -1
  189. package/src/user/auth-variables.ts +113 -0
  190. package/src/user/choose-account.tsx +1 -31
  191. package/src/user/index.ts +0 -1
  192. package/src/user/{user.tsx → user.ts} +123 -82
  193. package/src/utils/render.ts +93 -0
  194. package/src/{whoami.tsx → whoami.ts} +37 -71
  195. package/src/worker.ts +35 -3
  196. package/src/yargs-types.ts +22 -5
  197. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  198. package/templates/__tests__/tsconfig.json +8 -0
  199. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  200. package/templates/checked-fetch.js +9 -3
  201. package/templates/d1-beta-facade.js +95 -25
  202. package/templates/facade.d.ts +14 -0
  203. package/templates/first-party-worker-module-facade.ts +4 -3
  204. package/templates/format-dev-errors.ts +8 -6
  205. package/templates/gitignore +1 -0
  206. package/templates/init-tests/test-jest-new-worker.js +3 -5
  207. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  208. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  209. package/templates/middleware/loader-modules.ts +2 -2
  210. package/templates/middleware/loader-sw.ts +51 -31
  211. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  212. package/templates/new-worker.ts +3 -0
  213. package/templates/pages-dev-pipeline.ts +4 -1
  214. package/templates/pages-shim.ts +4 -1
  215. package/templates/pages-template-plugin.ts +19 -10
  216. package/templates/serve-static-assets.ts +17 -14
  217. package/templates/service-bindings-module-facade.js +1 -0
  218. package/templates/tsconfig-sanity.ts +11 -0
  219. package/templates/tsconfig.init.json +105 -0
  220. package/templates/tsconfig.json +5 -103
  221. package/templates/tsconfig.tsbuildinfo +1 -0
  222. package/wrangler-dist/cli.d.ts +826 -77
  223. package/wrangler-dist/cli.js +130734 -140838
  224. package/wrangler-dist/wasm-sync.wasm +0 -0
  225. package/src/__tests__/api-devregistry.test.js +0 -57
  226. package/src/__tests__/d1.test.ts +0 -72
  227. package/src/__tests__/dialogs.test.tsx +0 -40
  228. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  229. package/src/__tests__/pages.test.ts +0 -2223
  230. package/src/dialogs.tsx +0 -163
  231. package/src/environment-variables.ts +0 -50
  232. package/src/pages/build.tsx +0 -238
  233. package/src/user/env-vars.ts +0 -46
  234. package/templates/experimental-local-cache-stubs.js +0 -27
  235. /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  236. /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  237. /package/src/pages/{hash.tsx → hash.ts} +0 -0
@@ -13,14 +13,12 @@ import { getAssetPaths, getSiteAssetPaths } from "../sites";
13
13
  import { requireAuth } from "../user";
14
14
  import { collectKeyValues } from "../utils/collectKeyValues";
15
15
  import publish from "./publish";
16
- import type { ConfigPath } from "../index";
17
16
  import type {
18
- CommonYargsOptions,
19
- YargsOptionsToInterface,
17
+ CommonYargsArgv,
18
+ StrictYargsOptionsToInterface,
20
19
  } from "../yargs-types";
21
- import type { Argv, ArgumentsCamelCase } from "yargs";
22
20
 
23
- export function publishOptions(yargs: Argv<CommonYargsOptions>) {
21
+ export function publishOptions(yargs: CommonYargsArgv) {
24
22
  return (
25
23
  yargs
26
24
  .positional("script", {
@@ -82,6 +80,13 @@ export function publishOptions(yargs: Argv<CommonYargsOptions>) {
82
80
  deprecated: true,
83
81
  hidden: true,
84
82
  })
83
+ .option("public", {
84
+ describe: "Static assets to be served",
85
+ type: "string",
86
+ requiresArg: true,
87
+ deprecated: true,
88
+ hidden: true,
89
+ })
85
90
  .option("assets", {
86
91
  describe: "Static assets to be served",
87
92
  type: "string",
@@ -153,7 +158,7 @@ export function publishOptions(yargs: Argv<CommonYargsOptions>) {
153
158
  type: "boolean",
154
159
  })
155
160
  .option("node-compat", {
156
- describe: "Enable node.js compatibility",
161
+ describe: "Enable Node.js compatibility",
157
162
  type: "boolean",
158
163
  })
159
164
  .option("dry-run", {
@@ -179,14 +184,13 @@ export function publishOptions(yargs: Argv<CommonYargsOptions>) {
179
184
  );
180
185
  }
181
186
 
182
- type PublishArgs = YargsOptionsToInterface<typeof publishOptions>;
183
-
184
- export async function publishHandler(args: ArgumentsCamelCase<PublishArgs>) {
187
+ export async function publishHandler(
188
+ args: StrictYargsOptionsToInterface<typeof publishOptions>
189
+ ) {
185
190
  await printWranglerBanner();
186
191
 
187
192
  const configPath =
188
- (args.config as ConfigPath) ||
189
- (args.script && findWranglerToml(path.dirname(args.script)));
193
+ args.config || (args.script && findWranglerToml(path.dirname(args.script)));
190
194
  const config = readConfig(configPath, args);
191
195
  const entry = await getEntry(args, config, "publish");
192
196
  await metrics.sendMetricsEvent(
@@ -202,7 +206,7 @@ export async function publishHandler(args: ArgumentsCamelCase<PublishArgs>) {
202
206
  if (args.public) {
203
207
  throw new Error("The --public field has been renamed to --assets");
204
208
  }
205
- if (args["experimental-public"]) {
209
+ if (args.experimentalPublic) {
206
210
  throw new Error(
207
211
  "The --experimental-public field has been renamed to --assets"
208
212
  );
@@ -247,13 +251,13 @@ export async function publishHandler(args: ArgumentsCamelCase<PublishArgs>) {
247
251
  env: args.env,
248
252
  compatibilityDate: args.latest
249
253
  ? new Date().toISOString().substring(0, 10)
250
- : args["compatibility-date"],
251
- compatibilityFlags: args["compatibility-flags"],
254
+ : args.compatibilityDate,
255
+ compatibilityFlags: args.compatibilityFlags,
252
256
  vars: cliVars,
253
257
  defines: cliDefines,
254
258
  triggers: args.triggers,
255
- jsxFactory: args["jsx-factory"],
256
- jsxFragment: args["jsx-fragment"],
259
+ jsxFactory: args.jsxFactory,
260
+ jsxFragment: args.jsxFragment,
257
261
  tsconfig: args.tsconfig,
258
262
  routes: args.routes,
259
263
  assetPaths,
@@ -12,7 +12,8 @@ import {
12
12
  import { fetchListResult, fetchResult } from "../cfetch";
13
13
  import { printBindings } from "../config";
14
14
  import { createWorkerUploadForm } from "../create-worker-upload-form";
15
- import { confirm, fromDashMessagePrompt } from "../dialogs";
15
+ import { addHyphens } from "../deployments";
16
+ import { confirm } from "../dialogs";
16
17
  import { getMigrationsToUpload } from "../durable";
17
18
  import { logger } from "../logger";
18
19
  import { getMetricsUsageHeaders } from "../metrics";
@@ -20,6 +21,7 @@ import { ParseError } from "../parse";
20
21
  import { getQueue, putConsumer } from "../queues/client";
21
22
  import { getWorkersDevSubdomain } from "../routes";
22
23
  import { syncAssets } from "../sites";
24
+ import traverseModuleGraph from "../traverse-module-graph";
23
25
  import { identifyD1BindingsAsBeta } from "../worker";
24
26
  import { getZoneForRoute } from "../zones";
25
27
  import type { FetchError } from "../cfetch";
@@ -30,7 +32,6 @@ import type {
30
32
  ZoneNameRoute,
31
33
  CustomDomainRoute,
32
34
  } from "../config/environment";
33
- import type { DeploymentListRes } from "../deployments";
34
35
  import type { Entry } from "../entry";
35
36
  import type { PutConsumerBody } from "../queues/client";
36
37
  import type { AssetPaths } from "../sites";
@@ -93,7 +94,7 @@ function sleep(ms: number) {
93
94
 
94
95
  const scriptStartupErrorRegex = /startup/i;
95
96
 
96
- function errIsScriptSizeOrStartupErr(err: unknown) {
97
+ function errIsScriptSize(err: unknown): err is { code: 10027 } {
97
98
  if (!err) return false;
98
99
 
99
100
  // 10027 = workers.api.error.script_too_large
@@ -101,6 +102,12 @@ function errIsScriptSizeOrStartupErr(err: unknown) {
101
102
  return true;
102
103
  }
103
104
 
105
+ return false;
106
+ }
107
+
108
+ function errIsStartupErr(err: unknown): err is ParseError & { code: 10021 } {
109
+ if (!err) return false;
110
+
104
111
  // 10021 = validation error
105
112
  // no explicit error code for more granular errors than "invalid script"
106
113
  // but the error will contain a string error message directly from the
@@ -269,12 +276,14 @@ export default async function publish(props: Props): Promise<void> {
269
276
  };
270
277
  };
271
278
 
272
- if (
273
- (await fromDashMessagePrompt(
274
- default_environment.script.last_deployed_from
275
- )) === false
276
- )
277
- return;
279
+ if (default_environment.script.last_deployed_from === "dash") {
280
+ logger.warn(
281
+ `You are about to publish a Workers Service that was last published via the Cloudflare Dashboard.\nEdits that have been made via the dashboard will be overridden by your local code and config.`
282
+ );
283
+ if (!(await confirm("Would you like to continue?"))) {
284
+ return;
285
+ }
286
+ }
278
287
  } catch (e) {
279
288
  // code: 10090, message: workers.api.error.service_not_found
280
289
  // is thrown from the above fetchResult on the first publish of a Worker
@@ -327,17 +336,25 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
327
336
 
328
337
  const jsxFactory = props.jsxFactory || config.jsx_factory;
329
338
  const jsxFragment = props.jsxFragment || config.jsx_fragment;
330
- const keepVars = props.keepVars ?? config.keep_vars;
339
+ const keepVars = props.keepVars || config.keep_vars;
331
340
 
332
341
  const minify = props.minify ?? config.minify;
333
342
 
334
- const nodeCompat = props.nodeCompat ?? config.node_compat;
335
- if (nodeCompat) {
343
+ const legacyNodeCompat = props.nodeCompat ?? config.node_compat;
344
+ if (legacyNodeCompat) {
336
345
  logger.warn(
337
- "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."
346
+ "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."
338
347
  );
339
348
  }
340
349
 
350
+ const compatibilityFlags =
351
+ props.compatibilityFlags ?? config.compatibility_flags;
352
+ const nodejsCompat = compatibilityFlags.includes("nodejs_compat");
353
+ assert(
354
+ !(legacyNodeCompat && nodejsCompat),
355
+ "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."
356
+ );
357
+
341
358
  // Warn if user tries minify or node-compat with no-bundle
342
359
  if (props.noBundle && minify) {
343
360
  logger.warn(
@@ -345,7 +362,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
345
362
  );
346
363
  }
347
364
 
348
- if (props.noBundle && nodeCompat) {
365
+ if (props.noBundle && legacyNodeCompat) {
349
366
  logger.warn(
350
367
  "`--node-compat` and `--no-bundle` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process."
351
368
  );
@@ -385,7 +402,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
385
402
  : `/accounts/${accountId}/workers/scripts/${scriptName}`;
386
403
 
387
404
  let available_on_subdomain: boolean | undefined = undefined; // we'll set this later
388
- let scriptTag: string | null = null;
405
+ let deploymentId: string | null = null;
389
406
 
390
407
  const { format } = props.entry;
391
408
 
@@ -447,14 +464,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
447
464
  resolvedEntryPointPath,
448
465
  bundleType,
449
466
  }: Awaited<ReturnType<typeof bundleWorker>> = props.noBundle
450
- ? // we can skip the whole bundling step and mock a bundle here
451
- {
452
- modules: [],
453
- dependencies: {},
454
- resolvedEntryPointPath: props.entry.file,
455
- bundleType: props.entry.format === "modules" ? "esm" : "commonjs",
456
- stop: undefined,
457
- }
467
+ ? await traverseModuleGraph(props.entry, props.rules)
458
468
  : await bundleWorker(
459
469
  props.entry,
460
470
  typeof destination === "string" ? destination : destination.path,
@@ -464,12 +474,14 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
464
474
  betaD1Shims: identifyD1BindingsAsBeta(config.d1_databases)?.map(
465
475
  (db) => db.binding
466
476
  ),
477
+ doBindings: config.durable_objects.bindings,
467
478
  jsxFactory,
468
479
  jsxFragment,
469
480
  rules: props.rules,
470
481
  tsconfig: props.tsconfig ?? config.tsconfig,
471
482
  minify,
472
- nodeCompat,
483
+ legacyNodeCompat,
484
+ nodejsCompat,
473
485
  define: { ...config.define, ...props.defines },
474
486
  checkFetch: false,
475
487
  assets: config.assets && {
@@ -487,7 +499,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
487
499
  // This could potentially cause issues as we no longer have identical behaviour between dev and publish?
488
500
  targetConsumer: "publish",
489
501
  local: false,
490
- experimentalLocalStubCache: false,
502
+ experimentalLocal: false,
491
503
  }
492
504
  );
493
505
 
@@ -523,8 +535,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
523
535
  ? { binding: "__STATIC_CONTENT", id: assets.namespace }
524
536
  : []
525
537
  ),
538
+ send_email: config.send_email,
526
539
  vars: { ...config.vars, ...props.vars },
527
- metadata_binding: config.metadata_binding,
528
540
  wasm_modules: config.wasm_modules,
529
541
  text_blobs: {
530
542
  ...config.text_blobs,
@@ -541,9 +553,14 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
541
553
  r2_buckets: config.r2_buckets,
542
554
  d1_databases: identifyD1BindingsAsBeta(config.d1_databases),
543
555
  services: config.services,
556
+ analytics_engine_datasets: config.analytics_engine_datasets,
544
557
  dispatch_namespaces: config.dispatch_namespaces,
558
+ mtls_certificates: config.mtls_certificates,
545
559
  logfwdr: config.logfwdr,
546
- unsafe: config.unsafe?.bindings,
560
+ unsafe: {
561
+ bindings: config.unsafe.bindings,
562
+ metadata: config.unsafe.metadata,
563
+ },
547
564
  };
548
565
 
549
566
  if (assets.manifest) {
@@ -565,8 +582,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
565
582
  migrations,
566
583
  modules,
567
584
  compatibility_date: props.compatibilityDate ?? config.compatibility_date,
568
- compatibility_flags:
569
- props.compatibilityFlags ?? config.compatibility_flags,
585
+ compatibility_flags: compatibilityFlags,
570
586
  usage_model: config.usage_model,
571
587
  keepVars,
572
588
  logpush: props.logpush !== undefined ? props.logpush : config.logpush,
@@ -600,9 +616,9 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
600
616
 
601
617
  printBindings({ ...withoutStaticAssets, vars: maskedVars });
602
618
 
603
- await ensureQueuesExist(config);
604
-
605
619
  if (!props.dryRun) {
620
+ await ensureQueuesExist(config);
621
+
606
622
  // Upload the script so it has time to propagate.
607
623
  // We can also now tell whether available_on_subdomain is set
608
624
  try {
@@ -611,7 +627,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
611
627
  id: string | null;
612
628
  etag: string | null;
613
629
  pipeline_hash: string | null;
614
- tag: string | null;
630
+ deployment_id: string | null;
615
631
  }>(
616
632
  workerUrl,
617
633
  {
@@ -628,7 +644,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
628
644
  );
629
645
 
630
646
  available_on_subdomain = result.available_on_subdomain;
631
- scriptTag = result.tag;
647
+ deploymentId = addHyphens(result.deployment_id) ?? result.deployment_id;
632
648
 
633
649
  if (config.first_party_worker) {
634
650
  // Print some useful information returned after publishing
@@ -640,9 +656,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
640
656
  logger.log("Worker PipelineHash: ", result.pipeline_hash);
641
657
  }
642
658
  } catch (err) {
643
- if (errIsScriptSizeOrStartupErr(err)) {
644
- printOffendingDependencies(dependencies);
645
- }
659
+ helpIfErrorIsSizeOrScriptStartup(err, dependencies);
646
660
  throw err;
647
661
  }
648
662
  }
@@ -820,17 +834,27 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
820
834
  logger.log("No publish targets for", workerName, formatTime(deployMs));
821
835
  }
822
836
 
823
- try {
824
- const deploymentsList = await fetchResult<DeploymentListRes>(
825
- `/accounts/${accountId}/workers/versions/by-script/${scriptTag}`
826
- );
837
+ logger.log("Current Deployment ID:", deploymentId);
838
+ }
827
839
 
828
- logger.log("Current Deployment:", deploymentsList.latest.number);
829
- } catch (e) {
830
- if ((e as { code: number }).code === 10023) {
831
- // TODO: remove this try/catch once versions is completely rolled out
832
- }
833
- throw e;
840
+ export function helpIfErrorIsSizeOrScriptStartup(
841
+ err: unknown,
842
+ dependencies: { [path: string]: { bytesInOutput: number } }
843
+ ) {
844
+ if (errIsScriptSize(err)) {
845
+ printOffendingDependencies(dependencies);
846
+ } else if (errIsStartupErr(err)) {
847
+ const youFailed =
848
+ "Your Worker failed validation because it exceeded startup limits.";
849
+ const heresWhy =
850
+ "To ensure fast responses, we place constraints on Worker startup -- like how much CPU it can use, or how long it can take.";
851
+ const heresTheProblem =
852
+ "Your Worker failed validation, which means it hit one of these startup limits.";
853
+ const heresTheSolution =
854
+ "Try reducing the amount of work done during startup (outside the event handler), either by removing code or relocating it inside the event handler.";
855
+ logger.warn(
856
+ [youFailed, heresWhy, heresTheProblem, heresTheSolution].join("\n")
857
+ );
834
858
  }
835
859
  }
836
860
 
@@ -997,7 +1021,7 @@ async function ensureQueuesExist(config: Config) {
997
1021
  await getQueue(config, queue);
998
1022
  } catch (err) {
999
1023
  const queueErr = err as FetchError;
1000
- if (queueErr.code === 100123) {
1024
+ if (queueErr.code === 11000) {
1001
1025
  // queue_not_found
1002
1026
  throw new Error(
1003
1027
  `Queue "${queue}" does not exist. To create it, run: wrangler queues create ${queue}`
@@ -1019,6 +1043,7 @@ function updateQueueConsumers(config: Config): Promise<string[]>[] {
1019
1043
  max_wait_time_ms: consumer.max_batch_timeout
1020
1044
  ? 1000 * consumer.max_batch_timeout
1021
1045
  : undefined,
1046
+ max_concurrency: consumer.max_concurrency,
1022
1047
  },
1023
1048
  };
1024
1049
 
@@ -1,4 +1,3 @@
1
- import { type ConfigPath } from "..";
2
1
  import { readConfig } from "../config";
3
2
  import { confirm } from "../dialogs";
4
3
  import { CommandLineArgsError } from "../index";
@@ -7,13 +6,13 @@ import * as metrics from "../metrics";
7
6
  import { parseHumanDuration } from "../parse";
8
7
  import { requireAuth } from "../user";
9
8
  import * as pubsub from ".";
10
- import type { CommonYargsOptions } from "../yargs-types";
11
- import type { Argv, CommandModule } from "yargs";
9
+ import type { CommonYargsArgv, CommonYargsOptions } from "../yargs-types";
10
+ import type { CommandModule } from "yargs";
12
11
 
13
12
  export function pubSubCommands(
14
- pubsubYargs: Argv<CommonYargsOptions>,
13
+ pubsubYargs: CommonYargsArgv,
15
14
  subHelp: CommandModule<CommonYargsOptions, CommonYargsOptions>
16
- ): Argv {
15
+ ) {
17
16
  return pubsubYargs
18
17
  .command(subHelp)
19
18
  .command(
@@ -39,7 +38,7 @@ export function pubSubCommands(
39
38
  .epilogue(pubsub.pubSubBetaWarning);
40
39
  },
41
40
  async (args) => {
42
- const config = readConfig(args.config as ConfigPath, args);
41
+ const config = readConfig(args.config, args);
43
42
  const accountId = await requireAuth(config);
44
43
 
45
44
  const namespace: pubsub.PubSubNamespace = {
@@ -49,7 +48,7 @@ export function pubSubCommands(
49
48
  namespace.description = args.description;
50
49
  }
51
50
 
52
- logger.log(`Creating Pub/SubNamespace ${args.name}...`);
51
+ logger.log(`Creating Pub/Sub Namespace ${args.name}...`);
53
52
  await pubsub.createPubSubNamespace(accountId, namespace);
54
53
  logger.log(`Success! Created Pub/Sub Namespace ${args.name}`);
55
54
  await metrics.sendMetricsEvent("create pubsub namespace", {
@@ -64,7 +63,7 @@ export function pubSubCommands(
64
63
  return yargs.epilogue(pubsub.pubSubBetaWarning);
65
64
  },
66
65
  async (args) => {
67
- const config = readConfig(args.config as ConfigPath, args);
66
+ const config = readConfig(args.config, args);
68
67
  const accountId = await requireAuth(config);
69
68
 
70
69
  logger.log(await pubsub.listPubSubNamespaces(accountId));
@@ -86,7 +85,7 @@ export function pubSubCommands(
86
85
  .epilogue(pubsub.pubSubBetaWarning);
87
86
  },
88
87
  async (args) => {
89
- const config = readConfig(args.config as ConfigPath, args);
88
+ const config = readConfig(args.config, args);
90
89
  const accountId = await requireAuth(config);
91
90
 
92
91
  if (
@@ -116,7 +115,7 @@ export function pubSubCommands(
116
115
  .epilogue(pubsub.pubSubBetaWarning);
117
116
  },
118
117
  async (args) => {
119
- const config = readConfig(args.config as ConfigPath, args);
118
+ const config = readConfig(args.config, args);
120
119
  const accountId = await requireAuth(config);
121
120
 
122
121
  logger.log(
@@ -165,7 +164,7 @@ export function pubSubCommands(
165
164
  })
166
165
  .epilogue(pubsub.pubSubBetaWarning),
167
166
  async (args) => {
168
- const config = readConfig(args.config as ConfigPath, args);
167
+ const config = readConfig(args.config, args);
169
168
  const accountId = await requireAuth(config);
170
169
 
171
170
  const broker: pubsub.PubSubBroker = {
@@ -230,7 +229,7 @@ export function pubSubCommands(
230
229
  })
231
230
  .epilogue(pubsub.pubSubBetaWarning),
232
231
  async (args) => {
233
- const config = readConfig(args.config as ConfigPath, args);
232
+ const config = readConfig(args.config, args);
234
233
  const accountId = await requireAuth(config);
235
234
 
236
235
  const broker: pubsub.PubSubBrokerUpdate = {};
@@ -284,7 +283,7 @@ export function pubSubCommands(
284
283
  .epilogue(pubsub.pubSubBetaWarning);
285
284
  },
286
285
  async (args) => {
287
- const config = readConfig(args.config as ConfigPath, args);
286
+ const config = readConfig(args.config, args);
288
287
  const accountId = await requireAuth(config);
289
288
 
290
289
  logger.log(await pubsub.listPubSubBrokers(accountId, args.namespace));
@@ -314,7 +313,7 @@ export function pubSubCommands(
314
313
  .epilogue(pubsub.pubSubBetaWarning);
315
314
  },
316
315
  async (args) => {
317
- const config = readConfig(args.config as ConfigPath, args);
316
+ const config = readConfig(args.config, args);
318
317
  const accountId = await requireAuth(config);
319
318
 
320
319
  if (
@@ -354,7 +353,7 @@ export function pubSubCommands(
354
353
  .epilogue(pubsub.pubSubBetaWarning);
355
354
  },
356
355
  async (args) => {
357
- const config = readConfig(args.config as ConfigPath, args);
356
+ const config = readConfig(args.config, args);
358
357
  const accountId = await requireAuth(config);
359
358
 
360
359
  logger.log(
@@ -413,7 +412,7 @@ export function pubSubCommands(
413
412
  .epilogue(pubsub.pubSubBetaWarning);
414
413
  },
415
414
  async (args) => {
416
- const config = readConfig(args.config as ConfigPath, args);
415
+ const config = readConfig(args.config, args);
417
416
  const accountId = await requireAuth(config);
418
417
 
419
418
  let parsedExpiration: number | undefined;
@@ -473,7 +472,7 @@ export function pubSubCommands(
473
472
  .epilogue(pubsub.pubSubBetaWarning);
474
473
  },
475
474
  async (args) => {
476
- const config = readConfig(args.config as ConfigPath, args);
475
+ const config = readConfig(args.config, args);
477
476
  const accountId = await requireAuth(config);
478
477
 
479
478
  const numTokens = args.jti.length;
@@ -521,7 +520,7 @@ export function pubSubCommands(
521
520
  .epilogue(pubsub.pubSubBetaWarning);
522
521
  },
523
522
  async (args) => {
524
- const config = readConfig(args.config as ConfigPath, args);
523
+ const config = readConfig(args.config, args);
525
524
  const accountId = await requireAuth(config);
526
525
 
527
526
  const numTokens = args.jti.length;
@@ -562,7 +561,7 @@ export function pubSubCommands(
562
561
  .epilogue(pubsub.pubSubBetaWarning);
563
562
  },
564
563
  async (args) => {
565
- const config = readConfig(args.config as ConfigPath, args);
564
+ const config = readConfig(args.config, args);
566
565
  const accountId = await requireAuth(config);
567
566
 
568
567
  logger.log(`Listing previously revoked tokens for ${args.name}...`);
@@ -601,7 +600,7 @@ export function pubSubCommands(
601
600
  .epilogue(pubsub.pubSubBetaWarning);
602
601
  },
603
602
  async (args) => {
604
- const config = readConfig(args.config as ConfigPath, args);
603
+ const config = readConfig(args.config, args);
605
604
  const accountId = await requireAuth(config);
606
605
 
607
606
  logger.log(
@@ -1,21 +1,13 @@
1
- import { type Argv } from "yargs";
2
1
  import { readConfig } from "../../../../config";
3
2
  import { logger } from "../../../../logger";
4
3
  import { postConsumer } from "../../../client";
5
- import type { CommonYargsOptions } from "../../../../yargs-types";
4
+ import type {
5
+ CommonYargsArgv,
6
+ StrictYargsOptionsToInterface,
7
+ } from "../../../../yargs-types";
6
8
  import type { PostConsumerBody } from "../../../client";
7
9
 
8
- type Args = CommonYargsOptions & {
9
- config?: string;
10
- ["queue-name"]: string;
11
- ["script-name"]: string;
12
- ["batch-size"]?: number;
13
- ["batch-timeout"]?: number;
14
- ["message-retries"]?: number;
15
- ["dead-letter-queue"]?: string;
16
- };
17
-
18
- export function options(yargs: Argv<CommonYargsOptions>): Argv<Args> {
10
+ export function options(yargs: CommonYargsArgv) {
19
11
  return yargs
20
12
  .positional("queue-name", {
21
13
  type: "string",
@@ -45,27 +37,35 @@ export function options(yargs: Argv<CommonYargsOptions>): Argv<Args> {
45
37
  type: "string",
46
38
  describe: "Queue to send messages that failed to be consumed",
47
39
  },
40
+ "max-concurrency": {
41
+ type: "number",
42
+ describe:
43
+ "The maximum number of concurrent consumer Worker invocations. Must be a positive integer",
44
+ },
48
45
  });
49
46
  }
50
47
 
51
- export async function handler(args: Args) {
48
+ export async function handler(
49
+ args: StrictYargsOptionsToInterface<typeof options>
50
+ ) {
52
51
  const config = readConfig(args.config, args);
53
52
 
54
53
  const body: PostConsumerBody = {
55
- script_name: args["script-name"],
54
+ script_name: args.scriptName,
56
55
  // TODO(soon) is this still the correct usage of the environment?
57
- environment_name: args.env || "", // API expects empty string as default
56
+ environment_name: args.env ?? "", // API expects empty string as default
58
57
  settings: {
59
- batch_size: args["batch-size"],
60
- max_retries: args["message-retries"],
61
- max_wait_time_ms: args["batch-timeout"] // API expects milliseconds
62
- ? 1000 * args["batch-timeout"]
58
+ batch_size: args.batchSize,
59
+ max_retries: args.messageRetries,
60
+ max_wait_time_ms: args.batchTimeout // API expects milliseconds
61
+ ? 1000 * args.batchTimeout
63
62
  : undefined,
63
+ max_concurrency: args.maxConcurrency,
64
64
  },
65
- dead_letter_queue: args["dead-letter-queue"],
65
+ dead_letter_queue: args.deadLetterQueue,
66
66
  };
67
67
 
68
- logger.log(`Adding consumer to queue ${args["queue-name"]}.`);
69
- await postConsumer(config, args["queue-name"], body);
70
- logger.log(`Added consumer to queue ${args["queue-name"]}.`);
68
+ logger.log(`Adding consumer to queue ${args.queueName}.`);
69
+ await postConsumer(config, args.queueName, body);
70
+ logger.log(`Added consumer to queue ${args.queueName}.`);
71
71
  }
@@ -1,11 +1,8 @@
1
- import { type BuilderCallback } from "yargs";
2
- import { type CommonYargsOptions } from "../../../../yargs-types";
3
1
  import { options as addOptions, handler as addHandler } from "./add";
4
2
  import { options as removeOptions, handler as removeHandler } from "./remove";
3
+ import type { CommonYargsArgv } from "../../../../yargs-types";
5
4
 
6
- export const consumers: BuilderCallback<CommonYargsOptions, unknown> = (
7
- yargs
8
- ) => {
5
+ export function consumers(yargs: CommonYargsArgv) {
9
6
  yargs.command(
10
7
  "add <queue-name> <script-name>",
11
8
  "Add a Queue Consumer",
@@ -19,4 +16,4 @@ export const consumers: BuilderCallback<CommonYargsOptions, unknown> = (
19
16
  removeOptions,
20
17
  removeHandler
21
18
  );
22
- };
19
+ }
@@ -1,16 +1,12 @@
1
- import { type Argv } from "yargs";
2
1
  import { readConfig } from "../../../../config";
3
2
  import { logger } from "../../../../logger";
4
3
  import { deleteConsumer } from "../../../client";
5
- import type { CommonYargsOptions } from "../../../../yargs-types";
4
+ import type {
5
+ CommonYargsArgv,
6
+ StrictYargsOptionsToInterface,
7
+ } from "../../../../yargs-types";
6
8
 
7
- type Args = CommonYargsOptions & {
8
- config?: string;
9
- ["queue-name"]: string;
10
- ["script-name"]: string;
11
- };
12
-
13
- export function options(yargs: Argv<CommonYargsOptions>): Argv<Args> {
9
+ export function options(yargs: CommonYargsArgv) {
14
10
  return yargs
15
11
  .positional("queue-name", {
16
12
  type: "string",
@@ -24,15 +20,12 @@ export function options(yargs: Argv<CommonYargsOptions>): Argv<Args> {
24
20
  });
25
21
  }
26
22
 
27
- export async function handler(args: Args) {
23
+ export async function handler(
24
+ args: StrictYargsOptionsToInterface<typeof options>
25
+ ) {
28
26
  const config = readConfig(args.config, args);
29
27
 
30
- logger.log(`Removing consumer from queue ${args["queue-name"]}.`);
31
- await deleteConsumer(
32
- config,
33
- args["queue-name"],
34
- args["script-name"],
35
- args.env
36
- );
37
- logger.log(`Removed consumer from queue ${args["queue-name"]}.`);
28
+ logger.log(`Removing consumer from queue ${args.queueName}.`);
29
+ await deleteConsumer(config, args.queueName, args.scriptName, args.env);
30
+ logger.log(`Removed consumer from queue ${args.queueName}.`);
38
31
  }