From c716abcf5d1b9eb291d05addb1f47322cd4868c0 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Thu, 16 Dec 2021 20:57:14 +0000 Subject: [PATCH] fix: error and exit if `init --type` is used --- .changeset/forty-cooks-flash.md | 11 +++++++ packages/wrangler/src/__tests__/index.test.ts | 29 +++++++++++++++++++ packages/wrangler/src/index.tsx | 13 ++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .changeset/forty-cooks-flash.md diff --git a/.changeset/forty-cooks-flash.md b/.changeset/forty-cooks-flash.md new file mode 100644 index 000000000000..146db9de552b --- /dev/null +++ b/.changeset/forty-cooks-flash.md @@ -0,0 +1,11 @@ +--- +"wrangler": patch +--- + +Error and exit if the `--type` option is used for the `init` command. + +The `--type` option is no longer needed, nor supported. + +The type of a project is implicitly javascript, even if it includes a wasm (e.g. built from rust). + +Projects that would have had the `webpack` type need to be configured separately to have a custom build. diff --git a/packages/wrangler/src/__tests__/index.test.ts b/packages/wrangler/src/__tests__/index.test.ts index 3b074f54964d..119f4e4763ae 100644 --- a/packages/wrangler/src/__tests__/index.test.ts +++ b/packages/wrangler/src/__tests__/index.test.ts @@ -114,6 +114,35 @@ describe("wrangler", () => { const { stderr } = await w("init"); expect(stderr).toContain("wrangler.toml file already exists!"); }); + + it("should error if `--type` is used", async () => { + const noValue = await w("init --type"); + expect(noValue.stderr).toMatchInlineSnapshot( + `"The --type option is no longer supported."` + ); + }); + + it("should error if `--type javascript` is used", async () => { + const javascriptValue = await w("init --type javascript"); + expect(javascriptValue.stderr).toMatchInlineSnapshot( + `"The --type option is no longer supported."` + ); + }); + + it("should error if `--type rust` is used", async () => { + const rustValue = await w("init --type rust"); + expect(rustValue.stderr).toMatchInlineSnapshot( + `"The --type option is no longer supported."` + ); + }); + + it("should error if `--type webpack` is used", async () => { + const webpackValue = await w("init --type webpack"); + expect(webpackValue.stderr).toMatchInlineSnapshot(` + "The --type option is no longer supported. + If you wish to use webpack then you will need to create a custom build." + `); + }); }); describe("kv:namespace", () => { diff --git a/packages/wrangler/src/index.tsx b/packages/wrangler/src/index.tsx index c0e3a179f84b..9c331d39c837 100644 --- a/packages/wrangler/src/index.tsx +++ b/packages/wrangler/src/index.tsx @@ -187,7 +187,18 @@ export async function main(argv: string[]): Promise { type: "string", }); }, - async () => { + async (args) => { + if ("type" in args) { + let message = "The --type option is no longer supported."; + if (args.type === "webpack") { + message += + "\nIf you wish to use webpack then you will need to create a custom build."; + // TODO: Add a link to docs + } + console.error(message); + return; + } + const destination = path.join(process.cwd(), "wrangler.toml"); if (fs.existsSync(destination)) { console.error(