wrangler 0.0.0-e30d1013 → 0.0.0-e311bbbf

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 (236) 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 +26 -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 -39
  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 -52
  15. package/src/__tests__/dev.test.tsx +198 -90
  16. package/src/__tests__/generate.test.ts +8 -5
  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 +127 -26
  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 +1620 -830
  61. package/src/__tests__/pubsub.test.ts +226 -100
  62. package/src/__tests__/queues.test.ts +237 -76
  63. package/src/__tests__/r2.test.ts +37 -56
  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 +11 -2
  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 +221 -128
  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 +73 -16
  87. package/src/config/index.ts +99 -30
  88. package/src/config/validation-helpers.ts +1 -1
  89. package/src/config/validation.ts +248 -9
  90. package/src/create-worker-preview.ts +19 -8
  91. package/src/create-worker-upload-form.ts +48 -5
  92. package/src/d1/backups.tsx +43 -42
  93. package/src/d1/create.tsx +26 -21
  94. package/src/d1/{delete.tsx → delete.ts} +11 -14
  95. package/src/d1/execute.tsx +183 -170
  96. package/src/d1/index.ts +7 -6
  97. package/src/d1/list.tsx +22 -10
  98. package/src/d1/migrations/apply.tsx +212 -0
  99. package/src/d1/migrations/create.tsx +79 -0
  100. package/src/d1/migrations/helpers.ts +172 -0
  101. package/src/d1/migrations/index.ts +3 -0
  102. package/src/d1/migrations/list.tsx +95 -0
  103. package/src/d1/migrations/options.ts +23 -0
  104. package/src/d1/options.ts +3 -3
  105. package/src/d1/splitter.ts +161 -0
  106. package/src/d1/{types.tsx → types.ts} +1 -0
  107. package/src/d1/utils.ts +2 -1
  108. package/src/delete.ts +8 -16
  109. package/src/deployments.ts +333 -42
  110. package/src/deprecated/index.ts +8 -302
  111. package/src/dev/dev.tsx +57 -44
  112. package/src/dev/local.tsx +248 -74
  113. package/src/dev/remote.tsx +32 -3
  114. package/src/dev/start-server.ts +81 -66
  115. package/src/dev/use-esbuild.ts +17 -18
  116. package/src/dev/validate-dev-props.ts +9 -0
  117. package/src/{dev-registry.tsx → dev-registry.ts} +2 -1
  118. package/src/dev.tsx +178 -117
  119. package/src/dialogs.ts +136 -0
  120. package/src/dispatch-namespace.ts +21 -17
  121. package/src/docs/index.ts +97 -0
  122. package/src/entry.ts +19 -11
  123. package/src/environment-variables/factory.ts +88 -0
  124. package/src/environment-variables/misc-variables.ts +30 -0
  125. package/src/generate/index.ts +298 -0
  126. package/src/git-client.ts +15 -4
  127. package/src/{index.tsx → index.ts} +134 -59
  128. package/src/init.ts +249 -187
  129. package/src/inspect.ts +16 -1
  130. package/src/jest.d.ts +4 -0
  131. package/src/kv/index.ts +15 -17
  132. package/src/logger.ts +32 -5
  133. package/src/metrics/metrics-config.ts +3 -3
  134. package/src/metrics/send-event.ts +6 -1
  135. package/src/miniflare-cli/assets.ts +64 -28
  136. package/src/miniflare-cli/index.ts +4 -7
  137. package/src/miniflare-cli/tsconfig.json +9 -0
  138. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  139. package/src/miniflare-cli/types.ts +11 -0
  140. package/src/module-collection.ts +91 -25
  141. package/src/mtls-certificate/cli.ts +155 -0
  142. package/src/pages/build.ts +410 -0
  143. package/src/pages/buildFunctions.ts +140 -0
  144. package/src/pages/deployment-tails.ts +281 -0
  145. package/src/pages/deployments.tsx +11 -33
  146. package/src/pages/{dev.tsx → dev.ts} +147 -139
  147. package/src/pages/errors.ts +1 -0
  148. package/src/pages/functions/buildPlugin.ts +61 -54
  149. package/src/pages/functions/buildWorker.ts +159 -33
  150. package/src/pages/functions/tsconfig.json +8 -0
  151. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  152. package/src/pages/{functions.tsx → functions.ts} +8 -4
  153. package/src/pages/{index.tsx → index.ts} +11 -3
  154. package/src/pages/projects.tsx +12 -22
  155. package/src/pages/prompt-select-project.tsx +31 -0
  156. package/src/pages/publish.tsx +46 -225
  157. package/src/pages/types.ts +6 -9
  158. package/src/pages/upload.tsx +58 -14
  159. package/src/pages/utils.ts +12 -1
  160. package/src/parse.ts +23 -1
  161. package/src/paths.ts +1 -1
  162. package/src/proxy.ts +5 -0
  163. package/src/publish/index.ts +20 -16
  164. package/src/publish/publish.ts +71 -46
  165. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
  166. package/src/queues/cli/commands/consumer/add.ts +24 -24
  167. package/src/queues/cli/commands/consumer/index.ts +3 -6
  168. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  169. package/src/queues/cli/commands/create.ts +8 -8
  170. package/src/queues/cli/commands/delete.ts +8 -8
  171. package/src/queues/cli/commands/index.ts +6 -4
  172. package/src/queues/cli/commands/list.ts +8 -8
  173. package/src/queues/client.ts +1 -0
  174. package/src/queues/utils.ts +18 -0
  175. package/src/r2/helpers.ts +1 -0
  176. package/src/r2/index.ts +28 -28
  177. package/src/secret/index.ts +14 -16
  178. package/src/{sites.tsx → sites.ts} +1 -1
  179. package/src/tail/createTail.ts +94 -3
  180. package/src/tail/filters.ts +1 -1
  181. package/src/tail/index.ts +8 -11
  182. package/src/tail/printing.ts +15 -0
  183. package/src/traverse-module-graph.ts +53 -0
  184. package/src/tsconfig-sanity.ts +16 -0
  185. package/src/type-generation.ts +28 -20
  186. package/src/user/access.ts +0 -1
  187. package/src/user/auth-variables.ts +113 -0
  188. package/src/user/choose-account.tsx +1 -31
  189. package/src/user/index.ts +0 -1
  190. package/src/user/{user.tsx → user.ts} +123 -82
  191. package/src/utils/render.ts +93 -0
  192. package/src/{whoami.tsx → whoami.ts} +37 -71
  193. package/src/worker.ts +30 -1
  194. package/src/yargs-types.ts +22 -5
  195. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  196. package/templates/__tests__/tsconfig.json +8 -0
  197. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  198. package/templates/checked-fetch.js +9 -3
  199. package/templates/d1-beta-facade.js +51 -3
  200. package/templates/facade.d.ts +14 -0
  201. package/templates/first-party-worker-module-facade.ts +4 -3
  202. package/templates/format-dev-errors.ts +8 -6
  203. package/templates/gitignore +1 -0
  204. package/templates/init-tests/test-jest-new-worker.js +3 -5
  205. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  206. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  207. package/templates/middleware/loader-modules.ts +2 -2
  208. package/templates/middleware/loader-sw.ts +51 -31
  209. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  210. package/templates/new-worker.ts +3 -0
  211. package/templates/pages-dev-pipeline.ts +4 -1
  212. package/templates/pages-shim.ts +4 -1
  213. package/templates/pages-template-plugin.ts +19 -10
  214. package/templates/serve-static-assets.ts +17 -14
  215. package/templates/service-bindings-module-facade.js +1 -0
  216. package/templates/tsconfig-sanity.ts +11 -0
  217. package/templates/tsconfig.init.json +105 -0
  218. package/templates/tsconfig.json +5 -103
  219. package/templates/tsconfig.tsbuildinfo +1 -0
  220. package/wrangler-dist/cli.d.ts +820 -70
  221. package/wrangler-dist/cli.js +68161 -78780
  222. package/wrangler-dist/wasm-sync.wasm +0 -0
  223. package/src/__tests__/api-devregistry.test.js +0 -56
  224. package/src/__tests__/d1.test.ts +0 -74
  225. package/src/__tests__/dialogs.test.tsx +0 -40
  226. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  227. package/src/__tests__/pages.test.ts +0 -2387
  228. package/src/d1/migrations.tsx +0 -446
  229. package/src/dialogs.tsx +0 -169
  230. package/src/environment-variables.ts +0 -50
  231. package/src/pages/build.tsx +0 -270
  232. package/src/user/env-vars.ts +0 -46
  233. package/templates/experimental-local-cache-stubs.js +0 -27
  234. /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  235. /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  236. /package/src/pages/{hash.tsx → hash.ts} +0 -0
@@ -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,6 +535,7 @@ 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
540
  wasm_modules: config.wasm_modules,
528
541
  text_blobs: {
@@ -540,9 +553,14 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
540
553
  r2_buckets: config.r2_buckets,
541
554
  d1_databases: identifyD1BindingsAsBeta(config.d1_databases),
542
555
  services: config.services,
556
+ analytics_engine_datasets: config.analytics_engine_datasets,
543
557
  dispatch_namespaces: config.dispatch_namespaces,
558
+ mtls_certificates: config.mtls_certificates,
544
559
  logfwdr: config.logfwdr,
545
- unsafe: config.unsafe?.bindings,
560
+ unsafe: {
561
+ bindings: config.unsafe.bindings,
562
+ metadata: config.unsafe.metadata,
563
+ },
546
564
  };
547
565
 
548
566
  if (assets.manifest) {
@@ -564,8 +582,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
564
582
  migrations,
565
583
  modules,
566
584
  compatibility_date: props.compatibilityDate ?? config.compatibility_date,
567
- compatibility_flags:
568
- props.compatibilityFlags ?? config.compatibility_flags,
585
+ compatibility_flags: compatibilityFlags,
569
586
  usage_model: config.usage_model,
570
587
  keepVars,
571
588
  logpush: props.logpush !== undefined ? props.logpush : config.logpush,
@@ -599,9 +616,9 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
599
616
 
600
617
  printBindings({ ...withoutStaticAssets, vars: maskedVars });
601
618
 
602
- await ensureQueuesExist(config);
603
-
604
619
  if (!props.dryRun) {
620
+ await ensureQueuesExist(config);
621
+
605
622
  // Upload the script so it has time to propagate.
606
623
  // We can also now tell whether available_on_subdomain is set
607
624
  try {
@@ -610,7 +627,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
610
627
  id: string | null;
611
628
  etag: string | null;
612
629
  pipeline_hash: string | null;
613
- tag: string | null;
630
+ deployment_id: string | null;
614
631
  }>(
615
632
  workerUrl,
616
633
  {
@@ -627,7 +644,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
627
644
  );
628
645
 
629
646
  available_on_subdomain = result.available_on_subdomain;
630
- scriptTag = result.tag;
647
+ deploymentId = addHyphens(result.deployment_id) ?? result.deployment_id;
631
648
 
632
649
  if (config.first_party_worker) {
633
650
  // Print some useful information returned after publishing
@@ -639,9 +656,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
639
656
  logger.log("Worker PipelineHash: ", result.pipeline_hash);
640
657
  }
641
658
  } catch (err) {
642
- if (errIsScriptSizeOrStartupErr(err)) {
643
- printOffendingDependencies(dependencies);
644
- }
659
+ helpIfErrorIsSizeOrScriptStartup(err, dependencies);
645
660
  throw err;
646
661
  }
647
662
  }
@@ -819,18 +834,27 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
819
834
  logger.log("No publish targets for", workerName, formatTime(deployMs));
820
835
  }
821
836
 
822
- try {
823
- const deploymentsList = await fetchResult<DeploymentListRes>(
824
- `/accounts/${accountId}/workers/deployments/by-script/${scriptTag}`
825
- );
837
+ logger.log("Current Deployment ID:", deploymentId);
838
+ }
826
839
 
827
- logger.log("Current Deployment ID:", deploymentsList.latest.id);
828
- } catch (e) {
829
- if ((e as { code: number }).code === 10023) {
830
- // TODO: remove this try/catch once deployments is completely rolled out
831
- } else {
832
- throw e;
833
- }
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
 
@@ -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
  }
@@ -1,14 +1,12 @@
1
- import { type Argv } from "yargs";
2
1
  import { readConfig } from "../../../config";
3
2
  import { logger } from "../../../logger";
4
3
  import { createQueue } from "../../client";
4
+ import type {
5
+ CommonYargsArgv,
6
+ StrictYargsOptionsToInterface,
7
+ } from "../../../yargs-types";
5
8
 
6
- interface Args {
7
- config?: string;
8
- name: string;
9
- }
10
-
11
- export function options(yargs: Argv): Argv<Args> {
9
+ export function options(yargs: CommonYargsArgv) {
12
10
  return yargs.positional("name", {
13
11
  type: "string",
14
12
  demandOption: true,
@@ -16,7 +14,9 @@ export function options(yargs: Argv): Argv<Args> {
16
14
  });
17
15
  }
18
16
 
19
- export async function handler(args: Args) {
17
+ export async function handler(
18
+ args: StrictYargsOptionsToInterface<typeof options>
19
+ ) {
20
20
  const config = readConfig(args.config, args);
21
21
 
22
22
  logger.log(`Creating queue ${args.name}.`);
@@ -1,14 +1,12 @@
1
- import { type Argv } from "yargs";
2
1
  import { readConfig } from "../../../config";
3
2
  import { logger } from "../../../logger";
4
3
  import { deleteQueue } from "../../client";
4
+ import type {
5
+ CommonYargsArgv,
6
+ StrictYargsOptionsToInterface,
7
+ } from "../../../yargs-types";
5
8
 
6
- interface Args {
7
- config?: string;
8
- name: string;
9
- }
10
-
11
- export function options(yargs: Argv): Argv<Args> {
9
+ export function options(yargs: CommonYargsArgv) {
12
10
  // TODO(soon) --force option
13
11
  return yargs.positional("name", {
14
12
  type: "string",
@@ -17,7 +15,9 @@ export function options(yargs: Argv): Argv<Args> {
17
15
  });
18
16
  }
19
17
 
20
- export async function handler(args: Args) {
18
+ export async function handler(
19
+ args: StrictYargsOptionsToInterface<typeof options>
20
+ ) {
21
21
  const config = readConfig(args.config, args);
22
22
 
23
23
  logger.log(`Deleting queue ${args.name}.`);
@@ -1,12 +1,12 @@
1
- import { type BuilderCallback } from "yargs";
2
- import { type CommonYargsOptions } from "../../../yargs-types";
1
+ import { HandleUnauthorizedError } from "../../utils";
3
2
  import { consumers } from "./consumer";
4
3
 
5
4
  import { options as createOptions, handler as createHandler } from "./create";
6
5
  import { options as deleteOptions, handler as deleteHandler } from "./delete";
7
6
  import { options as listOptions, handler as listHandler } from "./list";
7
+ import type { CommonYargsArgv } from "../../../yargs-types";
8
8
 
9
- export const queues: BuilderCallback<CommonYargsOptions, unknown> = (yargs) => {
9
+ export function queues(yargs: CommonYargsArgv) {
10
10
  yargs.command("list", "List Queues", listOptions, listHandler);
11
11
 
12
12
  yargs.command(
@@ -30,4 +30,6 @@ export const queues: BuilderCallback<CommonYargsOptions, unknown> = (yargs) => {
30
30
  await consumers(consumersYargs);
31
31
  }
32
32
  );
33
- };
33
+
34
+ yargs.fail(HandleUnauthorizedError);
35
+ }