Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Unified Diff: sdk/lib/_internal/pub/lib/src/barback.dart

Issue 24886002: Support dart2js in pub serve. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/pub/lib/src/barback.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback.dart b/sdk/lib/_internal/pub/lib/src/barback.dart
index 803ec64fb69a049146313b9d4a05aaa3017c63fe..70b36b50b57b84db7415641d76a89ab36b8661fb 100644
--- a/sdk/lib/_internal/pub/lib/src/barback.dart
+++ b/sdk/lib/_internal/pub/lib/src/barback.dart
@@ -7,7 +7,10 @@ library pub.barback;
import 'dart:async';
import 'package:barback/barback.dart';
+import 'package:path/path.dart' as path;
+import 'barback/dart_forwarding_transformer.dart';
+import 'barback/dart2js_transformer.dart';
import 'barback/load_all_transformers.dart';
import 'barback/pub_package_provider.dart';
import 'barback/server.dart';
@@ -54,6 +57,14 @@ class TransformerId {
Future<BarbackServer> createServer(String host, int port, PackageGraph graph) {
var provider = new PubPackageProvider(graph);
var barback = new Barback(provider);
+
+ // TODO(rnystrom): Add dart2dart transformer here and some way to configure
+ // them.
+ var builtInTransformers = [
+ new Dart2JSTransformer(graph),
+ new DartForwardingTransformer()
+ ];
+
return BarbackServer.bind(host, port, barback, graph.entrypoint.root.name)
.then((server) {
watchSources(graph, barback);
@@ -75,7 +86,7 @@ Future<BarbackServer> createServer(String host, int port, PackageGraph graph) {
})
];
- loadAllTransformers(server, graph).then((_) {
+ loadAllTransformers(server, graph, builtInTransformers).then((_) {
if (!completer.isCompleted) completer.complete(server);
}).catchError((error) {
if (!completer.isCompleted) completer.completeError(error);
@@ -141,3 +152,38 @@ Uri idToPackageUri(AssetId id) {
return new Uri(scheme: 'package', path: id.path.replaceFirst('lib/', ''));
}
+
+/// Converts [uri] into an [AssetId] if it has a path containing "packages" or
+/// "assets".
+///
+/// If the URI doesn't contain one of those special directories, returns null.
+/// If it does contain a special directory, but lacks a following package name,
+/// throws a [FormatException].
+AssetId specialUrlToId(Uri url) {
+ var parts = path.url.split(url.path);
+
+ for (var pair in [["packages", "lib"], ["assets", "asset"]]) {
+ var partName = pair.first;
+ var dirName = pair.last;
+
+ // Find the package name and the relative path in the package.
+ var index = parts.indexOf(partName);
+ if (index == -1) continue;
+
+ // If we got here, the path *did* contain the special directory, which
+ // means we should not interpret it as a regular path. If it's missing the
+ // package name after the special directory, it's invalid.
+ if (index + 1 >= parts.length) {
+ throw new FormatException(
+ 'Invalid package path "${path.url.joinAll(parts)}". '
+ 'Expected package name after "$partName".');
+ }
+
+ var package = parts[index + 1];
+ var assetPath = path.url.join(dirName,
+ path.url.joinAll(parts.skip(index + 2)));
+ return new AssetId(package, assetPath);
+ }
+
+ return null;
+}
« no previous file with comments | « pkg/barback/lib/src/transform_logger.dart ('k') | sdk/lib/_internal/pub/lib/src/barback/dart2js_transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698