wrangler 0.0.0-ecc8b172 → 0.0.0-ecded1af1

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