Skip to content

Commit feea099

Browse files
authored
Add libraryRoot and packageConfigLoader to the LoadStrategy (#2390)
1 parent 74e9583 commit feea099

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

dwds/lib/src/loaders/strategy.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:typed_data';
6+
57
import 'package:dwds/src/debugging/metadata/provider.dart';
68
import 'package:dwds/src/readers/asset_reader.dart';
79
import 'package:dwds/src/services/expression_compiler.dart';
@@ -41,6 +43,10 @@ abstract class LoadStrategy {
4143
/// argument which is the module name to load.
4244
String get loadModuleSnippet;
4345

46+
/// The relative root path for library paths. The current directory will be
47+
/// used if this is not overridden.
48+
String? get libraryRoot => null;
49+
4450
/// The reload configuration for this strategy, e.g. liveReload.
4551
ReloadConfiguration get reloadConfiguration;
4652

@@ -107,6 +113,15 @@ abstract class LoadStrategy {
107113
/// Returns `null` if not a google3 app.
108114
String? g3RelativePath(String absolutePath);
109115

116+
/// Returns a loader to read the content of the package configuration.
117+
///
118+
/// The package configuration URIs will be resolved relative to
119+
/// [packageConfigPath], but the loader can read the config from a different
120+
/// location.
121+
///
122+
/// If null, the default loader will read from [packageConfigPath].
123+
Future<Uint8List?> Function(Uri uri)? get packageConfigLoader => null;
124+
110125
/// The absolute path to the app's package configuration.
111126
String get packageConfigPath {
112127
return _packageConfigPath ?? _defaultPackageConfigPath;

dwds/lib/src/utilities/dart_uri.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class DartUri {
211211
static Future<void> _loadPackageConfig(Uri uri) async {
212212
_packageConfig = await loadPackageConfigUri(
213213
uri,
214+
loader: globalToolConfiguration.loadStrategy.packageConfigLoader,
214215
onError: (e) {
215216
_logger.warning('Cannot read packages spec: $uri', e);
216217
},
@@ -237,7 +238,9 @@ class DartUri {
237238
// Both currentDirectoryUri and the libraryUri path should have '/'
238239
// separators, so we can join them as url paths to get the absolute file
239240
// url.
240-
libraryPath = p.url.join(currentDirectoryUri, uri.path.substring(1));
241+
final libraryRoot = globalToolConfiguration.loadStrategy.libraryRoot;
242+
libraryPath = p.url
243+
.join(libraryRoot ?? currentDirectoryUri, uri.path.substring(1));
241244
break;
242245
case 'package':
243246
libraryPath = _packageConfig?.resolve(uri)?.toString();

0 commit comments

Comments
 (0)