Skip to content

Commit

Permalink
fix: delegate wrangler build to wrangler publish (#1099)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
petebacondarwin authored May 26, 2022
1 parent 1eaefeb commit 175737f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
9 changes: 9 additions & 0 deletions .changeset/neat-frogs-smash.md
Original file line number Diff line number Diff line change
@@ -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`.
35 changes: 25 additions & 10 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -213,6 +213,7 @@ describe("wrangler", () => {
`);
});
});

describe("Deprecated commands", () => {
it("should print a deprecation message for 'generate'", async () => {
await runWrangler("generate").catch((err) => {
Expand All @@ -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));
}
27 changes: 24 additions & 3 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
);

Expand Down

0 comments on commit 175737f

Please sign in to comment.