diff --git a/dwds/lib/src/loaders/strategy.dart b/dwds/lib/src/loaders/strategy.dart index 77f43acd8..a8b077d42 100644 --- a/dwds/lib/src/loaders/strategy.dart +++ b/dwds/lib/src/loaders/strategy.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:typed_data'; + import 'package:dwds/src/debugging/metadata/provider.dart'; import 'package:dwds/src/readers/asset_reader.dart'; import 'package:dwds/src/services/expression_compiler.dart'; @@ -41,6 +43,10 @@ abstract class LoadStrategy { /// argument which is the module name to load. String get loadModuleSnippet; + /// The relative root path for library paths. The current directory will be + /// used if this is not overridden. + String? get libraryRoot => null; + /// The reload configuration for this strategy, e.g. liveReload. ReloadConfiguration get reloadConfiguration; @@ -107,6 +113,15 @@ abstract class LoadStrategy { /// Returns `null` if not a google3 app. String? g3RelativePath(String absolutePath); + /// Returns a loader to read the content of the package configuration. + /// + /// The package configuration URIs will be resolved relative to + /// [packageConfigPath], but the loader can read the config from a different + /// location. + /// + /// If null, the default loader will read from [packageConfigPath]. + Future Function(Uri uri)? get packageConfigLoader => null; + /// The absolute path to the app's package configuration. String get packageConfigPath { return _packageConfigPath ?? _defaultPackageConfigPath; diff --git a/dwds/lib/src/utilities/dart_uri.dart b/dwds/lib/src/utilities/dart_uri.dart index f8aa66ab2..c93e46697 100644 --- a/dwds/lib/src/utilities/dart_uri.dart +++ b/dwds/lib/src/utilities/dart_uri.dart @@ -211,6 +211,7 @@ class DartUri { static Future _loadPackageConfig(Uri uri) async { _packageConfig = await loadPackageConfigUri( uri, + loader: globalToolConfiguration.loadStrategy.packageConfigLoader, onError: (e) { _logger.warning('Cannot read packages spec: $uri', e); }, @@ -237,7 +238,9 @@ class DartUri { // Both currentDirectoryUri and the libraryUri path should have '/' // separators, so we can join them as url paths to get the absolute file // url. - libraryPath = p.url.join(currentDirectoryUri, uri.path.substring(1)); + final libraryRoot = globalToolConfiguration.loadStrategy.libraryRoot; + libraryPath = p.url + .join(libraryRoot ?? currentDirectoryUri, uri.path.substring(1)); break; case 'package': libraryPath = _packageConfig?.resolve(uri)?.toString();