@@ -105,13 +105,13 @@ Uri normalizeDartUrl(Uri url) => url.pathSegments.isNotEmpty
105105 ? url.replace (pathSegments: url.pathSegments.take (1 ))
106106 : url;
107107
108- /// Returns a `package:` URL into a `asset:` URL.
108+ /// Returns a `package:` URL converted to a `asset:` URL.
109109///
110110/// This makes internal comparison logic much easier, but still allows users
111111/// to define assets in terms of `package:` , which is something that makes more
112112/// sense to most.
113113///
114- /// For example this transforms `package:source_gen/source_gen.dart` into:
114+ /// For example, this transforms `package:source_gen/source_gen.dart` into:
115115/// `asset:source_gen/lib/source_gen.dart` .
116116Uri packageToAssetUrl (Uri url) => url.scheme == 'package'
117117 ? url.replace (
@@ -122,6 +122,24 @@ Uri packageToAssetUrl(Uri url) => url.scheme == 'package'
122122 ..addAll (url.pathSegments.skip (1 )))
123123 : url;
124124
125+ /// Returns a `asset:` URL converted to a `package:` URL.
126+ ///
127+ /// For example, this transformers `asset:source_gen/lib/source_gen.dart' into:
128+ /// `package:source_gen/source_gen.dart` . Asset URLs that aren't pointing to a
129+ /// file in the 'lib' folder are not modified.
130+ ///
131+ /// Asset URLs come from `package:build` , as they are able to describe URLs that
132+ /// are not describable using `package:...` , such as files in the `bin` , `tool` ,
133+ /// `web` , or even root directory of a package - `asset:some_lib/web/main.dart` .
134+ Uri assetToPackageUrl (Uri url) => url.scheme == 'asset' &&
135+ url.pathSegments.length >= 1 &&
136+ url.pathSegments[1 ] == 'lib'
137+ ? url.replace (
138+ scheme: 'package' ,
139+ pathSegments: [url.pathSegments.first]
140+ ..addAll (url.pathSegments.skip (2 )))
141+ : url;
142+
125143/// Returns all of the declarations in [unit] , including [unit] as the first
126144/// item.
127145Iterable <Element > getElementsFromLibraryElement (LibraryElement unit) sync * {
0 commit comments