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

Unified Diff: lib/src/package_root_resolver.dart

Issue 2132443003: Add package implementation. (Closed) Base URL: git@github.com:dart-lang/package_resolver@master
Patch Set: Code review changes Created 4 years, 5 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
« no previous file with comments | « lib/src/package_resolver.dart ('k') | lib/src/sync_package_resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/package_root_resolver.dart
diff --git a/lib/src/package_root_resolver.dart b/lib/src/package_root_resolver.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c9a06fff4f503c077dc3f1a380c03e6a192ec7fc
--- /dev/null
+++ b/lib/src/package_root_resolver.dart
@@ -0,0 +1,59 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io';
+
+import 'package:path/path.dart' as p;
+
+import 'async_package_resolver.dart';
+import 'package_resolver.dart';
+import 'sync_package_resolver.dart';
+import 'utils.dart';
+
+/// A package resolution strategy based on a package root URI.
+class PackageRootResolver implements SyncPackageResolver {
+ final packageConfigMap = null;
+ final packageConfigUri = null;
+
+ final Uri packageRoot;
+
+ PackageResolver get asAsync => new AsyncPackageResolver(this);
+
+ String get processArgument => "--package-root=$packageRoot";
+
+ PackageRootResolver(packageRoot)
+ : packageRoot = ensureTrailingSlash(asUri(packageRoot, "packageRoot"));
+
+ Uri resolveUri(packageUri) {
+ packageUri = asPackageUri(packageUri, "packageUri");
+
+ // Following [Isolate.resolvePackageUri], "package:foo" resolves to null.
+ if (packageUri.pathSegments.length == 1) return null;
+ return packageRoot.resolve(packageUri.path);
+ }
+
+ Uri urlFor(String package, [String path]) {
+ var result = packageRoot.resolve("$package/");
+ return path == null ? result : result.resolve(path);
+ }
+
+ Uri packageUriFor(url) {
+ var packageRootString = packageRoot.toString();
+ url = asUri(url, "url").toString();
+ if (!p.url.isWithin(packageRootString, url)) return null;
+
+ var relative = p.url.relative(url, from: packageRootString);
+ if (!relative.contains("/")) relative += "/";
+ return Uri.parse("package:$relative");
+ }
+
+ String packagePath(String package) {
+ if (packageRoot.scheme != 'file') return null;
+
+ var libLink = p.join(p.fromUri(packageRoot), package);
+ if (!new Link(libLink).existsSync()) return null;
+
+ return p.dirname(new Link(libLink).resolveSymbolicLinksSync());
+ }
+}
« no previous file with comments | « lib/src/package_resolver.dart ('k') | lib/src/sync_package_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698