4

I have two npm packages that are private repositories hosted on gitlab.com under a group organization. My first package lives well and get updated and downloaded by users of the same organisation.

To install a private scoped package, the doc says:

# Set URL for your scoped packages.
# For example package with name `@foo/bar` will use this URL for download
npm config set @foo:registry https://gitlab.example.com/api/v4/projects/<your_project_id>/packages/npm/

So my .npmrc looked like

@mygroup:registry=https://gitlab.com/api/v4/projects/<id-project-1>/packages/npm/
//gitlab.com/api/v4/projects/<id-project-1>/packages/npm/:_authToken=<token>
//gitlab.com/api/v4/projects/<id-project-2>/packages/npm/:_authToken=<token>
//gitlab.com/api/v4/packages/npm/:_authToken=<token>

Obviously, everything works fine for the first package but not for the second one.

What I can't understand is why a scoped package should refer to a unique project url?

Because of this, I can't install both of my packages: the url of my scoped packages will only be valid for one of them.

I looked at the api endpoint to return a list of my group's packages I found this: https://docs.gitlab.com/ee/api/packages.html#within-a-group

So I updated my .npmrc to

@mygroup:registry=https://gitlab.com/api/v4/groups/mygroup/packages/npm/
//gitlab.com/api/v4/projects/<id-project-1>/packages/npm/:_authToken=<token>
//gitlab.com/api/v4/projects/<id-project-2>/packages/npm/:_authToken=<token>
//gitlab.com/api/v4/packages/npm/:_authToken=<token>

But it doesn't work. On the group/group-id/packages route I only get gitlab infos but nothing in an npm friendly format.

How to install more than one private scoped npm package hosted under the same group?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Existe Deja
  • 1,227
  • 3
  • 14
  • 36

2 Answers2

2

I experienced some troubles using yarn (1.22.10) so I'll post more details here just to save couple of hours to anybody reading this.

For some unknown reasons I was able to install the package with npm but not with yarn and I got Request failed \"404 Not Found\"

I ended up by creating a .npmrc file at the root of the project (I'm working with docker) with the following content:

@my-org:registry=https://gitlab.com/api/v4/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken=<GITLAB_TOKEN_API_SCOPE>
//gitlab.com/api/v4/projects/<ID_PROJECT_1>/packages/npm/:_authToken=<GITLAB_TOKEN_API_SCOPE>
//gitlab.com/api/v4/projects/<ID_PROJECT_2>/packages/npm/:_authToken=<GITLAB_TOKEN_API_SCOPE>

Line 3 and 4 are required for yarn but not for npm.

To make it work replace @my-org by your gitlab organisation name, gitlab.com by the url where your projects are, <ID_PROJECT_X> by the ids of the projects you want to install and <GITLAB_TOKEN_API_SCOPE> by a personal token with an API scope.

Existe Deja
  • 1,227
  • 3
  • 14
  • 36
1

The instance level endpoint seems answer to your situation instance-level-npm-endpoint

Using:

npm config set @mygroup:registry https://gitlab.example.com/api/v4/packages/npm/
npm config set -- '//gitlab.example.com/api/v4/packages/npm/:_authToken' "<your_token>"

You should be able to publish @mygroup/project1 & @mygroup/project2

mpromonet
  • 11,326
  • 43
  • 62
  • 91