| Index: sdk/lib/_internal/pub/lib/src/barback.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/barback.dart b/sdk/lib/_internal/pub/lib/src/barback.dart
|
| index aba25de217427eb9eb6e5efc348534427bae24a8..a93d519e8104991b51c945b366d7c25dfdb8cdc6 100644
|
| --- a/sdk/lib/_internal/pub/lib/src/barback.dart
|
| +++ b/sdk/lib/_internal/pub/lib/src/barback.dart
|
| @@ -184,3 +184,52 @@ AssetId specialUrlToId(Uri url) {
|
|
|
| return null;
|
| }
|
| +
|
| +/// Converts [id] to a "servable path" for that asset.
|
| +///
|
| +/// This is the relative URL that could be used to request that asset from pub
|
| +/// serve. It's also the relative path that the asset will be output to by
|
| +/// pub build (except this always returns a path using URL separators).
|
| +///
|
| +/// [entrypoint] is the name of the entrypoint package.
|
| +///
|
| +/// Examples (where [entrypoint] is "myapp"):
|
| +///
|
| +/// myapp|web/index.html -> index.html
|
| +/// myapp|lib/lib.dart -> packages/myapp/lib.dart
|
| +/// foo|lib/foo.dart -> packages/foo/foo.dart
|
| +/// foo|asset/foo.png -> assets/foo/foo.png
|
| +/// myapp|test/main.dart -> ERROR
|
| +/// foo|web/
|
| +///
|
| +/// Throws a [FormatException] if [id] is not a valid public asset.
|
| +String idtoUrlPath(String entrypoint, AssetId id) {
|
| + var parts = path.url.split(id.path);
|
| +
|
| + if (parts.length < 2) {
|
| + throw new FormatException(
|
| + "Can not serve asset from top-level directory.");
|
| + }
|
| +
|
| + // Each top-level directory gets handled differently.
|
| + var dir = parts[0];
|
| + parts = parts.skip(1);
|
| +
|
| + switch (dir) {
|
| + case "asset":
|
| + return path.url.join("assets", id.package, path.url.joinAll(parts));
|
| +
|
| + case "lib":
|
| + return path.url.join("packages", id.package, path.url.joinAll(parts));
|
| +
|
| + case "web":
|
| + if (id.package != entrypoint) {
|
| + throw new FormatException(
|
| + 'Can only access "web" directory of root package.');
|
| + }
|
| + return path.url.joinAll(parts);
|
| +
|
| + default:
|
| + throw new FormatException('Cannot access assets from "$dir".');
|
| + }
|
| +}
|
|
|