https://github.com/alexei-sintotski/pubspec_yaml
Dart library to access and manipulate content of pubpec.yaml files
https://github.com/alexei-sintotski/pubspec_yaml
dart flutter pub pubspec
Last synced: 2 months ago
JSON representation
Dart library to access and manipulate content of pubpec.yaml files
- Host: GitHub
- URL: https://github.com/alexei-sintotski/pubspec_yaml
- Owner: alexei-sintotski
- License: mit
- Created: 2019-11-30T07:21:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-25T11:14:20.000Z (over 3 years ago)
- Last Synced: 2025-04-09T20:07:20.319Z (2 months ago)
- Topics: dart, flutter, pub, pubspec
- Language: Dart
- Homepage:
- Size: 161 KB
- Stars: 6
- Watchers: 2
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# pubspec_yaml [](https://travis-ci.org/alexei-sintotski/pubspec_yaml) [](https://codecov.io/gh/alexei-sintotski/pubspec_yaml) [](https://pub.dev/packages/pubspec_yaml)
Dart library to access and manipulate content of pubpec.yaml files
## Class PubspecYaml
PubspecYaml is a data type representing data stored in pubspec.yaml files.
The following fields are supported:
* Package name
* Package version
* Package description
* Package author/authors
* Package homepage, repository, and issue tracker
* Package documentation
* Package server specification
* Dependency specifications: regular, dev, and overrides
* SDK constraints
* Command-line executables provided by the packageOther fields are accessible via PubspecYaml.customFields as a JSON structure (Map).
## YAML Import
PubspecYaml provides two methods to import pubspec.yaml content:
* The factory method PubspecYaml.loadFromYamlString() creates an object from a string with pubspec.yaml content
* String extension method toPubspecYaml()## YAML Export
PubspecYaml.toYamlString() produces pubspec.yaml content that can be written to a file
## Data Manipulation
PubspecYaml uses functional_data extensions to enable equality operations and lenses (https://pub.dev/packages/functional_data).
## Example
The following Dart script checks whether production dependencies have overrides:
```
void main() {
final pubspecYaml = File('pubspec.yaml').readAsStringSync().toPubspecYaml();final productionOverrides = pubspecYaml.dependencyOverrides.where(
(override) => pubspecYaml.dependencies.any((
productionDependency,
) =>
productionDependency.package() == override.package()),
);if (productionOverrides.isEmpty) {
print('SUCCESS: No overrides of production dependencies detected');
} else {
print('WARNING: Overrides of production dependencies detected:');
productionOverrides.forEach(print);
}
}
```