dart-package-maintenance
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDart Package Maintenance
Dart包维护
Guidelines for maintaining Dart packages in alignment with Dart team best
practices.
符合Dart团队最佳实践的Dart包维护指南。
Versioning
版本管理
Semantic Versioning
语义化版本
- Major: Breaking changes.
- Minor: New features (non-breaking API changes).
- Patch: Bug fixes, documentation, or non-impacting changes.
- Unstable packages: Use .
0.major.minor+patch - Recommendation: Aim for as soon as the package is stable.
1.0.0
- 主版本号(Major):包含不兼容的破坏性变更。
- 次版本号(Minor):新增功能(API变更向前兼容)。
- 修订号(Patch):修复漏洞、更新文档,或是不影响功能的改动。
- 不稳定包:采用格式命名版本。
0.major.minor+patch - 建议:一旦包功能稳定,尽快发布版本。
1.0.0
Pre-Edit Verification
编辑前校验
-
Check Published Versions: Before modifyingor
CHANGELOG.md, ALWAYS check the currently released version (e.g., viapubspec.yamlorgit tag).pub.dev -
Do Not Amend Released Versions: Never add new entries to a version header that corresponds to a released tag.
-
Increment for New Changes: If the current version inmatches a released tag, increment the version (e.g., usually to
pubspec.yaml) and create a new section in-wip.CHANGELOG.md-
Consistency: Theheader must match the new
CHANGELOG.mdversion.pubspec.yaml -
SemVer Guidelines:
- Breaking Changes: Bump Major, reset Minor/Patch
(e.g., ,
2.0.0-wip).0.5.0-wip - New Features: Bump Minor, reset Patch
(e.g., ,
1.1.0-wip).0.4.5-wip - Bug Fixes: Bump Patch (e.g., ).
1.0.1-wip
- Breaking Changes: Bump Major, reset Minor/Patch
(e.g.,
-
-
检查已发布版本:修改或
CHANGELOG.md之前,务必检查当前已发布的版本(可通过pubspec.yaml或git tag查询)。pub.dev -
不得修改已发布版本:严禁在对应已发布标签的版本标题下新增更新条目。
-
新改动需升级版本:如果中的当前版本与已发布标签一致,需要升级版本号(通常添加
pubspec.yaml后缀),并在-wip中新增对应版本的更新章节。CHANGELOG.md-
一致性要求:中的版本标题必须与
CHANGELOG.md中的新版本号完全一致。pubspec.yaml -
语义化版本规范:
- 破坏性变更:升级主版本号,重置次版本号和修订号(例如、
2.0.0-wip)。0.5.0-wip - 新增功能:升级次版本号,重置修订号(例如、
1.1.0-wip)。0.4.5-wip - 漏洞修复:升级修订号(例如)。
1.0.1-wip
- 破坏性变更:升级主版本号,重置次版本号和修订号(例如
-
Work-in-Progress (WIP) Versions
开发中(WIP)版本
- Immediately after a publish, or on the first change after a publish, update
and
pubspec.yamlwith aCHANGELOG.mdsuffix (e.g.,-wip).1.1.0-wip - This indicates the current state is not yet published.
- 版本发布后立刻,或是发布后首次提交改动时,更新和
pubspec.yaml中的版本号,添加CHANGELOG.md后缀(例如-wip)。1.1.0-wip - 该后缀表示当前代码状态尚未发布。
Breaking Changes
破坏性变更
- Evaluate the impact on dependent packages and internal projects.
- Consider running changes through internal presubmits if possible.
- Prefer incremental rollouts (e.g., new behavior as opt-in) to minimize downstream breakage.
- 评估变更对依赖包和内部项目的影响。
- 条件允许的话,建议先通过内部预提交测试验证改动。
- 优先采用渐进式发布策略(例如新功能默认关闭,用户可手动开启),尽可能降低对下游项目的影响。
Publishing Process
发布流程
- Preparation: Remove the suffix from
-wipandpubspec.yamlin a dedicated pull request.CHANGELOG.md - Execution: Run (or
dart pub publish) and resolve all warnings and errors.flutter pub publish - Tagging: Create and push a git tag for the published version:
- For single-package repos:
v1.2.3 - For monorepos:
package_name-v1.2.3 - Example:
git tag v1.2.3 && git push --tags
- For single-package repos:
- 准备工作:在单独的拉取请求中移除和
pubspec.yaml版本号中的CHANGELOG.md后缀。-wip - 执行发布:运行(或
dart pub publish)命令,解决所有警告和错误。flutter pub publish - 打标签:为已发布的版本创建并推送git标签:
- 单包仓库:格式为
v1.2.3 - 多包monorepo仓库:格式为
包名-v1.2.3 - 示例命令:
git tag v1.2.3 && git push --tags
- 单包仓库:格式为
Pull Request Management
拉取请求(PR)管理
- Commits: Each PR should generally correspond to a single squashed commit upon merging.
- Shared History: Once a PR is open, avoid force pushing to the branch.
- Conflict Resolution: Prefer merging into the PR branch rather than rebasing to resolve conflicts. This preserves the review history and comments.
main - Reviewing: Add comments from the "Files changed" view to batch them.
- Local Inspection: Use to inspect changes locally in your IDE.
gh pr checkout <number>
- 提交规范:每个PR合并时通常应压缩为单个提交。
- 提交历史共享:PR创建后,避免对分支执行强制推送操作。
- 冲突解决:解决冲突时优先将分支合并到PR分支,而非变基,这样可以保留评审历史和评论内容。
main - 评审规范:在“文件变更”视图中批量添加评审评论。
- 本地校验:使用命令将PR拉取到本地,在IDE中查看改动。
gh pr checkout <PR编号>