4

I am working on a usecase where there is a requirement to publish multiple versions of same package.

enter image description here

I have to publish these version of package in to my gitlab npm registry. I have searched on this but everyone is telling to use scopes which is not possible in my requirement. Is there a way that i can publish both these versions to my gitlab registry?

when i try to publish first version its publishing fine but for second version its giving me an error -

enter image description here

Sai Vamsi
  • 111
  • 3
  • 19

2 Answers2

2

Alialising is the life saver if you want to publish multiple versions of same package in gitlab, especially if you are trying to publish unscoped packages.

#!/bin/sh

list=$(npm ll --json | jq -r 'recurse(.dependencies[]) | [.name+"@"+.version] |@csv' | sed 's/"//g'| sort -u)
for i in $list; do
        version_num=$(echo $i | rev | awk -F'@' '{print $1}' | tr '\.' '.'| rev);
        name=$(echo $i | perl -pne 's/@[0-9]+(\.[0-9]+)+$//');
        npm install $name-$version_num@npm:$i;
done


dirs=$(ls node_modules | grep -Eo ".*\-[0-9]+\.[0-9]+\.[0-9]+")
for i in $dirs; do
        echo $i
        npm publish node_modules/$i --registry https://gitlabserver.com/api/v4/projects/8/packages/npm/
done


atdirs=$(ls node_modules | grep "@")
for k in $atdirs; do
        indirs=$(ls  node_modules/$k | grep -Eo ".*\-[0-9]+\.[0-9]+\.[0-9]+")
        for j in $indirs;do
                echo $k/$j
                npm publish node_modules/$k/$j --registry https://gitlabserver.com/api/v4/projects/8/packages/npm/
        done
done
Sai Vamsi
  • 111
  • 3
  • 19
1

Unfortunately, you are forced to use scopes in the GitLab npm registry. See the documentation: Link

So the issue you are facing is not about the multiple Versions (that should work) but that you are not providing any scope.

On a side note: It seems like you are trying to proxy the actual entities package, while you try to use some private packages? You don't need to do so and I would recommend against that. Some solutions:

  • Use a Package Proxy like Nexus, jFrog or Verdaccio
  • You configure your npmrc to only use the GitLab Registry once a specific Scope is used and grab the package from npm.js or a mirror otherwise.
Lalaluka
  • 910
  • 1
  • 11
  • 16
  • 1
    Hi, yes i am trying to proxy the actual entities package in to my gitlab registry. My requirement is that i have to publish all the dependencies, sub dependencies of dependencies, peer dependencies all of them from package.json to the Gitlab registry one time so that during development i should be able to download each of the dependencies from gitlab registry instead of going to npm.js. my build environment will not have access to internet to download packages from npm.js. Also, if gitlab doesn't allow publishing unscoped then it should not even allow me for first version of package. – Sai Vamsi Aug 15 '22 at 05:34
  • 1
    I can only quote the documentation. I don't know why it might have worked the first time. Again for your pretty common use case I highly suggest you to use an actual offline proxy. Your workflow of manually uploading every dependency is unnecessarily complicated and will also require work if you update any dependency. Take a look at offline proxies as I mentioned above. – Lalaluka Aug 15 '22 at 07:04