[pubspec_parse] Add README usage examples #1807 - #2582
Merged
natebosch merged 2 commits intoSep 12, 2026
Conversation
Document Pubspec.parse for hosted and path dependencies, file loading, and lenient parsing. Fixes dart-lang#1807
|
|
||
| void main() { | ||
| final yaml = File('pubspec.yaml').readAsStringSync(); | ||
| final pubspec = Pubspec.parse(yaml, sourceUrl: Uri.parse('pubspec.yaml')); |
Contributor
There was a problem hiding this comment.
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
approved these changes
Sep 11, 2026
natebosch
left a comment
Member
There was a problem hiding this comment.
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
requested changes
Sep 11, 2026
natebosch
left a comment
Member
There was a problem hiding this comment.
Clicked the wrong button when asking for a move to example/
Point the README at example/example.dart instead of inlining the Dart.
Contributor
Author
|
Moved the Dart samples into example/ and pointed the README at that. |
natebosch
approved these changes
Sep 12, 2026
Member
|
Thanks! |
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.
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
Contribution guidelines:
dart format.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.