同时开发一个npm软件包和一个依赖它的项目 [英] Developing an npm package and a project that depends on it at the same time

查看:35
本文介绍了同时开发一个npm软件包和一个依赖它的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置/工作流程:

项目A 依赖于 package.json 中的自定义npm软件包.

Project A relies on a custom npm package in package.json.

当工程师从事 A项目时,他们不可避免地也会对自定义npm软件包进行更改.通过使他们克隆项目和自定义程序包存储库,然后应用 npm link 可以简化此过程.

As engineers work on Project A, they will inevitably be making changes to the custom npm package as well. This is streamlined by having them clone down both the project and custom package repos, then applying npm link.

(来源: http://justjs.com/posts/npm-link-developing-your-own-npm-modules-without-tears )

问题:

假设开发人员现在已完成对 Project A 和自定义npm软件包的更改.以下是后续步骤:

Assume a developer has now finished making changes to both Project A and the custom npm package. Here are the next steps:

  1. 他或她必须提交自定义程序包的请求请求,然后等待其被代码审查和合并.

  1. He or she must submit a Pull Request for the custom package and wait for it to be code reviewed and merged.

现在,他或她必须打开项目A 的拉取请求",其中包含在 package.json 中的自定义软件包上带有颠簸版本号.

He or she must now open Pull Request for Project A, containing a bumped version number on the custom package in package.json.

这感觉很笨拙,很容易阻止我们的其他开发人员.

This feels clunky and prone to blocking our other developers.

在构建自定义npm程序包和同时依赖它的项目时,有人对更好的工作流程有任何建议吗?

Does anyone have suggestions for a better workflow when building a custom npm package and a project that depends on it at the same time?

推荐答案

因此,您拥有依赖于程序包B的项目A.首先,如果B正在快速开发中,则使A依赖于B并没有多大意义(通过将其列出在package.json中并进行"npm install"-):它将给您带来的痛苦多于收获.取而代之的是,将B直接复制到A中并直接使用(不使用任何npm机器).

So you have project A depending on package B. First, if B is under rapid development, it does not make much sense to make A dependent on B (by listing it in package.json and 'npm install'-ing it): it'll bring you more pain than gain. Instead of this, copy B directly into the A and use it directly (without using any npm machinery).

仅当B的API足够稳定时,才将其发布为单独的模块并以npm方式依赖于它.

Only when B's API gets stable enough, publish it as a separate module and depend on it npm way.

但这还不是全部!为了使事物合理地分离和解耦,您应该使用git子模块.

But this is not all! To keep things reasonably separated and decoupled, you should use git submodules.

https://git-scm.com/book/en/v2/Git-Tools-Submodules

git的这一强大功能使您可以将一个git repo放入另一个git repo中.这样,您的两个项目都可以很好地分离.这也使得将B作为一个单独的单元发布的过程变得更加容易.

This great feature of git allows you to put one git repo inside another git repo. This way, both of your projects are reasonably well decoupled; also this makes the process of publishing B as a separate unit much easier.

我已经在两个独立的中型项目上尝试了两种方法(a)带有git branch依赖的npm与b)git子模块,没有npm),我更喜欢子模块:)

I've tried both approaches ( a) npm with git branch dependency vs. b) git submodules, no npm) on two separate middle-sized projects and I enjoyed the submodules way much more :)

这篇关于同时开发一个npm软件包和一个依赖它的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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