| 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.pubspec; | 5 library pub.pubspec; |
| 6 | 6 |
| 7 import 'package:yaml/yaml.dart'; | 7 import 'package:yaml/yaml.dart'; |
| 8 import 'package:path/path.dart' as path; | 8 import 'package:path/path.dart' as path; |
| 9 | 9 |
| 10 import 'barback.dart'; | 10 import 'barback/transformer_config.dart'; |
| 11 import 'io.dart'; | 11 import 'io.dart'; |
| 12 import 'package.dart'; | 12 import 'package.dart'; |
| 13 import 'source_registry.dart'; | 13 import 'source_registry.dart'; |
| 14 import 'utils.dart'; | 14 import 'utils.dart'; |
| 15 import 'version.dart'; | 15 import 'version.dart'; |
| 16 | 16 |
| 17 /// The parsed contents of a pubspec file. | 17 /// The parsed contents of a pubspec file. |
| 18 /// | 18 /// |
| 19 /// The fields of a pubspec are, for the most part, validated when they're first | 19 /// The fields of a pubspec are, for the most part, validated when they're first |
| 20 /// accessed. This allows a partially-invalid pubspec to be used if only the | 20 /// accessed. This allows a partially-invalid pubspec to be used if only the |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 /// | 107 /// |
| 108 /// Dependencies here will replace any dependency on a package with the same | 108 /// Dependencies here will replace any dependency on a package with the same |
| 109 /// name anywhere in the dependency graph. | 109 /// name anywhere in the dependency graph. |
| 110 List<PackageDep> get dependencyOverrides { | 110 List<PackageDep> get dependencyOverrides { |
| 111 if (_dependencyOverrides != null) return _dependencyOverrides; | 111 if (_dependencyOverrides != null) return _dependencyOverrides; |
| 112 _dependencyOverrides = _parseDependencies('dependency_overrides'); | 112 _dependencyOverrides = _parseDependencies('dependency_overrides'); |
| 113 return _dependencyOverrides; | 113 return _dependencyOverrides; |
| 114 } | 114 } |
| 115 List<PackageDep> _dependencyOverrides; | 115 List<PackageDep> _dependencyOverrides; |
| 116 | 116 |
| 117 /// The ids of the transformers to use for this package. | 117 /// The configurations of the transformers to use for this package. |
| 118 List<Set<TransformerId>> get transformers { | 118 List<Set<TransformerConfig>> get transformers { |
| 119 if (_transformers != null) return _transformers; | 119 if (_transformers != null) return _transformers; |
| 120 | 120 |
| 121 var transformers = fields['transformers']; | 121 var transformers = fields['transformers']; |
| 122 if (transformers == null) { | 122 if (transformers == null) { |
| 123 _transformers = []; | 123 _transformers = []; |
| 124 return _transformers; | 124 return _transformers; |
| 125 } | 125 } |
| 126 | 126 |
| 127 if (transformers is! List) { | 127 if (transformers is! List) { |
| 128 _error('"transformers" field must be a list, but was "$transformers".'); | 128 _error('"transformers" field must be a list, but was "$transformers".'); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 157 } | 157 } |
| 158 | 158 |
| 159 library = transformer.keys.single; | 159 library = transformer.keys.single; |
| 160 configuration = transformer.values.single; | 160 configuration = transformer.values.single; |
| 161 if (configuration is! Map) { | 161 if (configuration is! Map) { |
| 162 _error('"$field.$library" field must be a map, but was ' | 162 _error('"$field.$library" field must be a map, but was ' |
| 163 '"$configuration".'); | 163 '"$configuration".'); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 var id = _wrapFormatException("transformer configuration", | 167 var config = _wrapFormatException("transformer configuration", |
| 168 "$field.$library", | 168 "$field.$library", |
| 169 () => new TransformerId.parse(library, configuration)); | 169 () => new TransformerConfig.parse(library, configuration)); |
| 170 | 170 |
| 171 if (id.package != name && | 171 var package = config.id.package; |
| 172 !id.isBuiltInTransformer && | 172 if (package != name && |
| 173 !dependencies.any((ref) => ref.name == id.package) && | 173 !config.id.isBuiltInTransformer && |
| 174 !devDependencies.any((ref) => ref.name == id.package) && | 174 !dependencies.any((ref) => ref.name == package) && |
| 175 !dependencyOverrides.any((ref) => ref.name == id.package)) { | 175 !devDependencies.any((ref) => ref.name == package) && |
| 176 !dependencyOverrides.any((ref) => ref.name == package)) { |
| 176 _error('"$field.$library" refers to a package that\'s not a ' | 177 _error('"$field.$library" refers to a package that\'s not a ' |
| 177 'dependency.'); | 178 'dependency.'); |
| 178 } | 179 } |
| 179 | 180 |
| 180 return id; | 181 return config; |
| 181 }).toSet(); | 182 }).toSet(); |
| 182 }).toList(); | 183 }).toList(); |
| 183 | 184 |
| 184 return _transformers; | 185 return _transformers; |
| 185 } | 186 } |
| 186 List<Set<TransformerId>> _transformers; | 187 List<Set<TransformerConfig>> _transformers; |
| 187 | 188 |
| 188 /// The environment-related metadata. | 189 /// The environment-related metadata. |
| 189 PubspecEnvironment get environment { | 190 PubspecEnvironment get environment { |
| 190 if (_environment != null) return _environment; | 191 if (_environment != null) return _environment; |
| 191 | 192 |
| 192 var yaml = fields['environment']; | 193 var yaml = fields['environment']; |
| 193 if (yaml == null) { | 194 if (yaml == null) { |
| 194 _environment = new PubspecEnvironment(VersionConstraint.any); | 195 _environment = new PubspecEnvironment(VersionConstraint.any); |
| 195 return _environment; | 196 return _environment; |
| 196 } | 197 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 _location = null; | 239 _location = null; |
| 239 | 240 |
| 240 Pubspec.empty() | 241 Pubspec.empty() |
| 241 : _sources = null, | 242 : _sources = null, |
| 242 _location = null, | 243 _location = null, |
| 243 _name = null, | 244 _name = null, |
| 244 _version = Version.none, | 245 _version = Version.none, |
| 245 _dependencies = <PackageDep>[], | 246 _dependencies = <PackageDep>[], |
| 246 _devDependencies = <PackageDep>[], | 247 _devDependencies = <PackageDep>[], |
| 247 _environment = new PubspecEnvironment(), | 248 _environment = new PubspecEnvironment(), |
| 248 _transformers = <Set<TransformerId>>[], | 249 _transformers = <Set<TransformerConfig>>[], |
| 249 fields = {}; | 250 fields = {}; |
| 250 | 251 |
| 251 /// Returns a Pubspec object for an already-parsed map representing its | 252 /// Returns a Pubspec object for an already-parsed map representing its |
| 252 /// contents. | 253 /// contents. |
| 253 /// | 254 /// |
| 254 /// If [expectedName] is passed and the pubspec doesn't have a matching name | 255 /// If [expectedName] is passed and the pubspec doesn't have a matching name |
| 255 /// field, this will throw a [PubspecError]. | 256 /// field, this will throw a [PubspecError]. |
| 256 /// | 257 /// |
| 257 /// [location] is the location from which this pubspec was loaded. | 258 /// [location] is the location from which this pubspec was loaded. |
| 258 Pubspec.fromMap(this.fields, this._sources, {String expectedName, | 259 Pubspec.fromMap(this.fields, this._sources, {String expectedName, |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 513 |
| 513 return "$str:\n$subMessage"; | 514 return "$str:\n$subMessage"; |
| 514 } | 515 } |
| 515 } | 516 } |
| 516 | 517 |
| 517 /// Returns whether [uri] is a file URI. | 518 /// Returns whether [uri] is a file URI. |
| 518 /// | 519 /// |
| 519 /// This is slightly more complicated than just checking if the scheme is | 520 /// This is slightly more complicated than just checking if the scheme is |
| 520 /// 'file', since relative URIs also refer to the filesystem on the VM. | 521 /// 'file', since relative URIs also refer to the filesystem on the VM. |
| 521 bool _isFileUri(Uri uri) => uri.scheme == 'file' || uri.scheme == ''; | 522 bool _isFileUri(Uri uri) => uri.scheme == 'file' || uri.scheme == ''; |
| OLD | NEW |