软件包修补
概述
¥Overview
有时你需要对依赖进行小的更改,只是为了解决一些小问题。建议的操作是进行 PR 上游,但你的更改可能需要一些时间才能通过审核并最终发布;与此同时该做什么?你有两个选项:
¥It sometimes happen that you need to make small changes to a dependency, just to workaround some small issue. The recommended action is to make a PR upstream, but it may take time until your changes get through review and end up in a release; what to do in the meantime? You have two options:
-
你可以使用
git:
协议,只要正确设置,它就可以让你直接从其开发存储库安装项目。¥You can use the
git:
protocol, which will let you install a project straight from its development repository, provided it was correctly setup. -
或者你可以使用
patch:
协议直接从你的项目中对依赖进行小的更改,同时将它们与原始代码分开。¥Or you can use the
patch:
protocol to make small changes to the dependencies straight from your project, while keeping them separated from the original code.
不再需要等待合并和发布拉取请求,不再需要分叉存储库来修复阻止你的应用运行的一个小问题:内置补丁机制将始终让你自行解锁。
¥No more waiting around for pull requests to be merged and published, no more forking repos just to fix that one tiny thing preventing your app from working: the builtin patch mechanism will always let you unblock yourself.
制作补丁
¥Making patches
要创建补丁,请运行 yarn patch
命令并向其传递包名称,以使 Yarn 在临时文件夹中提取请求的包。然后你可以随意编辑补丁中的文件。
¥To create a patch, run the yarn patch
command and pass it a package name to make Yarn extract the requested package in a temporary folder. You're then free to edit the files within the patch at your convenience.
完成更改后,使用临时文件夹作为参数运行 yarn patch-commit -s
:补丁将在 .yarn/patches
中生成,并应用于你的项目。将其添加到 Git,你就可以开始了。
¥Once you're done with your changes, run yarn patch-commit -s
with the temporary folder as parameter: the patch will be generated in .yarn/patches
, and applied to your project. Add it to Git, and you're set to go.