Chromium Code Reviews| Index: lib/src/lock_file.dart |
| diff --git a/lib/src/lock_file.dart b/lib/src/lock_file.dart |
| index d79a42e2309c39e2b8a2473a3ccc7f0ce9c4c1fc..7c6d2221dd10f3df3a8a7b99d35bb7a101532dd3 100644 |
| --- a/lib/src/lock_file.dart |
| +++ b/lib/src/lock_file.dart |
| @@ -7,6 +7,7 @@ library pub.lock_file; |
| import 'dart:collection'; |
| import 'package:path/path.dart' as p; |
| +import 'package:package_config/packages_file.dart' as packages_file; |
| import 'package:pub_semver/pub_semver.dart'; |
| import 'package:source_span/source_span.dart'; |
| import 'package:yaml/yaml.dart'; |
| @@ -152,6 +153,31 @@ class LockFile { |
| return new LockFile._(packages, _sources); |
| } |
| + /// Returns the contents of the `.packages` file generated from this lockfile. |
| + /// |
| + /// If [entrypoint] is passed, a relative entry is added for its "lib/" |
| + /// directory. |
| + String packagesFile([String entrypoint]) { |
| + var header = """ |
| +Generated by pub on ${new DateTime.now()}. |
| +This file contains a map from Dart package names to Dart package locations. |
| +Dart tools, including the Dart VM and Dart analyzer, rely on the content. |
|
Bob Nystrom
2015/08/07 23:51:25
I don't think it's worth putting this in every fil
nweiz
2015/08/08 00:52:57
Done.
|
| +AUTO GENERATED - DO NOT EDIT |
| +"""; |
| + |
| + var map = new Map.fromIterable(ordered(packages.keys), value: (name) { |
| + var id = packages[name]; |
| + var source = _sources[id.source]; |
| + return p.toUri(p.join(source.getDirectory(id), "lib")); |
|
Bob Nystrom
2015/08/07 23:51:25
What do you think about making this path relative
nweiz
2015/08/08 00:52:57
It does that for path dependencies. For cached dep
|
| + }); |
| + |
| + if (entrypoint != null) map[entrypoint] = Uri.parse("lib/"); |
| + |
| + var text = new StringBuffer(); |
| + packages_file.write(text, map, comment: header); |
| + return text.toString(); |
| + } |
| + |
| /// Returns the serialized YAML text of the lock file. |
| /// |
| /// [packageDir] is the containing directory of the root package, used to |