humanize method

Uri humanize(
  1. Uri canonicalUrl
)

Return a human-friendly URL for canonicalUrl to use in a stack trace.

Returns canonicalUrl as-is if it hasn't been loaded by this cache.

Implementation

Uri humanize(Uri canonicalUrl) =>
    // If multiple original URLs canonicalize to the same thing, choose the
    // shortest one.
    minBy<Uri, int>(
            _canonicalizeCache.values
                .whereNotNull()
                .where((result) => result.$2 == canonicalUrl)
                .map((result) => result.originalUrl),
            (url) => url.path.length)
        // Use the canonicalized basename so that we display e.g.
        // package:example/_example.scss rather than package:example/example
        // in stack traces.
        .andThen((url) => url.resolve(p.url.basename(canonicalUrl.path))) ??
    // If we don't have an original URL cached, display the canonical URL
    // as-is.
    canonicalUrl;