32

I am trying to include a private BitBucket repository to my package.json, but I also would like to manage the version, as a normal module. currently I am using this

"package-name": "git+https://<user>:<password>@<url-repository>.git"

I already tried it, but it didn't work.

"package-name": "git+https://<user>:<password>@<url-repository>.git#v1.0"

Any idea?

Kelyane
  • 467
  • 2
  • 7
  • 19

3 Answers3

36
  1. Login to your bitbucket account and under user settings add an app password:

    > https://bitbucket.org/account/user/{yourUsername}/app-passwords

  2. Add package dependency to your package.json as:

"dependencies": {
"my-module": "git+https://Xaqron:pwd@bitbucket.org/Xaqron/my-module.git#*"
}

Replace Xaqron with your own username and pwd with app password from step one.

to install specific version add #v.v.v (i.e. #1.0.0) to the end of dependency URL.

Xaqron
  • 29,931
  • 42
  • 140
  • 205
  • 3
    that version is the branch actually just to be clear – TreantBG Mar 08 '18 at 18:05
  • specifically to find out where to set app passwords see this link https://confluence.atlassian.com/bitbucket/app-passwords-828781300.html – Karl Mar 13 '18 at 02:59
  • 1
    note: you must use your master Bitbucket username, not the "label" of the app password you created in step one. – HaterTot Jul 19 '18 at 14:54
  • Will it always take that specific version that is in the tag, or does it work with operators such as `^`, `>` etc? – Adam Gerthel Jan 21 '19 at 18:40
  • 3
    @AdamGerthel You can use version ranges by adding `#semver:whatever` at the end of URL. Example: `my-module.git#semver:^1.5.2`. – Xaqron Jan 22 '19 at 13:21
  • 5
    But this leaves my bitbucket password in package.json, which I'm likely to be tracking with git. Not a very secure solution. – wolfson109 Feb 18 '19 at 15:39
  • @wolfson109: Yes and the project itself should be private but App password is different from main account password and you can revoke it at any time. – Xaqron Feb 18 '19 at 22:47
  • 2
    @wolfson109 use `git+ssh` instead. – Pedro Moreira Jul 16 '19 at 21:53
  • @Xaqron i am using same steps, but this isn't working in my case. while installing it, showing premature close. – Deepak Tyagi Sep 15 '20 at 12:30
  • 1
    I followed the format but I am getting the confusing message: git checkout 1.0.2, error: pathspec '1.0.2' did not match any file(s) known to git. If I remove #1.0.2 at the end I get a premature close. – nishant Dec 08 '20 at 02:37
23

I am currently using this and it works:

{
  "dependencies": {
    "package-name": "git+ssh://git@<url-repository>.git#v0.1.0"
  }
}

I am using npm version 4.1.2 and self hosted bitbucket version 4.14.6

Guillaume
  • 2,912
  • 3
  • 35
  • 59
1

You have to git tag the version you want to install in the module repo. The repo url can be found in the module's package.json file, e.g.

"repository": {
    "type": "git",
    "url": "git+https://github.com/repo-owner-name/my-module.git" // <-- This line!
},

When you've added a tag (e.g. git tag -a 0.0.1 -m "auto release") to a release, it can be installed using:

"my-module": "git+https://bitbucket.org/repo-owner-name/my-module.git#0.0.1"
kuhr
  • 582
  • 8
  • 18