Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make npm fetch latest package from Git repo

Tags:

git

node.js

npm

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?

like image 954
chris Avatar asked Feb 24 '16 09:02

chris


People also ask

How to install an NPM package from a private GitHub repository?

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.

How to install a package from a different GitHub repository?

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:

Why is my code not in the npmjs repository?

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 ).

How do I install a specific version of a Github Branch?

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.


1 Answers

You can manually update a package.

npm update mymod

This will update your package-lock.json with latest hash commit.

like image 66
jm18457 Avatar answered Oct 27 '22 21:10

jm18457