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

Side by Side 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, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | utils/pub/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library('entrypoint'); 5 #library('entrypoint');
6 6
7 #import('io.dart'); 7 #import('io.dart');
8 #import('lock_file.dart'); 8 #import('lock_file.dart');
9 #import('package.dart'); 9 #import('package.dart');
10 #import('root_source.dart'); 10 #import('root_source.dart');
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 136 }
137 return versionSolver.solve(); 137 return versionSolver.solve();
138 }).chain(_installDependencies); 138 }).chain(_installDependencies);
139 } 139 }
140 140
141 /** 141 /**
142 * Installs all dependencies listed in [packageVersions] and writes a 142 * Installs all dependencies listed in [packageVersions] and writes a
143 * [LockFile]. 143 * [LockFile].
144 */ 144 */
145 Future _installDependencies(List<PackageId> packageVersions) { 145 Future _installDependencies(List<PackageId> packageVersions) {
146 return Futures.wait(packageVersions.map((id) { 146 return _removeUnusedDependencies(packageVersions).chain((_) {
147 if (id.source is RootSource) return new Future.immediate(id); 147 return Futures.wait(packageVersions.map((id) {
148 return install(id); 148 if (id.source is RootSource) return new Future.immediate(id);
149 })).chain(_saveLockFile).chain(_installSelfReference); 149 return install(id);
150 }));
151 }).chain(_saveLockFile).chain(_installSelfReference);
150 } 152 }
151 153
152 /** 154 /**
153 * Loads the list of concrete package versions from the `pubspec.lock`, if it 155 * Loads the list of concrete package versions from the `pubspec.lock`, if it
154 * exists. If it doesn't, this completes to an empty [LockFile]. 156 * exists. If it doesn't, this completes to an empty [LockFile].
155 * 157 *
156 * If there's an error reading the `pubspec.lock` file, this will print a 158 * If there's an error reading the `pubspec.lock` file, this will print a
157 * warning message and act as though the file doesn't exist. 159 * warning message and act as though the file doesn't exist.
158 */ 160 */
159 Future<LockFile> _loadLockFile() { 161 Future<LockFile> _loadLockFile() {
(...skipping 13 matching lines...) Expand all
173 175
174 return true; 176 return true;
175 }); 177 });
176 178
177 future.then((text) => 179 future.then((text) =>
178 completer.complete(new LockFile.parse(text, cache.sources))); 180 completer.complete(new LockFile.parse(text, cache.sources)));
179 return completer.future; 181 return completer.future;
180 } 182 }
181 183
182 /** 184 /**
185 * Removes all dependencies that are no longer depended on from the `packages`
186 * directory. [packageIds] is a list of all packages that are still depended
187 * on.
188 */
189 Future _removeUnusedDependencies(List<PackageId> packageIds) {
190 var dependenciesToKeep = packageIds.map((id) => id.name);
191
192 return dirExists(path).chain((exists) {
193 if (exists) return listDir(path);
194 return new Future.immediate([]);
195 }).chain((existingDependencies) {
196 existingDependencies = existingDependencies.map(basename);
197 var dependenciesToRemove =
198 new List.from(setMinus(existingDependencies, dependenciesToKeep));
Bob Nystrom 2012/08/25 00:13:30 Indent +2.
nweiz 2012/08/25 00:17:49 Done.
199 return Futures.wait(dependenciesToRemove.map((dependency) {
200 return deleteDir(join(path, dependency));
201 }));
202 });
203 }
204
205 /**
183 * Saves a list of concrete package versions to the `pubspec.lock` file. 206 * Saves a list of concrete package versions to the `pubspec.lock` file.
184 */ 207 */
185 Future _saveLockFile(List<PackageId> packageIds) { 208 Future _saveLockFile(List<PackageId> packageIds) {
186 var lockFile = new LockFile.empty(); 209 var lockFile = new LockFile.empty();
187 for (var id in packageIds) { 210 for (var id in packageIds) {
188 if (id.source is! RootSource) lockFile.packages[id.name] = id; 211 if (id.source is! RootSource) lockFile.packages[id.name] = id;
189 } 212 }
190 213
191 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); 214 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize());
192 } 215 }
(...skipping 23 matching lines...) Expand all
216 '$path.'; 239 '$path.';
217 }); 240 });
218 } 241 }
219 242
220 return future.transform((_) { 243 return future.transform((_) {
221 if (root.pubspec.name != null) return; 244 if (root.pubspec.name != null) return;
222 throw '"pubspec.yaml" must contain a "name" key.'; 245 throw '"pubspec.yaml" must contain a "name" key.';
223 }); 246 });
224 } 247 }
225 } 248 }
OLDNEW
« 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