pubspec_parse
1.7.0, released 4 weeks ago by tools.dart.dev
Parse pubspec.yaml files with a type‑safe API and detailed error reporting.
What it does
Provides classes to read and write pubspec.yaml content, exposing hosted, git, and path dependencies as typed objects. Supports lenient parsing, preserves map spans, and can serialize back to a Map.
AI-written summary of version 1.7.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to validate or transform a pubspec.yaml in a tool or CI step
- You are building a CLI that inspects package metadata
- You want a robust, typed representation of pubspec fields for analysis
Skip it when
- Parsing arbitrary YAML where a generic parser is sufficient
- Runtime pubspec parsing in a production Flutter app where size matters
Strengths
- Typed API for all pubspec fields
- Rich, precise error messages via checked_yaml
- Supports latest Dart pubspec features (git tag_pattern, falseSecrets, hooks, platforms)
- Lenient mode to ignore unknown keys
Weaknesses
- Specialized to pubspec files only, not a general YAML library
- No code‑generation support
- Adds another dependency if you already use a generic YAML parser
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 5
import 'package:pubspec_parse/pubspec_parse.dart';
void main() {
const yaml = '''name: my_pkg\nversion: 1.0.0\ndependencies:\n http: ^0.13.0''';
final pubspec = Pubspec.parse(yaml);
print(pubspec.name); // my_pkg
}Alternatives
Packages that do the same job and could replace pubspec_parse.
- deep_pick
Type-safe API for manual JSON parsing with useful error messages.
91Compare - pubspec_manager
Type-safe API to read, modify, and write pubspec.yaml while preserving comments.
78Compare - config
Typed CLI argument and config file parser with env support
84Compare - dart_either
Either monad for Dart and Flutter supporting type-safe error handling and railway-oriented programming.
81Compare
Works with
Packages commonly used together with pubspec_parse: ones it builds on, ones built on it, and its own family.
- yamlpubspec_parse depends on itA Dart library for parsing YAML documents into Dart data structures.
- pub_semverpubspec_parse depends on itVersions and version constraints implementing pub's versioning policy.
- json_annotationpubspec_parse depends on itProvides annotations for json_serializable to generate JSON (de)serialization code.
- checked_yamlpubspec_parse depends on itProvides checkedYamlDecode to give detailed errors when decoding YAML with json_serializable.
- analyzerSame familyPerforms static analysis of Dart code for tool integration and embedding.
- dart_styleSame familyProvides an API and CLI to format Dart source code automatically.
- coverageSame familyCollects, manipulates, and formats code coverage data in Dart
- cli_configSame familyLibrary to read config from CLI args, env vars, and JSON/YAML files