diff --git a/.changeset/khaki-years-act.md b/.changeset/khaki-years-act.md new file mode 100644 index 000000000000..ae7e4c36c608 --- /dev/null +++ b/.changeset/khaki-years-act.md @@ -0,0 +1,5 @@ +--- +"wrangler": minor +--- + +Add `-C, --cwd` global argument to the `wrangler` CLI to allow changing the current working directory before running any command. diff --git a/packages/wrangler/src/__tests__/ai.test.ts b/packages/wrangler/src/__tests__/ai.test.ts index 13cb23e2a078..66b14f8c25e9 100644 --- a/packages/wrangler/src/__tests__/ai.test.ts +++ b/packages/wrangler/src/__tests__/ai.test.ts @@ -27,6 +27,7 @@ describe("ai help", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -55,6 +56,7 @@ describe("ai help", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/cert.test.ts b/packages/wrangler/src/__tests__/cert.test.ts index 396f9793ec0e..233a6497711c 100644 --- a/packages/wrangler/src/__tests__/cert.test.ts +++ b/packages/wrangler/src/__tests__/cert.test.ts @@ -440,6 +440,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/cloudchamber/create.test.ts b/packages/wrangler/src/__tests__/cloudchamber/create.test.ts index d9475ad8fe0d..f4933213a1d2 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/create.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/create.test.ts @@ -87,6 +87,7 @@ describe("cloudchamber create", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts b/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts index 5856bb590b56..9cc4f7f6377b 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts @@ -40,6 +40,7 @@ describe("cloudchamber curl", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts b/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts index 10193cfeeeb4..b9c97ddba45a 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts @@ -36,6 +36,7 @@ describe("cloudchamber delete", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/cloudchamber/images.test.ts b/packages/wrangler/src/__tests__/cloudchamber/images.test.ts index 6bfe4ad9c572..a3cdc9188730 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/images.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/images.test.ts @@ -37,6 +37,7 @@ describe("cloudchamber image", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/cloudchamber/list.test.ts b/packages/wrangler/src/__tests__/cloudchamber/list.test.ts index cd9af2a35702..85e624fcd654 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/list.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/list.test.ts @@ -37,6 +37,7 @@ describe("cloudchamber list", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts b/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts index 83a06ce3e00d..433e2235dc9a 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts @@ -72,6 +72,7 @@ describe("cloudchamber modify", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/d1/d1.test.ts b/packages/wrangler/src/__tests__/d1/d1.test.ts index 8be9b0ecc892..3c79df0c5018 100644 --- a/packages/wrangler/src/__tests__/d1/d1.test.ts +++ b/packages/wrangler/src/__tests__/d1/d1.test.ts @@ -30,6 +30,7 @@ describe("d1", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -66,6 +67,7 @@ describe("d1", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -95,6 +97,7 @@ describe("d1", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -123,6 +126,7 @@ describe("d1", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/deployments.test.ts b/packages/wrangler/src/__tests__/deployments.test.ts index 3f29eb0a32fa..fb1a44b65c71 100644 --- a/packages/wrangler/src/__tests__/deployments.test.ts +++ b/packages/wrangler/src/__tests__/deployments.test.ts @@ -66,6 +66,7 @@ describe("deployments", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/dev.test.ts b/packages/wrangler/src/__tests__/dev.test.ts index 5cbce0f5ecb1..075bb599a762 100644 --- a/packages/wrangler/src/__tests__/dev.test.ts +++ b/packages/wrangler/src/__tests__/dev.test.ts @@ -1364,6 +1364,7 @@ describe.sequential("wrangler dev", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/docs.test.ts b/packages/wrangler/src/__tests__/docs.test.ts index 240e410504aa..e5591b40a083 100644 --- a/packages/wrangler/src/__tests__/docs.test.ts +++ b/packages/wrangler/src/__tests__/docs.test.ts @@ -58,6 +58,7 @@ describe("wrangler docs", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/hyperdrive.test.ts b/packages/wrangler/src/__tests__/hyperdrive.test.ts index 85873cee789a..d2211bac0353 100644 --- a/packages/wrangler/src/__tests__/hyperdrive.test.ts +++ b/packages/wrangler/src/__tests__/hyperdrive.test.ts @@ -38,6 +38,7 @@ describe("hyperdrive help", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -69,6 +70,7 @@ describe("hyperdrive help", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/index.test.ts b/packages/wrangler/src/__tests__/index.test.ts index 8bfc0b45bb16..d5e878a424cb 100644 --- a/packages/wrangler/src/__tests__/index.test.ts +++ b/packages/wrangler/src/__tests__/index.test.ts @@ -69,6 +69,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -126,6 +127,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -154,6 +156,14 @@ describe("wrangler", () => { `[Error: The argument "--config" expects a single value, but received multiple: ["wrangler.toml","example"].]` ); }); + + it("should change cwd with -C, --cwd", async () => { + const spy = vi.spyOn(process, "chdir").mockImplementation(() => {}); + await Promise.all([runWrangler("-C /path"), runWrangler("--cwd /path")]); + expect(process.chdir).toHaveBeenCalledTimes(2); + expect(process.chdir).toHaveBeenCalledWith("/path"); + spy.mockRestore(); + }); }); describe("preview", () => { @@ -192,6 +202,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -213,6 +224,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -235,6 +247,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -255,6 +268,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -275,6 +289,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/kv.test.ts b/packages/wrangler/src/__tests__/kv.test.ts index 187e559258ea..43a1b2a92ab2 100644 --- a/packages/wrangler/src/__tests__/kv.test.ts +++ b/packages/wrangler/src/__tests__/kv.test.ts @@ -48,6 +48,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -69,6 +70,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -97,6 +99,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -141,6 +144,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -172,6 +176,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -623,6 +628,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -664,6 +670,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -705,6 +712,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -746,6 +754,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -787,6 +796,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -1156,6 +1166,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -1192,6 +1203,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -1229,6 +1241,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -1800,6 +1813,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -1820,6 +1834,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -1838,6 +1853,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/mtls-certificates.test.ts b/packages/wrangler/src/__tests__/mtls-certificates.test.ts index 15b03f6bf00f..db6ee558221c 100644 --- a/packages/wrangler/src/__tests__/mtls-certificates.test.ts +++ b/packages/wrangler/src/__tests__/mtls-certificates.test.ts @@ -366,6 +366,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/pages/deploy.test.ts b/packages/wrangler/src/__tests__/pages/deploy.test.ts index 806f69219560..48a5a6705d0d 100644 --- a/packages/wrangler/src/__tests__/pages/deploy.test.ts +++ b/packages/wrangler/src/__tests__/pages/deploy.test.ts @@ -61,6 +61,7 @@ describe("pages deploy", () => { directory The directory of static files to upload [string] GLOBAL FLAGS + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/pages/pages.test.ts b/packages/wrangler/src/__tests__/pages/pages.test.ts index f8fedd5add50..d9a6bfe00e53 100644 --- a/packages/wrangler/src/__tests__/pages/pages.test.ts +++ b/packages/wrangler/src/__tests__/pages/pages.test.ts @@ -31,6 +31,7 @@ describe("pages", () => { wrangler pages download Download settings from your project GLOBAL FLAGS + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" `); @@ -50,6 +51,7 @@ describe("pages", () => { command The proxy command to run [deprecated] [string] GLOBAL FLAGS + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -96,6 +98,7 @@ describe("pages", () => { wrangler pages project delete [project-name] Delete a Cloudflare Pages project GLOBAL FLAGS + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" `); @@ -116,6 +119,7 @@ describe("pages", () => { wrangler pages deployment tail [deployment] Start a tailing session for a project's deployment and livestream logs from your Functions GLOBAL FLAGS + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" `); @@ -134,6 +138,7 @@ describe("pages", () => { directory The directory of static files to upload [string] GLOBAL FLAGS + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -165,6 +170,7 @@ describe("pages", () => { wrangler pages secret list List all secrets for a Pages project GLOBAL FLAGS + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" `); @@ -183,6 +189,7 @@ describe("pages", () => { wrangler pages download config [projectName] Experimental: Download your Pages project config as a Wrangler configuration file GLOBAL FLAGS + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" `); diff --git a/packages/wrangler/src/__tests__/pipelines.test.ts b/packages/wrangler/src/__tests__/pipelines.test.ts index 335dc28149f3..1f64c552785a 100644 --- a/packages/wrangler/src/__tests__/pipelines.test.ts +++ b/packages/wrangler/src/__tests__/pipelines.test.ts @@ -263,6 +263,7 @@ describe("pipelines", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -285,6 +286,7 @@ describe("pipelines", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/pubsub.test.ts b/packages/wrangler/src/__tests__/pubsub.test.ts index d76a11bc191b..694a7ae5960d 100644 --- a/packages/wrangler/src/__tests__/pubsub.test.ts +++ b/packages/wrangler/src/__tests__/pubsub.test.ts @@ -36,6 +36,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -68,6 +69,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -195,6 +197,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/queues.test.ts b/packages/wrangler/src/__tests__/queues.test.ts index e69a3ab20b6c..188ed0cc36e9 100644 --- a/packages/wrangler/src/__tests__/queues.test.ts +++ b/packages/wrangler/src/__tests__/queues.test.ts @@ -35,6 +35,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -108,6 +109,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -244,6 +246,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -366,6 +369,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -434,6 +438,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -481,6 +486,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -802,6 +808,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -1189,6 +1196,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -1235,6 +1243,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -1365,6 +1374,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -1452,6 +1462,7 @@ describe("wrangler", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/r2.test.ts b/packages/wrangler/src/__tests__/r2.test.ts index 4385bb97caf3..b9a492c890db 100644 --- a/packages/wrangler/src/__tests__/r2.test.ts +++ b/packages/wrangler/src/__tests__/r2.test.ts @@ -38,6 +38,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -66,6 +67,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -99,6 +101,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -137,6 +140,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -244,6 +248,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -277,6 +282,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -399,6 +405,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -428,6 +435,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -493,6 +501,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -556,6 +565,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -623,6 +633,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -714,6 +725,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -757,6 +769,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -808,6 +821,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -989,6 +1003,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -1349,6 +1364,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -1507,6 +1523,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -2295,6 +2312,7 @@ describe("r2", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/secret.test.ts b/packages/wrangler/src/__tests__/secret.test.ts index 9b11085d6bca..648e1b2a37d7 100644 --- a/packages/wrangler/src/__tests__/secret.test.ts +++ b/packages/wrangler/src/__tests__/secret.test.ts @@ -1091,6 +1091,7 @@ describe("wrangler secret", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/vectorize/vectorize.test.ts b/packages/wrangler/src/__tests__/vectorize/vectorize.test.ts index 2edc6a3e3e98..7ff95cb0dc09 100644 --- a/packages/wrangler/src/__tests__/vectorize/vectorize.test.ts +++ b/packages/wrangler/src/__tests__/vectorize/vectorize.test.ts @@ -40,6 +40,7 @@ describe("vectorize help", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -88,6 +89,7 @@ describe("vectorize help", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -124,6 +126,7 @@ describe("vectorize help", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] @@ -164,6 +167,7 @@ describe("vectorize help", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean] diff --git a/packages/wrangler/src/__tests__/versions/versions.help.test.ts b/packages/wrangler/src/__tests__/versions/versions.help.test.ts index c64a31356f77..ae3863e5c3a1 100644 --- a/packages/wrangler/src/__tests__/versions/versions.help.test.ts +++ b/packages/wrangler/src/__tests__/versions/versions.help.test.ts @@ -24,6 +24,7 @@ describe("versions --help", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -54,6 +55,7 @@ describe("versions subhelp", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/worker-namespace.test.ts b/packages/wrangler/src/__tests__/worker-namespace.test.ts index 8b1a6bcab1de..e6ae332dbe2f 100644 --- a/packages/wrangler/src/__tests__/worker-namespace.test.ts +++ b/packages/wrangler/src/__tests__/worker-namespace.test.ts @@ -43,6 +43,7 @@ describe("dispatch-namespace", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]", @@ -95,6 +96,7 @@ describe("dispatch-namespace", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -145,6 +147,7 @@ describe("dispatch-namespace", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -204,6 +207,7 @@ describe("dispatch-namespace", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -314,6 +318,7 @@ describe("dispatch-namespace", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/__tests__/workflows.test.ts b/packages/wrangler/src/__tests__/workflows.test.ts index 5d7b3d706de6..140d5fc5b87c 100644 --- a/packages/wrangler/src/__tests__/workflows.test.ts +++ b/packages/wrangler/src/__tests__/workflows.test.ts @@ -74,6 +74,7 @@ describe("wrangler workflows", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" @@ -104,6 +105,7 @@ describe("wrangler workflows", () => { GLOBAL FLAGS -c, --config Path to Wrangler configuration file [string] + -C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] -v, --version Show version number [boolean]" diff --git a/packages/wrangler/src/api/dev.ts b/packages/wrangler/src/api/dev.ts index 023d746598a9..bb4bffc823ea 100644 --- a/packages/wrangler/src/api/dev.ts +++ b/packages/wrangler/src/api/dev.ts @@ -183,6 +183,7 @@ export async function unstable_dev( ip: "127.0.0.1", inspectorPort: options?.inspectorPort ?? 0, v: undefined, + cwd: undefined, localProtocol: options?.localProtocol, httpsKeyPath: options?.httpsKeyPath, httpsCertPath: options?.httpsCertPath, diff --git a/packages/wrangler/src/generate/index.ts b/packages/wrangler/src/generate/index.ts index 301512335f18..240a49fb57e0 100644 --- a/packages/wrangler/src/generate/index.ts +++ b/packages/wrangler/src/generate/index.ts @@ -53,6 +53,7 @@ export async function generateHandler(args: GenerateArgs) { delegateC3: false, v: undefined, config: undefined, + cwd: undefined, env: undefined, type: undefined, _: args._, diff --git a/packages/wrangler/src/index.ts b/packages/wrangler/src/index.ts index db04b6db7490..8dbc20d4b555 100644 --- a/packages/wrangler/src/index.ts +++ b/packages/wrangler/src/index.ts @@ -223,6 +223,19 @@ export function createCLIParser(argv: string[]) { alias: "version", type: "boolean", }) + .option("cwd", { + describe: + "Run as if Wrangler was started in the specified directory instead of the current working directory", + alias: "C", + type: "string", + requiresArg: true, + }) + .check(demandSingleValue("cwd")) + .middleware((_argv) => { + if (_argv.cwd) { + process.chdir(_argv.cwd); + } + }) .option("config", { alias: "c", describe: "Path to Wrangler configuration file", @@ -301,7 +314,7 @@ export function createCLIParser(argv: string[]) { "Examples:": `${chalk.bold("EXAMPLES")}`, }); wrangler.group( - ["config", "env", "help", "version"], + ["config", "cwd", "env", "help", "version"], `${chalk.bold("GLOBAL FLAGS")}` ); wrangler.help("help", "Show help").alias("h", "help"); diff --git a/packages/wrangler/src/pages/dev.ts b/packages/wrangler/src/pages/dev.ts index 0b224531f30a..d8e706388ac0 100644 --- a/packages/wrangler/src/pages/dev.ts +++ b/packages/wrangler/src/pages/dev.ts @@ -895,6 +895,7 @@ export const Handler = async (args: PagesDevArguments) => { processEntrypoint: true, additionalModules: modules, v: undefined, + cwd: undefined, assets: undefined, name: undefined, noBundle: false, diff --git a/packages/wrangler/src/yargs-types.ts b/packages/wrangler/src/yargs-types.ts index edb7b63e51c3..2f28b4d9d477 100644 --- a/packages/wrangler/src/yargs-types.ts +++ b/packages/wrangler/src/yargs-types.ts @@ -6,6 +6,7 @@ import type { ArgumentsCamelCase, Argv, CommandModule } from "yargs"; */ export interface CommonYargsOptions { v: boolean | undefined; + cwd: string | undefined; config: string | undefined; env: string | undefined; "experimental-provision": boolean | undefined;