Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to support multiple private npm packages living in one git repo?

npm is very good at supporting packages publishes to the global/central npm repo, which doesn't work well for private, application code. npm also supports adding a git repo as a dependency, which lets you have a private dependency.

The problem is, as I understand to be best practice, my npm packages tend to be very tight and small, whereas my git repos tend to be larger, and will include several npm packages. I do not know any way to attain this granularity while pointing to a github URL. How to solve this?

UPDATE

I accepted the answer that says "don't do this, stay on the rails." I agree with this recommendation, but YMMV.

like image 889
djechlin Avatar asked Apr 30 '13 17:04

djechlin


People also ask

Can you have private npm packages?

With npm private packages, you can use the npm registry to host code that is only visible to you and chosen collaborators, allowing you to manage and use private code alongside public code in your projects. Private packages always have a scope, and scoped packages are private by default.

Where can I host npm private packages?

If you want to host a private NPM package but do not want to pay US$ 7 per user, per month to host it directly at https://www.npmjs.com/ this post is for you. Here I will share a very practical way you can host it privately for free at Github Packages Registry + NPM.

How do I install two npm packages?

When we install a package using the npm install package-name command, it will download the current stable version of the package inside node_modules folder and add it to package. json file. To install multiple versions of the same package, we need to use the package alias syntax which is supported from the npm v6.


2 Answers

I would suggest that one repo with multiple packages is a bad idea to start with for several reasons. You should be viewing a package as its own entity: independently built, tested, and deployed. All that to say, each package should live in its own repo.

That being said, I definitely understand the benefit of being able to do an npm install <package-group> of one "commons" package and have it grab all the packages you need in one shot. I would suggest looking at the grunt-contrib model for accomplishing this. In short, they have a bunch of grunt-contrib- packages (ex. grunt-contrib-coffee) each living in their own repositories. They then create a separate repository that defines the parent "grunt-contrib" package. All this parent package does is specify dependencies on all of the sub-packages. This allows you to do an npm install grunt-contrib-coffee (for example) and get just the grunt-contrib-coffee package; or you can do npm install grunt-contrib and get their entire suite all in one shot.

Hope this helps!

like image 162
Jacob Avatar answered Oct 11 '22 12:10

Jacob


You could also set up your own local npm repository.

  • Instructions for *nix/OSX
  • Instructions for Windows
like image 31
laktak Avatar answered Oct 11 '22 10:10

laktak