| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library pub.barback; | |
| 6 | |
| 7 import 'package:barback/barback.dart'; | |
| 8 import 'package:path/path.dart' as p; | |
| 9 import 'package:pub_semver/pub_semver.dart'; | |
| 10 | |
| 11 /// The currently supported versions of packages that this version of pub works | |
| 12 /// with. | |
| 13 /// | |
| 14 /// Pub implicitly constrains these packages to these versions as long as | |
| 15 /// barback is a dependency. | |
| 16 /// | |
| 17 /// Users' transformers are loaded in an isolate that uses the entrypoint | |
| 18 /// package's dependency versions. However, that isolate also loads code | |
| 19 /// provided by pub (`asset/dart/transformer_isolate.dart` and associated | |
| 20 /// files). This code uses these packages as well, so these constraints exist to | |
| 21 /// ensure that its usage of the packages remains valid. | |
| 22 /// | |
| 23 /// Most constraints here are like normal version constraints in that their | |
| 24 /// upper bound is the next major version of the package (or minor version for | |
| 25 /// pre-1.0.0 packages). If a new major version of the package is released, | |
| 26 /// these *must* be incremented to synchronize with that. | |
| 27 /// | |
| 28 /// The constraint on barback is different. Its upper bound is the next *patch* | |
| 29 /// version of barback—that is, the next version with new features. This is | |
| 30 /// because most barback features need additional serialization code to be fully | |
| 31 /// supported in pub, even if they're otherwise backwards-compatible. | |
| 32 /// | |
| 33 /// Whenever a new minor or patch version of barback is published, this *must* | |
| 34 /// be incremented to synchronize with that. See the barback [compatibility | |
| 35 /// documentation][compat] for details on the relationship between this | |
| 36 /// constraint and barback's version. | |
| 37 /// | |
| 38 /// [compat]: https://gist.github.com/nex3/10942218 | |
| 39 final pubConstraints = { | |
| 40 "barback": new VersionConstraint.parse(">=0.13.0 <0.15.3"), | |
| 41 "source_span": new VersionConstraint.parse(">=1.0.0 <2.0.0"), | |
| 42 "stack_trace": new VersionConstraint.parse(">=0.9.1 <2.0.0") | |
| 43 }; | |
| 44 | |
| 45 /// Converts [id] to a "package:" URI. | |
| 46 /// | |
| 47 /// This will throw an [ArgumentError] if [id] doesn't represent a library in | |
| 48 /// `lib/`. | |
| 49 Uri idToPackageUri(AssetId id) { | |
| 50 if (!id.path.startsWith('lib/')) { | |
| 51 throw new ArgumentError("Asset id $id doesn't identify a library."); | |
| 52 } | |
| 53 | |
| 54 return new Uri( | |
| 55 scheme: 'package', | |
| 56 path: p.url.join(id.package, id.path.replaceFirst('lib/', ''))); | |
| 57 } | |
| 58 | |
| 59 /// Converts [uri] into an [AssetId] if its path is within "packages". | |
| 60 /// | |
| 61 /// If the URL contains a special directory, but lacks a following package name, | |
| 62 /// throws a [FormatException]. | |
| 63 /// | |
| 64 /// If the URI doesn't contain one of those special directories, returns null. | |
| 65 AssetId packagesUrlToId(Uri url) { | |
| 66 var parts = p.url.split(url.path); | |
| 67 | |
| 68 // Strip the leading "/" from the URL. | |
| 69 if (parts.isNotEmpty && parts.first == "/") parts = parts.skip(1).toList(); | |
| 70 | |
| 71 if (parts.isEmpty) return null; | |
| 72 | |
| 73 // Check for "packages" in the URL. | |
| 74 // TODO(rnystrom): If we rewrite "package:" imports to relative imports that | |
| 75 // point to a canonical "packages" directory, we can limit "packages" to the | |
| 76 // root of the URL as well. See: #16649. | |
| 77 var index = parts.indexOf("packages"); | |
| 78 if (index == -1) return null; | |
| 79 | |
| 80 // There should be a package name after "packages". | |
| 81 if (parts.length <= index + 1) { | |
| 82 throw new FormatException( | |
| 83 'Invalid URL path "${url.path}". Expected package name ' 'after "package
s".'); | |
| 84 } | |
| 85 | |
| 86 var package = parts[index + 1]; | |
| 87 var assetPath = p.url.join("lib", p.url.joinAll(parts.skip(index + 2))); | |
| 88 return new AssetId(package, assetPath); | |
| 89 } | |
| OLD | NEW |