8

I have searched this topic for long time, currently all the solutions and examples work in git, but no direct solution for Mercurial.

Working example taken from somewhere similar links.

"private": true
to your package.json

Then to reference private npm module in package.json

{
    "name": "myapp",
    "dependencies": {
        "private-repo": "git+ssh://git@github.com:myaccount/myprivate.git#v1.0.0",
    }
}

As I read from official npm page this all works only with git https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

So how to do the same thing in Mercurial or currently it's seems to be possible only with Git ?

LarsW
  • 1,514
  • 1
  • 13
  • 25
Risto Novik
  • 8,199
  • 9
  • 50
  • 66

2 Answers2

11

If you are using Bitbucket to host your project's Mercurial repo, it does provide links to download snapshots of your project as a tar.gz file. These URLs are actually usable in package.json dependencies.

For example, my pagedown project's download page has a link to this URL for a gzipped snapshot of the latest default branch changes:

https://bitbucket.org/ncraike/pagedown/get/default.tar.gz

so in another project's package.json, I can specify:

"dependencies": {
    "pagedown": "https://bitbucket.org/ncraike/pagedown/get/default.tar.gz"
}

npm handles this fine when I do an npm install from the dependent package, installing it correctly to the node_modules subdirectory.

This isn't a general solution for Mercurial repositories (and I agree it'd be nice if npm accepted Mercurial URLs as well) but this could be a reasonable workaround if you're using Bitbucket or a similar site for hosting.

Nathan Craike
  • 5,031
  • 2
  • 24
  • 19
  • 2
    It appears that you can use this to retrieve a specific version by using the following syntax along with version tags: https://bitbucket.org/USERNAME/MODULENAME/get/TAG.tar.gz You can find these URLs on the downloads page under the tags tab. – jdp Jan 08 '14 at 05:04
  • Ah. Actually, yes, specific versions would probably be preferred, so your dependencies are stable and tested and don't change unexpectedly (eg whenever someone commits to default). – Nathan Craike Jan 14 '14 at 03:40
  • 6
    For private repos, how would I provide credentials without placing them into the package.json? – kierans Mar 07 '14 at 09:45
  • @kierans I have no idea if this would work, but my first instinct is to try adding `[auth]` section to `~/.hgrc` Details here: https://stackoverflow.com/questions/2584407/how-to-save-username-and-password-with-mercurial#2589195 – Jonathan Jun 01 '18 at 00:34
2

NPM supports git but does not support Mercurial. You could use something like Kiln to host your repository, which allows access as either Mercurial or git, but failing that you'll have to clone into local and point NPM at that.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169