Skip to content

Commit c4fd176

Browse files
Expose global flags from experimental_getWranglerCommands() (#10424)
* axpose global flags * remove -j flag * Create nervous-goats-sniff.md * Remove unnecessary experimental JSON config flag * Update TSDoc comment for experimental_getWranglerCommands return type Addresses GitHub comment from dario-piotrowicz asking to update the @returns documentation to reflect the new return type that includes both registry and globalFlags properties. Co-Authored-By: [email protected] <[email protected]> * Fix metrics tests after -j flag removal Update test expectations to match the new error message after the experimental JSON config flag was removed in 18b712e. Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 7b05c8e commit c4fd176

File tree

8 files changed

+132
-83
lines changed

8 files changed

+132
-83
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"playground-preview-worker": patch
3+
"turbo-r2-archive": patch
4+
"wrangler": patch
5+
---
6+
7+
Remove the `--experimental-json-config`/`-j` flag, which is no longer required.

.changeset/nervous-goats-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Expose global flags from `experimental_getWranglerCommands()`

packages/playground-preview-worker/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"build-middleware:loader": "pnpm dlx esbuild ../wrangler/templates/middleware/loader-modules.ts --outfile=src/middleware/loader.module.template",
99
"check:lint": "eslint . --max-warnings=0",
1010
"check:type": "tsc",
11-
"deploy": "wrangler -j deploy",
12-
"deploy:testing": "wrangler -j deploy -e testing",
13-
"start": "wrangler -j dev",
11+
"deploy": "wrangler deploy",
12+
"deploy:testing": "wrangler deploy -e testing",
13+
"start": "wrangler dev",
1414
"test:e2e": "vitest run"
1515
},
1616
"dependencies": {

packages/turbo-r2-archive/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"remote cache"
1212
],
1313
"scripts": {
14-
"build": "wrangler deploy -j --dry-run --outdir=./dist",
14+
"build": "wrangler deploy --dry-run --outdir=./dist",
1515
"check:lint": "eslint . --max-warnings=0",
16-
"deploy": "wrangler deploy -j",
17-
"start": "wrangler dev -j",
16+
"deploy": "wrangler deploy",
17+
"start": "wrangler dev",
1818
"type:check": "tsc"
1919
},
2020
"dependencies": {

packages/wrangler/src/__tests__/experimental-commands-api.test.ts

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,67 @@ import { describe, expect, test } from "vitest";
22
import { experimental_getWranglerCommands } from "../experimental-commands-api";
33

44
describe("experimental_getWranglerCommands", () => {
5+
test("returns global flags", () => {
6+
const commandTree = experimental_getWranglerCommands().globalFlags;
7+
8+
expect(commandTree).toMatchInlineSnapshot(`
9+
Object {
10+
"config": Object {
11+
"alias": "c",
12+
"describe": "Path to Wrangler configuration file",
13+
"requiresArg": true,
14+
"type": "string",
15+
},
16+
"cwd": Object {
17+
"describe": "Run as if Wrangler was started in the specified directory instead of the current working directory",
18+
"requiresArg": true,
19+
"type": "string",
20+
},
21+
"env": Object {
22+
"alias": "e",
23+
"describe": "Environment to use for operations, and for selecting .env and .dev.vars files",
24+
"requiresArg": true,
25+
"type": "string",
26+
},
27+
"env-file": Object {
28+
"array": true,
29+
"describe": "Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files",
30+
"requiresArg": true,
31+
"type": "string",
32+
},
33+
"experimental-provision": Object {
34+
"alias": Array [
35+
"x-provision",
36+
],
37+
"describe": "Experimental: Enable automatic resource provisioning",
38+
"hidden": true,
39+
"type": "boolean",
40+
},
41+
"experimental-remote-bindings": Object {
42+
"alias": Array [
43+
"x-remote-bindings",
44+
],
45+
"describe": "Experimental: Enable Remote Bindings",
46+
"hidden": true,
47+
"type": "boolean",
48+
},
49+
"v": Object {
50+
"alias": "version",
51+
"describe": "Show version number",
52+
"type": "boolean",
53+
},
54+
}
55+
`);
56+
});
557
test("returns command tree structure", () => {
6-
const commandTree = experimental_getWranglerCommands();
58+
const commandTree = experimental_getWranglerCommands().registry;
759

860
expect(commandTree).toBeDefined();
961
expect(commandTree.subtree).toBeInstanceOf(Map);
1062
});
1163

1264
test("includes expected commands with metadata", () => {
13-
const commandTree = experimental_getWranglerCommands();
65+
const commandTree = experimental_getWranglerCommands().registry;
1466

1567
expect(commandTree.subtree.has("docs")).toBe(true);
1668
expect(commandTree.subtree.has("init")).toBe(true);
@@ -24,7 +76,7 @@ describe("experimental_getWranglerCommands", () => {
2476
});
2577

2678
test("includes nested commands", () => {
27-
const commandTree = experimental_getWranglerCommands();
79+
const commandTree = experimental_getWranglerCommands().registry;
2880

2981
const d1Command = commandTree.subtree.get("d1");
3082
expect(d1Command?.subtree).toBeInstanceOf(Map);
@@ -34,7 +86,7 @@ describe("experimental_getWranglerCommands", () => {
3486
});
3587

3688
test("includes command arguments and metadata", () => {
37-
const commandTree = experimental_getWranglerCommands();
89+
const commandTree = experimental_getWranglerCommands().registry;
3890

3991
const initCommand = commandTree.subtree.get("init");
4092
expect(initCommand?.definition?.type).toBe("command");
@@ -47,7 +99,7 @@ describe("experimental_getWranglerCommands", () => {
4799
});
48100

49101
test("includes namespace commands", () => {
50-
const commandTree = experimental_getWranglerCommands();
102+
const commandTree = experimental_getWranglerCommands().registry;
51103

52104
const kvCommand = commandTree.subtree.get("kv");
53105
expect(kvCommand?.definition?.type).toBe("namespace");
@@ -57,7 +109,7 @@ describe("experimental_getWranglerCommands", () => {
57109
});
58110

59111
test("preserves command metadata properties", () => {
60-
const commandTree = experimental_getWranglerCommands();
112+
const commandTree = experimental_getWranglerCommands().registry;
61113

62114
const deployCommand = commandTree.subtree.get("deploy");
63115
if (deployCommand?.definition?.type === "command") {

packages/wrangler/src/__tests__/metrics.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ describe("metrics", () => {
197197
argsCombination: "",
198198
command: "wrangler docs",
199199
args: {
200-
xJsonConfig: true,
201-
j: true,
202200
search: ["<REDACTED>"],
203201
},
204202
};
@@ -455,12 +453,10 @@ describe("metrics", () => {
455453
await expect(
456454
runWrangler("docs arg -j=false")
457455
).rejects.toThrowErrorMatchingInlineSnapshot(
458-
`[Error: Wrangler now supports wrangler.json configuration files by default and ignores the value of the \`--experimental-json-config\` flag.]`
456+
`[Error: Unknown argument: j]`
459457
);
460458
expect(requests.count).toBe(2);
461-
expect(std.debug).toContain(
462-
'"errorMessage":"Wrangler now supports wrangler.json configuration files by default and ignores the value of the `--experimental-json-config` flag."'
463-
);
459+
expect(std.debug).toContain('"errorMessage":"yargs validation error"');
464460
});
465461

466462
it("should include an error message if the specific error has been allow-listed with a custom telemetry message", async () => {

packages/wrangler/src/experimental-commands-api.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import type { DefinitionTreeNode } from "./core/types";
55
* EXPERIMENTAL: Get all registered Wrangler commands for documentation generation.
66
* This API is experimental and may change without notice.
77
*
8-
* @returns The complete command tree structure with all metadata
8+
* @returns An object containing the command tree structure and global flags
99
*/
10-
export function experimental_getWranglerCommands(): DefinitionTreeNode {
11-
const { registry } = createCLIParser([]);
12-
return registry.getDefinitionTreeRoot();
10+
export function experimental_getWranglerCommands(): {
11+
registry: DefinitionTreeNode;
12+
globalFlags: ReturnType<typeof createCLIParser>["globalFlags"];
13+
} {
14+
const { registry, globalFlags } = createCLIParser([]);
15+
return { registry: registry.getDefinitionTreeRoot(), globalFlags };
1316
}

packages/wrangler/src/index.ts

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,51 @@ if (proxy) {
338338
}
339339

340340
export function createCLIParser(argv: string[]) {
341+
const globalFlags = {
342+
v: {
343+
describe: "Show version number",
344+
alias: "version",
345+
type: "boolean",
346+
},
347+
cwd: {
348+
describe:
349+
"Run as if Wrangler was started in the specified directory instead of the current working directory",
350+
type: "string",
351+
requiresArg: true,
352+
},
353+
config: {
354+
alias: "c",
355+
describe: "Path to Wrangler configuration file",
356+
type: "string",
357+
requiresArg: true,
358+
},
359+
env: {
360+
alias: "e",
361+
describe:
362+
"Environment to use for operations, and for selecting .env and .dev.vars files",
363+
type: "string",
364+
requiresArg: true,
365+
},
366+
"env-file": {
367+
describe:
368+
"Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files",
369+
type: "string",
370+
array: true,
371+
requiresArg: true,
372+
},
373+
"experimental-remote-bindings": {
374+
describe: `Experimental: Enable Remote Bindings`,
375+
type: "boolean",
376+
hidden: true,
377+
alias: ["x-remote-bindings"],
378+
},
379+
"experimental-provision": {
380+
describe: `Experimental: Enable automatic resource provisioning`,
381+
type: "boolean",
382+
hidden: true,
383+
alias: ["x-provision"],
384+
},
385+
} as const;
341386
// Type check result against CommonYargsOptions to make sure we've included
342387
// all common options
343388
const wrangler: CommonYargsArgv = makeCLI(argv)
@@ -362,29 +407,13 @@ export function createCLIParser(argv: string[]) {
362407
// Define global options here, so they get included in the `Argv` type of
363408
// the `wrangler` variable
364409
.version(false)
365-
.option("v", {
366-
describe: "Show version number",
367-
alias: "version",
368-
type: "boolean",
369-
})
370-
.option("cwd", {
371-
describe:
372-
"Run as if Wrangler was started in the specified directory instead of the current working directory",
373-
type: "string",
374-
requiresArg: true,
375-
})
410+
.options(globalFlags)
376411
.check(demandSingleValue("cwd"))
377412
.middleware((_argv) => {
378413
if (_argv.cwd) {
379414
process.chdir(_argv.cwd);
380415
}
381416
})
382-
.option("config", {
383-
alias: "c",
384-
describe: "Path to Wrangler configuration file",
385-
type: "string",
386-
requiresArg: true,
387-
})
388417
.check(
389418
demandSingleValue(
390419
"config",
@@ -394,38 +423,7 @@ export function createCLIParser(argv: string[]) {
394423
(configArgv["_"][0] === "pages" && configArgv["_"][1] === "dev")
395424
)
396425
)
397-
.option("env", {
398-
alias: "e",
399-
describe:
400-
"Environment to use for operations, and for selecting .env and .dev.vars files",
401-
type: "string",
402-
requiresArg: true,
403-
})
404-
.option("env-file", {
405-
describe:
406-
"Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files",
407-
type: "string",
408-
array: true,
409-
requiresArg: true,
410-
})
411426
.check(demandSingleValue("env"))
412-
.option("experimental-json-config", {
413-
alias: "j",
414-
describe: `Support wrangler.json.`,
415-
type: "boolean",
416-
default: true,
417-
deprecated: true,
418-
hidden: true,
419-
})
420-
.check((args) => {
421-
if (args["experimental-json-config"] === false) {
422-
throw new CommandLineArgsError(
423-
`Wrangler now supports wrangler.json configuration files by default and ignores the value of the \`--experimental-json-config\` flag.`,
424-
{ telemetryMessage: true }
425-
);
426-
}
427-
return true;
428-
})
429427
.check((args) => {
430428
// Set process environment params from `.env` files if available.
431429
const resolvedEnvFilePaths = (
@@ -447,18 +445,6 @@ export function createCLIParser(argv: string[]) {
447445

448446
return true;
449447
})
450-
.option("experimental-remote-bindings", {
451-
describe: `Experimental: Enable Remote Bindings`,
452-
type: "boolean",
453-
hidden: true,
454-
alias: ["x-remote-bindings"],
455-
})
456-
.option("experimental-provision", {
457-
describe: `Experimental: Enable automatic resource provisioning`,
458-
type: "boolean",
459-
hidden: true,
460-
alias: ["x-provision"],
461-
})
462448
.epilogue(
463449
`Please report any issues to ${chalk.hex("#3B818D")(
464450
"https://github.com/cloudflare/workers-sdk/issues/new/choose"
@@ -1477,7 +1463,7 @@ export function createCLIParser(argv: string[]) {
14771463

14781464
wrangler.exitProcess(false);
14791465

1480-
return { wrangler, registry };
1466+
return { wrangler, registry, globalFlags };
14811467
}
14821468

14831469
export async function main(argv: string[]): Promise<void> {

0 commit comments

Comments
 (0)