diff --git a/.changeset/five-suits-rest.md b/.changeset/five-suits-rest.md new file mode 100644 index 000000000000..cae677642a42 --- /dev/null +++ b/.changeset/five-suits-rest.md @@ -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. diff --git a/packages/wrangler/src/__tests__/dev.test.tsx b/packages/wrangler/src/__tests__/dev.test.tsx index 587c1c892e95..8dfdbe7497bf 100644 --- a/packages/wrangler/src/__tests__/dev.test.tsx +++ b/packages/wrangler/src/__tests__/dev.test.tsx @@ -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"; @@ -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, "")) .toMatchInlineSnapshot(` diff --git a/packages/wrangler/src/index.ts b/packages/wrangler/src/index.ts index d6ee989bb94e..e05cdb42d91e 100644 --- a/packages/wrangler/src/index.ts +++ b/packages/wrangler/src/index.ts @@ -1,3 +1,4 @@ +import module from "node:module"; import os from "node:os"; import TOML from "@iarna/toml"; import chalk from "chalk"; @@ -813,8 +814,15 @@ export async function main(argv: string[]): Promise { 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` +