OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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.pub_package_provider; | 5 library pub.pub_package_provider; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
11 | 11 |
12 import '../io.dart'; | 12 import '../io.dart'; |
13 import '../package_graph.dart'; | 13 import '../package_graph.dart'; |
14 import '../preprocess.dart'; | 14 import '../preprocess.dart'; |
15 import '../sdk.dart' as sdk; | 15 import '../sdk.dart' as sdk; |
16 import '../utils.dart'; | 16 import '../utils.dart'; |
17 | 17 |
18 /// An implementation of barback's [PackageProvider] interface so that barback | 18 /// An implementation of barback's [PackageProvider] interface so that barback |
19 /// can find assets within pub packages. | 19 /// can find assets within pub packages. |
20 class PubPackageProvider implements PackageProvider { | 20 class PubPackageProvider implements PackageProvider { |
21 final PackageGraph _graph; | 21 final PackageGraph _graph; |
22 final List<String> packages; | 22 final List<String> packages; |
23 | 23 |
24 PubPackageProvider(PackageGraph graph, [Iterable<String> packages]) | 24 PubPackageProvider(PackageGraph graph) |
25 : _graph = graph, | 25 : _graph = graph, |
26 packages = [r"$pub", r"$sdk"] | 26 packages = [r"$pub", r"$sdk"]..addAll(graph.packages.keys); |
27 ..addAll(packages == null ? graph.packages.keys : packages); | |
28 | 27 |
29 Future<Asset> getAsset(AssetId id) { | 28 Future<Asset> getAsset(AssetId id) { |
30 // "$pub" is a psuedo-package that allows pub's transformer-loading | 29 // "$pub" is a psuedo-package that allows pub's transformer-loading |
31 // infrastructure to share code with pub proper. | 30 // infrastructure to share code with pub proper. |
32 if (id.package == r'$pub') { | 31 if (id.package == r'$pub') { |
33 var components = path.url.split(id.path); | 32 var components = path.url.split(id.path); |
34 assert(components.isNotEmpty); | 33 assert(components.isNotEmpty); |
35 assert(components.first == 'lib'); | 34 assert(components.first == 'lib'); |
36 components[0] = 'dart'; | 35 components[0] = 'dart'; |
37 var file = assetPath(path.joinAll(components)); | 36 var file = assetPath(path.joinAll(components)); |
(...skipping 22 matching lines...) Expand all Loading... |
60 // since dart2js adds it and expects it to be there. | 59 // since dart2js adds it and expects it to be there. |
61 var parts = path.split(path.fromUri(id.path)); | 60 var parts = path.split(path.fromUri(id.path)); |
62 assert(parts.isNotEmpty && parts[0] == 'lib'); | 61 assert(parts.isNotEmpty && parts[0] == 'lib'); |
63 parts = parts.skip(1); | 62 parts = parts.skip(1); |
64 | 63 |
65 var file = path.join(sdk.rootDirectory, path.joinAll(parts)); | 64 var file = path.join(sdk.rootDirectory, path.joinAll(parts)); |
66 return new Future.value(new Asset.fromPath(id, file)); | 65 return new Future.value(new Asset.fromPath(id, file)); |
67 } | 66 } |
68 | 67 |
69 var nativePath = path.fromUri(id.path); | 68 var nativePath = path.fromUri(id.path); |
70 var file = path.join(_graph.packages[id.package].dir, nativePath); | 69 var file = _graph.packages[id.package].path(nativePath); |
71 return new Future.value(new Asset.fromPath(id, file)); | 70 return new Future.value(new Asset.fromPath(id, file)); |
72 } | 71 } |
73 } | 72 } |
OLD | NEW |