fix(pubspec): pin hosted dependency versions from pubspec.lock to speed up pub get - #118
Closed
qinshah wants to merge 1 commit into
Closed
fix(pubspec): pin hosted dependency versions from pubspec.lock to speed up pub get#118qinshah wants to merge 1 commit into
qinshah wants to merge 1 commit into
Conversation
Speeds up `flutter pub get` by reducing version resolution work for hosted packages: all `^x.y.z` and `any` constraints in dependencies / dependency_overrides / dev_dependencies are replaced with the exact version resolved in pubspec.lock. Git dependencies are intentionally LEFT UNTOUCHED. Their `ref:` is a branch/tag name and other git packages may reference them by that name (e.g. audio_service depends on audio_session at br_v0.2.2_ohos). Rewriting ref to a commit SHA breaks pub's version solving. Commented-out entries and non-deps sections (flutter_launcher_icons, flutter_native_splash, flutter:) are left untouched. Also adds scripts/pin_pubspec.py, the script used to regenerate this file from pubspec.lock (reusable next time lock is updated).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
固定 pubspec.yaml 中 hosted 依赖的版本,加速 pub get
变更内容
通过 scripts/pin_pubspec.py 脚本,从当前
pubspec.lock反向改写pubspec.yaml:dependencies/dependency_overrides/dev_dependencies中所有^x.y.z形式的版本约束,替换为 lock 里解析出的精确版本any约束(vector_math、fixnum、json_annotation、collection等)替换为 lock 里的精确版本sdk: flutter、flutter_launcher_icons/flutter_native_splash/flutter:等 section 不动Git 依赖不动
ref: <branch/tag>保持原样不改写为 commit SHA。原因:git 包之间会通过 ref 名字互相引用,例如
audio_service(git 依赖)的 pubspec 里指定了audio_session的 ref 是br_v0.2.2_ohos。如果把audio_session的 ref 改成 commit SHA,pub 解析时两者约束不匹配,version solving 直接失败。所以 git 包的 ref 不能动。验证结果
在
qinshah/PiliPlus的fix/pubspec-pin-versions分支上手动触发了 pr_check workflow,flutter pub get和dart analyze全部通过:完整的 Actions 运行历史可以到 https://github.com/qinshah/PiliPlus/actions 查看。
附带脚本
scripts/pin_pubspec.py是用于生成此次改动的脚本,下次 lock 更新后可以重新跑一遍来重新 pin 版本,保持依赖版本与 lock 一致。