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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'dart:io';
6
7 import 'package:path/path.dart' as p;
8
9 import 'async_package_resolver.dart';
10 import 'package_resolver.dart';
11 import 'sync_package_resolver.dart';
12 import 'utils.dart';
13
14 /// A package resolution strategy based on a package root URI.
15 class PackageRootResolver implements SyncPackageResolver {
16 final packageConfigMap = null;
17 final packageConfigUri = null;
18
19 final Uri packageRoot;
20
21 PackageResolver get asAsync => new AsyncPackageResolver(this);
22
23 String get processArgument => "--package-root=$packageRoot";
24
25 PackageRootResolver(packageRoot)
26 : packageRoot = ensureTrailingSlash(asUri(packageRoot, "packageRoot"));
27
28 Uri resolveUri(packageUri) {
29 packageUri = asPackageUri(packageUri, "packageUri");
30
31 // Following [Isolate.resolvePackageUri], "package:foo" resolves to null.
32 if (packageUri.pathSegments.length == 1) return null;
33 return packageRoot.resolve(packageUri.path);
34 }
35
36 Uri urlFor(String package, [String path]) {
37 var result = packageRoot.resolve("$package/");
38 return path == null ? result : result.resolve(path);
39 }
40
41 Uri packageUriFor(url) {
42 var packageRootString = packageRoot.toString();
43 url = asUri(url, "url").toString();
44 if (!p.url.isWithin(packageRootString, url)) return null;
45
46 var relative = p.url.relative(url, from: packageRootString);
47 if (!relative.contains("/")) relative += "/";
48 return Uri.parse("package:$relative");
49 }
50
51 String packagePath(String package) {
52 if (packageRoot.scheme != 'file') return null;
53
54 var libLink = p.join(p.fromUri(packageRoot), package);
55 if (!new Link(libLink).existsSync()) return null;
56
57 return p.dirname(new Link(libLink).resolveSymbolicLinksSync());
58 }
59 }
OLDNEW
« 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