pubspec_yaml 1.0.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • new74

pubspec_yaml Build Status codecov pubspec_lock version

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 package

Other fields are accessible via PubspecYaml.customFields as a JSON structure (Map<String, dynamic>).

YAML Import / Export #

PubspecYaml provides two methods to serialize pubspec.yaml content:

  • The factory method PubspecYaml.loadFromYamlString() creates an object from a string with pubspec.yaml content
  • 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).

Usage #

To use pubspec_yaml, add the following dependency to pubspec.yaml:

dependencies:
  pubspec_yaml: ^1.0.0

Example #

The following Dart script checks whether production dependencies have overrides:

import 'dart:io';

import 'package:pubspec_yaml/pubspec_yaml.dart';

// ignore_for_file: avoid_print

void main() {
  final pubspecYamlContent = File('pubspec.yaml').readAsStringSync();
  final pubspecYaml = PubspecYaml.loadFromYamlString(pubspecYamlContent);

  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);
  }
}

[1.0.0+1] - 2019-12-22

  • README.md correction

[1.0.0] - 2019-12-22

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 package

Other fields are accessible via PubspecYaml.customFields as a JSON structure (Map<String, dynamic>).

example/main.dart

import 'dart:io';

import 'package:pubspec_yaml/pubspec_yaml.dart';

// ignore_for_file: avoid_print

void main() {
  final pubspecYamlContent = File('pubspec.yaml').readAsStringSync();
  final pubspecYaml = PubspecYaml.loadFromYamlString(pubspecYamlContent);

  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);
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  pubspec_yaml: ^1.0.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:pubspec_yaml/pubspec_yaml.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
48
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Format lib/src/dependency_specs/git_package_dependency_spec.g.dart.

Run dartfmt to format lib/src/dependency_specs/git_package_dependency_spec.g.dart.

Format lib/src/dependency_specs/hosted_package_dependency_spec.g.dart.

Run dartfmt to format lib/src/dependency_specs/hosted_package_dependency_spec.g.dart.

Format lib/src/dependency_specs/path_package_dependency_spec.dart.

Run dartfmt to format lib/src/dependency_specs/path_package_dependency_spec.dart.

Fix additional 7 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/dependency_specs/path_package_dependency_spec.g.dart (Run dartfmt to format lib/src/dependency_specs/path_package_dependency_spec.g.dart.)
  • lib/src/dependency_specs/sdk_package_dependency_spec.g.dart (Run dartfmt to format lib/src/dependency_specs/sdk_package_dependency_spec.g.dart.)
  • lib/src/internal/load_from_yaml.dart (Run dartfmt to format lib/src/internal/load_from_yaml.dart.)
  • lib/src/internal/yaml_formatter.dart (Run dartfmt to format lib/src/internal/yaml_formatter.dart.)
  • lib/src/package_dependency_spec.dart (Run dartfmt to format lib/src/package_dependency_spec.dart.)
  • lib/src/package_dependency_spec.g.dart (Run dartfmt to format lib/src/package_dependency_spec.g.dart.)
  • lib/src/pubspec_yaml.g.dart (Run dartfmt to format lib/src/pubspec_yaml.g.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
collection ^1.14.0 1.14.12
functional_data ^0.2.0 0.2.3
json2yaml ^1.0.1 1.0.1
meta ^1.1.0 1.1.8
plain_optional ^0.1.0 0.1.3
sum_types ^0.2.0 0.2.1+2
yaml ^2.2.0 2.2.0
Transitive dependencies
charcode 1.1.2
path 1.6.4
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
Dev dependencies
build_runner ^1.7.0
dependency_validator ^1.0.0
functional_data_generator ^0.2.0
sum_types_generator ^0.2.0
test ^1.8.0
test_coverage ^0.3.0