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

Unified Diff: lib/src/current_isolate_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/async_package_resolver.dart ('k') | lib/src/no_package_resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/current_isolate_resolver.dart
diff --git a/lib/src/current_isolate_resolver.dart b/lib/src/current_isolate_resolver.dart
new file mode 100644
index 0000000000000000000000000000000000000000..eb4dc9b57a721f0ceb6ea45a0772ca2f44c8f3b4
--- /dev/null
+++ b/lib/src/current_isolate_resolver.dart
@@ -0,0 +1,70 @@
+// 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:async';
+import 'dart:isolate';
+
+import 'package:path/path.dart' as p;
+
+import 'package_config_resolver.dart';
+import 'package_resolver.dart';
+import 'package_root_resolver.dart';
+import 'sync_package_resolver.dart';
+import 'utils.dart';
+
+/// The package resolution strategy used by the current isolate.
+class CurrentIsolateResolver implements PackageResolver {
+ Future<Map<String, Uri>> get packageConfigMap async {
+ if (_packageConfigMap != null) return _packageConfigMap;
+
+ var url = await Isolate.packageConfig;
+ if (url == null) return null;
+
+ return await loadConfigMap(url);
+ }
+ Map<String, Uri> _packageConfigMap;
+
+ Future<Uri> get packageConfigUri => Isolate.packageConfig;
+
+ Future<Uri> get packageRoot => Isolate.packageRoot;
+
+ Future<SyncPackageResolver> get asSync async {
+ var root = await packageRoot;
+ if (root != null) return new PackageRootResolver(root);
+
+ var map = await packageConfigMap;
+
+ // It's hard to imagine how there would be no package resolution strategy
+ // for an Isolate that can load the package_resolver package, but it's easy
+ // to handle that case so we do.
+ if (map == null) return SyncPackageResolver.none;
+
+ return new PackageConfigResolver(map, uri: await packageConfigUri);
+ }
+
+ Future<String> get processArgument async {
+ var configUri = await packageConfigUri;
+ if (configUri != null) return "--packages=$configUri";
+
+ var root = await packageRoot;
+ if (root != null) return "--package-root=$root";
+
+ return null;
+ }
+
+ Future<Uri> resolveUri(packageUri) =>
+ Isolate.resolvePackageUri(asPackageUri(packageUri, "packageUri"));
+
+ Future<Uri> urlFor(String package, [String path]) =>
+ Isolate.resolvePackageUri(Uri.parse("package:$package/${path ?? ''}"));
+
+ Future<Uri> packageUriFor(url) async => (await asSync).packageUriFor(url);
+
+ Future<String> packagePath(String package) async {
+ var root = await packageRoot;
+ if (root != null) return new PackageRootResolver(root).packagePath(package);
+
+ return p.dirname(p.fromUri(await urlFor(package)));
+ }
+}
« no previous file with comments | « lib/src/async_package_resolver.dart ('k') | lib/src/no_package_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698