Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libraryRoot and packageConfigLoader to the LoadStrategy #2390

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 16 additions & 0 deletions dwds/lib/src/loaders/strategy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -107,6 +113,16 @@ 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<Uint8List?> Function(Uri uri)? get packageConfigLoader => null;

/// The absolute path to the app's package configuration.
String get packageConfigPath {
return _packageConfigPath ?? _defaultPackageConfigPath;
Expand Down
5 changes: 4 additions & 1 deletion dwds/lib/src/utilities/dart_uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class DartUri {
static Future<void> _loadPackageConfig(Uri uri) async {
_packageConfig = await loadPackageConfigUri(
uri,
loader: globalToolConfiguration.loadStrategy.packageConfigLoader,
onError: (e) {
_logger.warning('Cannot read packages spec: $uri', e);
},
Expand All @@ -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();
Expand Down
Loading