OLD | NEW |
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 sdk_source; | 5 library sdk_source; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'io.dart'; | 8 import 'io.dart'; |
9 import 'package.dart'; | 9 import 'package.dart'; |
10 import 'pubspec.dart'; | 10 import 'pubspec.dart'; |
11 import 'sdk.dart' as sdk; | 11 import 'sdk.dart' as sdk; |
12 import 'source.dart'; | 12 import 'source.dart'; |
| 13 import 'utils.dart'; |
13 import 'version.dart'; | 14 import 'version.dart'; |
14 | 15 |
15 /// A package source that uses libraries from the Dart SDK. | 16 /// A package source that uses libraries from the Dart SDK. |
16 class SdkSource extends Source { | 17 class SdkSource extends Source { |
17 final String name = "sdk"; | 18 final String name = "sdk"; |
18 final bool shouldCache = false; | 19 final bool shouldCache = false; |
19 | 20 |
20 /// SDK packages are not individually versioned. Instead, their version is | 21 /// SDK packages are not individually versioned. Instead, their version is |
21 /// inferred from the revision number of the SDK itself. | 22 /// inferred from the revision number of the SDK itself. |
22 Future<Pubspec> describe(PackageId id) { | 23 Future<Pubspec> describe(PackageId id) { |
23 return _getPackagePath(id).then((packageDir) { | 24 // Make sure all errors propagate through future. |
| 25 return defer(() { |
| 26 var packageDir = _getPackagePath(id); |
24 // TODO(rnystrom): What if packageDir is null? | 27 // TODO(rnystrom): What if packageDir is null? |
25 return Package.load(id.name, packageDir, systemCache.sources); | 28 var package = new Package(id.name, packageDir, systemCache.sources); |
26 }).then((package) { | |
27 // Ignore the pubspec's version, and use the SDK's. | 29 // Ignore the pubspec's version, and use the SDK's. |
28 return new Pubspec(id.name, sdk.version, package.pubspec.dependencies, | 30 return new Pubspec(id.name, sdk.version, package.pubspec.dependencies, |
29 package.pubspec.environment); | 31 package.pubspec.environment); |
30 }); | 32 }); |
31 } | 33 } |
32 | 34 |
33 /// Since all the SDK files are already available locally, installation just | 35 /// Since all the SDK files are already available locally, installation just |
34 /// involves symlinking the SDK library into the packages directory. | 36 /// involves symlinking the SDK library into the packages directory. |
35 Future<bool> install(PackageId id, String destPath) { | 37 Future<bool> install(PackageId id, String destPath) { |
36 return _getPackagePath(id).then((path) { | 38 return defer(() { |
37 if (path == null) return new Future<bool>.immediate(false); | 39 var path = _getPackagePath(id); |
| 40 if (path == null) return false; |
38 | 41 |
39 return createPackageSymlink(id.name, path, destPath).then( | 42 return createPackageSymlink(id.name, path, destPath).then((_) => true); |
40 (_) => true); | |
41 }); | 43 }); |
42 } | 44 } |
43 | 45 |
44 /// Gets the path in the SDK's "pkg" directory to the directory containing | 46 /// Gets the path in the SDK's "pkg" directory to the directory containing |
45 /// package [id]. Returns `null` if the package could not be found. | 47 /// package [id]. Returns `null` if the package could not be found. |
46 Future<String> _getPackagePath(PackageId id) { | 48 String _getPackagePath(PackageId id) { |
47 var pkgPath = join(sdk.rootDirectory, "pkg", id.description); | 49 var pkgPath = join(sdk.rootDirectory, "pkg", id.description); |
48 return dirExists(pkgPath).then((found) => found ? pkgPath : null); | 50 return dirExists(pkgPath) ? pkgPath : null; |
49 } | 51 } |
50 } | 52 } |
OLD | NEW |