Chromium Code Reviews| 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.lock_file; | 5 library pub.lock_file; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 10 import 'package:package_config/packages_file.dart' as packages_file; | |
| 10 import 'package:pub_semver/pub_semver.dart'; | 11 import 'package:pub_semver/pub_semver.dart'; |
| 11 import 'package:source_span/source_span.dart'; | 12 import 'package:source_span/source_span.dart'; |
| 12 import 'package:yaml/yaml.dart'; | 13 import 'package:yaml/yaml.dart'; |
| 13 | 14 |
| 14 import 'io.dart'; | 15 import 'io.dart'; |
| 15 import 'package.dart'; | 16 import 'package.dart'; |
| 16 import 'source_registry.dart'; | 17 import 'source_registry.dart'; |
| 17 import 'utils.dart'; | 18 import 'utils.dart'; |
| 18 | 19 |
| 19 /// A parsed and validated `pubspec.lock` file. | 20 /// A parsed and validated `pubspec.lock` file. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 /// | 146 /// |
| 146 /// Returns an identical [LockFile] if there's no package named [name]. | 147 /// Returns an identical [LockFile] if there's no package named [name]. |
| 147 LockFile removePackage(String name) { | 148 LockFile removePackage(String name) { |
| 148 if (!this.packages.containsKey(name)) return this; | 149 if (!this.packages.containsKey(name)) return this; |
| 149 | 150 |
| 150 var packages = new Map.from(this.packages); | 151 var packages = new Map.from(this.packages); |
| 151 packages.remove(name); | 152 packages.remove(name); |
| 152 return new LockFile._(packages, _sources); | 153 return new LockFile._(packages, _sources); |
| 153 } | 154 } |
| 154 | 155 |
| 156 /// Returns the contents of the `.packages` file generated from this lockfile. | |
| 157 /// | |
| 158 /// If [entrypoint] is passed, a relative entry is added for its "lib/" | |
| 159 /// directory. | |
| 160 String packagesFile([String entrypoint]) { | |
| 161 var header = """ | |
| 162 Generated by pub on ${new DateTime.now()}. | |
| 163 This file contains a map from Dart package names to Dart package locations. | |
| 164 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.
| |
| 165 AUTO GENERATED - DO NOT EDIT | |
| 166 """; | |
| 167 | |
| 168 var map = new Map.fromIterable(ordered(packages.keys), value: (name) { | |
| 169 var id = packages[name]; | |
| 170 var source = _sources[id.source]; | |
| 171 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
| |
| 172 }); | |
| 173 | |
| 174 if (entrypoint != null) map[entrypoint] = Uri.parse("lib/"); | |
| 175 | |
| 176 var text = new StringBuffer(); | |
| 177 packages_file.write(text, map, comment: header); | |
| 178 return text.toString(); | |
| 179 } | |
| 180 | |
| 155 /// Returns the serialized YAML text of the lock file. | 181 /// Returns the serialized YAML text of the lock file. |
| 156 /// | 182 /// |
| 157 /// [packageDir] is the containing directory of the root package, used to | 183 /// [packageDir] is the containing directory of the root package, used to |
| 158 /// properly serialize package descriptions. | 184 /// properly serialize package descriptions. |
| 159 String serialize(String packageDir) { | 185 String serialize(String packageDir) { |
| 160 // Convert the dependencies to a simple object. | 186 // Convert the dependencies to a simple object. |
| 161 var data = {}; | 187 var data = {}; |
| 162 packages.forEach((name, package) { | 188 packages.forEach((name, package) { |
| 163 var description = _sources[package.source] | 189 var description = _sources[package.source] |
| 164 .serializeDescription(packageDir, package.description); | 190 .serializeDescription(packageDir, package.description); |
| 165 | 191 |
| 166 data[name] = { | 192 data[name] = { |
| 167 'version': package.version.toString(), | 193 'version': package.version.toString(), |
| 168 'source': package.source, | 194 'source': package.source, |
| 169 'description': description | 195 'description': description |
| 170 }; | 196 }; |
| 171 }); | 197 }); |
| 172 | 198 |
| 173 return """ | 199 return """ |
| 174 # Generated by pub | 200 # Generated by pub |
| 175 # See http://pub.dartlang.org/doc/glossary.html#lockfile | 201 # See http://pub.dartlang.org/doc/glossary.html#lockfile |
| 176 ${yamlToString({'packages': data})} | 202 ${yamlToString({'packages': data})} |
| 177 """; | 203 """; |
| 178 } | 204 } |
| 179 } | 205 } |
| OLD | NEW |