pom依赖各节点说明
by Santhosh Reddy
由Santhosh Reddy
如何使用未发布的节点依赖项 (How to work with unpublished Node dependencies)
If you are a Node.js developer, you have definitely ended up in a situation where you want to use an unfinished feature from another Node dependency.
如果您是Node.js开发人员,那么您肯定会遇到想要使用另一个Node依赖项中未完成的功能的情况。
Let’s elaborate on this a bit. For example, your entire project is broken logically into 4 npm modules. One module, which is the main one, depends on the other 3 modules. With this setup, you might have to change the code in sub-modules and check if it works well with your main Node module.
让我们详细说明一下。 例如,整个项目在逻辑上分为4个npm模块。 一个模块是主要模块,它依赖于其他三个模块。 使用此设置,您可能必须更改子模块中的代码,并检查它是否与主Node模块一起使用。
The simplest way is to publish the modules to npm. Use the new versions in your main node module. Well, the downside with this approach is if you have made a mistake in your submodules, you have to re-publish and use them accordingly. But, things don’t stop there. You will have to repeat this until your main node module is stable. A headache. Right? I know.
最简单的方法是将模块发布到npm。 在主节点模块中使用新版本。 好的,这种方法的缺点是,如果您在子模块中犯了一个错误,则必须重新发布并相应地使用它们。 但是,事情并不止于此。 您必须重复此操作,直到主节点模块稳定。 头痛。 对? 我知道。
So, how do we get around this problem?
那么,我们如何解决这个问题呢?
使用npm链接 (Using npm link)
With this approach, you can work with any Node dependencies if they are checked out at some location in your local machine. All you have to do is run the below command in the root folder of the package, which is a dependency for your main node module.
通过这种方法,如果在本地计算机的某个位置检出了所有节点依赖项,则可以使用它们。 您所要做的就是在软件包的根文件夹中运行以下命令,这是您的主节点模块的依赖项。
So what does this do? If you have worked on Node-based projects, you know there is a node_modules folder which has your installed dependencies. Similarly, there is a global folder for the dependencies. The above command creates a symbolic link for the package in which this command is run. You have to run this command again in the package where you want to use the dependency code with the name in package.json
.
那么,这是做什么的呢? 如果您从事基于节点的项目,那么您将知道有一个node_modules文件夹,其中包含已安装的依赖项。 同样,也有一个用于依赖项的全局文件夹。 上面的命令为运行此命令的程序包创建一个符号链接。 您必须在要使用名称为package.json
的依赖代码的包中再次运行此命令。
With this, any changes you make to your dependency Node module can be used directly without having to re-install. The above 2 steps can be made short with the below command.
这样,您对依赖节点模块所做的任何更改都可以直接使用,而无需重新安装。 使用以下命令可以简化以上两个步骤。
npm link <relative-path-to-the-dependency>
从github获取源代码 (Getting the source from github)
Now, let’s discuss another use case where you are not the one working on your dependency, but a colleague of yours. And they don’t want to publish the code until they make sure the feature is complete to some extent.
现在,让我们讨论另一种用例,其中您不是依赖关系的人,而是您的同事。 并且他们直到确定功能在某种程度上完整之后才希望发布代码。
But you need this person’s code to test any early stage integration issues. I am assuming you both use the Git version control system for managing your code. You can get the changes your colleague has pushed to git with the link to the repository code as below in your file.
但是您需要此人的代码来测试任何早期集成问题。 我假设你们俩都使用Git版本控制系统来管理代码。 您可以通过文件中的存储库代码链接来获取同事推送到git的更改,如下所示。
package.json
package.json
'package-name': git@github.com:<repository-name>.git#<branch-name>
Once you’ve placed the above path in package.json
file, you need to run a clean npm install
to get the latest code from git.
将上述路径放入package.json
文件后,需要运行npm install
来从git获取最新代码。
Hope you enjoyed the article. If you liked it, please do clap and share with others.
希望您喜欢这篇文章。 如果喜欢,请拍手并与他人分享。
Comment down below if you’ve another way of working with Node dependencies.
如果您还有另一种使用Node依赖项的方法,请在下面注释掉。
Originally published at humbleposts.com.
最初发布于humbleposts.com 。
翻译自: https://www.freecodecamp.org/news/working-with-unpublished-node-dependencies-f396ea1a363a/
pom依赖各节点说明