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 pub.entrypoint; | 5 library pub.entrypoint; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 /// Loads the entrypoint from a package at [rootDir]. | 47 /// Loads the entrypoint from a package at [rootDir]. |
48 Entrypoint(String rootDir, SystemCache cache) | 48 Entrypoint(String rootDir, SystemCache cache) |
49 : root = new Package.load(null, rootDir, cache.sources), | 49 : root = new Package.load(null, rootDir, cache.sources), |
50 cache = cache; | 50 cache = cache; |
51 | 51 |
52 // TODO(rnystrom): Make this path configurable. | 52 // TODO(rnystrom): Make this path configurable. |
53 /// The path to the entrypoint's "packages" directory. | 53 /// The path to the entrypoint's "packages" directory. |
54 String get packagesDir => path.join(root.dir, 'packages'); | 54 String get packagesDir => path.join(root.dir, 'packages'); |
55 | 55 |
56 /// `true` if the entrypoint package currently has a lock file. | 56 /// `true` if the entrypoint package currently has a lock file. |
57 bool get lockFileExists => entryExists(_lockFilePath); | 57 bool get lockFileExists => entryExists(lockFilePath); |
| 58 |
| 59 /// The path to the entrypoint package's lockfile. |
| 60 String get lockFilePath => path.join(root.dir, 'pubspec.lock'); |
58 | 61 |
59 /// Ensures that the package identified by [id] is installed to the directory. | 62 /// Ensures that the package identified by [id] is installed to the directory. |
60 /// Returns the resolved [PackageId]. | 63 /// Returns the resolved [PackageId]. |
61 /// | 64 /// |
62 /// If this completes successfully, the package is guaranteed to be importable | 65 /// If this completes successfully, the package is guaranteed to be importable |
63 /// using the `package:` scheme. | 66 /// using the `package:` scheme. |
64 /// | 67 /// |
65 /// This will automatically install the package to the system-wide cache as | 68 /// This will automatically install the package to the system-wide cache as |
66 /// well if it requires network access to retrieve (specifically, if the | 69 /// well if it requires network access to retrieve (specifically, if the |
67 /// package's source has [shouldCache] as `true`). | 70 /// package's source has [shouldCache] as `true`). |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 _saveLockFile(ids); | 146 _saveLockFile(ids); |
144 _installSelfReference(); | 147 _installSelfReference(); |
145 _linkSecondaryPackageDirs(); | 148 _linkSecondaryPackageDirs(); |
146 }); | 149 }); |
147 } | 150 } |
148 | 151 |
149 /// Loads the list of concrete package versions from the `pubspec.lock`, if it | 152 /// Loads the list of concrete package versions from the `pubspec.lock`, if it |
150 /// exists. If it doesn't, this completes to an empty [LockFile]. | 153 /// exists. If it doesn't, this completes to an empty [LockFile]. |
151 LockFile loadLockFile() { | 154 LockFile loadLockFile() { |
152 if (!lockFileExists) return new LockFile.empty(); | 155 if (!lockFileExists) return new LockFile.empty(); |
153 return new LockFile.load(_lockFilePath, cache.sources); | 156 return new LockFile.load(lockFilePath, cache.sources); |
154 } | 157 } |
155 | 158 |
156 /// Determines whether or not the lockfile is out of date with respect to the | 159 /// Determines whether or not the lockfile is out of date with respect to the |
157 /// pubspec. | 160 /// pubspec. |
158 /// | 161 /// |
159 /// This will be `false` if there is no lockfile at all, or if the pubspec | 162 /// This will be `false` if there is no lockfile at all, or if the pubspec |
160 /// contains dependencies that are not in the lockfile or that don't match | 163 /// contains dependencies that are not in the lockfile or that don't match |
161 /// what's in there. | 164 /// what's in there. |
162 bool isLockFileUpToDate() { | 165 bool isLockFileUpToDate() { |
163 var lockFile = loadLockFile(); | 166 var lockFile = loadLockFile(); |
(...skipping 12 matching lines...) Expand all Loading... |
176 | 179 |
177 return true; | 180 return true; |
178 } | 181 } |
179 | 182 |
180 if (!root.dependencies.every(checkDependency)) return false; | 183 if (!root.dependencies.every(checkDependency)) return false; |
181 if (!root.devDependencies.every(checkDependency)) return false; | 184 if (!root.devDependencies.every(checkDependency)) return false; |
182 | 185 |
183 return true; | 186 return true; |
184 } | 187 } |
185 | 188 |
186 /// The path to the entrypoint package's lockfile. | |
187 String get _lockFilePath => path.join(root.dir, 'pubspec.lock'); | |
188 | |
189 /// Saves a list of concrete package versions to the `pubspec.lock` file. | 189 /// Saves a list of concrete package versions to the `pubspec.lock` file. |
190 void _saveLockFile(List<PackageId> packageIds) { | 190 void _saveLockFile(List<PackageId> packageIds) { |
191 var lockFile = new LockFile.empty(); | 191 var lockFile = new LockFile.empty(); |
192 for (var id in packageIds) { | 192 for (var id in packageIds) { |
193 if (!id.isRoot) lockFile.packages[id.name] = id; | 193 if (!id.isRoot) lockFile.packages[id.name] = id; |
194 } | 194 } |
195 | 195 |
196 var lockFilePath = path.join(root.dir, 'pubspec.lock'); | 196 var lockFilePath = path.join(root.dir, 'pubspec.lock'); |
197 writeTextFile(lockFilePath, lockFile.serialize()); | 197 writeTextFile(lockFilePath, lockFile.serialize()); |
198 } | 198 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 // Skip directories and broken symlinks. | 295 // Skip directories and broken symlinks. |
296 if (!fileExists(file)) return false; | 296 if (!fileExists(file)) return false; |
297 | 297 |
298 var relative = path.relative(file, from: beneath); | 298 var relative = path.relative(file, from: beneath); |
299 if (_BLACKLISTED_FILES.contains(path.basename(relative))) return false; | 299 if (_BLACKLISTED_FILES.contains(path.basename(relative))) return false; |
300 return !path.split(relative).any(_BLACKLISTED_DIRS.contains); | 300 return !path.split(relative).any(_BLACKLISTED_DIRS.contains); |
301 }).toList(); | 301 }).toList(); |
302 }); | 302 }); |
303 } | 303 } |
304 } | 304 } |
OLD | NEW |