Skip to content

Commit 2d7800d

Browse files
committed
added util method for webdev to compute package config path and pass it to the load strategy
1 parent adc54a6 commit 2d7800d

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

dwds/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
## 24.3.5-wip
2+
- Allow clients to specify the `packageConfigPath` in `LoadStrategy` class and associated providers.
3+
14
## 24.3.4
25

3-
- Allow clients to specify the `packageConfigPath` in `LoadStrategy` class and associated providers.
46
- 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)
57
- Added support for hot reload using the DDC library bundle format.
68

dwds/lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dwds
22
# Every time this changes you need to run `dart run build_runner build`.
3-
version: 24.3.4
3+
version: 24.3.5-wip
44
description: >-
55
A service that proxies between the Chrome debug protocol and the Dart VM
66
service protocol.

webdev/lib/src/serve/utils.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,26 @@ Future<void> _removeDeleted(String from, String to) async {
8282
}
8383
}
8484
}
85+
86+
/// Returns the absolute file path of the `package_config.json` file in the `.dart_tool`
87+
/// directory, searching recursively from the current directory hierarchy.
88+
/// If `_packageConfigPath` is already set, it returns the cached value immediately.
89+
String? findPackageConfigFilePath() {
90+
var candidateDir = Directory(p.current).absolute;
91+
while (true) {
92+
final candidatePackageConfigFile =
93+
File(p.join(candidateDir.path, '.dart_tool', 'package_config.json'));
94+
95+
if (candidatePackageConfigFile.existsSync()) {
96+
return candidatePackageConfigFile.path;
97+
}
98+
99+
final parentDir = candidateDir.parent;
100+
if (parentDir.path == candidateDir.path) {
101+
// We've reached the root directory
102+
return null;
103+
}
104+
105+
candidateDir = parentDir;
106+
}
107+
}

webdev/lib/src/serve/webdev_server.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import '../command/configuration.dart';
2121
import '../util.dart';
2222
import 'chrome.dart';
2323
import 'handlers/favicon_handler.dart';
24+
import 'utils.dart' show findPackageConfigFilePath;
2425

2526
Logger _logger = Logger('WebDevServer');
2627

@@ -141,6 +142,7 @@ class WebDevServer {
141142
options.configuration.reload,
142143
assetReader,
143144
buildSettings,
145+
packageConfigPath: findPackageConfigFilePath(),
144146
).strategy;
145147

146148
if (options.configuration.enableExpressionEvaluation) {

0 commit comments

Comments
 (0)