@@ -8,7 +8,6 @@ import 'package:logging/logging.dart';
8
8
import 'package:package_config/package_config.dart';
9
9
import 'package:path/path.dart' as p;
10
10
11
- import '../loaders/require.dart';
12
11
import '../loaders/strategy.dart';
13
12
import 'sdk_configuration.dart';
14
13
@@ -30,26 +29,22 @@ class DartUri {
30
29
/// path is a web server path and so relative to the directory being
31
30
/// served, not to the package.
32
31
///
33
- /// The optional [serverUri] is a temporary workaround for a bug with construction.
34
- /// Older SDKs (before D24) gave us a path that didn't include the full path,
35
- /// e.g. main.dart rather than hello_world/main.dart and src/path.dart rather than
36
- /// packages/path/src/path.dart. The optional [serverUri] is the full URI of the
37
- /// JS script. The dirname of that path should give us the missing prefix.
38
- factory DartUri(String uri, [String serverUri]) {
32
+ /// The optional [root] is the directory the app is served from.
33
+ factory DartUri(String uri, [String root]) {
39
34
final serverPath = globalLoadStrategy.serverPathForAppUri(uri);
40
35
if (serverPath != null) {
41
36
return DartUri._(serverPath);
42
37
}
43
38
// TODO(annagrin): Support creating DartUris from `dart:` uris.
44
39
// Issue: https://github.com/dart-lang/webdev/issues/1584
45
40
if (uri.startsWith('package:')) {
46
- return DartUri._fromPackageUri(uri, serverUri: serverUri );
41
+ return DartUri._fromPackageUri(uri, root: root );
47
42
}
48
43
if (uri.startsWith('file:')) {
49
- return DartUri._fromFileUri(uri, serverUri: serverUri );
44
+ return DartUri._fromFileUri(uri, root: root );
50
45
}
51
46
if (uri.startsWith('/packages/')) {
52
- return DartUri._fromRelativePath(uri, serverUri: serverUri );
47
+ return DartUri._fromRelativePath(uri, root: root );
53
48
}
54
49
if (uri.startsWith('/')) {
55
50
return DartUri._fromRelativePath(uri);
@@ -65,32 +60,30 @@ class DartUri {
65
60
String toString() => 'DartUri: $serverPath';
66
61
67
62
/// Construct from a package: URI
68
- factory DartUri._fromPackageUri(String uri, {String serverUri}) {
69
- final basePath = basePathForServerUri(serverUri);
63
+ factory DartUri._fromPackageUri(String uri, {String root}) {
70
64
final packagePath = 'packages/${uri.substring("package:".length)}';
71
- if (serverUri != null) {
72
- final relativePath = p.url.join(basePath , packagePath);
65
+ if (root != null) {
66
+ final relativePath = p.url.join(root , packagePath);
73
67
return DartUri._fromRelativePath(relativePath);
74
68
}
75
69
return DartUri._(packagePath);
76
70
}
77
71
78
72
/// Construct from a file: URI
79
- factory DartUri._fromFileUri(String uri, {String serverUri }) {
73
+ factory DartUri._fromFileUri(String uri, {String root }) {
80
74
final libraryName = _resolvedUriToUri[uri];
81
- if (libraryName != null) return DartUri(libraryName, serverUri );
75
+ if (libraryName != null) return DartUri(libraryName, root );
82
76
// This is not one of our recorded libraries.
83
77
throw ArgumentError.value(uri, 'uri', 'Unknown library');
84
78
}
85
79
86
80
/// Construct from a path, relative to the directory being served.
87
- factory DartUri._fromRelativePath(String uri, {String serverUri }) {
81
+ factory DartUri._fromRelativePath(String uri, {String root }) {
88
82
uri = uri[0] == '.' ? uri.substring(1) : uri;
89
83
uri = uri[0] == '/' ? uri.substring(1) : uri;
90
84
91
- if (serverUri != null) {
92
- final basePath = basePathForServerUri(serverUri);
93
- return DartUri._fromRelativePath(p.url.join(basePath, uri));
85
+ if (root != null) {
86
+ return DartUri._fromRelativePath(p.url.join(root, uri));
94
87
}
95
88
return DartUri._(uri);
96
89
}
0 commit comments