Skip to content

[pubspec_parse] Add README usage examples #1807 - #2582

Merged
natebosch merged 2 commits into
dart-lang:mainfrom
AzazelSensei:docs-1807-pubspec-parse-readme
Sep 12, 2026
Merged

[pubspec_parse] Add README usage examples #1807#2582
natebosch merged 2 commits into
dart-lang:mainfrom
AzazelSensei:docs-1807-pubspec-parse-readme

Conversation

@AzazelSensei

Copy link
Copy Markdown
Contributor

Adds a Usage section to the pubspec_parse README so you can parse a pubspec without reading the library source. Covers hosted and path dependencies, loading from a file, and lenient mode.

Fixes #1807


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.

Document Pubspec.parse for hosted and path dependencies, file loading, and lenient parsing.

Fixes dart-lang#1807

@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 bumps the version of pubspec_parse to 1.6.1 and adds comprehensive usage examples to the README. Feedback is provided to use Uri.file instead of Uri.parse for cross-platform compatibility when loading a file path.

Comment thread pkgs/pubspec_parse/README.md Outdated

void main() {
final yaml = File('pubspec.yaml').readAsStringSync();
final pubspec = Pubspec.parse(yaml, sourceUrl: Uri.parse('pubspec.yaml'));

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.

medium

Using Uri.parse with a file path is discouraged in Dart because it does not handle platform-specific path separators (like backslashes on Windows) or special characters correctly. Instead, use Uri.file to ensure cross-platform compatibility.

Suggested change
final pubspec = Pubspec.parse(yaml, sourceUrl: Uri.parse('pubspec.yaml'));
final pubspec = Pubspec.parse(yaml, sourceUrl: Uri.file('pubspec.yaml'));

@natebosch natebosch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about making an example directory and moving the Dart code there? I think that's a bit more reader friendly than complete blocks of of Dart in the readme.

@natebosch natebosch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clicked the wrong button when asking for a move to example/

Point the README at example/example.dart instead of inlining the Dart.
@AzazelSensei

Copy link
Copy Markdown
Contributor Author

Moved the Dart samples into example/ and pointed the README at that.

@natebosch

Copy link
Copy Markdown
Member

Thanks!

@natebosch
natebosch merged commit d9320c7 into dart-lang:main Sep 12, 2026
22 checks passed
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.

Add some examples and usage details in the readme.

2 participants