@@ -8,7 +8,6 @@ import 'package:logging/logging.dart';
88import 'package:package_config/package_config.dart' ;
99import 'package:path/path.dart' as p;
1010
11- import '../loaders/require.dart' ;
1211import '../loaders/strategy.dart' ;
1312import 'sdk_configuration.dart' ;
1413
@@ -30,26 +29,22 @@ class DartUri {
3029 /// path is a web server path and so relative to the directory being
3130 /// served, not to the package.
3231 ///
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]) {
3934 final serverPath = globalLoadStrategy.serverPathForAppUri (uri);
4035 if (serverPath != null ) {
4136 return DartUri ._(serverPath);
4237 }
4338 // TODO(annagrin): Support creating DartUris from `dart:` uris.
4439 // Issue: https://github.com/dart-lang/webdev/issues/1584
4540 if (uri.startsWith ('package:' )) {
46- return DartUri ._fromPackageUri (uri, serverUri : serverUri );
41+ return DartUri ._fromPackageUri (uri, root : root );
4742 }
4843 if (uri.startsWith ('file:' )) {
49- return DartUri ._fromFileUri (uri, serverUri : serverUri );
44+ return DartUri ._fromFileUri (uri, root : root );
5045 }
5146 if (uri.startsWith ('/packages/' )) {
52- return DartUri ._fromRelativePath (uri, serverUri : serverUri );
47+ return DartUri ._fromRelativePath (uri, root : root );
5348 }
5449 if (uri.startsWith ('/' )) {
5550 return DartUri ._fromRelativePath (uri);
@@ -65,32 +60,30 @@ class DartUri {
6560 String toString () => 'DartUri: $serverPath ' ;
6661
6762 /// 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}) {
7064 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);
7367 return DartUri ._fromRelativePath (relativePath);
7468 }
7569 return DartUri ._(packagePath);
7670 }
7771
7872 /// Construct from a file: URI
79- factory DartUri ._fromFileUri (String uri, {String serverUri }) {
73+ factory DartUri ._fromFileUri (String uri, {String root }) {
8074 final libraryName = _resolvedUriToUri[uri];
81- if (libraryName != null ) return DartUri (libraryName, serverUri );
75+ if (libraryName != null ) return DartUri (libraryName, root );
8276 // This is not one of our recorded libraries.
8377 throw ArgumentError .value (uri, 'uri' , 'Unknown library' );
8478 }
8579
8680 /// 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 }) {
8882 uri = uri[0 ] == '.' ? uri.substring (1 ) : uri;
8983 uri = uri[0 ] == '/' ? uri.substring (1 ) : uri;
9084
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));
9487 }
9588 return DartUri ._(uri);
9689 }
0 commit comments