Reputation: 8109
I have an git repo and I'm trying to set it as a dependency in my project.
Using NPM, my package.json
looks like this:
"devDependencies": {
"grunt": "~0.4.0",
"grunt-contrib-connect": "~0.2.0",
"grunt-contrib-watch": "~0.3.1",
"custom": "git://github.com/myGitHubRepo/repo.js.git#b7d53a0cfbe496ad89bde6f22324219d098dedb3",
"grunt-contrib-copy": "~0.4.0"
}
On the first
npm install
It install everything and fetches the repository with no problem. But if I change this commit hash to let's say
"custom": "git://github.com/myGitHubRepo/repo.js.git#d6da3a0...", // a different one
It doesn't update! Can anyone point me out how could I get this behavior?
I would simply like to share this code and be able to at some point change this version and the npm
would automatically update this.
Upvotes: 34
Views: 22889
Reputation: 11
The solution I found is to delete package-lock.json
and then execute npm i
Upvotes: 1
Reputation: 1125
I encountered this question and all the answers had their own set of issues so I had to find a better means.
I have discovered a newer way to prevent this npm issue with package upgrades on install within the docs (this MAY require newer versions of npm):
Ensure you are tagging versions in your repo.
Then you can include your repo using this slightly modified URL:
git+ssh://git@<repo url>.git#semver:<tag/package version>
This behaves MUCH better and has no issues with downgrading or upgrading the version as I have seen thus far.
Upvotes: 5
Reputation:
Manually updating the package, as suggested by @Nestoro also worked for me:
npm update
npm install <your package name>
Upvotes: 0
Reputation: 854
manually updating that specific package did the trick for me.
and to do that automatically i added this postinstall script to my package.json
"scripts": {
...
"postinstall": "npm update custom"
}
Upvotes: 13
Reputation: 4582
Ok this is how it is done.
I was also confused.
So i have a private npm module at [email protected]:myModule/MySweetModule.git
I have just published the latest tagged version. Unfortunately i cannot figure out how that works, BUT it works off your master. SOOO your master branch can be your integration branch and you have stage branch for building up the next version. Upon version completion, just merge it into master and increment your private repo's version (so your private repo now went from 1.0.0 to 1.0.1). If you call npm install
it will update your repo if the master's package.json version is greater than current working repo. It will always take the latest repo.
I agree. So lets do it a better way! If you tags
for your private repo releases you can reference them by "custom": "git+ssh://[email protected]:usr/proj.git#TAG_NAME"
So it i have a tag called 0.1.0
, then i would have the url in package.json versioned like so. "custom": "git+ssh://[email protected]:usr/proj.git#0.1.0"
I believe that this is the best approach to your answer. But i am not a gitanista
If you try to go back a version, it appears it does not work. so from version 0.2.2
to 0.2.1
it will not update your project. Make sure you do npm remove myProj
then npm install
if you roll back a version.
Upvotes: 18