Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Add support for writing defaultPackageName and fragment in .packages #54

Merged
merged 1 commit into from
Sep 2, 2019

Conversation

jonasfj
Copy link
Member

@jonasfj jonasfj commented Aug 28, 2019

  • Added support for writing a defaultPackageName.
  • Fixed bug when Uri included a fragment.
  • More tests (added utf8 test cases).

@jonasfj jonasfj requested a review from lrhn August 28, 2019 14:17
lib/packages_file.dart Outdated Show resolved Hide resolved
@@ -106,10 +106,13 @@ Map<String, Uri> parse(List<int> source, Uri baseLocation,
/// If [baseUri] is provided, package locations will be made relative
/// to the base URI, if possible, before writing.
///
/// If [defaultPackageName] is provided, the output will contain a
/// `:<defaultPackageName>` entry.
Copy link
Member

@lrhn lrhn Aug 29, 2019

Choose a reason for hiding this comment

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

If defaultPackageName is provided, then the map must not contain an empty-named entry, otherwise it can (and we should probably check that it has a valid package name as value), and then that will be the default package name (and not get a trailing /).

That's the format you get when reading a .packages file, so we should support writing it too.

@jonasfj jonasfj force-pushed the write-default-package-name branch from 9a2311c to e7c5b8a Compare September 2, 2019 11:33
@jonasfj jonasfj requested a review from lrhn September 2, 2019 11:33
Copy link
Member

@lrhn lrhn left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

/// All the keys of [packageMapping] must be valid package names,
/// and the values must be URIs that do not have the `package:` scheme.
void write(StringSink output, Map<String, Uri> packageMapping,
{Uri baseUri, String comment}) {
{Uri baseUri, String comment, bool allowDefaultPackage = false}) {
ArgumentError.checkNotNull(allowDefaultPackage, 'allowDefaultPackage');
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't bother with this check. It will fail below if the value is null, and an optional parameter with a non-null default value is only null if someone explicitly passes that.
It is not documented that null is accepted, so that should be assumed to be an error, and so rare that I don't want to add code for it.

(When comes NNBD, this check will be unnecessary anyway).

Now it's here, it's fine, but not something I'd usually bother doing.

@@ -128,6 +133,21 @@ void write(StringSink output, Map<String, Uri> packageMapping,
}

packageMapping.forEach((String packageName, Uri uri) {
// If [packageName] is empty then [uri] is the _default package name_.
if (allowDefaultPackage && packageName.isEmpty) {
final defaultPackageName = uri.toString();
Copy link
Member

Choose a reason for hiding this comment

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

Don't bother using final for local variables. Just use var.

That's just personal style, but it's my package 😁.

(You can let it stay, I'll just remove it later).

@lrhn lrhn merged commit 3fb3733 into dart-lang:master Sep 2, 2019
mosuem pushed a commit to dart-lang/tools that referenced this pull request Dec 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants