Index: utils/pub/entrypoint.dart |
diff --git a/utils/pub/entrypoint.dart b/utils/pub/entrypoint.dart |
index 32dbb612180244f16a17a2f00b00965bb7f28d64..d7e17ab493df0f1d3fe9322f6d7f0304cfe16a98 100644 |
--- a/utils/pub/entrypoint.dart |
+++ b/utils/pub/entrypoint.dart |
@@ -143,10 +143,12 @@ class Entrypoint { |
* [LockFile]. |
*/ |
Future _installDependencies(List<PackageId> packageVersions) { |
- return Futures.wait(packageVersions.map((id) { |
- if (id.source is RootSource) return new Future.immediate(id); |
- return install(id); |
- })).chain(_saveLockFile).chain(_installSelfReference); |
+ return _removeUnusedDependencies(packageVersions).chain((_) { |
+ return Futures.wait(packageVersions.map((id) { |
+ if (id.source is RootSource) return new Future.immediate(id); |
+ return install(id); |
+ })); |
+ }).chain(_saveLockFile).chain(_installSelfReference); |
} |
/** |
@@ -180,6 +182,27 @@ class Entrypoint { |
} |
/** |
+ * Removes all dependencies that are no longer depended on from the `packages` |
+ * directory. [packageIds] is a list of all packages that are still depended |
+ * on. |
+ */ |
+ Future _removeUnusedDependencies(List<PackageId> packageIds) { |
+ var dependenciesToKeep = packageIds.map((id) => id.name); |
+ |
+ return dirExists(path).chain((exists) { |
+ if (exists) return listDir(path); |
+ return new Future.immediate([]); |
+ }).chain((existingDependencies) { |
+ existingDependencies = existingDependencies.map(basename); |
+ var dependenciesToRemove = |
+ new List.from(setMinus(existingDependencies, dependenciesToKeep)); |
Bob Nystrom
2012/08/25 00:13:30
Indent +2.
nweiz
2012/08/25 00:17:49
Done.
|
+ return Futures.wait(dependenciesToRemove.map((dependency) { |
+ return deleteDir(join(path, dependency)); |
+ })); |
+ }); |
+ } |
+ |
+ /** |
* Saves a list of concrete package versions to the `pubspec.lock` file. |
*/ |
Future _saveLockFile(List<PackageId> packageIds) { |