Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: lib/packages.dart

Issue 1142363005: Added .packages, packages/ discovery. (Closed) Base URL: https://github.com/dart-lang/package_config.git@master
Patch Set: Addressed comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/packagemap.dart ('k') | lib/packages_file.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "dart:async" show Future;
8 import "discovery.dart" show findPackages;
9 import "src/packages_impl.dart";
10
11 /// A package resolution strategy.
12 ///
13 /// Allows converting a `package:` URI to a different kind of URI.
14 ///
15 /// May also allow listing the available packages and converting
16 /// to a `Map<String, Uri>` that gives the base location of each available
17 /// package. In some cases there is no way to find the available packages,
18 /// in which case [packages] and [asMap] will throw if used.
19 /// One such case is if the packages are resolved relative to a
20 /// `packages/` directory available over HTTP.
21 abstract class Packages {
22
23 /// A [Packages] resolver containing no packages.
24 ///
25 /// This constant object is returned by [find] above if no
26 /// package resolution strategy is found.
27 static const Packages noPackages = const NoPackages();
28
29 /// Create a `Packages` object based on a map from package name to base URI.
30 ///
31 /// The resulting `Packages` object will resolve package URIs by using this
32 /// map.
33 /// There is no validation of the map containing only valid package names,
34 factory Packages(Map<String, Uri> packageMapping) =>
35 new MapPackages(packageMapping);
36
37 /// Attempts to find a package resolution strategy for a Dart script.
38 ///
39 /// The [baseLocation] should point to a Dart script or to its directory.
40 /// The function goes through the following steps in order to search for
41 /// a packages resolution strategy:
42 ///
43 /// * First check if a `.packages` file in the script's directory.
44 /// If a file is found, its content is loaded and interpreted as a map
45 /// from package names to package location URIs.
46 /// If loading or parsing of the file fails, so does this function.
47 /// * Then if `baseLocation` is not a `file:` URI,
48 /// assume that a `packages/` directory exists in the script's directory,
49 /// and return a `Packages` object that resolves package URIs as
50 /// paths into that directory.
51 /// * If `baseLocation` is a `file:` URI, instead *check* whether
52 /// a `packages/` directory exists in the script directory.
53 /// If it does, return a `Packages` object that resolves package URIs
54 /// as paths into that directory. This `Packages` object is able to
55 /// read the directory and see which packages are available.
56 /// * Otherwise, check each directory in the parent path of `baseLocation`
57 /// for the existence of a `.packages` file. If one is found, it is loaded
58 /// just as in the first step.
59 /// * If no file is found before reaching the file system root,
60 /// the constant [noPacakages] is returned. It's a `Packages` object
61 /// with no available packages.
62 ///
63 static Future<Packages> find(Uri baseLocation) => findPackages(baseLocation);
64
65 /// Resolve a package URI into a non-package URI.
66 ///
67 /// Translates a `package:` URI, according to the package resolution
68 /// strategy, into a URI that can be loaded.
69 /// By default, only `file`, `http` and `https` URIs are returned.
70 /// Custom `Packages` objects may return other URIs.
71 ///
72 /// If resolution fails because a package with the requested package name
73 /// is not available, the [notFound] function is called.
74 /// If no `notFound` function is provided, it defaults to throwing an error.
75 ///
76 /// The [packageUri] must be a valid package URI.
77 Uri resolve(Uri packageUri, {Uri notFound(Uri packageUri)});
78
79 /// Return the names of the available packages.
80 ///
81 /// Returns an iterable that allows iterating the names of available packages.
82 ///
83 /// Some `Packages` objects are unable to find the package names,
84 /// and getting `packages` from such a `Packages` object will throw.
85 Iterable<String> get packages;
86
87 /// Return the names-to-base-URI mapping of the available packages.
88 ///
89 /// Returns a map from package name to a base URI.
90 /// The [resolve] method will resolve a package URI with a specific package
91 /// name to a path extending the base URI that this map gives for that
92 /// package name.
93 ///
94 /// Some `Packages` objects are unable to find the package names,
95 /// and calling `asMap` on such a `Packages` object will throw.
96 Map<String, Uri> asMap();
97 }
OLDNEW
« no previous file with comments | « lib/packagemap.dart ('k') | lib/packages_file.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698