Skip to content

Commit 4246bbc

Browse files
authored
Added method findPackageConfigFilePath to find the package_config.json 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
1 parent 616da45 commit 4246bbc

9 files changed

+59
-21
lines changed

Diff for: dwds/CHANGELOG.md

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

36
- 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)

Diff for: dwds/lib/src/loaders/build_runner_require.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class BuildRunnerRequireStrategyProvider {
2222
final ReloadConfiguration _configuration;
2323
final AssetReader _assetReader;
2424
final BuildSettings _buildSettings;
25+
final String? _packageConfigPath;
2526

2627
late final RequireStrategy _requireStrategy = RequireStrategy(
2728
_configuration,
@@ -34,14 +35,16 @@ class BuildRunnerRequireStrategyProvider {
3435
_moduleInfoForProvider,
3536
_assetReader,
3637
_buildSettings,
38+
packageConfigPath: _packageConfigPath,
3739
);
3840

3941
BuildRunnerRequireStrategyProvider(
4042
this._assetHandler,
4143
this._configuration,
4244
this._assetReader,
43-
this._buildSettings,
44-
);
45+
this._buildSettings, {
46+
String? packageConfigPath,
47+
}) : _packageConfigPath = packageConfigPath;
4548

4649
RequireStrategy get strategy => _requireStrategy;
4750

Diff for: dwds/lib/src/loaders/ddc.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ class DdcStrategy extends LoadStrategy {
141141
this._moduleInfoForProvider,
142142
AssetReader assetReader,
143143
this._buildSettings,
144-
this._g3RelativePath,
144+
this._g3RelativePath, {
145145
String? packageConfigPath,
146-
) : super(assetReader, packageConfigPath: packageConfigPath);
146+
}) : super(assetReader, packageConfigPath: packageConfigPath);
147147

148148
@override
149149
Handler get handler => (request) async {

Diff for: dwds/lib/src/loaders/ddc_library_bundle.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ class DdcLibraryBundleStrategy extends LoadStrategy {
111111
this._moduleInfoForProvider,
112112
AssetReader assetReader,
113113
this._buildSettings,
114-
this._g3RelativePath,
114+
this._g3RelativePath, {
115115
String? packageConfigPath,
116-
) : super(assetReader, packageConfigPath: packageConfigPath);
116+
}) : super(assetReader, packageConfigPath: packageConfigPath);
117117

118118
@override
119119
Handler get handler => (request) async {

Diff for: dwds/lib/src/loaders/frontend_server_strategy_provider.dart

+17-10
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ abstract class FrontendServerStrategyProvider<T extends LoadStrategy> {
1818
final Future<Map<String, String>> Function() _digestsProvider;
1919
final String _basePath;
2020
final BuildSettings _buildSettings;
21+
final String? _packageConfigPath;
2122

2223
FrontendServerStrategyProvider(
2324
this._configuration,
2425
this._assetReader,
2526
this._packageUriMapper,
2627
this._digestsProvider,
27-
this._buildSettings,
28-
) : _basePath = _assetReader.basePath;
28+
this._buildSettings, {
29+
String? packageConfigPath,
30+
}) : _basePath = _assetReader.basePath,
31+
_packageConfigPath = packageConfigPath;
2932

3033
T get strategy;
3134

@@ -118,16 +121,17 @@ class FrontendServerDdcStrategyProvider
118121
_assetReader,
119122
_buildSettings,
120123
(String _) => null,
121-
null,
124+
packageConfigPath: _packageConfigPath,
122125
);
123126

124127
FrontendServerDdcStrategyProvider(
125128
super._configuration,
126129
super._assetReader,
127130
super._packageUriMapper,
128131
super._digestsProvider,
129-
super._buildSettings,
130-
);
132+
super._buildSettings, {
133+
super.packageConfigPath,
134+
});
131135

132136
@override
133137
DdcStrategy get strategy => _ddcStrategy;
@@ -150,16 +154,17 @@ class FrontendServerDdcLibraryBundleStrategyProvider
150154
_assetReader,
151155
_buildSettings,
152156
(String _) => null,
153-
null,
157+
packageConfigPath: _packageConfigPath,
154158
);
155159

156160
FrontendServerDdcLibraryBundleStrategyProvider(
157161
super._configuration,
158162
super._assetReader,
159163
super._packageUriMapper,
160164
super._digestsProvider,
161-
super._buildSettings,
162-
);
165+
super._buildSettings, {
166+
super.packageConfigPath,
167+
});
163168

164169
@override
165170
DdcLibraryBundleStrategy get strategy => _libraryBundleStrategy;
@@ -179,15 +184,17 @@ class FrontendServerRequireStrategyProvider
179184
_moduleInfoForProvider,
180185
_assetReader,
181186
_buildSettings,
187+
packageConfigPath: _packageConfigPath,
182188
);
183189

184190
FrontendServerRequireStrategyProvider(
185191
super._configuration,
186192
super._assetReader,
187193
super._packageUriMapper,
188194
super._digestsProvider,
189-
super._buildSettings,
190-
);
195+
super._buildSettings, {
196+
super.packageConfigPath,
197+
});
191198

192199
@override
193200
RequireStrategy get strategy => _requireStrategy;

Diff for: dwds/lib/src/loaders/require.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ class RequireStrategy extends LoadStrategy {
137137
this._serverPathForAppUri,
138138
this._moduleInfoForProvider,
139139
AssetReader assetReader,
140-
this._buildSettings,
141-
) : super(assetReader);
140+
this._buildSettings, {
141+
String? packageConfigPath,
142+
}) : super(assetReader, packageConfigPath: packageConfigPath);
142143

143144
@override
144145
Handler get handler => (request) async {

Diff for: dwds/lib/src/loaders/strategy.dart

+25-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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:io';
56
import 'dart:typed_data';
67

78
import 'package:dwds/src/debugging/dart_runtime_debugger.dart';
@@ -20,7 +21,7 @@ abstract class LoadStrategy {
2021
LoadStrategy(
2122
this._assetReader, {
2223
String? packageConfigPath,
23-
}) : _packageConfigPath = packageConfigPath;
24+
}) : _packageConfigPath = packageConfigPath ?? _findPackageConfigFilePath();
2425

2526
/// The ID for this strategy.
2627
///
@@ -83,6 +84,29 @@ abstract class LoadStrategy {
8384
'package_config.json',
8485
);
8586

87+
/// Returns the absolute file path of the `package_config.json` file in the `.dart_tool`
88+
/// directory, searching recursively from the current directory hierarchy.
89+
static String? _findPackageConfigFilePath() {
90+
var candidateDir = Directory(DartUri.currentDirectory).absolute;
91+
92+
while (true) {
93+
final candidatePackageConfigFile =
94+
File(p.join(candidateDir.path, '.dart_tool', 'package_config.json'));
95+
96+
if (candidatePackageConfigFile.existsSync()) {
97+
return candidatePackageConfigFile.path;
98+
}
99+
100+
final parentDir = candidateDir.parent;
101+
if (parentDir.path == candidateDir.path) {
102+
// We've reached the root directory
103+
return null;
104+
}
105+
106+
candidateDir = parentDir;
107+
}
108+
}
109+
86110
/// Returns the bootstrap required for this [LoadStrategy].
87111
///
88112
/// The bootstrap is appended to the end of the entry point module.

Diff for: dwds/lib/src/version.dart

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dwds/pubspec.yaml

+1-1
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
44
description: >-
55
A service that proxies between the Chrome debug protocol and the Dart VM
66
service protocol.

0 commit comments

Comments
 (0)