Skip to content

Commit

Permalink
Only show compatibility date fallback warning if new version available
Browse files Browse the repository at this point in the history
When a compatibility date greater than the installed `workerd` version
is selected, Miniflare logs a warning. The intention here is to warn
users if they've set a compatibility date, but haven't updated
`workerd`, so features they've requested won't be available.
The problem is that this warning is only actionable if there's an
update available. This change suppresses the warning if there's no
new version available.
  • Loading branch information
mrbbot committed Oct 18, 2023
1 parent c2457cb commit 398fcfe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/wrangler/src/dev/miniflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ModuleTypeToRuleType } from "../deployment-bundle/module-collection";
import { withSourceURLs } from "../deployment-bundle/source-url";
import { getHttpsOptions } from "../https-options";
import { logger } from "../logger";
import { updateCheck } from "../update-check";
import type { Config } from "../config";
import type {
CfD1Database,
Expand Down Expand Up @@ -122,10 +123,19 @@ class WranglerLog extends Log {

warn(message: string) {
// Only log warning about requesting a compatibility date after the workerd
// binary's version once
// binary's version once, and only if there's an update available.
if (message.startsWith("The latest compatibility date supported by")) {
if (this.#warnedCompatibilityDateFallback) return;
this.#warnedCompatibilityDateFallback = true;
return void updateCheck().then((maybeNewVersion) => {
if (maybeNewVersion === undefined) return;
message += [
"",
"Features enabled by your requested compatibility date may not be available.",
`Upgrade to \`wrangler@${maybeNewVersion}\` to remove this warning.`,
].join("\n");
super.warn(message);
});
}
super.warn(message);
}
Expand Down
10 changes: 9 additions & 1 deletion packages/wrangler/src/update-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import checkForUpdate from "update-check";
import pkg from "../package.json";
import type { Result } from "update-check";

export async function updateCheck(): Promise<string | undefined> {
async function doUpdateCheck(): Promise<string | undefined> {
let update: Result | null = null;
try {
// default cache for update check is 1 day
Expand All @@ -14,3 +14,11 @@ export async function updateCheck(): Promise<string | undefined> {
}
return update?.latest;
}

// Memoise update check promise, so we can call this multiple times as required
// without having to prop drill the result. It's unlikely to change through the
// process lifetime.
let updateCheckPromise: Promise<string | undefined>;
export function updateCheck(): Promise<string | undefined> {
return (updateCheckPromise ??= doUpdateCheck());
}

0 comments on commit 398fcfe

Please sign in to comment.