| 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('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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 return future; | 100 return future; |
| 101 } | 101 } |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * Installs all dependencies of the [root] package to its "packages" | 104 * Installs all dependencies of the [root] package to its "packages" |
| 105 * directory, respecting the [LockFile] if present. Returns a [Future] that | 105 * directory, respecting the [LockFile] if present. Returns a [Future] that |
| 106 * completes when all dependencies are installed. | 106 * completes when all dependencies are installed. |
| 107 */ | 107 */ |
| 108 Future installDependencies() { | 108 Future installDependencies() { |
| 109 return _validatePubspec() | 109 return _loadLockFile() |
| 110 .chain((_) => _loadLockFile()) | |
| 111 .chain((lockFile) => resolveVersions(cache.sources, root, lockFile)) | 110 .chain((lockFile) => resolveVersions(cache.sources, root, lockFile)) |
| 112 .chain(_installDependencies); | 111 .chain(_installDependencies); |
| 113 } | 112 } |
| 114 | 113 |
| 115 /** | 114 /** |
| 116 * Installs the latest available versions of all dependencies of the [root] | 115 * Installs the latest available versions of all dependencies of the [root] |
| 117 * package to its "package" directory, writing a new [LockFile]. Returns a | 116 * package to its "package" directory, writing a new [LockFile]. Returns a |
| 118 * [Future] that completes when all dependencies are installed. | 117 * [Future] that completes when all dependencies are installed. |
| 119 */ | 118 */ |
| 120 Future updateAllDependencies() { | 119 Future updateAllDependencies() { |
| 121 return _validatePubspec() | 120 return resolveVersions(cache.sources, root, new LockFile.empty()) |
| 122 .chain((_) => resolveVersions(cache.sources, root, new LockFile.empty())) | |
| 123 .chain(_installDependencies); | 121 .chain(_installDependencies); |
| 124 } | 122 } |
| 125 | 123 |
| 126 /** | 124 /** |
| 127 * Installs the latest available versions of [dependencies], while leaving | 125 * Installs the latest available versions of [dependencies], while leaving |
| 128 * other dependencies as specified by the [LockFile] if possible. Returns a | 126 * other dependencies as specified by the [LockFile] if possible. Returns a |
| 129 * [Future] that completes when all dependencies are installed. | 127 * [Future] that completes when all dependencies are installed. |
| 130 */ | 128 */ |
| 131 Future updateDependencies(List<String> dependencies) { | 129 Future updateDependencies(List<String> dependencies) { |
| 132 return _validatePubspec().chain((_) => _loadLockFile()).chain((lockFile) { | 130 return _loadLockFile().chain((lockFile) { |
| 133 var versionSolver = new VersionSolver(cache.sources, root, lockFile); | 131 var versionSolver = new VersionSolver(cache.sources, root, lockFile); |
| 134 for (var dependency in dependencies) { | 132 for (var dependency in dependencies) { |
| 135 versionSolver.useLatestVersion(dependency); | 133 versionSolver.useLatestVersion(dependency); |
| 136 } | 134 } |
| 137 return versionSolver.solve(); | 135 return versionSolver.solve(); |
| 138 }).chain(_installDependencies); | 136 }).chain(_installDependencies); |
| 139 } | 137 } |
| 140 | 138 |
| 141 /** | 139 /** |
| 142 * Installs all dependencies listed in [packageVersions] and writes a | 140 * Installs all dependencies listed in [packageVersions] and writes a |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 /** | 289 /** |
| 292 * Creates a symlink to the `packages` directory in [dir] if none exists. | 290 * Creates a symlink to the `packages` directory in [dir] if none exists. |
| 293 */ | 291 */ |
| 294 Future _linkSecondaryPackageDir(String dir) { | 292 Future _linkSecondaryPackageDir(String dir) { |
| 295 var to = join(dir, 'packages'); | 293 var to = join(dir, 'packages'); |
| 296 return exists(to).chain((exists) { | 294 return exists(to).chain((exists) { |
| 297 if (exists) return new Future.immediate(null); | 295 if (exists) return new Future.immediate(null); |
| 298 return createSymlink(path, to); | 296 return createSymlink(path, to); |
| 299 }); | 297 }); |
| 300 } | 298 } |
| 301 | |
| 302 /** | |
| 303 * Validate that the pubspec for the entrypoint exists and specifies the name | |
| 304 * of the root package. | |
| 305 */ | |
| 306 Future _validatePubspec() { | |
| 307 var future = new Future.immediate(null);; | |
| 308 if (root.pubspec.isEmpty) { | |
| 309 future = exists(join(root.dir, "pubspec.yaml")).transform((exists) { | |
| 310 if (exists) return; | |
| 311 throw 'Could not find a file named "pubspec.yaml" in the directory ' | |
| 312 '$path.'; | |
| 313 }); | |
| 314 } | |
| 315 | |
| 316 return future.transform((_) { | |
| 317 if (root.pubspec.name != null) return; | |
| 318 throw '"pubspec.yaml" is missing the required "name" field (e.g. "name: ' | |
| 319 '${root.name}").'; | |
| 320 }); | |
| 321 } | |
| 322 } | 299 } |
| OLD | NEW |