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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
| 8 import 'package:async/async.dart'; |
8 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
| 10 import 'package:collection/collection.dart'; |
9 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
| 12 import 'package:pub_semver/pub_semver.dart'; |
10 | 13 |
11 import '../io.dart'; | 14 import '../io.dart'; |
| 15 import '../package.dart'; |
12 import '../package_graph.dart'; | 16 import '../package_graph.dart'; |
13 import '../preprocess.dart'; | 17 import '../preprocess.dart'; |
14 import '../sdk.dart' as sdk; | 18 import '../sdk.dart' as sdk; |
15 import '../utils.dart'; | |
16 | 19 |
17 /// The path to the lib directory of the compiler_unsupported package used by | 20 /// The path to the lib directory of the compiler_unsupported package used by |
18 /// pub. | 21 /// pub. |
19 /// | 22 /// |
20 /// This is used to make sure dart2js is running against its own version of its | 23 /// This is used to make sure dart2js is running against its own version of its |
21 /// internal libraries when running from the pub repo. It's `null` if we're | 24 /// internal libraries when running from the pub repo. It's `null` if we're |
22 /// running from the Dart repo or from the built SDK. | 25 /// running from the Dart repo or from the built SDK. |
23 final _compilerUnsupportedLib = (() { | 26 final _compilerUnsupportedLib = (() { |
24 if (runningFromSdk) return null; | 27 if (runningFromSdk) return null; |
25 if (runningFromDartRepo) return null; | 28 if (runningFromDartRepo) return null; |
(...skipping 30 matching lines...) Expand all Loading... |
56 var file = assetPath(path.joinAll(components)); | 59 var file = assetPath(path.joinAll(components)); |
57 _assertExists(file, id); | 60 _assertExists(file, id); |
58 | 61 |
59 // Barback may not be in the package graph if there are no user-defined | 62 // Barback may not be in the package graph if there are no user-defined |
60 // transformers being used at all. The "$pub" sources are still provided, | 63 // transformers being used at all. The "$pub" sources are still provided, |
61 // but will never be loaded. | 64 // but will never be loaded. |
62 if (!_graph.packages.containsKey("barback")) { | 65 if (!_graph.packages.containsKey("barback")) { |
63 return new Asset.fromPath(id, file); | 66 return new Asset.fromPath(id, file); |
64 } | 67 } |
65 | 68 |
66 var versions = mapMap(_graph.packages, | 69 var versions = mapMap/*<String, Package, String, Version>*/( |
| 70 _graph.packages, |
67 value: (_, package) => package.version); | 71 value: (_, package) => package.version); |
68 var contents = readTextFile(file); | 72 var contents = readTextFile(file); |
69 contents = preprocess(contents, versions, path.toUri(file)); | 73 contents = preprocess(contents, versions, path.toUri(file)); |
70 return new Asset.fromString(id, contents); | 74 return new Asset.fromString(id, contents); |
71 } | 75 } |
72 | 76 |
73 // "$sdk" is a pseudo-package that provides access to the Dart library | 77 // "$sdk" is a pseudo-package that provides access to the Dart library |
74 // sources in the SDK. The dart2js transformer uses this to locate the Dart | 78 // sources in the SDK. The dart2js transformer uses this to locate the Dart |
75 // sources for "dart:" libraries. | 79 // sources for "dart:" libraries. |
76 if (id.package == r'$sdk') { | 80 if (id.package == r'$sdk') { |
(...skipping 11 matching lines...) Expand all Loading... |
88 return new Asset.fromPath(id, file); | 92 return new Asset.fromPath(id, file); |
89 } | 93 } |
90 | 94 |
91 // If we're running from pub's repo, our version of dart2js comes from | 95 // If we're running from pub's repo, our version of dart2js comes from |
92 // compiler_unsupported and may expect different SDK sources than the | 96 // compiler_unsupported and may expect different SDK sources than the |
93 // actual SDK we're using. Handily, compiler_unsupported contains a full | 97 // actual SDK we're using. Handily, compiler_unsupported contains a full |
94 // (ZLib-encoded) copy of the SDK, so we load sources from that instead. | 98 // (ZLib-encoded) copy of the SDK, so we load sources from that instead. |
95 var file = path.join(_compilerUnsupportedLib, 'sdk', | 99 var file = path.join(_compilerUnsupportedLib, 'sdk', |
96 path.joinAll(parts.skip(1))) + "_"; | 100 path.joinAll(parts.skip(1))) + "_"; |
97 _assertExists(file, id); | 101 _assertExists(file, id); |
98 return new Asset.fromStream(id, callbackStream(() => | 102 return new Asset.fromStream(id, new LazyStream(() => |
99 _zlib.decoder.bind(new File(file).openRead()))); | 103 _zlib.decoder.bind(new File(file).openRead()))); |
100 } | 104 } |
101 | 105 |
102 var nativePath = path.fromUri(id.path); | 106 var nativePath = path.fromUri(id.path); |
103 var file = _graph.packages[id.package].path(nativePath); | 107 var file = _graph.packages[id.package].path(nativePath); |
104 _assertExists(file, id); | 108 _assertExists(file, id); |
105 return new Asset.fromPath(id, file); | 109 return new Asset.fromPath(id, file); |
106 } | 110 } |
107 | 111 |
108 /// Throw an [AssetNotFoundException] for [id] if [path] doesn't exist. | 112 /// Throw an [AssetNotFoundException] for [id] if [path] doesn't exist. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 } else { | 154 } else { |
151 var package = _graph.packages[packageName]; | 155 var package = _graph.packages[packageName]; |
152 return new Stream.fromIterable( | 156 return new Stream.fromIterable( |
153 package.listFiles(beneath: 'lib').map((file) { | 157 package.listFiles(beneath: 'lib').map((file) { |
154 return new AssetId(packageName, | 158 return new AssetId(packageName, |
155 path.toUri(package.relative(file)).toString()); | 159 path.toUri(package.relative(file)).toString()); |
156 })); | 160 })); |
157 } | 161 } |
158 } | 162 } |
159 } | 163 } |
OLD | NEW |