wrangler 2.8.1 → 2.9.0

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 (66) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/d1/d1.test.ts +10 -52
  3. package/src/__tests__/d1/migrate.test.ts +48 -0
  4. package/src/__tests__/dev.test.tsx +5 -4
  5. package/src/__tests__/index.test.ts +35 -28
  6. package/src/__tests__/kv.test.ts +55 -44
  7. package/src/__tests__/pages.test.ts +27 -20
  8. package/src/__tests__/parse.test.ts +106 -0
  9. package/src/__tests__/pubsub.test.ts +15 -12
  10. package/src/__tests__/queues.test.ts +35 -28
  11. package/src/__tests__/r2.test.ts +25 -20
  12. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  13. package/src/__tests__/worker-namespace.test.ts +25 -20
  14. package/src/api/dev.ts +80 -11
  15. package/src/api/pages/publish.tsx +7 -4
  16. package/src/bundle.ts +1 -1
  17. package/src/config/config.ts +7 -0
  18. package/src/config/index.ts +24 -20
  19. package/src/d1/backups.tsx +20 -24
  20. package/src/d1/create.tsx +6 -5
  21. package/src/d1/delete.ts +7 -10
  22. package/src/d1/execute.tsx +82 -84
  23. package/src/d1/index.ts +5 -6
  24. package/src/d1/list.tsx +21 -9
  25. package/src/d1/migrations/apply.tsx +7 -5
  26. package/src/d1/migrations/create.tsx +7 -10
  27. package/src/d1/migrations/list.tsx +7 -5
  28. package/src/d1/migrations/options.ts +2 -2
  29. package/src/d1/options.ts +3 -3
  30. package/src/delete.ts +5 -8
  31. package/src/deprecated/index.ts +7 -8
  32. package/src/dev.tsx +42 -80
  33. package/src/dispatch-namespace.ts +20 -16
  34. package/src/docs/index.ts +7 -8
  35. package/src/generate/index.ts +5 -7
  36. package/src/index.ts +22 -21
  37. package/src/init.ts +5 -7
  38. package/src/kv/index.ts +15 -17
  39. package/src/pages/build.ts +6 -4
  40. package/src/pages/deployment-tails.ts +7 -10
  41. package/src/pages/deployments.tsx +6 -4
  42. package/src/pages/dev.ts +15 -17
  43. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  44. package/src/pages/functions.ts +8 -4
  45. package/src/pages/index.ts +3 -3
  46. package/src/pages/projects.tsx +7 -12
  47. package/src/pages/publish.tsx +6 -4
  48. package/src/pages/types.ts +5 -0
  49. package/src/pages/upload.tsx +6 -4
  50. package/src/parse.ts +23 -1
  51. package/src/publish/index.ts +19 -15
  52. package/src/publish/publish.ts +2 -2
  53. package/src/pubsub/pubsub-commands.ts +18 -19
  54. package/src/queues/cli/commands/consumer/add.ts +18 -24
  55. package/src/queues/cli/commands/consumer/index.ts +3 -6
  56. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  57. package/src/queues/cli/commands/create.ts +8 -8
  58. package/src/queues/cli/commands/delete.ts +8 -8
  59. package/src/queues/cli/commands/index.ts +3 -4
  60. package/src/queues/cli/commands/list.ts +8 -8
  61. package/src/r2/index.ts +28 -28
  62. package/src/secret/index.ts +9 -14
  63. package/src/tail/index.ts +6 -8
  64. package/src/yargs-types.ts +18 -5
  65. package/templates/checked-fetch.js +9 -1
  66. package/wrangler-dist/cli.js +1969 -1228
package/src/dev.tsx CHANGED
@@ -19,7 +19,6 @@ import { collectKeyValues } from "./utils/collectKeyValues";
19
19
  import { identifyD1BindingsAsBeta } from "./worker";
20
20
  import { getHostFromRoute, getZoneForRoute, getZoneIdFromHost } from "./zones";
21
21
  import {
22
- type ConfigPath,
23
22
  DEFAULT_INSPECTOR_PORT,
24
23
  DEFAULT_LOCAL_PORT,
25
24
  getDevCompatibilityDate,
@@ -30,59 +29,15 @@ import {
30
29
  } from "./index";
31
30
  import type { Config, Environment } from "./config";
32
31
  import type { Route } from "./config/environment";
32
+ import type { LoggerLevel } from "./logger";
33
33
  import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types";
34
34
  import type { CfWorkerInit } from "./worker";
35
- import type { CommonYargsOptions } from "./yargs-types";
36
- import type { Argv, ArgumentsCamelCase } from "yargs";
37
-
38
- interface DevArgs {
39
- config?: string;
40
- script?: string;
41
- name?: string;
42
- bundle?: boolean;
43
- build?: boolean;
44
- format?: string;
45
- env?: string;
46
- "compatibility-date"?: string;
47
- "compatibility-flags"?: string[];
48
- latest?: boolean;
49
- ip?: string;
50
- inspect?: boolean;
51
- port?: number;
52
- "inspector-port"?: number;
53
- routes?: string[];
54
- host?: string;
55
- "local-protocol"?: "http" | "https";
56
- "local-upstream"?: string | undefined;
57
- "experimental-public"?: string;
58
- public?: string;
59
- assets?: string;
60
- site?: string;
61
- "site-include"?: string[];
62
- "site-exclude"?: string[];
63
- "upstream-protocol"?: "http" | "https";
64
- "jsx-factory"?: string;
65
- "jsx-fragment"?: string;
66
- tsconfig?: string;
67
- local?: boolean;
68
- "experimental-local"?: boolean;
69
- "experimental-local-remote-kv"?: boolean;
70
- minify?: boolean;
71
- var?: string[];
72
- define?: string[];
73
- "node-compat"?: boolean;
74
- "experimental-enable-local-persistence"?: boolean;
75
- persist?: boolean;
76
- "persist-to"?: string;
77
- "live-reload"?: boolean;
78
- onReady?: (ip: string, port: number) => void;
79
- logLevel?: "none" | "info" | "error" | "log" | "warn" | "debug";
80
- logPrefix?: string;
81
- showInteractiveDevSession?: boolean;
82
- "test-scheduled"?: boolean;
83
- }
35
+ import type {
36
+ CommonYargsArgv,
37
+ StrictYargsOptionsToInterface,
38
+ } from "./yargs-types";
84
39
 
85
- export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
40
+ export function devOptions(yargs: CommonYargsArgv) {
86
41
  return (
87
42
  yargs
88
43
  .positional("script", {
@@ -177,6 +132,13 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
177
132
  type: "string",
178
133
  requiresArg: true,
179
134
  })
135
+ .option("public", {
136
+ describe: "(Deprecated) Static assets to be served",
137
+ type: "string",
138
+ requiresArg: true,
139
+ deprecated: true,
140
+ hidden: true,
141
+ })
180
142
  .option("site", {
181
143
  describe: "Root folder of static assets for Workers Sites",
182
144
  type: "string",
@@ -322,12 +284,15 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
322
284
  .option("log-level", {
323
285
  choices: ["debug", "info", "log", "warn", "error", "none"] as const,
324
286
  describe: "Specify logging level",
325
- default: "log",
287
+ // Yargs requires this to type log-level properly
288
+ default: "log" as LoggerLevel,
326
289
  })
327
290
  );
328
291
  }
329
292
 
330
- export async function devHandler(args: ArgumentsCamelCase<DevArgs>) {
293
+ type DevArguments = StrictYargsOptionsToInterface<typeof devOptions>;
294
+
295
+ export async function devHandler(args: DevArguments) {
331
296
  if (!(args.local || args.experimentalLocal)) {
332
297
  const isLoggedIn = await loginOrRefreshIfRequired();
333
298
  if (!isLoggedIn) {
@@ -371,13 +336,16 @@ export type AdditionalDevProps = {
371
336
  d1Databases?: Environment["d1_databases"];
372
337
  };
373
338
 
374
- type StartDevOptions = ArgumentsCamelCase<DevArgs> &
339
+ type StartDevOptions = DevArguments &
375
340
  // These options can be passed in directly when called with the `wrangler.dev()` API.
376
341
  // They aren't exposed as CLI arguments.
377
342
  AdditionalDevProps & {
378
343
  forceLocal?: boolean;
379
344
  disableDevRegistry?: boolean;
380
345
  enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
346
+ onReady?: (ip: string, port: number) => void;
347
+ logPrefix?: string;
348
+ showInteractiveDevSession?: boolean;
381
349
  };
382
350
 
383
351
  export async function startDev(args: StartDevOptions) {
@@ -400,9 +368,8 @@ export async function startDev(args: StartDevOptions) {
400
368
  }
401
369
 
402
370
  const configPath =
403
- (args.config as ConfigPath) ||
404
- ((args.script &&
405
- findWranglerToml(path.dirname(args.script))) as ConfigPath);
371
+ args.config ||
372
+ (args.script && findWranglerToml(path.dirname(args.script)));
406
373
  let config = readConfig(configPath, args);
407
374
 
408
375
  if (config.configPath) {
@@ -466,12 +433,12 @@ export async function startDev(args: StartDevOptions) {
466
433
  initialMode={
467
434
  args.local || args.experimentalLocal ? "local" : "remote"
468
435
  }
469
- jsxFactory={args["jsx-factory"] || configParam.jsx_factory}
470
- jsxFragment={args["jsx-fragment"] || configParam.jsx_fragment}
436
+ jsxFactory={args.jsxFactory || configParam.jsx_factory}
437
+ jsxFragment={args.jsxFragment || configParam.jsx_fragment}
471
438
  tsconfig={args.tsconfig ?? configParam.tsconfig}
472
439
  upstreamProtocol={upstreamProtocol}
473
440
  localProtocol={args.localProtocol || configParam.dev.local_protocol}
474
- localUpstream={args["local-upstream"] || host}
441
+ localUpstream={args.localUpstream ?? host}
475
442
  localPersistencePath={localPersistencePath}
476
443
  liveReload={args.liveReload || false}
477
444
  accountId={configParam.account_id || getAccountFromCache()?.id}
@@ -506,7 +473,7 @@ export async function startDev(args: StartDevOptions) {
506
473
  enablePagesAssetsServiceBinding={args.enablePagesAssetsServiceBinding}
507
474
  firstPartyWorker={configParam.first_party_worker}
508
475
  sendMetrics={configParam.send_metrics}
509
- testScheduled={args["test-scheduled"]}
476
+ testScheduled={args.testScheduled}
510
477
  experimentalLocal={args.experimentalLocal}
511
478
  experimentalLocalRemoteKv={args.experimentalLocalRemoteKv}
512
479
  />
@@ -551,9 +518,7 @@ export async function startApiDev(args: StartDevOptions) {
551
518
  await printWranglerBanner();
552
519
 
553
520
  const configPath =
554
- (args.config as ConfigPath) ||
555
- ((args.script &&
556
- findWranglerToml(path.dirname(args.script))) as ConfigPath);
521
+ args.config || (args.script && findWranglerToml(path.dirname(args.script)));
557
522
  const config = readConfig(configPath, args);
558
523
 
559
524
  const {
@@ -601,34 +566,32 @@ export async function startApiDev(args: StartDevOptions) {
601
566
  build: configParam.build || {},
602
567
  define: { ...config.define, ...cliDefines },
603
568
  initialMode: args.local ? "local" : "remote",
604
- jsxFactory: args["jsx-factory"] || configParam.jsx_factory,
605
- jsxFragment: args["jsx-fragment"] || configParam.jsx_fragment,
569
+ jsxFactory: args.jsxFactory ?? configParam.jsx_factory,
570
+ jsxFragment: args.jsxFragment ?? configParam.jsx_fragment,
606
571
  tsconfig: args.tsconfig ?? configParam.tsconfig,
607
572
  upstreamProtocol: upstreamProtocol,
608
- localProtocol: args.localProtocol || configParam.dev.local_protocol,
609
- localUpstream: args["local-upstream"] || host,
573
+ localProtocol: args.localProtocol ?? configParam.dev.local_protocol,
574
+ localUpstream: args.localUpstream ?? host,
610
575
  localPersistencePath,
611
- liveReload: args.liveReload || false,
612
- accountId: configParam.account_id || getAccountFromCache()?.id,
576
+ liveReload: args.liveReload ?? false,
577
+ accountId: configParam.account_id ?? getAccountFromCache()?.id,
613
578
  assetPaths: assetPaths,
614
579
  assetsConfig: configParam.assets,
615
580
  //port can be 0, which means to use a random port
616
581
  initialPort: args.port ?? configParam.dev.port ?? (await getLocalPort()),
617
- initialIp: args.ip || configParam.dev.ip,
582
+ initialIp: args.ip ?? configParam.dev.ip,
618
583
  inspectorPort:
619
- args["inspector-port"] ??
584
+ args.inspectorPort ??
620
585
  configParam.dev.inspector_port ??
621
586
  (await getInspectorPort()),
622
587
  isWorkersSite: Boolean(args.site || configParam.site),
623
588
  compatibilityDate: getDevCompatibilityDate(
624
589
  config,
625
590
  // Only `compatibilityDate` will be set when using `unstable_dev`
626
- args["compatibility-date"] ?? args.compatibilityDate
591
+ args.compatibilityDate
627
592
  ),
628
593
  compatibilityFlags:
629
- args["compatibility-flags"] ??
630
- args.compatibilityFlags ??
631
- configParam.compatibility_flags,
594
+ args.compatibilityFlags ?? configParam.compatibility_flags,
632
595
  usageModel: configParam.usage_model,
633
596
  bindings: bindings,
634
597
  crons: configParam.triggers.crons,
@@ -751,8 +714,7 @@ async function validateDevServerSettings(
751
714
  "Passing --inspect is unnecessary, now you can always connect to devtools."
752
715
  );
753
716
  }
754
-
755
- if (args["experimental-public"]) {
717
+ if (args.experimentalPublic) {
756
718
  throw new Error(
757
719
  "The --experimental-public field has been renamed to --assets"
758
720
  );
@@ -762,7 +724,7 @@ async function validateDevServerSettings(
762
724
  throw new Error("The --public field has been renamed to --assets");
763
725
  }
764
726
 
765
- if ((args.assets || config.assets) && (args.site || config.site)) {
727
+ if ((args.assets ?? config.assets) && (args.site ?? config.site)) {
766
728
  throw new Error("Cannot use Assets and Workers Sites in the same Worker.");
767
729
  }
768
730
 
@@ -772,7 +734,7 @@ async function validateDevServerSettings(
772
734
  );
773
735
  }
774
736
  const upstreamProtocol =
775
- args["upstream-protocol"] || config.dev.upstream_protocol;
737
+ args.upstreamProtocol ?? config.dev.upstream_protocol;
776
738
  if (upstreamProtocol === "http") {
777
739
  logger.warn(
778
740
  "Setting upstream-protocol to http is not currently implemented.\n" +
@@ -4,9 +4,8 @@ import { logger } from "./logger";
4
4
  import * as metrics from "./metrics";
5
5
  import { requireAuth } from "./user";
6
6
  import { printWranglerBanner } from ".";
7
- import type { ConfigPath } from ".";
8
- import type { CommonYargsOptions } from "./yargs-types";
9
- import type { Argv, CommandModule } from "yargs";
7
+ import type { CommonYargsArgv, CommonYargsOptions } from "./yargs-types";
8
+ import type { CommandModule } from "yargs";
10
9
 
11
10
  type Namespace = {
12
11
  namespace_id: string;
@@ -106,19 +105,24 @@ async function renameWorkerNamespace(
106
105
  }
107
106
 
108
107
  export function workerNamespaceCommands(
109
- workerNamespaceYargs: Argv<CommonYargsOptions>,
108
+ workerNamespaceYargs: CommonYargsArgv,
110
109
  subHelp: CommandModule<CommonYargsOptions, CommonYargsOptions>
111
110
  ) {
112
111
  return workerNamespaceYargs
113
112
  .command(subHelp)
114
- .command("list", "List all dispatch namespaces", {}, async (args) => {
115
- const config = readConfig(args.config as ConfigPath, args);
116
- const accountId = await requireAuth(config);
117
- await listWorkerNamespaces(accountId);
118
- await metrics.sendMetricsEvent("list dispatch namespaces", {
119
- sendMetrics: config.send_metrics,
120
- });
121
- })
113
+ .command(
114
+ "list",
115
+ "List all dispatch namespaces",
116
+ (args) => args,
117
+ async (args) => {
118
+ const config = readConfig(args.config, args);
119
+ const accountId = await requireAuth(config);
120
+ await listWorkerNamespaces(accountId);
121
+ await metrics.sendMetricsEvent("list dispatch namespaces", {
122
+ sendMetrics: config.send_metrics,
123
+ });
124
+ }
125
+ )
122
126
  .command(
123
127
  "get <name>",
124
128
  "Get information about a dispatch namespace",
@@ -130,7 +134,7 @@ export function workerNamespaceCommands(
130
134
  });
131
135
  },
132
136
  async (args) => {
133
- const config = readConfig(args.config as ConfigPath, args);
137
+ const config = readConfig(args.config, args);
134
138
  const accountId = await requireAuth(config);
135
139
  await getWorkerNamespaceInfo(accountId, args.name);
136
140
  await metrics.sendMetricsEvent("view dispatch namespace", {
@@ -150,7 +154,7 @@ export function workerNamespaceCommands(
150
154
  },
151
155
  async (args) => {
152
156
  await printWranglerBanner();
153
- const config = readConfig(args.config as ConfigPath, args);
157
+ const config = readConfig(args.config, args);
154
158
  const accountId = await requireAuth(config);
155
159
  await createWorkerNamespace(accountId, args.name);
156
160
  await metrics.sendMetricsEvent("create dispatch namespace", {
@@ -170,7 +174,7 @@ export function workerNamespaceCommands(
170
174
  },
171
175
  async (args) => {
172
176
  await printWranglerBanner();
173
- const config = readConfig(args.config as ConfigPath, args);
177
+ const config = readConfig(args.config, args);
174
178
  const accountId = await requireAuth(config);
175
179
  await deleteWorkerNamespace(accountId, args.name);
176
180
  await metrics.sendMetricsEvent("delete dispatch namespace", {
@@ -196,7 +200,7 @@ export function workerNamespaceCommands(
196
200
  },
197
201
  async (args) => {
198
202
  await printWranglerBanner();
199
- const config = readConfig(args.config as ConfigPath, args);
203
+ const config = readConfig(args.config, args);
200
204
  const accountId = await requireAuth(config);
201
205
  await renameWorkerNamespace(accountId, args.oldName, args.newName);
202
206
  await metrics.sendMetricsEvent("rename dispatch namespace", {
package/src/docs/index.ts CHANGED
@@ -5,10 +5,9 @@ import * as metrics from "../metrics";
5
5
  import openInBrowser from "../open-in-browser";
6
6
 
7
7
  import type {
8
- CommonYargsOptions,
9
- YargsOptionsToInterface,
8
+ CommonYargsArgv,
9
+ StrictYargsOptionsToInterface,
10
10
  } from "../yargs-types";
11
- import type { ArgumentsCamelCase, Argv } from "yargs";
12
11
 
13
12
  const argToUrlHash = {
14
13
  d1: "d1",
@@ -34,7 +33,7 @@ const argToUrlHash = {
34
33
  deployments: "deployments",
35
34
  };
36
35
 
37
- export function docsOptions(yargs: Argv<CommonYargsOptions>) {
36
+ export function docsOptions(yargs: CommonYargsArgv) {
38
37
  return yargs.positional("command", {
39
38
  describe: "Enter the wrangler command you want to know more about",
40
39
  type: "string",
@@ -69,13 +68,13 @@ export function docsOptions(yargs: Argv<CommonYargsOptions>) {
69
68
  });
70
69
  }
71
70
 
72
- type DocsArgs = YargsOptionsToInterface<typeof docsOptions>;
73
-
74
71
  function isValidParam(k: string): k is keyof typeof argToUrlHash {
75
72
  return k in argToUrlHash;
76
73
  }
77
74
 
78
- export async function docsHandler(args: ArgumentsCamelCase<DocsArgs>) {
75
+ export async function docsHandler(
76
+ args: StrictYargsOptionsToInterface<typeof docsOptions>
77
+ ) {
79
78
  let urlToOpen =
80
79
  "https://developers.cloudflare.com/workers/wrangler/commands/";
81
80
 
@@ -91,7 +90,7 @@ export async function docsHandler(args: ArgumentsCamelCase<DocsArgs>) {
91
90
 
92
91
  logger.log(`Opening a link in your default browser: ${urlToOpen}`);
93
92
  await openInBrowser(urlToOpen);
94
- const config = readConfig(undefined, {});
93
+ const config = readConfig(undefined, args);
95
94
  await metrics.sendMetricsEvent("view docs", {
96
95
  sendMetrics: config.send_metrics,
97
96
  });
@@ -5,12 +5,11 @@ import { CommandLineArgsError, printWranglerBanner } from "../index";
5
5
  import { initHandler } from "../init";
6
6
  import { logger } from "../logger";
7
7
  import type {
8
- CommonYargsOptions,
9
- YargsOptionsToInterface,
8
+ CommonYargsArgv,
9
+ StrictYargsOptionsToInterface,
10
10
  } from "../yargs-types";
11
- import type { Argv } from "yargs";
12
11
 
13
- export function generateOptions(yargs: Argv<CommonYargsOptions>) {
12
+ export function generateOptions(yargs: CommonYargsArgv) {
14
13
  return yargs
15
14
  .positional("name", {
16
15
  describe: "Name of the Workers project",
@@ -34,7 +33,7 @@ export function generateOptions(yargs: Argv<CommonYargsOptions>) {
34
33
  deprecated: true,
35
34
  });
36
35
  }
37
- type GenerateArgs = YargsOptionsToInterface<typeof generateOptions>;
36
+ type GenerateArgs = StrictYargsOptionsToInterface<typeof generateOptions>;
38
37
 
39
38
  // Originally, generate was a rust function: https://github.com/cloudflare/wrangler/blob/master/src/cli/mod.rs#L106-L123
40
39
  export async function generateHandler(args: GenerateArgs) {
@@ -44,17 +43,16 @@ export async function generateHandler(args: GenerateArgs) {
44
43
  if (args.template === undefined) {
45
44
  return initHandler({
46
45
  name: args.name,
47
- template: undefined,
48
46
  site: undefined,
49
47
  yes: undefined,
50
48
  fromDash: undefined,
51
- "from-dash": undefined,
52
49
  v: undefined,
53
50
  config: undefined,
54
51
  env: undefined,
55
52
  type: undefined,
56
53
  _: args._,
57
54
  $0: args.$0,
55
+ experimentalJsonConfig: false,
58
56
  });
59
57
  }
60
58
 
package/src/index.ts CHANGED
@@ -50,12 +50,9 @@ import {
50
50
  import { whoami } from "./whoami";
51
51
 
52
52
  import type { Config } from "./config";
53
- import type { CommonYargsOptions } from "./yargs-types";
54
- import type { ArgumentsCamelCase } from "yargs";
53
+ import type { CommonYargsArgv, CommonYargsOptions } from "./yargs-types";
55
54
  import type Yargs from "yargs";
56
55
 
57
- export type ConfigPath = string | undefined;
58
-
59
56
  const resetColor = "\x1b[0m";
60
57
  const fgGreenColor = "\x1b[32m";
61
58
  export const DEFAULT_LOCAL_PORT = 8787;
@@ -176,7 +173,7 @@ export class CommandLineArgsError extends Error {}
176
173
  export function createCLIParser(argv: string[]) {
177
174
  // Type check result against CommonYargsOptions to make sure we've included
178
175
  // all common options
179
- const wrangler: Yargs.Argv<CommonYargsOptions> = makeCLI(argv)
176
+ const wrangler: CommonYargsArgv = makeCLI(argv)
180
177
  .strict()
181
178
  // We handle errors ourselves in a try-catch around `yargs.parse`.
182
179
  // If you want the "help info" to be displayed then throw an instance of `CommandLineArgsError`.
@@ -212,6 +209,11 @@ export function createCLIParser(argv: string[]) {
212
209
  type: "string",
213
210
  requiresArg: true,
214
211
  })
212
+ .option("experimental-json-config", {
213
+ alias: "j",
214
+ describe: `Experimental: Support wrangler.json`,
215
+ type: "boolean",
216
+ })
215
217
  .check((args) => {
216
218
  // Grab locally specified env params from `.env` file
217
219
  const loaded = loadDotEnv(".env", args.env);
@@ -221,7 +223,10 @@ export function createCLIParser(argv: string[]) {
221
223
  return true;
222
224
  });
223
225
 
224
- wrangler.group(["config", "env", "help", "version"], "Flags:");
226
+ wrangler.group(
227
+ ["experimental-json-config", "config", "env", "help", "version"],
228
+ "Flags:"
229
+ );
225
230
  wrangler.help().alias("h", "help");
226
231
 
227
232
  // Default help command that supports the subcommands
@@ -486,7 +491,7 @@ export function createCLIParser(argv: string[]) {
486
491
  return;
487
492
  }
488
493
  await login({ browser: args.browser });
489
- const config = readConfig(args.config as ConfigPath, args);
494
+ const config = readConfig(args.config, args);
490
495
  await metrics.sendMetricsEvent("login user", {
491
496
  sendMetrics: config.send_metrics,
492
497
  });
@@ -503,10 +508,10 @@ export function createCLIParser(argv: string[]) {
503
508
  "logout",
504
509
  "🚪 Logout from Cloudflare",
505
510
  () => {},
506
- async () => {
511
+ async (args) => {
507
512
  await printWranglerBanner();
508
513
  await logout();
509
- const config = readConfig(undefined, {});
514
+ const config = readConfig(undefined, args);
510
515
  await metrics.sendMetricsEvent("logout user", {
511
516
  sendMetrics: config.send_metrics,
512
517
  });
@@ -518,10 +523,10 @@ export function createCLIParser(argv: string[]) {
518
523
  "whoami",
519
524
  "🕵️ Retrieve your user info and test your auth config",
520
525
  () => {},
521
- async () => {
526
+ async (args) => {
522
527
  await printWranglerBanner();
523
528
  await whoami();
524
- const config = readConfig(undefined, {});
529
+ const config = readConfig(undefined, args);
525
530
  await metrics.sendMetricsEvent("view accounts", {
526
531
  sendMetrics: config.send_metrics,
527
532
  });
@@ -533,9 +538,9 @@ export function createCLIParser(argv: string[]) {
533
538
  "types",
534
539
  "📝 Generate types from bindings & module rules in config",
535
540
  () => {},
536
- async () => {
541
+ async (args) => {
537
542
  await printWranglerBanner();
538
- const config = readConfig(undefined, {});
543
+ const config = readConfig(undefined, args);
539
544
 
540
545
  const configBindings: Partial<Config> = {
541
546
  kv_namespaces: config.kv_namespaces ?? [],
@@ -567,20 +572,16 @@ export function createCLIParser(argv: string[]) {
567
572
  wrangler.command(
568
573
  "deployments",
569
574
  "🚢 Displays the 10 most recent deployments for a worker",
570
- (yargs) => {
575
+ (yargs) =>
571
576
  yargs
572
577
  .option("name", {
573
578
  describe: "The name of your worker",
574
579
  type: "string",
575
580
  })
576
- .epilogue(deploymentsWarning);
577
- },
578
- async (deploymentsYargs: ArgumentsCamelCase<{ name: string }>) => {
581
+ .epilogue(deploymentsWarning),
582
+ async (deploymentsYargs) => {
579
583
  await printWranglerBanner();
580
- const config = readConfig(
581
- deploymentsYargs.config as ConfigPath,
582
- deploymentsYargs
583
- );
584
+ const config = readConfig(deploymentsYargs.config, deploymentsYargs);
584
585
  const accountId = await requireAuth(config);
585
586
  const scriptName = getScriptName(
586
587
  { name: deploymentsYargs.name, env: undefined },
package/src/init.ts CHANGED
@@ -20,16 +20,14 @@ import { CommandLineArgsError, printWranglerBanner } from "./index";
20
20
  import type { RawConfig } from "./config";
21
21
  import type { Route, SimpleRoute } from "./config/environment";
22
22
  import type { WorkerMetadata } from "./create-worker-upload-form";
23
- import type { ConfigPath } from "./index";
24
23
  import type { PackageManager } from "./package-manager";
25
24
  import type { PackageJSON } from "./parse";
26
25
  import type {
27
- CommonYargsOptions,
28
- YargsOptionsToInterface,
26
+ CommonYargsArgv,
27
+ StrictYargsOptionsToInterface,
29
28
  } from "./yargs-types";
30
- import type { Argv } from "yargs";
31
29
 
32
- export function initOptions(yargs: Argv<CommonYargsOptions>) {
30
+ export function initOptions(yargs: CommonYargsArgv) {
33
31
  return yargs
34
32
  .positional("name", {
35
33
  describe: "The name of your worker",
@@ -60,7 +58,7 @@ export function initOptions(yargs: Argv<CommonYargsOptions>) {
60
58
  });
61
59
  }
62
60
 
63
- type InitArgs = YargsOptionsToInterface<typeof initOptions>;
61
+ type InitArgs = StrictYargsOptionsToInterface<typeof initOptions>;
64
62
 
65
63
  export type ServiceMetadataRes = {
66
64
  id: string;
@@ -170,7 +168,7 @@ export async function initHandler(args: InitArgs) {
170
168
 
171
169
  // If --from-dash, check that script actually exists
172
170
  if (fromDashScriptName) {
173
- const config = readConfig(args.config as ConfigPath, args);
171
+ const config = readConfig(args.config, args);
174
172
  accountId = await requireAuth(config);
175
173
  try {
176
174
  serviceMetadata = await fetchResult<ServiceMetadataRes>(