如何保存对NPM模块所做的本地更改? [英] How can I preserve local changes made to an NPM module?

查看:37
本文介绍了如何保存对NPM模块所做的本地更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用NPM拉下了一个节点模块,并将其添加到 package.json 中.但是有必要更改一些模块代码,因为它不能100%满足我的要求.

I've pulled down a node module using NPM, and added it to package.json. However there was a need to change some of the module's code as it didn't meet my requirements 100%.

通常,当我使用node和 git 时,我会忽略 node_modules 目录,并在部署到服务器时使用 npm install .

Typically when I'm working with node and git I would ignore the node_modules directory and use npm install when deploying to a server.

我想知道在我的场景中有什么最佳实践,有没有一种方法可以在 package.json 中定义一个模块,如果在运行 npm时该模块已经本地存在,则应该忽略该模块安装?这已经是所有模块的默认行为吗?如果有人运行了 npm更新,该怎么办?我认为该模块的最新版本将被删除并覆盖我的更改吗?

I'm wondering what best practise would be in my scenario, is there a way of defining a module in package.json that should be ignored if it already exists locally when running npm install? Is this already the default behaviour for all modules? How would that work if someone ran npm update? I would assume the latest version of that module would be pulled down and would overwrite my changes?

或者,我已经考虑过分叉该模块的原始git repo,将我的fork重新发布到NPM,然后改为使用它.

Alternatively I've thought about forking the original git repo for the module, republishing my fork to NPM and then using that instead.

提示和想法将不胜感激:)

Tips and ideas would be greatly appreciated :)

推荐答案

或者,我考虑过为该模块分叉原始的git repo,将我的fork重新发布到NPM,然后改为使用它.

Alternatively I've thought about forking the original git repo for the module, republishing my fork to NPM and then using that instead.

您在这里有正确的主意.在NPM下,您绝对不想在托管资源和版本控制跟踪的资源之间分散关注点.分叉存储库,然后回答以下问题:如果将功能添加到现有模块中,拉取请求是否可能会尽快合并并发布到NPM?

You have the right idea here. Under NPM, you definitely don't want to split your concerns between hosted and version control-tracked resources. Fork the repo, and then answer this question: if you add the functionality to the existing module, is the pull request likely to be merged and published to NPM soon enough for you?

如果答案是否定的,因为该功能不符合原始模块的意图,则最好创建自己的模块,并确保在README中记下您的叉子.

If the answer is no because the functionality doesn't meet the intentions of the original module, you're better off creating your own, making sure to note your fork in the README.

如果您正在等待PR,则可以在过渡期间选择.NPM允许您直接链接到叉子的.git文件

If you're waiting on the PR, you have an option in the interim. NPM lets you link directly to your fork's .git file.

这篇关于如何保存对NPM模块所做的本地更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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