Gadi Gadi - 2 months ago 8
Git Question

Node.JS: Working with multiple Git repositories

We have a node.js project with a few modules which spans across multiple Git repositories. The modules have dependencies between them.

For example:

common
module resides in its own repository.
execution
module resides in a separate repository, and has a (npm) dependency on
common
.

So, the directory structure in
execution
includes (once
npm install
is executed)
common
under
node_modules
.

Our problem is, when developers are working on
execution
, they some times need to modify
common
as well. In order to 'see' their changes, they have one of two options we currently use: Either modify
node_modules/common
(which is ugly, untracked, etc.), or modify the
common
repository, then push+npm install their changes (which, while cleaner, is quite cumbersome).

What we're wondering is if there's a better alternative for this work process...

Answer

I assume you are using them as a dependency using package.json, which allows you to require them with the name and not the path. (You also have goodies of the version handling with this.) . I couldnt find any option to remove the step of npm install but I did found something which can remove the step of git push and will make your npm install faster.

Local dependencies.
Using local paths as dependencies which can be your some other git repo, you can make changes directly to the git repo of your dependency. This allows you to change the code and test it without pushing. (Although you have to do npm install again in the main module, which will duplicate the working copy of your dependency in your node modules).

Word of caution : You have to take care that you push the final changes made to your dependency code once you have finished working on both, otherwise other developers might go in inconsistent state.

How to add local dependencies

 "dependencies" : {
       "here" : "file:./test/git/repo/here#0.0.1"
 }

Note that this local dependency feature was added to npm in version 2.0. So you might need to update your node if you dont already have npm 2.0+

Comments