Skip to content

Commit

Permalink
polish: include a copy-pastable message when trying to publish withou…
Browse files Browse the repository at this point in the history
…t a compatibility date
  • Loading branch information
threepointone committed Jun 19, 2022
1 parent f7d362e commit 7f92a5a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-flowers-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

polish: include a copy-pastable message when trying to publish without a compatibility date
19 changes: 19 additions & 0 deletions packages/wrangler/src/__tests__/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2876,6 +2876,25 @@ addEventListener('fetch', event => {});`
expect(std.err).toMatchInlineSnapshot(`""`);
});

it("should error if a compatibility_date is not available in wrangler.toml or cli args", async () => {
writeWorkerSource();
let err: undefined | Error;
try {
await runWrangler("publish ./index.js");
} catch (e) {
err = e as Error;
}

expect(err?.message.replaceAll(/\d/g, "X")).toMatchInlineSnapshot(`
"A compatibility_date is required when publishing. Add the following to your wrangler.toml file:.
\`\`\`
compatibility_date = \\"XXXX-XX-XX\\"
\`\`\`
Or you could pass it in your terminal as \`--compatibility-date XXXX-XX-XX\`
See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information."
`);
});

it("should enable the workers.dev domain if workers_dev is undefined and subdomain is not already available", async () => {
writeWranglerToml();
writeWorkerSource();
Expand Down
16 changes: 12 additions & 4 deletions packages/wrangler/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,18 @@ export default async function publish(props: Props): Promise<void> {
// TODO: warn if git/hg has uncommitted changes
const { config, accountId } = props;

assert(
props.compatibilityDate || config.compatibility_date,
"A compatibility_date is required when publishing. Add one to your wrangler.toml file, or pass it in your terminal as --compatibility-date. See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information."
);
if (!(props.compatibilityDate || config.compatibility_date)) {
const compatibilityDateStr = `${new Date().getFullYear()}-${(
new Date().getMonth() + ""
).padStart(2, "0")}-${(new Date().getDate() + "").padStart(2, "0")}`;

throw new Error(`A compatibility_date is required when publishing. Add the following to your wrangler.toml file:.
\`\`\`
compatibility_date = "${compatibilityDateStr}"
\`\`\`
Or you could pass it in your terminal as \`--compatibility-date ${compatibilityDateStr}\`
See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information.`);
}

const triggers = props.triggers || config.triggers?.crons;
const routes =
Expand Down

0 comments on commit 7f92a5a

Please sign in to comment.