From b324b6dadcc13441905207d96b5db706f62d9c9c Mon Sep 17 00:00:00 2001 From: Carmen Popoviciu Date: Mon, 13 May 2024 12:10:09 +0200 Subject: [PATCH] fix(wrangler): Display correct global flags in `wrangler pages --help` `wrangler pages --help` currently displays a list of global flags that are not all supported by Pages, such as `--env`, `--config`, and `--experimental-json-config`. This commit ensure that only flags that apply to Pages are listed when running `--help`. Fixes #5725 --- .changeset/quiet-wolves-camp.md | 19 ++++++++++++ .../src/__tests__/pages/deploy.test.ts | 30 ++++++++++++++++--- .../wrangler/src/__tests__/pages/dev.test.ts | 16 ++++++++++ .../src/__tests__/pages/pages.test.ts | 7 ++--- packages/wrangler/src/index.ts | 4 +++ packages/wrangler/src/pages/deploy.tsx | 11 +++++++ packages/wrangler/src/pages/dev.ts | 11 +++++++ 7 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 .changeset/quiet-wolves-camp.md diff --git a/.changeset/quiet-wolves-camp.md b/.changeset/quiet-wolves-camp.md new file mode 100644 index 000000000000..de0553cc7390 --- /dev/null +++ b/.changeset/quiet-wolves-camp.md @@ -0,0 +1,19 @@ +--- +"wrangler": minor +--- + +fix: Display correct global flags in `wrangler pages --help` + +Running `wrangler pages --help` will list, amongst others, the following global flags: + +``` +-j, --experimental-json-config +-c, --config +-e, --env +-h, --help +-v, --version +``` + +This is not accurate, since flags such as `--config`, `--experimental-json-config`, or `env` are not supported by Pages. + +This commit ensures we display the correct global flags that apply to Pages. diff --git a/packages/wrangler/src/__tests__/pages/deploy.test.ts b/packages/wrangler/src/__tests__/pages/deploy.test.ts index 5bb79c792bfd..5f5246a4fe7f 100644 --- a/packages/wrangler/src/__tests__/pages/deploy.test.ts +++ b/packages/wrangler/src/__tests__/pages/deploy.test.ts @@ -58,10 +58,8 @@ describe("pages deploy", () => { directory The directory of static files to upload [string] Flags: - -j, --experimental-json-config Experimental: Support wrangler.json [boolean] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean] + -h, --help Show help [boolean] + -v, --version Show version number [boolean] Options: --project-name The name of the project you want to deploy to [string] @@ -90,6 +88,30 @@ describe("pages deploy", () => { ); }); + it("should error if the [--config] command line arg was specififed", async () => { + await expect( + runWrangler("pages deploy public --config=/path/to/wrangler.toml") + ).rejects.toThrowErrorMatchingInlineSnapshot( + `"Pages does not support custom paths for the \`wrangler.toml\` configuration file"` + ); + }); + + it("should error if the [--experimental-json-config] command line arg was specififed", async () => { + await expect( + runWrangler("pages deploy public --experimental-json-config") + ).rejects.toThrowErrorMatchingInlineSnapshot( + `"Pages does not support \`wrangler.json\`"` + ); + }); + + it("should error if the [--env] command line arg was specififed", async () => { + await expect( + runWrangler("pages deploy public --env=production") + ).rejects.toThrowErrorMatchingInlineSnapshot( + `"Pages does not support imperatively targeting a particular environment"` + ); + }); + it("should upload a directory of files", async () => { writeFileSync("logo.png", "foobar"); mockGetUploadTokenRequest( diff --git a/packages/wrangler/src/__tests__/pages/dev.test.ts b/packages/wrangler/src/__tests__/pages/dev.test.ts index 4434be4d9d0c..b85b182ba87a 100644 --- a/packages/wrangler/src/__tests__/pages/dev.test.ts +++ b/packages/wrangler/src/__tests__/pages/dev.test.ts @@ -33,4 +33,20 @@ describe("pages dev", () => { `"Pages does not support custom paths for the \`wrangler.toml\` configuration file"` ); }); + + it("should error if the [--experimental-json-config] command line arg was specififed", async () => { + await expect( + runWrangler("pages dev public --experimental-json-config") + ).rejects.toThrowErrorMatchingInlineSnapshot( + `"Pages does not support \`wrangler.json\`"` + ); + }); + + it("should error if the [--env] command line arg was specififed", async () => { + await expect( + runWrangler("pages dev public --env=production") + ).rejects.toThrowErrorMatchingInlineSnapshot( + `"Pages does not support imperatively targeting a particular environment"` + ); + }); }); diff --git a/packages/wrangler/src/__tests__/pages/pages.test.ts b/packages/wrangler/src/__tests__/pages/pages.test.ts index 9225f1ece43a..03305c1797c1 100644 --- a/packages/wrangler/src/__tests__/pages/pages.test.ts +++ b/packages/wrangler/src/__tests__/pages/pages.test.ts @@ -31,11 +31,8 @@ describe("pages", () => { wrangler pages download ⚡️ Download settings from your project Flags: - -j, --experimental-json-config Experimental: Support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); diff --git a/packages/wrangler/src/index.ts b/packages/wrangler/src/index.ts index c19adf33515b..ed1f744717d2 100644 --- a/packages/wrangler/src/index.ts +++ b/packages/wrangler/src/index.ts @@ -432,6 +432,10 @@ export function createCLIParser(argv: string[]) { // pages wrangler.command("pages", "⚡️ Configure Cloudflare Pages", (pagesYargs) => { + // Pages does not support the `--config`, `--experimental-json-config`, + // and `--env` flags, therefore hiding them from the global flags list. + pagesYargs.hide("config").hide("env").hide("experimental-json-config"); + return pages(pagesYargs, subHelp); }); diff --git a/packages/wrangler/src/pages/deploy.tsx b/packages/wrangler/src/pages/deploy.tsx index 0a212f72e638..398391fa8c27 100644 --- a/packages/wrangler/src/pages/deploy.tsx +++ b/packages/wrangler/src/pages/deploy.tsx @@ -101,6 +101,17 @@ export const Handler = async (args: PagesDeployArgs) => { ); } + if (args.experimentalJsonConfig) { + throw new FatalError("Pages does not support `wrangler.json`", 1); + } + + if (args.env) { + throw new FatalError( + "Pages does not support targeting an environment with the --env flag. Use the --branch flag to target your production or preview branch", + 1 + ); + } + let config: Config | undefined; const configPath = findWranglerToml(process.cwd(), false); diff --git a/packages/wrangler/src/pages/dev.ts b/packages/wrangler/src/pages/dev.ts index e04a92a7be83..24e739abb475 100644 --- a/packages/wrangler/src/pages/dev.ts +++ b/packages/wrangler/src/pages/dev.ts @@ -263,6 +263,17 @@ export const Handler = async (args: PagesDevArguments) => { ); } + if (args.experimentalJsonConfig) { + throw new FatalError("Pages does not support `wrangler.json`", 1); + } + + if (args.env) { + throw new FatalError( + "Pages does not support targeting an environment with the --env flag. Use the --branch flag to target your production or preview branch", + 1 + ); + } + if (args.scriptPath !== undefined) { logger.warn( `\`--script-path\` is deprecated and will be removed in a future version of Wrangler.\nThe Worker script should be named \`_worker.js\` and located in the build output directory of your project (specified with \`wrangler pages dev \`).`