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

Add support for configuring different repositories for scopes #24

Open
ilg-ul opened this issue Aug 13, 2019 · 10 comments
Open

Add support for configuring different repositories for scopes #24

ilg-ul opened this issue Aug 13, 2019 · 10 comments
Assignees

Comments

@ilg-ul
Copy link
Contributor

ilg-ul commented Aug 13, 2019

npm can be configured with something like

@codertocat:registry=https://npm.pkg.github.com/

in .npmrc or npm config.

xpm should use these definitions too, and access the correct server.

@ilg-ul ilg-ul self-assigned this Aug 13, 2019
@JoeBenczarski
Copy link

This would be a very useful feature if xpm supported the various registry configuration methods npm supports. Is this still planned to be supported?

  1. global config - 'npm set registry http://localhost:4873/'
  2. project specific config - 'npm set registry http://localhost:4873/ --location project'
  3. scope specific config - 'npm config set @my-scope:registry http://localhost:4873'

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Mar 4, 2024

Yes, it is still planned, but for now I'm not sure exactly what needs to be done.

xpm uses exactly the same modules to access the packages as npm, so, with the proper configuration, I expected they both behave the same, but I had no time to further investigate.

As a temporary workaround, you can refer private git or ftp resources, as you can with npm.

@JoeBenczarski
Copy link

I investigated on my local setup how to get this to work. The problem appears with not passing proper options to pacote methods. To get a package to install from a private registry, I had to at least pass a 'registry' option to pacote.manifest() and pacote.extract() as seen in the below images. I didn't thoroughly test this, I only tested that it would install the package from a private registry I setup locally.

image

image

From what I understand of the npm code they handle things a bit differently, but the idea is similar. It seems npm has a
set of options that are passed to pacote.

image

Also, npm seems to store a resolved link to the package in their package-lock which is probably used for future installs.

image

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Mar 4, 2024

Can you clarify how you defined your custom npm configuration to access the local registry?

Can you determine what options does npm pass to pacote in this setup?

Actually I'd be interested to know what npm passes to pacote in a use case with multiple selective registries, configured via npm config ..., which seems to be the most complex case.

I remember long time ago I tried to understand if npm does check the configuration itself to determine the proper registry for a package, or passes some global configuration to pacote, which later does the registry selection, but I did not reach any conclusion.

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Mar 4, 2024

Did you really install a local server on port 4873, or it is just an example. If you did, what server did you use?

@JoeBenczarski
Copy link

Did you really install a local server on port 4873, or it is just an example. If you did, what server did you use?

I was testing this on a local server. I was testing this out using verdaccio (https://verdaccio.org/). The setup is quite simple.

@JoeBenczarski
Copy link

Can you clarify how you defined your custom npm configuration to access the local registry?

I used both 'npm set registry http://localhost:4873/' and 'npm config set @my-scope:registry http://localhost:4873/'
With this, using 'npm install ' worked correctly.

Can you determine what options does npm pass to pacote in this setup?

I was not able to find how to enable debug/trace in npm. If you know how to do this, I can find out what options are passed to pacote.

@JoeBenczarski
Copy link

I was able to get npm to show me the options.

opts.txt

In this scenario, I have set a scope specific registry using '@Myscope' using 'npm config set @Myscope:registry http://localhost:4873/'. What is interesting is that the options still have registry pointing to registry.npmjs.org. That makes sense because I did not globally change registry. Also, the options include '@Myscope:registry': 'http://localhost:4873' which I also expected to see.

What is not obvious to me is how the scope specific registry is resolved. The pacote docs don't seem to indicate it would use the scope specific registry option. However, I did see an option for this in the Arborist docs (https://github.com/npm/arborist). I'm not too familiar with Arborist though.

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Mar 5, 2024

I did not check, but I guess pacote passes the options to arborist.

Anyways, it appears that npm does not the selection itself, so xpm should not do it either.

The question now is how to get the registry and multiple @myscope:registry options (possibly other too) in order to pass them to pacote.

I think that using separate xpm configuration files for these options doesn't make much sense, probably parsing the npm configuration files would be more appropriate.

@JoeBenczarski
Copy link

Anyways, it appears that npm does not the selection itself, so xpm should not do it either.

The question now is how to get the registry and multiple @myscope:registry options (possibly other too) in order to pass them to pacote.

I think that using separate xpm configuration files for these options doesn't make much sense, probably parsing the npm configuration files would be more appropriate.

Agreed, reading the options from the global/user/project npmrc files, and passing those to pacote seems to be the right solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants