diff --git a/.changeset/neat-frogs-smash.md b/.changeset/neat-frogs-smash.md new file mode 100644 index 000000000000..390fb447ab3f --- /dev/null +++ b/.changeset/neat-frogs-smash.md @@ -0,0 +1,9 @@ +--- +"wrangler": patch +--- + +fix: delegate `wrangler build` to `wrangler publish` + +Since `wrangler publish --dry-run --outdir=dist` is basically the same result +as what Wrangler 1 did with `wrangler build` let's run that for the user if +they try to run `wrangler build`. diff --git a/packages/wrangler/src/__tests__/index.test.ts b/packages/wrangler/src/__tests__/index.test.ts index 7c527a641de1..252aef4d85c5 100644 --- a/packages/wrangler/src/__tests__/index.test.ts +++ b/packages/wrangler/src/__tests__/index.test.ts @@ -2,6 +2,8 @@ import { getPackageManager } from "../package-manager"; import { mockConsoleMethods } from "./helpers/mock-console"; import { runInTempDir } from "./helpers/run-in-tmp"; import { runWrangler } from "./helpers/run-wrangler"; +import { writeWorkerSource } from "./helpers/write-worker-source"; +import writeWranglerToml from "./helpers/write-wrangler-toml"; import type { PackageManager } from "../package-manager"; describe("wrangler", () => { @@ -113,9 +115,6 @@ describe("wrangler", () => { }); describe("subcommand implicit help ran on incomplete command execution", () => { - function endEventLoop() { - return new Promise((resolve) => setImmediate(resolve)); - } it("no subcommand for 'secret' should display a list of available subcommands", async () => { await runWrangler("secret"); await endEventLoop(); @@ -195,6 +194,7 @@ describe("wrangler", () => { -v, --version Show version number [boolean]" `); }); + it("no subcommand 'r2' should display a list of available subcommands", async () => { await runWrangler("r2"); await endEventLoop(); @@ -213,6 +213,7 @@ describe("wrangler", () => { `); }); }); + describe("Deprecated commands", () => { it("should print a deprecation message for 'generate'", async () => { await runWrangler("generate").catch((err) => { @@ -229,13 +230,27 @@ describe("wrangler", () => { `); }); }); - it("should print a deprecation message for 'build'", async () => { - await runWrangler("build").catch((err) => { - expect(err.message).toMatchInlineSnapshot(` - "Deprecation: - \`wrangler build\` has been deprecated, please refer to https://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build for alternatives" - `); - }); + }); + + it("should print a deprecation message for 'build' and then try to run `publish --dry-run --outdir`", async () => { + writeWranglerToml({ + main: "index.js", }); + writeWorkerSource(); + await runWrangler("build"); + await endEventLoop(); + expect(std.out).toMatchInlineSnapshot(` + "▲ [WARNING] Deprecation: \`wrangler build\` has been deprecated. + + Please refer to https://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build for more information. + Attempting to run \`wrangler publish --dry-run --outdir=dist\` for you instead: + + + --dry-run: exiting now." + `); }); }); + +function endEventLoop() { + return new Promise((resolve) => setImmediate(resolve)); +} diff --git a/packages/wrangler/src/index.tsx b/packages/wrangler/src/index.tsx index 6ced1cc65b01..0c4f44144990 100644 --- a/packages/wrangler/src/index.tsx +++ b/packages/wrangler/src/index.tsx @@ -785,13 +785,34 @@ function createCLIParser(argv: string[]) { (yargs) => { return yargs.option("env", { describe: "Perform on a specific environment", + type: "string", }); }, - () => { + async (buildArgs) => { // "[DEPRECATED] 🦀 Build your project (if applicable)", - throw new DeprecationError( - "`wrangler build` has been deprecated, please refer to https://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build for alternatives" + + const envFlag = buildArgs.env ? ` --env=${buildArgs.env}` : ""; + logger.log( + formatMessage({ + kind: "warning", + text: "Deprecation: `wrangler build` has been deprecated.", + notes: [ + { + text: "Please refer to https://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build for more information.", + }, + { + text: `Attempting to run \`wrangler publish --dry-run --outdir=dist${envFlag}\` for you instead:`, + }, + ], + }) ); + + await createCLIParser([ + "publish", + "--dry-run", + "--outdir=dist", + ...(buildArgs.env ? ["--env", buildArgs.env] : []), + ]).parse(); } );