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

Side by Side Diff: lib/src/command/list_package_dirs.dart

Issue 1276673006: Make Source.getDirectory synchronous. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « lib/src/command/cache_add.dart ('k') | lib/src/entrypoint.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 pub.command.list_package_dirs; 5 library pub.command.list_package_dirs;
6 6
7 import 'dart:async';
8
9 import 'package:path/path.dart' as p; 7 import 'package:path/path.dart' as p;
10 8
11 import '../command.dart'; 9 import '../command.dart';
12 import '../log.dart' as log; 10 import '../log.dart' as log;
13 import '../utils.dart'; 11 import '../utils.dart';
14 12
15 /// Handles the `list-package-dirs` pub command. 13 /// Handles the `list-package-dirs` pub command.
16 class ListPackageDirsCommand extends PubCommand { 14 class ListPackageDirsCommand extends PubCommand {
17 String get name => "list-package-dirs"; 15 String get name => "list-package-dirs";
18 String get description => "Print local paths to dependencies."; 16 String get description => "Print local paths to dependencies.";
19 String get invocation => "pub list-package-dirs"; 17 String get invocation => "pub list-package-dirs";
20 bool get takesArguments => false; 18 bool get takesArguments => false;
21 bool get hidden => true; 19 bool get hidden => true;
22 20
23 ListPackageDirsCommand() { 21 ListPackageDirsCommand() {
24 argParser.addOption("format", 22 argParser.addOption("format",
25 help: "How output should be displayed.", 23 help: "How output should be displayed.",
26 allowed: ["json"]); 24 allowed: ["json"]);
27 } 25 }
28 26
29 Future run() { 27 void run() {
30 log.json.enabled = true; 28 log.json.enabled = true;
31 29
32 if (!entrypoint.lockFileExists) { 30 if (!entrypoint.lockFileExists) {
33 dataError('Package "myapp" has no lockfile. Please run "pub get" first.'); 31 dataError('Package "myapp" has no lockfile. Please run "pub get" first.');
34 } 32 }
35 33
36 var output = {}; 34 var output = {};
37 35
38 // Include the local paths to all locked packages. 36 // Include the local paths to all locked packages.
39 var packages = {}; 37 var packages = mapMap(entrypoint.lockFile.packages, value: (name, package) {
40 var futures = [];
41 entrypoint.lockFile.packages.forEach((name, package) {
42 var source = entrypoint.cache.sources[package.source]; 38 var source = entrypoint.cache.sources[package.source];
43 futures.add(source.getDirectory(package).then((packageDir) { 39 var packageDir = source.getDirectory(package);
44 // Normalize paths and make them absolute for backwards compatibility 40 // Normalize paths and make them absolute for backwards compatibility
45 // with the protocol used by the analyzer. 41 // with the protocol used by the analyzer.
46 packages[name] = p.normalize(p.absolute(p.join(packageDir, "lib"))); 42 return p.normalize(p.absolute(p.join(packageDir, "lib")));
47 }));
48 }); 43 });
49 44
50 output["packages"] = packages;
51
52 // Include the self link. 45 // Include the self link.
53 packages[entrypoint.root.name] = 46 packages[entrypoint.root.name] =
54 p.normalize(p.absolute(entrypoint.root.path("lib"))); 47 p.normalize(p.absolute(entrypoint.root.path("lib")));
55 48
49 output["packages"] = packages;
50
56 // Include the file(s) which when modified will affect the results. For pub, 51 // Include the file(s) which when modified will affect the results. For pub,
57 // that's just the pubspec and lockfile. 52 // that's just the pubspec and lockfile.
58 output["input_files"] = [ 53 output["input_files"] = [
59 p.normalize(p.absolute(entrypoint.lockFilePath)), 54 p.normalize(p.absolute(entrypoint.lockFilePath)),
60 p.normalize(p.absolute(entrypoint.pubspecPath)) 55 p.normalize(p.absolute(entrypoint.pubspecPath))
61 ]; 56 ];
62 57
63 return Future.wait(futures).then((_) { 58 log.json.message(output);
64 log.json.message(output);
65 });
66 } 59 }
67 } 60 }
68 61
OLDNEW
« no previous file with comments | « lib/src/command/cache_add.dart ('k') | lib/src/entrypoint.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698