Skip to content

Commit

Permalink
Merge pull request dart-lang/package_config#115 from dart-lang/cleanup
Browse files Browse the repository at this point in the history
Misc cleanup
  • Loading branch information
mit-mit authored Sep 13, 2021
2 parents 0061cdb + 754c0a8 commit 0963c4c
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 14 deletions.
6 changes: 5 additions & 1 deletion pkgs/package_config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 2.0.2-dev
## 2.0.2

- Update package description and README.
- Change to package:lints for style checking.
- Add an example.

## 2.0.1

Expand Down
8 changes: 7 additions & 1 deletion pkgs/package_config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
Support for working with **Package Configuration** files as described
in the Package Configuration v2 [design document](https://github.com/dart-lang/language/blob/master/accepted/future-releases/language-versioning/package-config-file-v2.md).

The primary libraries are
A Dart package configuration file is used to resolve Dart package names (e.g.
`foobar`) to Dart files containing the source code for that package (e.g.
`file:///Users/myuser/.pub-cache/hosted/pub.dartlang.org/foobar-1.1.0`). The
standard package configuration file is `.dart_tool/package_config.json`, and is
written by the Dart tool when the command `dart pub get` is run.

The primary libraries of this package are
* `package_config.dart`:
Defines the `PackageConfig` class and other types needed to use
package configurations, and provides functions to find, read and
Expand Down
2 changes: 1 addition & 1 deletion pkgs/package_config/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# 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.

include: package:pedantic/analysis_options.1.9.0.yaml
include: package:lints/recommended.yaml
18 changes: 18 additions & 0 deletions pkgs/package_config/example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2020, 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 'package:package_config/package_config.dart';
import 'dart:io' show Directory;

void main() async {
var packageConfig = await findPackageConfig(Directory.current);
if (packageConfig == null) {
print('Failed to locate or read package config.');
} else {
print('This package depends on ${packageConfig.packages.length} packages:');
for (var package in packageConfig.packages) {
print('- ${package.name}');
}
}
}
8 changes: 7 additions & 1 deletion pkgs/package_config/lib/package_config_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
// BSD-style license that can be found in the LICENSE file.

/// A package configuration is a way to assign file paths to package URIs,
/// and vice-versa,
/// and vice-versa.
///
/// {@canonicalFor package_config.InvalidLanguageVersion}
/// {@canonicalFor package_config.LanguageVersion}
/// {@canonicalFor package_config.Package}
/// {@canonicalFor package_config.PackageConfig}
/// {@canonicalFor errors.PackageConfigError}
library package_config.package_config_types;

export 'src/package_config.dart'
Expand Down
4 changes: 2 additions & 2 deletions pkgs/package_config/lib/src/package_config_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final _jsonUtf8Decoder = json.fuse(utf8).decoder;
PackageConfig parsePackageConfigBytes(
Uint8List bytes, Uri file, void Function(Object error) onError) {
// TODO(lrn): Make this simpler. Maybe parse directly from bytes.
var jsonObject;
Object? jsonObject;
try {
jsonObject = _jsonUtf8Decoder.convert(bytes);
} on FormatException catch (e) {
Expand All @@ -47,7 +47,7 @@ PackageConfig parsePackageConfigBytes(

PackageConfig parsePackageConfigString(
String source, Uri file, void Function(Object error) onError) {
var jsonObject;
Object? jsonObject;
try {
jsonObject = jsonDecode(source);
} on FormatException catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions pkgs/package_config/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: package_config
version: 2.0.2-dev
description: Support for working with Package Configuration files.
version: 2.0.2
description: Support for reading and writing Dart Package Configuration files.
homepage: https://github.com/dart-lang/package_config

environment:
Expand All @@ -13,5 +13,5 @@ dev_dependencies:
build_runner: ^2.0.0
build_test: ^2.1.2
build_web_compilers: ^3.0.0
pedantic: ^1.10.0
lints: ^1.0.0
test: ^1.16.0
3 changes: 1 addition & 2 deletions pkgs/package_config/test/discovery_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ void main() {
'.packages': packagesFile,
'subdir': {'script.dart': 'main(){}'}
}, (Directory directory) async {
var config;
config = await findPackageConfig(subdir(directory, 'subdir/'));
var config = (await findPackageConfig(subdir(directory, 'subdir/')))!;
expect(config.version, 1);
validatePackagesFile(config, directory);
});
Expand Down
5 changes: 2 additions & 3 deletions pkgs/package_config/test/discovery_uri_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ void main() {
'.packages': packagesFile,
'subdir': {'script.dart': 'main(){}'}
}, (directory, loader) async {
var config;
config = await findPackageConfigUri(directory.resolve('subdir/'),
loader: loader);
var config = (await findPackageConfigUri(directory.resolve('subdir/'),
loader: loader))!;
expect(config.version, 1);
validatePackagesFile(config, directory);
});
Expand Down

0 comments on commit 0963c4c

Please sign in to comment.