Skip to content

Commit

Permalink
Added method findPackageConfigFilePath to find the package_config.jso…
Browse files Browse the repository at this point in the history
…n file (#2587)

* added findPackageConfigFilePath to find the package_config.json file

* updated Changelog

* updated strategy providers to allow clients to specify package config path

* added util method for webdev to compute package config path and pass it to the load strategy

* updated docstring

* revert changes to webdev

* Set DWDS version to 24.3.5 to prepare for release
  • Loading branch information
jyameo authored Feb 11, 2025
1 parent 616da45 commit 4246bbc
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 21 deletions.
3 changes: 3 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 24.3.5
- Allow clients to specify the `packageConfigPath` in `LoadStrategy` class and associated providers.

## 24.3.4

- Added support for some debugging APIs with the DDC library bundle format. - [#2566](https://github.com/dart-lang/webdev/issues/2566), [#2573](https://github.com/dart-lang/webdev/issues/2573)
Expand Down
7 changes: 5 additions & 2 deletions dwds/lib/src/loaders/build_runner_require.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BuildRunnerRequireStrategyProvider {
final ReloadConfiguration _configuration;
final AssetReader _assetReader;
final BuildSettings _buildSettings;
final String? _packageConfigPath;

late final RequireStrategy _requireStrategy = RequireStrategy(
_configuration,
Expand All @@ -34,14 +35,16 @@ class BuildRunnerRequireStrategyProvider {
_moduleInfoForProvider,
_assetReader,
_buildSettings,
packageConfigPath: _packageConfigPath,
);

BuildRunnerRequireStrategyProvider(
this._assetHandler,
this._configuration,
this._assetReader,
this._buildSettings,
);
this._buildSettings, {
String? packageConfigPath,
}) : _packageConfigPath = packageConfigPath;

RequireStrategy get strategy => _requireStrategy;

Expand Down
4 changes: 2 additions & 2 deletions dwds/lib/src/loaders/ddc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ class DdcStrategy extends LoadStrategy {
this._moduleInfoForProvider,
AssetReader assetReader,
this._buildSettings,
this._g3RelativePath,
this._g3RelativePath, {
String? packageConfigPath,
) : super(assetReader, packageConfigPath: packageConfigPath);
}) : super(assetReader, packageConfigPath: packageConfigPath);

@override
Handler get handler => (request) async {
Expand Down
4 changes: 2 additions & 2 deletions dwds/lib/src/loaders/ddc_library_bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ class DdcLibraryBundleStrategy extends LoadStrategy {
this._moduleInfoForProvider,
AssetReader assetReader,
this._buildSettings,
this._g3RelativePath,
this._g3RelativePath, {
String? packageConfigPath,
) : super(assetReader, packageConfigPath: packageConfigPath);
}) : super(assetReader, packageConfigPath: packageConfigPath);

@override
Handler get handler => (request) async {
Expand Down
27 changes: 17 additions & 10 deletions dwds/lib/src/loaders/frontend_server_strategy_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ abstract class FrontendServerStrategyProvider<T extends LoadStrategy> {
final Future<Map<String, String>> Function() _digestsProvider;
final String _basePath;
final BuildSettings _buildSettings;
final String? _packageConfigPath;

FrontendServerStrategyProvider(
this._configuration,
this._assetReader,
this._packageUriMapper,
this._digestsProvider,
this._buildSettings,
) : _basePath = _assetReader.basePath;
this._buildSettings, {
String? packageConfigPath,
}) : _basePath = _assetReader.basePath,
_packageConfigPath = packageConfigPath;

T get strategy;

Expand Down Expand Up @@ -118,16 +121,17 @@ class FrontendServerDdcStrategyProvider
_assetReader,
_buildSettings,
(String _) => null,
null,
packageConfigPath: _packageConfigPath,
);

FrontendServerDdcStrategyProvider(
super._configuration,
super._assetReader,
super._packageUriMapper,
super._digestsProvider,
super._buildSettings,
);
super._buildSettings, {
super.packageConfigPath,
});

@override
DdcStrategy get strategy => _ddcStrategy;
Expand All @@ -150,16 +154,17 @@ class FrontendServerDdcLibraryBundleStrategyProvider
_assetReader,
_buildSettings,
(String _) => null,
null,
packageConfigPath: _packageConfigPath,
);

FrontendServerDdcLibraryBundleStrategyProvider(
super._configuration,
super._assetReader,
super._packageUriMapper,
super._digestsProvider,
super._buildSettings,
);
super._buildSettings, {
super.packageConfigPath,
});

@override
DdcLibraryBundleStrategy get strategy => _libraryBundleStrategy;
Expand All @@ -179,15 +184,17 @@ class FrontendServerRequireStrategyProvider
_moduleInfoForProvider,
_assetReader,
_buildSettings,
packageConfigPath: _packageConfigPath,
);

FrontendServerRequireStrategyProvider(
super._configuration,
super._assetReader,
super._packageUriMapper,
super._digestsProvider,
super._buildSettings,
);
super._buildSettings, {
super.packageConfigPath,
});

@override
RequireStrategy get strategy => _requireStrategy;
Expand Down
5 changes: 3 additions & 2 deletions dwds/lib/src/loaders/require.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ class RequireStrategy extends LoadStrategy {
this._serverPathForAppUri,
this._moduleInfoForProvider,
AssetReader assetReader,
this._buildSettings,
) : super(assetReader);
this._buildSettings, {
String? packageConfigPath,
}) : super(assetReader, packageConfigPath: packageConfigPath);

@override
Handler get handler => (request) async {
Expand Down
26 changes: 25 additions & 1 deletion dwds/lib/src/loaders/strategy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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:io';
import 'dart:typed_data';

import 'package:dwds/src/debugging/dart_runtime_debugger.dart';
Expand All @@ -20,7 +21,7 @@ abstract class LoadStrategy {
LoadStrategy(
this._assetReader, {
String? packageConfigPath,
}) : _packageConfigPath = packageConfigPath;
}) : _packageConfigPath = packageConfigPath ?? _findPackageConfigFilePath();

/// The ID for this strategy.
///
Expand Down Expand Up @@ -83,6 +84,29 @@ abstract class LoadStrategy {
'package_config.json',
);

/// Returns the absolute file path of the `package_config.json` file in the `.dart_tool`
/// directory, searching recursively from the current directory hierarchy.
static String? _findPackageConfigFilePath() {
var candidateDir = Directory(DartUri.currentDirectory).absolute;

while (true) {
final candidatePackageConfigFile =
File(p.join(candidateDir.path, '.dart_tool', 'package_config.json'));

if (candidatePackageConfigFile.existsSync()) {
return candidatePackageConfigFile.path;
}

final parentDir = candidateDir.parent;
if (parentDir.path == candidateDir.path) {
// We've reached the root directory
return null;
}

candidateDir = parentDir;
}
}

/// Returns the bootstrap required for this [LoadStrategy].
///
/// The bootstrap is appended to the end of the entry point module.
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dwds/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dwds
# Every time this changes you need to run `dart run build_runner build`.
version: 24.3.4
version: 24.3.5
description: >-
A service that proxies between the Chrome debug protocol and the Dart VM
service protocol.
Expand Down

0 comments on commit 4246bbc

Please sign in to comment.