Managing development of 2+ nodejs packages with dependencies
I am developing 2 node.js packages, each managed in their own git repository. Package B depends on package A, so my local directory structure looks like this:
A1/ B/ node_modules/ A2/
If I make a change to the local code of A1, I would like to test it with B before pushing it to the public repository. How can I do this?
In it's current state, B has it's own local copy (A2), so it is referencing a different version. B is a public package, so I would like to avoid directly modifying the source code of B to reference A1.
One possible solution is to have 2 local copies of B: B1 is the released, public version that has it's own local dependency on A2, and B2 is my own private version that directly references A1 using something like require('./../A1').
A1/ B1/ node_modules/ A2/ B2/
This seems kind of ugly (and would force me to maintain 2 copies of B), and I'm wondering if there's a recommended way to handle this situation?
In simplest case symlinks will do the trick. But you may go further and use some kind of fancy build system like grunt, gulp and so forth. I'm using classic make scripts for all of my projects. So you can just copy one project into another before testing it e.g:
NPM = /usr/bin/env npm MODULES = ./node_modules/ PROJECTS_PATH = ../ DEPENDENCY = project_a/ default: test test: copy $(NPM) test copy: @rm -rf $(MODULES)$(DEPENDENCY) @cp -r $(PROJECTS_PATH)$(DEPENDENCY) $(MODULES)$(DEPENDENCY) install: @rm -rf $(MODULES) $(NPM) install .PHONY: test
It is not the best build script but it will do the job. Most unix systems will have make installed. So it is pretty portable too.