Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make .packages files be more clever about defaults. #80

Merged
merged 3 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Updated to support new rules for picking `package_config.json` over
a specified `.packages`.
- Deduce package root from `.packages` derived package configuration,
and default all such packages to language version 2.7.

## 1.9.1

Expand Down
21 changes: 17 additions & 4 deletions lib/src/packages_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import "package_config_impl.dart";
import "util.dart";
import "errors.dart";

/// The language version prior to the release of language versioning.
///
/// This is the default language version used by all packages from a
/// `.packages` file.
final LanguageVersion _languageVersion = LanguageVersion(2, 7);

/// Parses a `.packages` file into a [PackageConfig].
///
/// The [source] is the byte content of a `.packages` file, assumed to be
Expand Down Expand Up @@ -100,17 +106,24 @@ PackageConfig parse(
"Package URI as location for package", source, separatorIndex + 1));
continue;
}
if (!packageLocation.path.endsWith('/')) {
packageLocation =
packageLocation.replace(path: packageLocation.path + "/");
var path = packageLocation.path;
if (!path.endsWith('/')) {
path += "/";
packageLocation = packageLocation.replace(path: path);
}
if (packageNames.contains(packageName)) {
onError(PackageConfigFormatException(
"Same package name occured more than once", source, start));
continue;
}
var rootUri = packageLocation;
if (path.endsWith("/lib/")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this always be relative to something else? That is, can path ever be lib/?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "root" package will have a path of lib/.

Copy link
Member Author

@lrhn lrhn Mar 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URI reference from the file has already been resolved against the base URI at this point. It can't be lib/ unless the base URI is empty (which it must not be).

// Assume default Pub package layout. Include package itself in root.
rootUri =
packageLocation.replace(path: path.substring(0, path.length - 4));
}
var package = SimplePackage.validate(
packageName, packageLocation, packageLocation, null, null, (error) {
packageName, rootUri, packageLocation, _languageVersion, null, (error) {
if (error is ArgumentError) {
onError(PackageConfigFormatException(error.message, source));
} else {
Expand Down