pubspec_lock 1.0.1 copy "pubspec_lock: ^1.0.1" to clipboard
pubspec_lock: ^1.0.1 copied to clipboard

outdated

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

pubspec_lock Build Status codecov #

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

Class PubspecLock #

PubspecLock is a data type representing 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 check whether all Dart dependencies are taken from pub.dev.

import 'dart:io';

import 'package:pubspec_lock/pubspec_lock.dart';

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);
4
likes
0
pub points
72%
popularity

Publisher

verified publisherdart-borg.dev

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

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

functional_data, meta, sum_types, yaml

More

Packages that depend on pubspec_lock