| 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 |
| 11 import 'git.dart' as git; | |
| 12 import 'io.dart'; | 11 import 'io.dart'; |
| 13 import 'lock_file.dart'; | 12 import 'lock_file.dart'; |
| 14 import 'log.dart' as log; | 13 import 'log.dart' as log; |
| 15 import 'package.dart'; | 14 import 'package.dart'; |
| 16 import 'package_graph.dart'; | 15 import 'package_graph.dart'; |
| 17 import 'solver/version_solver.dart'; | 16 import 'solver/version_solver.dart'; |
| 18 import 'source/cached.dart'; | 17 import 'source/cached.dart'; |
| 19 import 'system_cache.dart'; | 18 import 'system_cache.dart'; |
| 20 import 'utils.dart'; | 19 import 'utils.dart'; |
| 21 | 20 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 })); | 318 })); |
| 320 } | 319 } |
| 321 | 320 |
| 322 /// Creates a symlink to the `packages` directory in [dir]. Will replace one | 321 /// Creates a symlink to the `packages` directory in [dir]. Will replace one |
| 323 /// if already there. | 322 /// if already there. |
| 324 void _linkSecondaryPackageDir(String dir) { | 323 void _linkSecondaryPackageDir(String dir) { |
| 325 var symlink = path.join(dir, 'packages'); | 324 var symlink = path.join(dir, 'packages'); |
| 326 if (entryExists(symlink)) deleteEntry(symlink); | 325 if (entryExists(symlink)) deleteEntry(symlink); |
| 327 createSymlink(packagesDir, symlink, relative: true); | 326 createSymlink(packagesDir, symlink, relative: true); |
| 328 } | 327 } |
| 329 | |
| 330 /// The basenames of files that are automatically excluded from archives. | |
| 331 final _BLACKLISTED_FILES = const ['pubspec.lock']; | |
| 332 | |
| 333 /// The basenames of directories that are automatically excluded from | |
| 334 /// archives. | |
| 335 final _BLACKLISTED_DIRS = const ['packages']; | |
| 336 | |
| 337 /// Returns a list of files that are considered to be part of this package. | |
| 338 /// | |
| 339 /// If this is a Git repository, this will respect .gitignore; otherwise, it | |
| 340 /// will return all non-hidden, non-blacklisted files. | |
| 341 /// | |
| 342 /// If [beneath] is passed, this will only return files beneath that path. | |
| 343 List<String> packageFiles({String beneath}) { | |
| 344 if (beneath == null) beneath = root.dir; | |
| 345 | |
| 346 var files; | |
| 347 if (git.isInstalled && dirExists(path.join(root.dir, '.git'))) { | |
| 348 // Later versions of git do not allow a path for ls-files that appears to | |
| 349 // be outside of the repo, so make sure we give it a relative path. | |
| 350 var relativeBeneath = path.relative(beneath, from: root.dir); | |
| 351 | |
| 352 // List all files that aren't gitignored, including those not checked in | |
| 353 // to Git. | |
| 354 files = git.runSync( | |
| 355 ["ls-files", "--cached", "--others", "--exclude-standard", | |
| 356 relativeBeneath], | |
| 357 workingDir: root.dir); | |
| 358 // Git always prints files relative to the project root, but we want them | |
| 359 // relative to the working directory. It also prints forward slashes on | |
| 360 // Windows which we normalize away for easier testing. | |
| 361 files = files.map((file) => path.normalize(path.join(root.dir, file))); | |
| 362 } else { | |
| 363 files = listDir(beneath, recursive: true); | |
| 364 } | |
| 365 | |
| 366 return files.where((file) { | |
| 367 // Skip directories and broken symlinks. | |
| 368 if (!fileExists(file)) return false; | |
| 369 | |
| 370 var relative = path.relative(file, from: beneath); | |
| 371 if (_BLACKLISTED_FILES.contains(path.basename(relative))) return false; | |
| 372 return !path.split(relative).any(_BLACKLISTED_DIRS.contains); | |
| 373 }).toList(); | |
| 374 } | |
| 375 } | 328 } |
| OLD | NEW |