Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a new message telling the user that a new version of Astro is available #10734

Merged
merged 15 commits into from Apr 24, 2024

Conversation

Princesseuh
Copy link
Member

@Princesseuh Princesseuh commented Apr 9, 2024

Changes

Check for update on startup of the dev command. This will appear in both the console and the dev toolbar's home app and can be disabled if unwanted.

There's a few heuristics to make it less annoying:

  • Only once every 10 days
  • Only if you're more than 5 patches behind

We can make this more or less strict, it's two constants.

image

image

Testing

Tested manually

Docs

There's some docs in there!

Copy link

changeset-bot bot commented Apr 9, 2024

🦋 Changeset detected

Latest commit: ad7d5ca

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr A PR that includes documentation for review semver: minor Change triggers a `minor` release labels Apr 9, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@matthewp
Copy link
Contributor

Can you add screenshots of both?

@bluwy
Copy link
Member

bluwy commented Apr 10, 2024

Hmm personally I'm not a fan of tools that yap about new versions (turbo, pnpm) as I'd upgrade dependencies myself when I have a reason to, but maybe that's just me 😅 (dev toolbar only is fine though)

@Princesseuh
Copy link
Member Author

Hmm personally I'm not a fan of tools that yap about new versions (turbo, pnpm) as I'd upgrade dependencies myself when I have a reason to, but maybe that's just me 😅 (dev toolbar only is fine though)

I can agree! Though I think the message here isn't quite as visually bold as pnpm's or turbo's, so it doesn't bother me as much personally. I also cannot deny that pnpm is the most updated package manager in our stats, ha.

@Princesseuh Princesseuh added this to the 4.7.0 milestone Apr 10, 2024
@matthewp
Copy link
Contributor

Core discussed async and this is the current status:

  • Fewer options, probably getting rid of the option to check the semver range and to just check latest always.
  • Desire to not show the message all of the time. Need to investigate some other commands here.
  • Don't want the toolbar notification to be shown.
  • Unsure if there is consensus on the devtoolbar part at all, need to follow-up async.

@@ -161,3 +162,56 @@ async function installPackage(
return false;
}
}

export async function fetchPackageJson(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fished this out of astro add, code is unchanged. astro add is insanely big so fishing things out of it is honestly just good.

if (res.status >= 200 && res.status < 300) {
return await res.json();
} else if (res.status === 404) {
// 404 means the package doesn't exist, so we don't need an error message here
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a quite odd pattern that astro add does everywhere where functions return errors, kinda neat

}

if (preferences) {
await preferences.set('_variables.lastUpdateCheck', Date.now(), { reloadServer: false });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I had a choice to make here:

  • Use a new file, a new system, etc to store variables like this
  • Re-use preferences under a private namespace

I went with the later when I realized adding a new store with different values to preferences would require change a lot of type utils and stuff for very little value. I think it's not a problem... You're not supposed to change the config file manually, and the CLI won't show this private namespace.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That definitely seems reasonable. We have this same problem with telemetry, too, so probably worth generalizing a pattern at somepoint.

@alexanderniebuhr
Copy link
Member

alexanderniebuhr commented Apr 19, 2024

Quick comment from my side, would the update checker fail for users who don't have npm installed? It sounds like yes based on the description of this PR Check for update using npm at launch
I explicitly set my node install to not install the bundled version of npm, so I don't think we can take having npm installed as a requirement.

@Princesseuh
Copy link
Member Author

Princesseuh commented Apr 19, 2024

Quick comment from my side, would the update checker fail for users who don't have npm installed? It sounds like yes based on the description of this PR Check for update using npm at launch I explicitly set my node install to not install the bundled version of npm, so I don't think we can take having npm installed as a requirement.

Description was outdated, doesn't use npm anymore. It uses whichever package manager is used by the project to find the registry, with a fallback to the default registry for special cases, same as astro add!

.changeset/pink-rivers-knock.md Outdated Show resolved Hide resolved
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look great, awesome work! Just a few small comments, but nothing blocking!

Comment on lines +202 to +203
// A copy of this function also exists in the create-astro package
let _registry: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this default to process.env.npm_config_registry or is that value just totally irrelevant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value seems to be irrelevant in many cases, I've even seen npm issues saying that it doesn't respect it. No idea how that works.

packages/astro/src/core/messages.ts Outdated Show resolved Hide resolved

export async function shouldCheckForUpdates(preferences: AstroPreferences): Promise<boolean> {
const timeSinceLastCheck = Date.now() - (await preferences.get('checkUpdates._lastCheck'));
const hasCheckUpdatesEnabled = await preferences.get('checkUpdates.enabled');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's very nice! Not sure if we have a preferences reference page yet, but this would definitely be something to document.

packages/astro/src/preferences/defaults.ts Outdated Show resolved Hide resolved
packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving for docs!

@Princesseuh Princesseuh merged commit 6fc4c0e into main Apr 24, 2024
14 checks passed
@Princesseuh Princesseuh deleted the feat/update-check branch April 24, 2024 15:55
@astrobot-houston astrobot-houston mentioned this pull request Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr A PR that includes documentation for review pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants