Skip to content

Commit

Permalink
Resolve review problem
Browse files Browse the repository at this point in the history
  • Loading branch information
QingXia-Ela committed May 13, 2024
1 parent 3fc317c commit 3c53f95
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .changeset/warm-schools-applaud.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"astro": patch
---

fix: prevent error appear when check latest version fail(#11012)
Prevents unhandledrejection error when checking for latest Astro version
44 changes: 20 additions & 24 deletions packages/astro/src/core/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,32 @@ export default async function dev(inlineConfig: AstroInlineConfig): Promise<DevS
// Don't await this, we don't want to block the dev server from starting
shouldCheckForUpdates(restart.container.settings.preferences).then(async (shouldCheck) => {
if (shouldCheck) {
try {
const version = await fetchLatestAstroVersion(restart.container.settings.preferences);
const version = await fetchLatestAstroVersion(restart.container.settings.preferences);

if (gt(version, currentVersion)) {
// Only update the latestAstroVersion if the latest version is greater than the current version, that way we don't need to check that again
// whenever we check for the latest version elsewhere
restart.container.settings.latestAstroVersion = version;
if (gt(version, currentVersion)) {
// Only update the latestAstroVersion if the latest version is greater than the current version, that way we don't need to check that again
// whenever we check for the latest version elsewhere
restart.container.settings.latestAstroVersion = version;

const sameMajor = major(version) === major(currentVersion);
const sameMinor = minor(version) === minor(currentVersion);
const patchDistance = patch(version) - patch(currentVersion);
const sameMajor = major(version) === major(currentVersion);
const sameMinor = minor(version) === minor(currentVersion);
const patchDistance = patch(version) - patch(currentVersion);

if (sameMajor && sameMinor && patchDistance < MAX_PATCH_DISTANCE) {
// Don't bother the user with a log if they're only a few patch versions behind
// We can still tell them in the dev toolbar, which has a more opt-in nature
return;
}

logger.warn(
'SKIP_FORMAT',
await msg.newVersionAvailable({
latestVersion: version,
})
);
if (sameMajor && sameMinor && patchDistance < MAX_PATCH_DISTANCE) {
// Don't bother the user with a log if they're only a few patch versions behind
// We can still tell them in the dev toolbar, which has a more opt-in nature
return;
}
} catch (e) {
// Do nothing, check version fail shouldn't block server running.

logger.warn(
'SKIP_FORMAT',
await msg.newVersionAvailable({
latestVersion: version,
})
);
}
}
});
}).catch(() => { });
} catch (e) {
// Just ignore the error, we don't want to block the dev server from starting and this is just a nice-to-have feature
}
Expand Down

0 comments on commit 3c53f95

Please sign in to comment.