Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I target a git #branch@version with npm?

Tags:

npm

I have a fork in github. I am able to install target like this in npm

"my-fork-of-a-package": "github:my-profile/my-fork-of-a-package#branch"

in package.json. However I am unable to target a tag of the branch or a version number.

I'm looking for a some kind of @version or @tag or @commitHash syntax. Something kinda like this - except for that this doesn't work. '"my-fork-of-a-package": "github:my-profile/my-fork-of-a-package#branch@version"

like image 213
Tarek Adam Avatar asked Dec 17 '25 19:12

Tarek Adam


2 Answers

You can do this by using the #semver:<semver> notation like so:

"my-fork-of-a-package": "github:my-profile/my-fork-of-a-package#semver:v1.0.27"
  • see https://docs.npmjs.com/cli-commands/install
like image 50
tenfishsticks Avatar answered Dec 21 '25 12:12

tenfishsticks


Your question is tricky for a potential answer because generally, a branch implies the version number.

As per docs:

npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]:

Install the package at https://gitlab.com/gitlabname/gitlabrepo by attempting to clone it using git.

If # is provided, it will be used to clone exactly that commit. If the commit-ish has the format #semver:, can be any valid semver range or exact version

https://docs.npmjs.com/cli/install

Why don't you simply consolidate on only one level (branch1-v1, branch1-v2,branch2-v1...)?

You can effectively call a #branch, so i think it would be safe for you to rename & update your data structure to be 1 big pool with specific names.

That way, you'll be able to call the specific package/git through #branch1{your-own-separator}version-X.X

TL;DR: Add tags in name, will look messy but that's why search/indexes exist.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!