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

Fix invalid URLs being returned from getRegistry, synchronize all copies of the function #10117

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

hippotastic
Copy link
Contributor

Changes

  • Fixes an issue reported in a Discord support thread.
  • The getRegistry functions used in our CLI tools create astro, astro add and @astrojs/upgrade assumed that the output of the CLI command <package manager> config get registry would always be a URL. However, in the reported case, the command output started with a warning message, which was then returned by getRegistry without further validation, causing all dependent functionality to fail in unexpected ways.
  • This PR validates the output by trying to construct a URL instance from it, which will either throw an error that gets caught by the catch clause, or have an empty host. In both cases, our existing fallback URL https://registry.npmjs.org will now be used.
  • I also synchronized the slightly different 3 copies of the function as far as possible. They all use the caching logic that was already present in create-astro now, which could speed up the other CLI commands. In the future, we should investigate if we can actually use the same function from all tools instead of keeping 3 copies.

Testing

  • I tested the changes locally and didn't encounter any issues.

Docs

  • Just a bugfix, no docs should be needed.

Copy link

changeset-bot bot commented Feb 14, 2024

🦋 Changeset detected

Latest commit: 77e297d

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: create-astro Related to the `create-astro` package (scope) pkg: astro Related to the core `astro` package (scope) labels Feb 14, 2024
Copy link
Contributor

@lilnasy lilnasy left a comment

Choose a reason for hiding this comment

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

Looks great to me, thanks for the quick PR!

@matthewp matthewp merged commit 51b6ff7 into withastro:main Feb 14, 2024
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Feb 14, 2024
@hippotastic hippotastic deleted the fix-getregistry-invalid-url branch February 14, 2024 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: create-astro Related to the `create-astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants