Skip to main content

pubspec_parse 1.7.0 copy "pubspec_parse: ^1.7.0" to clipboard
pubspec_parse: ^1.7.0 copied to clipboard

Simple package for parsing pubspec.yaml files with a type-safe API and rich error reporting.

example/example.dart

// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:pubspec_parse/pubspec_parse.dart';

void main() {
  const yaml = '''
name: my_package
version: 1.2.3
environment:
  sdk: ^3.8.0
dependencies:
  collection: ^1.19.0
  path:
    path: ../path
''';

  final pubspec = Pubspec.parse(yaml);
  print(pubspec.name); // my_package
  print(pubspec.version); // 1.2.3

  final collection = pubspec.dependencies['collection'];
  if (collection is HostedDependency) {
    print(collection.version); // ^1.19.0
  }

  final path = pubspec.dependencies['path'];
  if (path is PathDependency) {
    print(path.path); // ../path
  }

  final fromFile = File('pubspec.yaml').readAsStringSync();
  final parsedFile = Pubspec.parse(
    fromFile,
    sourceUrl: Uri.file('pubspec.yaml'),
  );
  print('${parsedFile.name} ${parsedFile.version}');
}
59
likes
160
points
14M
downloads

Documentation

API reference

Publisher

verified publishertools.dart.dev

Weekly Downloads

Simple package for parsing pubspec.yaml files with a type-safe API and rich error reporting.

Repository (GitHub)
View/report issues
Contributing

Topics

#dart-pub

License

BSD-3-Clause (license)

Dependencies

checked_yaml, collection, json_annotation, pub_semver, yaml

More

Packages that depend on pubspec_parse