Skip to content

Commit

Permalink
Use installed workerd version as default compat date instead of now
Browse files Browse the repository at this point in the history
`wrangler dev` would previously use the current date as the default
compatibility date if one wasn't set in `wrangler.toml`. Before the
previous commit, this would show a warning if it was greater than the
installed `workerd` version. Whilst using the current date as the
default would no longer log a warning with this change, if there was
an update it would. This change sets the default to the `workerd`
version instead.
  • Loading branch information
mrbbot committed Oct 18, 2023
1 parent 2938eeb commit b07bd1d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .changeset/five-suits-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"wrangler": minor
---

fix: suppress compatibility date fallback warnings if no `wrangler` update is available

If a compatibility date greater than the installed version of `workerd` was
configured, a warning would be logged. This warning was only actionable if a new
version of `wrangler` was available. The intent here was to warn if a user set
a new compatibility date, but forgot to update `wrangler` meaning changes
enabled by the new date wouldn't take effect. This change hides the warning if
no update is available.

It also changes the default compatibility date for `wrangler dev` sessions
without a configured compatibility date to the installed version of `workerd`.
This previously defaulted to the current date, which may have been unsupported
by the installed runtime.
10 changes: 9 additions & 1 deletion packages/wrangler/src/__tests__/dev.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from "node:fs";
import module from "node:module";
import getPort from "get-port";
import { rest } from "msw";
import patchConsole from "patch-console";
Expand Down Expand Up @@ -68,7 +69,14 @@ describe("wrangler dev", () => {
});
fs.writeFileSync("index.js", `export default {};`);
await runWrangler("dev");
const currentDate = new Date().toISOString().substring(0, 10);

const miniflareEntry = require.resolve("miniflare");
const miniflareRequire = module.createRequire(miniflareEntry);
const miniflareWorkerd = miniflareRequire("workerd") as {
compatibilityDate: string;
};
const currentDate = miniflareWorkerd.compatibilityDate;

expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.warn.replaceAll(currentDate, "<current-date>"))
.toMatchInlineSnapshot(`
Expand Down
12 changes: 10 additions & 2 deletions packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import module from "node:module";
import os from "node:os";
import TOML from "@iarna/toml";
import chalk from "chalk";
Expand Down Expand Up @@ -813,8 +814,15 @@ export async function main(argv: string[]): Promise<void> {
export function getDevCompatibilityDate(
config: Config,
compatibilityDate = config.compatibility_date
) {
const currentDate = new Date().toISOString().substring(0, 10);
): string {
// Get the maximum compatibility date supported by the installed Miniflare
const miniflareEntry = require.resolve("miniflare");
const miniflareRequire = module.createRequire(miniflareEntry);
const miniflareWorkerd = miniflareRequire("workerd") as {
compatibilityDate: string;
};
const currentDate = miniflareWorkerd.compatibilityDate;

if (config.configPath !== undefined && compatibilityDate === undefined) {
logger.warn(
`No compatibility_date was specified. Using today's date: ${currentDate}.\n` +
Expand Down

0 comments on commit b07bd1d

Please sign in to comment.