@@ -14,6 +14,7 @@ import 'require.dart';
1414class FrontendServerRequireStrategyProvider {
1515 final ReloadConfiguration _configuration;
1616 final AssetReader _assetReader;
17+ final PackageUriMapper _packageUriMapper;
1718 final Future <Map <String , String >> Function () _digestsProvider;
1819 final String _basePath;
1920
@@ -29,26 +30,31 @@ class FrontendServerRequireStrategyProvider {
2930 _assetReader,
3031 );
3132
32- FrontendServerRequireStrategyProvider (this ._configuration, this ._assetReader,
33- this ._digestsProvider, this ._basePath);
33+ FrontendServerRequireStrategyProvider (
34+ this ._configuration,
35+ this ._assetReader,
36+ this ._packageUriMapper,
37+ this ._digestsProvider,
38+ this ._basePath,
39+ );
3440
3541 RequireStrategy get strategy => _requireStrategy;
3642
3743 String _removeBasePath (String path) {
3844 if (_basePath.isEmpty) return path;
39- // If path is a server path it might start with a '/'.
40- final base = path. startsWith ( '/' ) ? '/$ _basePath ' : _basePath ;
41- return path. startsWith ( base ) ? path .substring (base .length) : path ;
45+
46+ final stripped = stripLeadingSlashes (path) ;
47+ return stripLeadingSlashes (stripped .substring (_basePath .length)) ;
4248 }
4349
4450 String _addBasePath (String serverPath) => _basePath.isEmpty
45- ? relativizePath (serverPath)
46- : '$_basePath /${relativizePath (serverPath )}' ;
51+ ? stripLeadingSlashes (serverPath)
52+ : '$_basePath /${stripLeadingSlashes (serverPath )}' ;
4753
4854 Future <Map <String , String >> _moduleProvider (
4955 MetadataProvider metadataProvider) async =>
5056 (await metadataProvider.moduleToModulePath).map ((key, value) =>
51- MapEntry (key, relativizePath (removeJsExtension (value))));
57+ MapEntry (key, stripLeadingSlashes (removeJsExtension (value))));
5258
5359 Future <String ?> _moduleForServerPath (
5460 MetadataProvider metadataProvider, String serverPath) async {
@@ -65,9 +71,16 @@ class FrontendServerRequireStrategyProvider {
6571 MetadataProvider metadataProvider, String module) async =>
6672 _addBasePath ((await metadataProvider.moduleToSourceMap)[module] ?? '' );
6773
68- String ? _serverPathForAppUri (String appUri) {
69- if (appUri.startsWith ('org-dartlang-app:' )) {
70- return _addBasePath (Uri .parse (appUri).path);
74+ String ? _serverPathForAppUri (String appUrl) {
75+ final appUri = Uri .parse (appUrl);
76+ if (appUri.isScheme ('org-dartlang-app' )) {
77+ return _addBasePath (appUri.path);
78+ }
79+ if (appUri.isScheme ('package' )) {
80+ final resolved = _packageUriMapper.packageUriToServerPath (appUri);
81+ if (resolved != null ) {
82+ return resolved;
83+ }
7184 }
7285 return null ;
7386 }
0 commit comments