Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wrangler): Display correct global flags in wrangler pages --help #5814

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changeset/quiet-wolves-camp.md
Original file line number Diff line number Diff line change
@@ -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.
30 changes: 26 additions & 4 deletions packages/wrangler/src/__tests__/pages/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions packages/wrangler/src/__tests__/pages/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
);
});
});
7 changes: 2 additions & 5 deletions packages/wrangler/src/__tests__/pages/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
`);
});

Expand Down
4 changes: 4 additions & 0 deletions packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
CarmenPopoviciu marked this conversation as resolved.
Show resolved Hide resolved

return pages(pagesYargs, subHelp);
});

Expand Down
11 changes: 11 additions & 0 deletions packages/wrangler/src/pages/deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions packages/wrangler/src/pages/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <directory>\`).`
Expand Down
Loading