In maven, if module A depends on Module B. When you change B locally, you can easily use mvn install (for B) to deploy B into the local repo, so A can get the updated B without downloading from the remote repo. This is pretty efficient.
However, in NPM world, I can't find the equivalent. I have package A depends on B, during dev time, I'm frequently changing B, I definitely don't want to run npm publish for every single change. That's slow and doesn't make any sense to publish partially finished package B to the public.
I know NPM supports local dependency, but that way has few drawbacks:
I want to find an efficient way for dev process to meet the following requirements:
My idea is there should be a simple NPM registry dev proxy, During dev time, NPM connects to this proxy. By default, it downloads packages from the upstream registry. We can config it, so for particular dependencies e.g. B, it will download from specified directory e.g. local B's dist directory. Thus, we never touch A's package.json.
Is there any similar solution or any other better suggestion on this problem?
npm link seems to do most of what you're asking.
You don't have to change package.json - it doesn't affect it in any way. After you've run npm link
once, all changes to the linked package will be seen by your package instantly. Because it only changes your node_modules
folder, as long as you aren't carrying that from dev to remote (you shouldn't be committing it to version control anyway), there are no changes back that you need to remember.
You may still have to run npm link path/to/linked/package
every time you change to dev mode, but that's a fairly painless command which doesn't get anything from remote.