使用依赖性管理2+ nodejs包的开发 [英] Managing development of 2+ nodejs packages with dependencies

查看:223
本文介绍了使用依赖性管理2+ nodejs包的开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发2个node.js包,每个包都在自己的git存储库中进行管理。包 B 取决于包 A ,所以我的本地目录结构如下所示:

  A1 / 
B /
node_modules /
A2 /

如果我对 A1 的本地代码进行更改,我想用 B ,然后将其推送到公共存储库。如何做到这一点?



在它的当前状态下, B 有自己的本地副本( A2 ),所以它引用了不同的版本。 B 是一个公共包,所以我想避免直接修改 B 的源代码来引用

一个可能的解决方案是有两个本地副本 B B1 是已发布的公共版本,它具有对 A2 的本地依赖关系,并且 B2 是我自己的私有版本,它使用类似于 require('./../ A1'')直接引用 A1

  A1 / 
B1 /
node_modules /
A2 /
B2 /

这看起来很丑陋(并且会迫使我维护2份 B ),我想知道是否有推荐的方式来处理这种情况?



谢谢。

解决方案

在最简单的情况下,符号链接可以解决问题。但是你可能会走得更远,并使用某种花哨的构建系统,如咕噜咕噜,吞咽等等。
我为我的所有项目使用了经典的make脚本。所以你可以在测试之前拷贝一个项目到另一个项目中,例如: b MODULES = ./node_modules/
PROJECTS_PATH = ../
DEPENDENCY = project_a /

default:test

test:copy
$(NPM)test
$ b copy:
@rm -rf $(MODULES)$(DEPENDENCY)
@cp -r $(PROJECTS_PATH)$(依存)$(模块)$(DEPENDENCY)

install:
@rm -rf $(MODULES)
$(NPM)安装

.PHONY:test

这不是最好的构建脚本,但它可以完成这项工作。大多数unix系统将安装 make 。所以它也非常便携。


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?

Thanks.

解决方案

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.

这篇关于使用依赖性管理2+ nodejs包的开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆