Packages / do npm tags work ?

Hello,

I am using a Github Action to publish to Github Packages (npm):

main.yml:

on: push

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: 12
        registry-url: 'https://npm.pkg.github.com'
        scope: '@PeterHewat'
    - run: npm publish # --tag next
      continue-on-error: true
      env:
        NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

If I use the command “npm publish” in my workflow, it creates a package using the current version defined in my packages.json. This works fine. What I do not understand is that if I use the command “npm publish --tag next” in order to specify an npm tag to my package, the package is generated, but I find no trace of the tag. There is a difference though: the package isn’t listed as being the latest (cf. 1.0.5 / 1.0.6):

test_github_package_tags.png

What I would like to do is manage npm tags in order to be able to target latest/next dependencies like what is done here for example:

https://www.npmjs.com/package/@angular/core?activeTab=versions

Does Github Packages support this?

For now, if I run the command “npm install github:peterhewat/test-packages@next” I get the error “…is not a valid repository name”. I have to remove the tag at the end as follows: “npm install github:peterhewat/test-packages”. This will install the last package created even if it is not specified as “latest version” (ie. 1.0.6 instead of 1.0.5 which is the “latest version”).

I tried to publish a new version 1.0.1 with next tag to my package, the same as yours, the latest version is still the previous one.  

I managed to install package with tag next in the following example: 

npm install @yanjingzhu/npmpackages@next

npm install.png 

There is the result: 

Please check whether this could work for you.

Hi @yanjingzhu 

Thanks for your message. Unfortunetly, it doesn’t work. If you publish another package with a different tag (ex: “beta”), it won’t be taken into account. The dependency @next will just get the latest package ignoring the “next” and “beta” tags.

I got the following reply from GitHub Support:

Hi Peter,

Thanks for reaching out.

-- Does Github Packages support this?

Publishing a node package using --tag isn't supported, however you could use a
distribution tag instead– Ie. npm dist-tag add @owner/package@x.x.x latest and
then perform the install using npm install @owner/package@latest.

Please let me know if you need something else.

Cheers,

Melanie

My initial tests with dist-tag haven’t worked either. I’ll keep on looking into this.

Hello again @yanjingzhu 

–tag does seem to work for my use case after all.

Cheers,

Peter 

1 Like

I am so glad to hear that you have resolved your issue. In my example, I also used  npm publish --tag next as you said . 

next tag.png

One of the last pages of packages handels about combination of automatisation and modification, actions

That I must evaluate first, but yes it’s the only exception with packages. The last example I guess

Good job! I was sure it worked in theory, but when I read about it I was sure that someone was bullying me again. It’s fun if it’s friendly, strange doug that yesterday everyone believed that woman. Then I panicked.

Are you now the issuer? Or am I wrong?

What a pithy. It should be good training stuff.

npm publish --tag CUSTOM_TAG is work. but npm dist-tag add @owner/package@version tag is not work.

❯ npm dist-tag add @owner/package@$VERSION $TAG
npm ERR! code E404
npm ERR! 404 Not Found - GET https://npm.pkg.github.com/banksalad/-/package/@owner%2fpackage/dist-tags
npm ERR! 404 
npm ERR! 404  '@owner/package@version' is not in the npm registry.
...