Skip to content

[pubspec_parse] Expose version constraint on PathDependency - #2581

Merged
kevmoo merged 3 commits into
dart-lang:mainfrom
hkarmoush:pubspec_parse-fix-git-path-version-constraint-1809
Oct 19, 2026
Merged

kevmoo merged 3 commits into
dart-lang:mainfrom
hkarmoush:pubspec_parse-fix-git-path-version-constraint-1809

Conversation

@hkarmoush

@hkarmoush hkarmoush commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

A version key alongside path is silently dropped today, even though pub's solver still validates it against the resolved package's version. Parse and expose it instead of discarding it, matching the version field already exposed on GitDependency.

(This originally also touched GitDependency, but that's since landed separately via the tag-pattern work, so this PR is now scoped to PathDependency only.)

Fixes #1809

Test plan

  • dart test — all 122 tests pass
  • dart analyze — no issues
  • dart format — clean
  • Added regression tests: path dep with a version key, default (null) when absent, and invalid/non-String version values

@hkarmoush
hkarmoush requested a review from a team September 3, 2026 09:56

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for exposing the version constraint key in GitDependency and PathDependency instead of silently discarding it. It updates constructors, serialization, equality checks, and adds corresponding tests. Feedback was provided regarding PathDependency.fromData where casting version as String? could lead to a runtime TypeError if a VersionConstraint object is passed directly; a type check is suggested to make the factory constructor more robust.

@hkarmoush
hkarmoush force-pushed the pubspec_parse-fix-git-path-version-constraint-1809 branch from 2184543 to 6caacfe Compare October 4, 2026 18:48
@hkarmoush hkarmoush changed the title [pubspec_parse] Expose version constraint on GitDependency and PathDependency [pubspec_parse] Expose version constraint on PathDependency Oct 4, 2026
@hkarmoush

Copy link
Copy Markdown
Contributor Author

Addressed the review comment in 6caacfe (and rebased):

  • PathDependency.fromData's version parameter is now typed VersionConstraint? directly instead of Object?, so there's no as String? cast that could throw if a caller passes an already-parsed VersionConstraint programmatically.

The GitDependency half of this PR's original diff has since landed separately via the tagPattern work (GitDependency.version and fromData's typed signature), so this PR is now rebased and scoped to PathDependency only. Updated the title/description to match.

@kevmoo

kevmoo commented Oct 19, 2026

Copy link
Copy Markdown
Member

Could you make three quick updates so we can land this?

  1. Fix cla/google check: Commit 6caacfe includes a Co-Authored-By: Claude Sonnet 5 <[email protected]> trailer, which causes the Google CLA bot to fail on [email protected]. Please amend the commit message to remove the Co-Authored-By line.
  2. Rebase on main: Resolve the small conflict in pkgs/pubspec_parse/CHANGELOG.md.
  3. Add toJson test coverage: In pkgs/pubspec_parse/test/tojson_test.dart (inside the 'dependencies' test), add a PathDependency case with a version constraint and assert its .toJson() output (similar to the 'kittens' GitDependency check at lines 225–291).

A `version` key alongside `path` is silently dropped today, even though
pub's solver still validates it against the resolved package's version.
Parse and expose it instead of discarding it, matching the `version`
field already exposed on GitDependency.

Generalizes `_optionalConstraintFromData` (previously GitDependency-only)
to take a className for its error messages, so both dependency types get
correctly attributed parse errors.
@hkarmoush
hkarmoush force-pushed the pubspec_parse-fix-git-path-version-constraint-1809 branch from 6caacfe to 871f5e9 Compare October 19, 2026 20:47
@hkarmoush

Copy link
Copy Markdown
Contributor Author

Thanks, all three done. Dropped the Co-Authored-By trailer from the commit message so the CLA check should pass now, rebased on main (kept both changelog entries), and added a PathDependency with a version constraint to the toJson test, including the round trip.

@kevmoo

kevmoo commented Oct 19, 2026

Copy link
Copy Markdown
Member

please fix the changelog churn! (just landed those, sorry)

…-path-version-constraint-1809

# Conflicts:
#	pkgs/pubspec_parse/CHANGELOG.md
@kevmoo
kevmoo merged commit 7a4ea6f into dart-lang:main Oct 19, 2026
22 checks passed
copybara-service Bot pushed a commit to dart-lang/sdk that referenced this pull request Oct 20, 2026
tools (https://github.com/dart-lang/tools/compare/f6c7a2d..4d7715a):
  4d7715ac  Mon Oct 19 16:09:30 2026 -0700  Kevin Moore  Replace `@dart-lang/dart-bat` with `@dart-lang/dart-ecosystem-team` in `CODEOWNERS` (dart-lang/tools#2697)
  a22c558c  Tue Oct 20 06:56:10 2026 +0900  YeungKC  [markdown] Check the first character before inline syntax regexes (dart-lang/tools#2695)
  c57bde49  Mon Oct 19 14:40:39 2026 -0700  dart-ecosystem-bot[bot]  [boring] Update BoringSSL to 64188f17 (dart-lang/tools#2692)
  7a4ea6f8  Tue Oct 20 00:09:47 2026 +0300  Hasan Armoush  [pubspec_parse] Expose version constraint on PathDependency (dart-lang/tools#2581)
  85e03753  Mon Oct 19 22:41:32 2026 +0200  Lukas Klingsbo  [pubspec_parse] Add hooks field to Pubspec (dart-lang/tools#2568)
  13139ec6  Mon Oct 19 22:28:47 2026 +0200  Lukas Klingsbo  [pubspec_parse] Add false_secrets field to Pubspec (dart-lang/tools#2567)
  462d92bf  Mon Oct 19 21:56:25 2026 +0200  Lukas Klingsbo  [pubspec_parse] Add platforms field to Pubspec (dart-lang/tools#2566)

TEST=ci

Change-Id: I106b05a08a7395f72e01a86a952abd41f4630831
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/566840
Commit-Queue: Kevin Moore <[email protected]>
Reviewed-by: Nate Bosch <[email protected]>
@kevmoo

kevmoo commented Oct 21, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution! Published in pubspec_parse 1.7.0.

@hkarmoush

Copy link
Copy Markdown
Contributor Author

Thanks for the quick merge and release, @kevmoo! I also posted a rough design for additionalProperties on #1816 last week. Whenever you get a chance, I'd value your take before I start on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitDependency and PathDependency can have version constraints

2 participants