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

Unified Diff: utils/pub/entrypoint.dart

Issue 10867070: Support removing dead packages with `pub install`. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | utils/pub/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « no previous file | utils/pub/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698