OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library package_config.packages; |
| 6 |
| 7 import "src/packages_impl.dart"; |
| 8 |
| 9 /// A package resolution strategy. |
| 10 /// |
| 11 /// Allows converting a `package:` URI to a different kind of URI. |
| 12 /// |
| 13 /// May also allow listing the available packages and converting |
| 14 /// to a `Map<String, Uri>` that gives the base location of each available |
| 15 /// package. In some cases there is no way to find the available packages, |
| 16 /// in which case [packages] and [asMap] will throw if used. |
| 17 /// One such case is if the packages are resolved relative to a |
| 18 /// `packages/` directory available over HTTP. |
| 19 abstract class Packages { |
| 20 |
| 21 /// A [Packages] resolver containing no packages. |
| 22 /// |
| 23 /// This constant object is returned by [find] above if no |
| 24 /// package resolution strategy is found. |
| 25 static const Packages noPackages = const NoPackages(); |
| 26 |
| 27 /// Resolve a package URI into a non-package URI. |
| 28 /// |
| 29 /// Translates a `package:` URI, according to the package resolution |
| 30 /// strategy, into a URI that can be loaded. |
| 31 /// By default, only `file`, `http` and `https` URIs are returned. |
| 32 /// Custom `Packages` objects may return other URIs. |
| 33 /// |
| 34 /// If resolution fails because a package with the requested package name |
| 35 /// is not available, the [notFound] function is called. |
| 36 /// If no `notFound` function is provided, it defaults to throwing an error. |
| 37 /// |
| 38 /// The [packageUri] must be a valid package URI. |
| 39 Uri resolve(Uri packageUri, {Uri notFound(Uri packageUri)}); |
| 40 |
| 41 /// Return the names of the available packages. |
| 42 /// |
| 43 /// Returns an iterable that allows iterating the names of available packages. |
| 44 /// |
| 45 /// Some `Packages` objects are unable to find the package names, |
| 46 /// and getting `packages` from such a `Packages` object will throw. |
| 47 Iterable<String> get packages; |
| 48 |
| 49 /// Return the names-to-base-URI mapping of the available packages. |
| 50 /// |
| 51 /// Returns a map from package name to a base URI. |
| 52 /// The [resolve] method will resolve a package URI with a specific package |
| 53 /// name to a path extending the base URI that this map gives for that |
| 54 /// package name. |
| 55 /// |
| 56 /// Some `Packages` objects are unable to find the package names, |
| 57 /// and calling `asMap` on such a `Packages` object will throw. |
| 58 Map<String, Uri> asMap(); |
| 59 } |
OLD | NEW |