感谢你的贡献,你真棒!
关于开源项目,有许多不同类型的贡献,它们都非常有价值。以下是一些在你准备贡献时应该会有所帮助的指南。
在你贡献代码之前,你需要先 fork (派生) 这个仓库。具体操作会因你的贡献类型而略有不同。
react-router
代码的改动都应该从 dev
分支创建新分支,并最终合并到 dev
分支。main
分支创建新分支,并最终合并到 main
分支。以下步骤将帮助你设置好环境,以便向此仓库贡献改动。
Fork (派生) 此仓库(点击此页面右上角的 Fork 按钮)。
将你 fork 的仓库克隆到本地。
# in a terminal, cd to parent directory where you want your clone to be, then
git clone https://github.com/<your_github_username>/react-router.git
cd react-router
# if you are making *any* code changes, make sure to checkout the dev branch
git checkout dev
安装依赖并构建。React Router 使用 pnpm,因此你也应该使用 pnpm。如果你使用 npm
安装,将会生成不必要的 package-lock.json
文件。
请遵循问题模板,并提供清晰的重现步骤和代码示例。最好是提交一个带有失败测试的拉取请求。其次是将展示该 bug 的 StackBlitz 链接或仓库链接。
示例可以直接添加到 main 分支。从你本地克隆的 main 分支创建一个新分支。完成后,创建一个拉取请求并概述你的示例。
请提供周到的评论和一些示例代码,展示你希望如何在应用中使用 React Router。如果你能先说明当前 API 的局限性,然后再得出关于需要更改或添加内容的结论,这有助于讨论。
根据经验,小巧的 API 通常更好,因此除非当前 API 存在明显的局限性,我们可能不太愿意添加新内容。话虽如此,我们一直渴望听到我们之前没有考虑到的用例,所以请不要害羞! :)
如果你需要修复一个 bug 但没有人去修复,最好的办法就是你自己提供修复并创建一个拉取请求。开源代码属于我们所有人,推动其发展是我们共同的责任。
拉取请求只需要两名或更多协作者的批准即可合并;如果 PR 作者本身是协作者,则算作一名批准。
dev
分支。你可以在 GitHub 中创建 PR 时,在“Compare changes”(比较更改)标题下方的下拉菜单中设置基础分支:
所有修复 bug 或添加新功能的提交都需要测试。
所有修改或添加 API 的提交必须通过一个拉取请求进行,并且该拉取请求同时更新所有相关的示例和文档。
文档位于 docs
目录下。一旦修改进入 main
分支,它们将自动发布到文档网站。
如果你想预览改动在文档网站上的效果,请克隆 react-router-website
仓库,并按照 README.md
中的说明在本地查看你的改动。
React Router 使用 monorepo (单仓库) 来托管多个包的代码。这些包位于 packages
目录下。
我们使用 pnpm workspaces 来管理依赖安装和运行各种脚本。要完成所有安装,请确保你已安装 pnpm,然后从仓库根目录运行 pnpm install
。
从根目录调用 pnpm build
将运行构建,这应该只需要几秒钟。同时构建所有包很重要,因为各个包之间存在依赖关系。
在运行测试之前,你需要先进行构建。构建完成后,从根目录运行 pnpm test
将运行所有包的测试。如果你想运行特定包的测试,请使用 pnpm test --projects packages/<包名>
# Test all packages
pnpm test
# Test only react-router-dom
pnpm test --projects packages/react-router-dom
这个仓库为不同的目的维护了不同的分支。它们大致如下所示:
- main > the most recent release and current docs
- dev > code under active development between stable releases
- v5 > the most recent code for a specific major release
可能还有用于各种特性和实验的其他分支,但所有核心活动都基于这些分支进行。
当需要发布新版本时,我们会根据版本类型,遵循基于我们分支策略的流程。
react-router@next
版本我们从 dev
分支的当前状态创建实验性版本。可以使用 @next
标签安装它们。
pnpm add react-router-dom@next
# or
npm install react-router-dom@next
随着拉取请求合并到 dev
分支,这些版本将自动发布。
# Start from the dev branch.
git checkout dev
# Merge the main branch into dev to ensure that any hotfixes and
# docs updates are available in the release.
git merge main
# Create a new release branch from dev.
git checkout -b release/v6.1.0
# Create a new tag and update version references throughout the
# codebase.
pnpm run version [nextVersion]
# Push the release branch along with the new release tag.
git push origin release/v6.1.0 --follow-tags
# Wait for GitHub actions to run all tests. If the tests pass, the
# release is ready to go! Merge the release branch into main and dev.
git checkout main
git merge release/v6.1.0
git checkout dev
git merge release/v6.1.0
# The release branch can now be deleted.
git branch -D release/v6.1.0
git push origin --delete release/v6.1.0
# Now go to GitHub and create the release from the new tag. Let
# GitHub Actions take care of the rest!
有时我们会遇到需要立即修复的关键 bug。如果该 bug 影响最新版本,我们可以直接从 main
分支(或存在该 bug 的相关主要版本分支)创建一个新版本。
# From the main branch, make sure to run the build and all tests
# before creating a new release.
pnpm install && pnpm build && pnpm test
# Assuming the tests pass, create the release tag and update
# version references throughout the codebase.
pnpm run version [nextVersion]
# Push changes along with the new release tag.
git push origin main --follow-tags
# In GitHub, create the release from the new tag and it will be
# published via GitHub actions
# When the hot-fix is done, merge the changes into dev and clean
# up conflicts as needed.
git checkout dev
git merge main
git push origin dev