Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/global_packages.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/global_packages.dart b/sdk/lib/_internal/pub/lib/src/global_packages.dart |
| index bbb289a50e740578e00f8e128e92d1fb09d31c51..96f59a7714126f99050d9ed6f8a97a89ae312049 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/global_packages.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/global_packages.dart |
| @@ -63,15 +63,14 @@ class GlobalPackages { |
| /// Caches the package located in the Git repository [repo] and makes it the |
| /// active global version. |
| - Future activateGit(String repo) { |
| + Future activateGit(String repo) async { |
| var source = cache.sources["git"] as GitSource; |
| - return source.getPackageNameFromRepo(repo).then((name) { |
| - // Call this just to log what the current active package is, if any. |
| - _describeActive(name); |
| + var name = await source.getPackageNameFromRepo(repo); |
| + // Call this just to log what the current active package is, if any. |
| + _describeActive(name); |
| - return _installInCache( |
| - new PackageDep(name, "git", VersionConstraint.any, repo)); |
| - }); |
| + return _installInCache( |
|
nweiz
2014/08/29 23:30:41
"return" -> "await"
Bob Nystrom
2014/09/03 23:44:17
Done.
|
| + new PackageDep(name, "git", VersionConstraint.any, repo)); |
| } |
| /// Finds the latest version of the hosted package with [name] that matches |
| @@ -82,26 +81,25 @@ class GlobalPackages { |
| } |
| /// Makes the local package at [path] globally active. |
| - Future activatePath(String path) { |
| + Future activatePath(String path) async { |
| var entrypoint = new Entrypoint(path, cache); |
| // Get the package's dependencies. |
| - return entrypoint.ensureLockFileIsUpToDate().then((_) { |
| - var name = entrypoint.root.name; |
| + await entrypoint.ensureLockFileIsUpToDate(); |
| + var name = entrypoint.root.name; |
| - // Call this just to log what the current active package is, if any. |
| - _describeActive(name); |
| + // Call this just to log what the current active package is, if any. |
| + _describeActive(name); |
| - // Write a lockfile that points to the local package. |
| - var fullPath = canonicalize(entrypoint.root.dir); |
| - var id = new PackageId(name, "path", entrypoint.root.version, |
| - PathSource.describePath(fullPath)); |
| - _writeLockFile(name, new LockFile([id])); |
| - }); |
| + // Write a lockfile that points to the local package. |
| + var fullPath = canonicalize(entrypoint.root.dir); |
| + var id = new PackageId(name, "path", entrypoint.root.version, |
| + PathSource.describePath(fullPath)); |
| + _writeLockFile(name, new LockFile([id])); |
| } |
| /// Installs the package [dep] and its dependencies into the system cache. |
| - Future _installInCache(PackageDep dep) { |
| + Future _installInCache(PackageDep dep) async { |
| var source = cache.sources[dep.source]; |
| // Create a dummy package with just [dep] so we can do resolution on it. |
| @@ -109,35 +107,32 @@ class GlobalPackages { |
| dependencies: [dep], sources: cache.sources)); |
| // Resolve it and download its dependencies. |
| - return resolveVersions(SolveType.GET, cache.sources, root).then((result) { |
| - if (!result.succeeded) { |
| - // If the package specified by the user doesn't exist, we want to |
| - // surface that as a [DataError] with the associated exit code. |
| - if (result.error.package != dep.name) throw result.error; |
| - if (result.error is NoVersionException) dataError(result.error.message); |
| - throw result.error; |
| - } |
| - result.showReport(SolveType.GET); |
| + var result = await resolveVersions(SolveType.GET, cache.sources, root); |
| + if (!result.succeeded) { |
| + // If the package specified by the user doesn't exist, we want to |
| + // surface that as a [DataError] with the associated exit code. |
| + if (result.error.package != dep.name) throw result.error; |
| + if (result.error is NoVersionException) dataError(result.error.message); |
| + throw result.error; |
| + } |
| + result.showReport(SolveType.GET); |
| - // Make sure all of the dependencies are locally installed. |
| - return Future.wait(result.packages.map(_cacheDependency)); |
| - }).then((ids) { |
| - _writeLockFile(dep.name, new LockFile(ids)); |
| - }); |
| + // Make sure all of the dependencies are locally installed. |
| + var ids = await Future.wait(result.packages.map(_cacheDependency)); |
| + _writeLockFile(dep.name, new LockFile(ids)); |
| } |
| /// Downloads [id] into the system cache if it's a cached package. |
| /// |
| /// Returns the resolved [PackageId] for [id]. |
| - Future<PackageId> _cacheDependency(PackageId id) { |
| + Future<PackageId> _cacheDependency(PackageId id) async { |
| var source = cache.sources[id.source]; |
| - return syncFuture(() { |
| - if (id.isRoot) return null; |
| - if (source is! CachedSource) return null; |
| + if (!id.isRoot && source is CachedSource) { |
| + await source.downloadToSystemCache(id); |
| + } |
| - return source.downloadToSystemCache(id); |
| - }).then((_) => source.resolveId(id)); |
| + return source.resolveId(id); |
| } |
| /// Finishes activating package [package] by saving [lockFile] in the cache. |
| @@ -203,6 +198,8 @@ class GlobalPackages { |
| /// |
| /// Returns an [Entrypoint] loaded with the active package if found. |
| Future<Entrypoint> find(String name) { |
| + // TODO(rnystrom): Use async/await here when on __ catch is supported. |
| + // See: https://github.com/dart-lang/async_await/issues/27 |
| return syncFuture(() { |
| var lockFile; |
| try { |