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

astro add does not respect scoped registry configurations #10740

Open
1 task done
diesieben07 opened this issue Apr 10, 2024 · 5 comments
Open
1 task done

astro add does not respect scoped registry configurations #10740

diesieben07 opened this issue Apr 10, 2024 · 5 comments
Labels
- P2: nice to have Not breaking anything but nice to have (priority)

Comments

@diesieben07
Copy link

Astro Info

Astro                    v4.5.18
Node                     v20.11.1
System                   Linux (x64)
Package Manager          npm
Output                   hybrid
Adapter                  none
Integrations             @astrojs/preact

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

astro add does not work if the package being added is in a custom registry and that custom registry is configured for the package's scope only. Astro ignores the custom registry and reports that the package does not exist.

What's the expected result?

astro add will query the NPM config for the registry using npm config get registry.
When a scoped package is being added, such as @example/astro-integration this is incorrect, as it ignores any registry that is configured for that scope only. Instead in case of a scoped package Astro should first query npm config get @example:registry and only if that returns undefined fall back to npm config get registry.

Link to Minimal Reproducible Example

n/a

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Apr 10, 2024
@matthewp matthewp added - P2: nice to have Not breaking anything but nice to have (priority) and removed needs triage Issue needs to be triaged labels Apr 10, 2024
@matthewp
Copy link
Contributor

PR welcome here.

@diesieben07
Copy link
Author

diesieben07 commented Apr 10, 2024

In looking into this further, I noticed that astro add will use plain fetch requests to talk to the registry. This will fail in case of a private registry.

I will work on a PR that replaces this with npm show commands if possible. These will automatically respect the NPM config anyways, so there would not be a need to parse it.

@rishi-raj-jain
Copy link
Contributor

@diesieben07

If possible, can you share an example of what happens right now and what's the expected behaviour. I'm trying to understand this better in a given use case.

@diesieben07
Copy link
Author

diesieben07 commented Apr 12, 2024

We have a private NPM registry that requires authentication. We are hosting an Astro Integration in it and want to enable using it with astro add. NPM is configured to use our private registry for our package scope using .npmrc.

When doing astro add @example/our-integration the Astro CLI will attempt to fetch information about this package from the NPM registry. It does not take the scope configuration (or authentication info for that matter) configured in .npmrc into account. Thus it attempts to use the normal NPM registry instead of our private one. This obviously fails, because the package does not exist there and astro add then fails, reporting the package to not exist.

I did some experiments in trying to make this work. The part about using a separate registry for the scope is trivial (just run npm config get @example:registry first). But authentication info is much less trivial, because the NPM CLI refuses to output it on the command line, so astro add would have to analyze the config file itself, which is more complex than you might think.

@rishi-raj-jain
Copy link
Contributor

@diesieben07

Appreciate the prompt and detailed response. I totally understand it now.

I'll have to try it out myself by creating my own private package and then try raising a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority)
Projects
None yet
Development

No branches or pull requests

3 participants