你如何修改别人的库/模块? [英] How do you modify other's library/ module?

查看:33
本文介绍了你如何修改别人的库/模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向这个模块添加一个卡片组件:https://snack.expo.io/@xcarpentier/gifted-chat(演示)

I want to add a Card component to this module: https://snack.expo.io/@xcarpentier/gifted-chat (demo)

例如,如果在气泡消息上使用 onLongPress(),我希望显示附加信息(在气泡消息正下方,作为小卡片,如 Tinder Card).

For example, if using onLongPress() on the Bubble Message, i want additional info to appear (right below that Bubble Message, as a small card, like Tinder Card).

我该怎么做?我是否需要克隆源代码然后修改它以适合我的需要?

How do I do that? Do I need to clone the source code and then modify it to fit what I need?

推荐答案

虽然您可以编辑 node_modules 文件夹中的文件,但这并不是一个好的长期解决方案.为什么不呢?

Although you are able to edit the file in your node_modules folder, it is not a great long-term solution. Why not?

  • 流程与使用其他模块不一致
  • 另一个 npm install 将覆盖您的更改
  • 其他想要实现该功能的人将无法使用您的解决方案

如果你仍然想走这条路,最快的方法是通过 npm 链接它.如果此链接 不再可用,您可以按照以下步骤链接模块:

If you would still like to go this route, the quickest way to go about it would be by linking it via npm. In the event this link is not available anymore, you can link a module following these steps:

  1. 在您的终端中,导航到您修改过的节点模块
  2. 使用 npm link
  3. 创建全局符号链接
  4. 导航到您应用的根目录
  5. 使用 npm link name-of-module 引用该符号链接
  1. In your terminal, navigate to the node module you have modified
  2. Create a global symlink with npm link
  3. Navigate to your app's root directory
  4. Reference that symlink with npm link name-of-module

同样,这不是一个永久性的解决方案,只能用于快速测试对模块的修改.

Again, this is not a permanent solution and should only be used for quickly testing modifications to a module.

分叉 repo 是维护特定于该模块的提交的好方法,您可以将您的修改分享给开源社区.一些 fork 的原因 在 Github 帮助 wiki 中有解释,但这样做是很直接.

Forking the repo is a good way to maintain the commits specific to that module, and you can share your modifications to the open-source community. Some reasons to fork are explained in the Github help wiki, but doing it is pretty straight-forward.

  1. 导航到您要更改的包的 Github 存储库
  2. 按右上角的Fork按钮
  3. npm install git+your-forked-repo-url 在你的项目根目录下(不要忘记npm uninstall旧的)
  1. Navigate to the Github repo of the package you are wanting to change
  2. Press the Fork button in the top right corner
  3. npm install git+your-forked-repo-url in your project's root directory (don't forget to npm uninstall the old one)

现在,您可以按照不良解决方案中提到的流程在本地测试对该包的更改.在您对它们感到满意后,您可以将这些更改复制到您的分叉存储库并将它们推送到 Github(您会希望提升您的版本,但如果您想将更改与上游回购).然后对您的存储库执行另一个 npm install,使这些更改在您的 node_modules 文件夹中更加永久.

Now, you can follow the process mentioned in the Bad Solution to locally test out changes to that package. After you're satisfied with them, you can copy those changes over to your forked repo and push them to Github (you'll want bump your version, but you may have some merge conflicts to resolve if you ever want to merge changes with the upstream repo). Then do another npm install of your repo make those changes more permanent in your node_modules folder.

如果你想了解你分叉的仓库的最新情况,Github 解释了这个过程 此处.

If you would like to stay up-to-date with the repo you forked from, Github explains the process here.

选择更好的解决方案.

这篇关于你如何修改别人的库/模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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