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

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

Issue 24886002: Support dart2js in pub serve. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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/server.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback/server.dart b/sdk/lib/_internal/pub/lib/src/barback/server.dart
index a2ce379e49637edcea89dbc4d40e3e8d05e5096f..ce533f1927b177990dc177db2fb3c3ee454b11a0 100644
--- a/sdk/lib/_internal/pub/lib/src/barback/server.dart
+++ b/sdk/lib/_internal/pub/lib/src/barback/server.dart
@@ -8,9 +8,9 @@ import 'dart:async';
import 'dart:io';
import 'package:barback/barback.dart';
-import 'package:path/path.dart' as path;
import 'package:stack_trace/stack_trace.dart';
+import '../barback.dart';
import '../log.dart' as log;
import '../utils.dart';
@@ -75,7 +75,7 @@ class BarbackServer {
return;
}
- var id = _getIdFromUri(request.uri);
+ var id = uriToId(_rootPackage, request.uri);
if (id == null) {
_notFound(request, "Path ${request.uri.path} is not valid.");
return;
@@ -151,53 +151,6 @@ class BarbackServer {
request.response.close();
}
- /// Converts a request [uri] into an [AssetId] that can be requested from
- /// barback.
- AssetId _getIdFromUri(Uri uri) {
- var parts = path.url.split(uri.path);
-
- // Strip the leading "/" from the URL.
- parts.removeAt(0);
-
- var isSpecial = false;
-
- // Checks to see if [uri]'s path contains a special directory [name] that
- // identifies an asset within some package. If so, maps the package name
- // and path following that to be within [dir] inside that package.
- AssetId _trySpecialUrl(String name, String dir) {
- // Find the package name and the relative path in the package.
- var index = parts.indexOf(name);
- if (index == -1) return null;
-
- // If we got here, the path *did* contain the special directory, which
- // means we should not interpret it as a regular path, even if it's
- // missing the package name after it, which makes it invalid here.
- isSpecial = true;
- if (index + 1 >= parts.length) return null;
-
- var package = parts[index + 1];
- var assetPath = path.url.join(dir,
- path.url.joinAll(parts.skip(index + 2)));
- return new AssetId(package, assetPath);
- }
-
- // See if it's "packages" URL.
- var id = _trySpecialUrl("packages", "lib");
- if (id != null) return id;
-
- // See if it's an "assets" URL.
- id = _trySpecialUrl("assets", "asset");
- if (id != null) return id;
-
- // If we got here, we had a path like "/packages" which is a special
- // directory, but not a valid path since it lacks a following package name.
- if (isSpecial) return null;
-
- // Otherwise, it's a path in current package's web directory.
- return new AssetId(_rootPackage,
- path.url.join("web", path.url.joinAll(parts)));
- }
-
/// Log [message] at [log.Level.FINE] with metadata about [request].
void _logRequest(HttpRequest request, String message) =>
log.fine("BarbackServer ${request.method} ${request.uri}\n$message");

Powered by Google App Engine
This is Rietveld 408576698