My question is similar to this one.
A project has a dependency on a Git module which resides in a privately-hosted repository:
"dependencies": {
"mymod": "git+https://mygitserver:8443/scm/od/mymod.git",
...
}
The intention is for this to be a snapshot dependency, so whenever any mymod
code gets modified, the project pulls down the latest version.
The question is, what command should I properly use to update my project to the latest version of the module?
The only thing that I have found that works is:
rm -rf node_modules/mymod
npm install
Running npm install
alone does nothing (given that it has been run once already), as noted by @Vishwanath in his question, because the module is already installed. npm upgrade
is inappropriate, because I also have dependencies on a lot of other modules, and I do not want to upgrade them all to newer versions.
I guess I could explicitly version mymod
and then update my local package.json
with the new version whenever it changes, but that creates an ongoing maintenance task.
It seems like npm
has enough information to determine when an upgrade is needed, because node_modules/mymod/package.json
contains the last known head revision, which it could compare to the current head revision:
"gitHead": "b63f0df8ef...",
"_resolved": "git+https://mygitserver:8443/scm/od/mymod.git#b63f0df8ef..."
Does npm
have a preferred way of handling snapshot dependencies like this?
An npm package can be installed from a private GitHub repository using an SSH repository link. SSH links are only available to logged-in users and can be used to access the private repositories of your GitHub.
The npm command will try to install the package using git clone. The npm command can also install the package from different GitHub repository states using a commit hash value, which can be used to install the package with a commit id:
Code published to npmjs.com is often not what's in the repository for the package. It is common to "compile" JavaScript source files into versions meant for general consumption in libraries. That's what's usually published to npmjs.com. It is so common that it's a feature of npm to automatically run a "build" step before publishing ( npm publish ).
The branch name can be used to install a branch as a package: Similarly, the tag or version names can be used to install a specific version of a GitHub package: gist can also be added using the id of a gist: An npm package can be installed from a private GitHub repository using an SSH repository link.
You can manually update a package.
npm update mymod
This will update your package-lock.json with latest hash commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With