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...
With Git, using multiple repositories is the only way to work efficiently. This enables each team to work independently, and do their work faster. You can also make sure that developers only have access to the repositories they need access to (thus making Git more secure.)
A multi repo can better support granular access control and configuration changes. If you have a large team that collaborates on a complex infrastructure system, multiple source repositories allow you to localize changes and lessen the blast radius of failed infrastructure updates across the system.
You could avoid modifying your package.json
file by using the npm link
command. This will automatically configure the execution
package to symlink its node_modules/common
directory to your local clone of common
.
How to use this method
common
directory type: npm link
. This will create a global reference to your common
folder in npm
, identified by common
(assuming common
is the exact name of your node package).execution
directory type: npm link common
. This will symlink the node_modules/common
folder into your local copy of the common
directory.When you're done making changes to your common
folder, you need to update that package online, and then change the package.json
of execution
to point to the updated version of common
.
I prefer this method over the one suggesting to point package.json
to your local repository, because that leaves your package.json
in an invalid state that you might accidentally commit and push.
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+
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