Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 85fecfd

Browse files
committed
Add additional warning for semver major updates
1 parent ec5c2ec commit 85fecfd

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/cli.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "./index";
1616

1717
const defaultPort = 8787;
18+
const numericCompare = new Intl.Collator(undefined, { numeric: true }).compare;
1819

1920
function stripUndefinedOptions(options: Options): Options {
2021
return Object.entries(options)
@@ -278,7 +279,7 @@ export async function updateCheck({
278279
const res = await fetch(`${registry}${pkg.name}/latest`, {
279280
headers: { Accept: "application/json" },
280281
});
281-
const registryVersion = (await res.json()).version;
282+
const registryVersion: string = (await res.json()).version;
282283
if (!registryVersion) return;
283284

284285
// Record new last check time
@@ -287,12 +288,18 @@ export async function updateCheck({
287288
// Log version if latest version is greater than the currently installed
288289
if (semiver(registryVersion, pkg.version) > 0) {
289290
log.warn(
290-
[
291-
`Miniflare ${registryVersion} is available,`,
292-
`but you're using ${pkg.version}.`,
293-
"Update for improved compatibility with Cloudflare Workers.",
294-
].join(" ")
291+
`Miniflare ${registryVersion} is available, ` +
292+
`but you're using ${pkg.version}. ` +
293+
"Update for improved compatibility with Cloudflare Workers."
295294
);
295+
const registryMajor = registryVersion.split(".")[0];
296+
const pkgMajor = pkg.version.split(".")[0];
297+
if (numericCompare(registryMajor, pkgMajor) > 0) {
298+
log.warn(
299+
`${registryVersion} includes breaking changes.` +
300+
"Make sure you check the changelog before upgrading."
301+
);
302+
}
296303
}
297304
}
298305

test/cli.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ test("updateCheck: logs if updated version available", async (t) => {
266266
const now = 172800000; // 2 days since unix epoch (must be > 1 day)
267267
const registry = await useServer(t, (req, res) => {
268268
t.is(req.url, "/miniflare/latest");
269-
res.end('{"version": "2.0.0"}');
269+
res.end('{"version": "1.1.0"}');
270270
});
271271
const log = new TestLog();
272272
await updateCheck({
@@ -281,12 +281,35 @@ test("updateCheck: logs if updated version available", async (t) => {
281281
t.is(log.warns.length, 1);
282282
t.regex(
283283
log.warns[0],
284-
/^Miniflare 2\.0\.0 is available, but you're using 1\.0\.0/
284+
/^Miniflare 1\.1\.0 is available, but you're using 1\.0\.0/
285285
);
286286
// Check last update check file written
287287
const lastCheck = await fs.readFile(path.join(tmp, "update-check"), "utf8");
288288
t.is(lastCheck, now.toString());
289289
});
290+
test("updateCheck: logs additional warning on semver major change", async (t) => {
291+
const tmp = await useTmp(t);
292+
const now = 172800000; // 2 days since unix epoch (must be > 1 day)
293+
const registry = await useServer(t, (req, res) => {
294+
res.end('{"version": "2.0.0"}');
295+
});
296+
const log = new TestLog();
297+
await updateCheck({
298+
pkg: { name: "miniflare", version: "1.0.0" },
299+
cachePath: tmp,
300+
now,
301+
registry: registry.http.toString(),
302+
log,
303+
});
304+
305+
// Check update messages logged
306+
t.is(log.warns.length, 2);
307+
t.regex(
308+
log.warns[0],
309+
/^Miniflare 2\.0\.0 is available, but you're using 1\.0\.0/
310+
);
311+
t.regex(log.warns[1], /^2\.0\.0 includes breaking changes/);
312+
});
290313
test("updateCheck: doesn't log if no updated version available", async (t) => {
291314
const tmp = await useTmp(t);
292315
const now = 172800000; // 2 days since unix epoch (must be > 1 day)

0 commit comments

Comments
 (0)