感谢您的贡献,您太棒了!
说到开源,可以做出许多不同类型的贡献,所有这些贡献都很有价值。以下是一些指南,应该可以帮助您准备贡献。
在您可以为代码库做出贡献之前,您需要 Fork 仓库。这看起来会有点不同,具体取决于您要做的贡献类型
react-router
代码的内容都应从 dev
分支分叉并合并到该分支中main
分支分叉并合并到该分支中以下步骤将帮助您设置好环境,以便为该仓库贡献更改
# 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
npm
安装,则会生成不必要的 package-lock.json
文件。请遵守 issue 模板,并提供清晰的重现路径以及代码示例。最好是提交一个包含失败测试的 pull request。其次是提供指向 CodeSandbox 或仓库的链接,以说明该错误。
示例可以直接添加到 main 分支。从您本地克隆的 main 分支创建一个分支。完成后,创建一个 pull request 并概述您的示例。
请提供周到的评论和一些示例代码,以展示您希望如何在您的应用中使用 React Router。如果您可以先向我们展示您如何受到当前 API 的限制,然后再跳到关于需要更改和/或添加什么内容的结论,这将有助于对话。
我们从经验中了解到,小型 API 通常更好,因此除非当前 API 存在明显的限制,否则我们可能不太愿意添加新内容。话虽如此,我们始终渴望听到我们以前没有考虑过的情况,所以请不要害羞! :)
如果您需要修复一个 Bug 但没有人修复它,那么最好的办法是为它提供一个修复程序并创建一个 pull request。开源代码属于我们所有人,推动其向前发展是我们所有人的责任。
Pull request 只需要两个或更多协作者的批准即可合并;当 PR 作者是协作者时,这算作一个批准。
dev
分支。您可以在 GitHub 中创作 PR 时设置 base,在“Compare changes”标题下方的下拉列表中设置:
所有修复 Bug 或添加功能的提交都需要进行测试。
<blink>
不要在没有测试的情况下合并代码!</blink>
所有更改或添加到 API 的提交都必须在 pull request 中完成,该 pull request 还会更新所有相关的示例和文档。
文档位于 docs
目录中。一旦更改进入 main
分支,它们将自动发布到文档站点。
如果您想预览更改在文档站点上的外观,请克隆 react-router-website
仓库,并按照 README.md
中的说明在本地查看您的更改。
React Router 使用 monorepo 来托管多个包的代码。这些包位于 packages
目录中。
我们使用 pnpm 工作区来管理依赖项的安装和运行各种脚本。要安装所有内容,请确保您已安装 pnpm,然后从仓库根目录运行 pnpm install
。
从根目录调用 pnpm build
将运行构建,这应该只需要几秒钟。一起构建所有包非常重要,因为各个包彼此之间存在依赖关系。
在运行测试之前,您需要运行构建。构建完成后,从根目录运行 pnpm test
将运行每个包的测试。如果要为特定包运行测试,请使用 pnpm test --projects packages/<package-name>
# 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
这些版本将随着 PR 合并到 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