pubspec_lock 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new73

pubspec_lock Build Status codecov pubspec_lock version

Dart library to access and manipulate content of pubpec.lock files

Class PubspecLock #

PubspecLock represents data stored in pubspec.lock files. It provides the following facilities:

class PubspecLock {
  final Iterable<SdkDependency> sdks;
  final Iterable<PackageDependency> packages;

  const PubspecLock({this.sdks = const {}, this.packages = const {}});
  factory PubspecLock.loadFromYamlString(String content);

  String toYaml();
}

Usage #

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

dependencies:
  pubspec_lock:

Full example #

The following Dart script checks whether all Dart dependencies are taken from pub.dev.

import 'dart:io';

import 'package:pubspec_lock/pubspec_lock.dart';

void main() {
  final fileContent = File('pubspec.lock').readAsStringSync();
  final pubspecLock = PubspecLock.loadFromYamlString(fileContent);
  print('Loaded pubspec.lock with '
        '${pubspecLock.packages.length} package dependencies:');

  final depsNotHostedByPubDev = [
    for (final package in pubspecLock.packages)
      if (!isHostedByPubDev(package))
        package
  ];

  if (depsNotHostedByPubDev.isEmpty)
    print('SUCCESS: All dependencies are hosted by pub.dev');
  else {
    print('WARNING: Dependencies hosted outside of pub.dev:');
    depsNotHostedByPubDev.forEach(print);
  }
}

bool isHostedByPubDev(PackageDependency package) =>
    package.iswitcho(
      hosted: (package) => package.url == 'https://pub.dartlang.org',
      otherwise: () => false,
    );

[1.1.0] - 2019-12-07

  • YAML formatting with json2yaml i.s.o. using ad-hoc YAML generator

[1.0.2] - 2019-11-24

  • README.md readability is improved

[1.0.1] - 2019-11-24

  • Fixed quality issues reported by pub.dev

[1.0.0] - 2019-11-24

  • PubspecLock is a data type representing data stored in pubspec.lock files.
  • Provides parser of pubspec.lock YAML string
  • Provides formatter to pubspec.lock YAML string
  • https://pub.dev/packages/functional_data is used to provide data type facilities

example/main.dart

import 'dart:io';

import 'package:pubspec_lock/pubspec_lock.dart';

// ignore_for_file: avoid_print

void main() {
  final pubspecLock = PubspecLock.loadFromYamlString(File('pubspec.lock').readAsStringSync());
  print('Loaded pubspec.lock with ${pubspecLock.packages.length} package dependencies:');

  final depsNotHostedByPubDev = [for (final package in pubspecLock.packages) if (!isHostedByPubDev(package)) package];

  if (depsNotHostedByPubDev.isEmpty) {
    print('SUCCESS: All dependencies are hosted by pub.dev');
  } else {
    print('WARNING: Dependencies hosted outside of pub.dev:');
    depsNotHostedByPubDev.forEach(print);
  }
}

bool isHostedByPubDev(PackageDependency package) =>
    package.iswitcho(hosted: (package) => package.url == 'https://pub.dartlang.org', otherwise: () => false);

Use this package as a library

1. Depend on it

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


dependencies:
  pubspec_lock: ^1.1.0

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_lock/pubspec_lock.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
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]
73
Learn more about scoring.

We analyzed this package on Dec 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4

Health suggestions

Format lib/src/git_package_dependency.g.dart.

Run dartfmt to format lib/src/git_package_dependency.g.dart.

Format lib/src/hosted_package_dependency.g.dart.

Run dartfmt to format lib/src/hosted_package_dependency.g.dart.

Format lib/src/internal/format_to_yaml.dart.

Run dartfmt to format lib/src/internal/format_to_yaml.dart.

Fix additional 8 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/internal/load_packages.dart (Run dartfmt to format lib/src/internal/load_packages.dart.)
  • lib/src/internal/load_sdks.dart (Run dartfmt to format lib/src/internal/load_sdks.dart.)
  • lib/src/package_dependency.dart (Run dartfmt to format lib/src/package_dependency.dart.)
  • lib/src/package_dependency.g.dart (Run dartfmt to format lib/src/package_dependency.g.dart.)
  • lib/src/path_package_dependency.g.dart (Run dartfmt to format lib/src/path_package_dependency.g.dart.)
  • lib/src/pubspec_lock.g.dart (Run dartfmt to format lib/src/pubspec_lock.g.dart.)
  • lib/src/sdk_dependency.g.dart (Run dartfmt to format lib/src/sdk_dependency.g.dart.)
  • lib/src/sdk_package_dependency.g.dart (Run dartfmt to format lib/src/sdk_package_dependency.g.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
functional_data ^0.2.0 0.2.3
json2yaml ^1.0.0 1.0.0+3
meta ^1.0.0 1.1.8
sum_types ^0.2.0 0.2.1+2
yaml ^2.0.0 2.2.0
Transitive dependencies
charcode 1.1.2
collection 1.14.12
path 1.6.4
source_span 1.5.5
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