wrangler 0.0.0-e7a0cd5b → 0.0.0-e7c06d78

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