Pass the package config directly to the load strategy instead of depending on an app entrypoint (#2203)
diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md
index 10d2a2d..19b2499 100644
--- a/dwds/CHANGELOG.md
+++ b/dwds/CHANGELOG.md
@@ -2,7 +2,7 @@
**Breaking changes**
-- Allow clients to specify where to find the package config. - [#2199](https://github.com/dart-lang/webdev/pull/2199).
+- Allow clients to specify where to find the package config. - [#2203](https://github.com/dart-lang/webdev/pull/2203).
- Allow clients to specify a way to convert absolute paths to g3-relative paths. - [#2200](https://github.com/dart-lang/webdev/pull/2200)
## 20.0.1
diff --git a/dwds/lib/src/loaders/legacy.dart b/dwds/lib/src/loaders/legacy.dart
index 1f57368..bdb9a7a 100644
--- a/dwds/lib/src/loaders/legacy.dart
+++ b/dwds/lib/src/loaders/legacy.dart
@@ -66,16 +66,6 @@
/// an app URI.
final String? Function(String appUri) _serverPathForAppUri;
- /// Returns the absolute path to the app's package config, determined by the
- /// app's [entrypoint] path.
- ///
- /// Example:
- ///
- /// main_module.bootstrap.js
- /// -> /Users/john_doe/my_dart_app/.dart_tool/package_config.json
- ///
- final String? Function(String entrypoint) _packageConfigLocator;
-
/// Returns the relative path in google3, determined by the [absolutePath].
///
/// Returns `null` if not a google3 app.
@@ -92,9 +82,9 @@
this._moduleInfoForProvider,
AssetReader assetReader,
this._appEntrypoint,
- this._packageConfigLocator,
this._g3RelativePath,
- ) : super(assetReader);
+ String? packageConfigPath,
+ ) : super(assetReader, packageConfigPath: packageConfigPath);
@override
Handler get handler => (request) => Response.notFound(request.url.toString());
@@ -141,9 +131,5 @@
Uri? get appEntrypoint => _appEntrypoint;
@override
- String? packageConfigLocator(String entrypoint) =>
- _packageConfigLocator(entrypoint);
-
- @override
String? g3RelativePath(String absolutePath) => _g3RelativePath(absolutePath);
}
diff --git a/dwds/lib/src/loaders/require.dart b/dwds/lib/src/loaders/require.dart
index aa347db..e499aca 100644
--- a/dwds/lib/src/loaders/require.dart
+++ b/dwds/lib/src/loaders/require.dart
@@ -285,8 +285,5 @@
_moduleInfoForProvider(metadataProviderFor(entrypoint));
@override
- String? packageConfigLocator(String entrypoint) => null;
-
- @override
String? g3RelativePath(String absolutePath) => null;
}
diff --git a/dwds/lib/src/loaders/strategy.dart b/dwds/lib/src/loaders/strategy.dart
index ff5aa6c..b3cbb8d 100644
--- a/dwds/lib/src/loaders/strategy.dart
+++ b/dwds/lib/src/loaders/strategy.dart
@@ -11,10 +11,13 @@
abstract class LoadStrategy {
final AssetReader _assetReader;
+ final String? _packageConfigPath;
final _providers = <String, MetadataProvider>{};
- String? _packageConfigPath;
- LoadStrategy(this._assetReader);
+ LoadStrategy(
+ this._assetReader, {
+ String? packageConfigPath,
+ }) : _packageConfigPath = packageConfigPath;
/// The ID for this strategy.
///
@@ -100,28 +103,17 @@
/// an app URI.
String? serverPathForAppUri(String appUri);
- /// Returns the absolute path to the app's package config, determined by the
- /// app's [entrypoint] path.
- ///
- /// Example:
- ///
- /// main_module.bootstrap.js
- /// -> /Users/john_doe/my_dart_app/.dart_tool/package_config.json
- ///
- String? packageConfigLocator(String entrypoint);
-
/// Returns the relative path in google3, determined by the [absolutePath].
///
/// Returns `null` if not a google3 app.
String? g3RelativePath(String absolutePath);
- /// The absolute path to the app's package config, or null if not provided by
- /// [packageConfigLocator].
+ /// The absolute path to the app's package configuration.
String get packageConfigPath {
return _packageConfigPath ?? _defaultPackageConfigPath;
}
- /// The default package config path, if none is provided by the load strategy.
+ /// The default package config path if none is provided.
String get _defaultPackageConfigPath => p.join(
DartUri.currentDirectory,
'.dart_tool',
@@ -142,7 +134,6 @@
/// provided [entrypoint].
void trackEntrypoint(String entrypoint) {
final metadataProvider = MetadataProvider(entrypoint, _assetReader);
- _packageConfigPath = packageConfigLocator(entrypoint);
_providers[metadataProvider.entrypoint] = metadataProvider;
}
}
diff --git a/dwds/test/fixtures/fakes.dart b/dwds/test/fixtures/fakes.dart
index 1b2f9b5..c981fc9 100644
--- a/dwds/test/fixtures/fakes.dart
+++ b/dwds/test/fixtures/fakes.dart
@@ -314,8 +314,9 @@
class FakeStrategy extends LoadStrategy {
FakeStrategy(
- AssetReader assetReader,
- ) : super(assetReader);
+ AssetReader assetReader, {
+ String? packageConfigPath,
+ }) : super(assetReader, packageConfigPath: packageConfigPath);
@override
Future<String> bootstrapFor(String entrypoint) async => 'dummy_bootstrap';
@@ -342,9 +343,6 @@
Uri? get appEntrypoint => Uri.parse('package:myapp/main.dart');
@override
- String? packageConfigLocator(String entrypoint) => null;
-
- @override
String? g3RelativePath(String absolutePath) => null;
@override
diff --git a/dwds/test/load_strategy_test.dart b/dwds/test/load_strategy_test.dart
index dccd495..8e5833e 100644
--- a/dwds/test/load_strategy_test.dart
+++ b/dwds/test/load_strategy_test.dart
@@ -5,7 +5,6 @@
@TestOn('vm')
@Timeout(Duration(minutes: 1))
-import 'package:dwds/asset_reader.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:test_common/test_sdk_configuration.dart';
@@ -14,16 +13,6 @@
import 'fixtures/fakes.dart';
import 'fixtures/project.dart';
-class LoadStrategyCustomPackageConfig extends FakeStrategy {
- LoadStrategyCustomPackageConfig(
- AssetReader assetReader,
- ) : super(assetReader);
-
- @override
- String? packageConfigLocator(String entrypoint) =>
- '$entrypoint/custom/package_config/path';
-}
-
void main() {
final provider = TestSdkConfigurationProvider();
tearDownAll(provider.dispose);
@@ -45,7 +34,6 @@
final strategy = FakeStrategy(FakeAssetReader());
test('defaults to "./dart_tool/packageconfig.json"', () {
- strategy.trackEntrypoint('my_app/entrypoint');
expect(
p.split(strategy.packageConfigPath).join('/'),
endsWith('_testSound/.dart_tool/package_config.json'),
@@ -53,14 +41,16 @@
});
});
- group('When the packageConfigLocator specifies a package config path', () {
- final strategy = LoadStrategyCustomPackageConfig(FakeAssetReader());
+ group('When a custom package config path is specified', () {
+ final strategy = FakeStrategy(
+ FakeAssetReader(),
+ packageConfigPath: 'custom/package_config/path',
+ );
test('uses the specified package config path', () {
- strategy.trackEntrypoint('my_app/entrypoint');
expect(
strategy.packageConfigPath,
- equals('my_app/entrypoint/custom/package_config/path'),
+ equals('custom/package_config/path'),
);
});
});