Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions dwds/lib/src/utilities/dart_uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,21 @@ class DartUri {
final packageUri = _resolvedUriToUri[uri];
if (packageUri != null) return packageUri;

// If this is an internal app, then the given uri might be g3-relative:
// If this is an internal app, then the given uri might
// be relative or absolute google3 uri.
if (globalToolConfiguration.appMetadata.isInternalBuild) {
// TODO(https://github.com/dart-lang/webdev/issues/2198): Verify if the
// intermediary conversion to resolvedUri is causing performance issues.
final resolvedUri = _g3RelativeUriToResolvedUri[uri];
return _resolvedUriToUri[resolvedUri];
final g3PackageUri = _resolvedUriToUri[resolvedUri];
if (g3PackageUri != null) {
return g3PackageUri;
}

// If the input is an absolute URI (like file:/// or google3:///),
// return it as is, as DWDS can use it directly.
final parsedUri = Uri.tryParse(uri);
if (parsedUri != null && parsedUri.hasAbsolutePath) {
return uri;
}
}

return null;
Expand Down
12 changes: 12 additions & 0 deletions dwds/test/dart_uri_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,17 @@ void main() {
final resolved = DartUri.toPackageUri('g3:///path.dart');
expect(resolved, 'package:path/path.dart');
});

test('can resolve absolute file paths', () {
final absolute = 'file:///cloud/user/workspace/project/path.dart';
final resolved = DartUri.toPackageUri(absolute);
expect(resolved, absolute);
});

test('can resolve absolute g3 paths', () {
final absolute = 'google3:///cloud/user/workspace/project/path.dart';
final resolved = DartUri.toPackageUri(absolute);
expect(resolved, absolute);
});
});
}
Loading