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
  • Loading branch information
mrbbot committed Oct 17, 2023
1 parent f6ae8ce commit 8154bf6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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 8154bf6

Please sign in to comment.