From ccb551478f6209dae01ac622b608d4941a2fea52 Mon Sep 17 00:00:00 2001 From: Jessy Yameogo Date: Tue, 4 Feb 2025 14:33:15 -0500 Subject: [PATCH 1/7] added findPackageConfigFilePath to find the package_config.json file --- dwds/lib/src/loaders/strategy.dart | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/dwds/lib/src/loaders/strategy.dart b/dwds/lib/src/loaders/strategy.dart index 1527e13d2..428158efe 100644 --- a/dwds/lib/src/loaders/strategy.dart +++ b/dwds/lib/src/loaders/strategy.dart @@ -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'; @@ -20,7 +21,7 @@ abstract class LoadStrategy { LoadStrategy( this._assetReader, { String? packageConfigPath, - }) : _packageConfigPath = packageConfigPath; + }) : _packageConfigPath = packageConfigPath ?? _findPackageConfigFilePath(); /// The ID for this strategy. /// @@ -83,6 +84,30 @@ 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. + /// If `_packageConfigPath` is already set, it returns the cached value immediately. + 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. From 720b74b9c1ea9d5d78a8314dd4d3dc06c803bbab Mon Sep 17 00:00:00 2001 From: Jessy Yameogo Date: Tue, 4 Feb 2025 14:43:08 -0500 Subject: [PATCH 2/7] updated Changelog --- dwds/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 06e6ac816..5615fe912 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,5 +1,6 @@ ## 24.3.4 +- Ensure `packageConfigPath` is initialized in `LoadStrategy` at construction. - 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) - Added support for hot reload using the DDC library bundle format. From adc54a60ccae9938d5a489c78e0a011d53812525 Mon Sep 17 00:00:00 2001 From: Jessy Yameogo Date: Wed, 5 Feb 2025 12:39:35 -0500 Subject: [PATCH 3/7] updated strategy providers to allow clients to specify package config path --- dwds/CHANGELOG.md | 2 +- .../lib/src/loaders/build_runner_require.dart | 7 +++-- dwds/lib/src/loaders/ddc.dart | 4 +-- dwds/lib/src/loaders/ddc_library_bundle.dart | 4 +-- .../frontend_server_strategy_provider.dart | 27 ++++++++++++------- dwds/lib/src/loaders/require.dart | 5 ++-- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 5615fe912..56f449aad 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,6 +1,6 @@ ## 24.3.4 -- Ensure `packageConfigPath` is initialized in `LoadStrategy` at construction. +- Allow clients to specify the `packageConfigPath` in `LoadStrategy` class and associated providers. - 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) - Added support for hot reload using the DDC library bundle format. diff --git a/dwds/lib/src/loaders/build_runner_require.dart b/dwds/lib/src/loaders/build_runner_require.dart index 91dda5f26..f034a3fd8 100644 --- a/dwds/lib/src/loaders/build_runner_require.dart +++ b/dwds/lib/src/loaders/build_runner_require.dart @@ -22,6 +22,7 @@ class BuildRunnerRequireStrategyProvider { final ReloadConfiguration _configuration; final AssetReader _assetReader; final BuildSettings _buildSettings; + final String? _packageConfigPath; late final RequireStrategy _requireStrategy = RequireStrategy( _configuration, @@ -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; diff --git a/dwds/lib/src/loaders/ddc.dart b/dwds/lib/src/loaders/ddc.dart index b3338afb5..384142388 100644 --- a/dwds/lib/src/loaders/ddc.dart +++ b/dwds/lib/src/loaders/ddc.dart @@ -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 { diff --git a/dwds/lib/src/loaders/ddc_library_bundle.dart b/dwds/lib/src/loaders/ddc_library_bundle.dart index 54d0dac97..fb3fba017 100644 --- a/dwds/lib/src/loaders/ddc_library_bundle.dart +++ b/dwds/lib/src/loaders/ddc_library_bundle.dart @@ -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 { diff --git a/dwds/lib/src/loaders/frontend_server_strategy_provider.dart b/dwds/lib/src/loaders/frontend_server_strategy_provider.dart index d46362645..a12cf7d9e 100644 --- a/dwds/lib/src/loaders/frontend_server_strategy_provider.dart +++ b/dwds/lib/src/loaders/frontend_server_strategy_provider.dart @@ -18,14 +18,17 @@ abstract class FrontendServerStrategyProvider { final Future> 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; @@ -118,7 +121,7 @@ class FrontendServerDdcStrategyProvider _assetReader, _buildSettings, (String _) => null, - null, + packageConfigPath: _packageConfigPath, ); FrontendServerDdcStrategyProvider( @@ -126,8 +129,9 @@ class FrontendServerDdcStrategyProvider super._assetReader, super._packageUriMapper, super._digestsProvider, - super._buildSettings, - ); + super._buildSettings, { + super.packageConfigPath, + }); @override DdcStrategy get strategy => _ddcStrategy; @@ -150,7 +154,7 @@ class FrontendServerDdcLibraryBundleStrategyProvider _assetReader, _buildSettings, (String _) => null, - null, + packageConfigPath: _packageConfigPath, ); FrontendServerDdcLibraryBundleStrategyProvider( @@ -158,8 +162,9 @@ class FrontendServerDdcLibraryBundleStrategyProvider super._assetReader, super._packageUriMapper, super._digestsProvider, - super._buildSettings, - ); + super._buildSettings, { + super.packageConfigPath, + }); @override DdcLibraryBundleStrategy get strategy => _libraryBundleStrategy; @@ -179,6 +184,7 @@ class FrontendServerRequireStrategyProvider _moduleInfoForProvider, _assetReader, _buildSettings, + packageConfigPath: _packageConfigPath, ); FrontendServerRequireStrategyProvider( @@ -186,8 +192,9 @@ class FrontendServerRequireStrategyProvider super._assetReader, super._packageUriMapper, super._digestsProvider, - super._buildSettings, - ); + super._buildSettings, { + super.packageConfigPath, + }); @override RequireStrategy get strategy => _requireStrategy; diff --git a/dwds/lib/src/loaders/require.dart b/dwds/lib/src/loaders/require.dart index ba189174b..a78a58eaa 100644 --- a/dwds/lib/src/loaders/require.dart +++ b/dwds/lib/src/loaders/require.dart @@ -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 { From 2d7800d068cbd63e4629ceeb7004e291c8cdc107 Mon Sep 17 00:00:00 2001 From: Jessy Yameogo Date: Wed, 5 Feb 2025 13:35:44 -0500 Subject: [PATCH 4/7] added util method for webdev to compute package config path and pass it to the load strategy --- dwds/CHANGELOG.md | 4 +++- dwds/lib/src/version.dart | 2 +- dwds/pubspec.yaml | 2 +- webdev/lib/src/serve/utils.dart | 23 +++++++++++++++++++++++ webdev/lib/src/serve/webdev_server.dart | 2 ++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 56f449aad..32a9c6458 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,6 +1,8 @@ +## 24.3.5-wip +- Allow clients to specify the `packageConfigPath` in `LoadStrategy` class and associated providers. + ## 24.3.4 -- Allow clients to specify the `packageConfigPath` in `LoadStrategy` class and associated providers. - 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) - Added support for hot reload using the DDC library bundle format. diff --git a/dwds/lib/src/version.dart b/dwds/lib/src/version.dart index 27fbeb7b9..f972c7ba0 100644 --- a/dwds/lib/src/version.dart +++ b/dwds/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '24.3.4'; +const packageVersion = '24.3.5-wip'; diff --git a/dwds/pubspec.yaml b/dwds/pubspec.yaml index 4c8257ca0..73ce9f575 100644 --- a/dwds/pubspec.yaml +++ b/dwds/pubspec.yaml @@ -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-wip description: >- A service that proxies between the Chrome debug protocol and the Dart VM service protocol. diff --git a/webdev/lib/src/serve/utils.dart b/webdev/lib/src/serve/utils.dart index 962305b59..8ace79588 100644 --- a/webdev/lib/src/serve/utils.dart +++ b/webdev/lib/src/serve/utils.dart @@ -82,3 +82,26 @@ Future _removeDeleted(String from, String to) async { } } } + +/// Returns the absolute file path of the `package_config.json` file in the `.dart_tool` +/// directory, searching recursively from the current directory hierarchy. +/// If `_packageConfigPath` is already set, it returns the cached value immediately. +String? findPackageConfigFilePath() { + var candidateDir = Directory(p.current).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; + } +} diff --git a/webdev/lib/src/serve/webdev_server.dart b/webdev/lib/src/serve/webdev_server.dart index bdf632091..edcfb848a 100644 --- a/webdev/lib/src/serve/webdev_server.dart +++ b/webdev/lib/src/serve/webdev_server.dart @@ -21,6 +21,7 @@ import '../command/configuration.dart'; import '../util.dart'; import 'chrome.dart'; import 'handlers/favicon_handler.dart'; +import 'utils.dart' show findPackageConfigFilePath; Logger _logger = Logger('WebDevServer'); @@ -141,6 +142,7 @@ class WebDevServer { options.configuration.reload, assetReader, buildSettings, + packageConfigPath: findPackageConfigFilePath(), ).strategy; if (options.configuration.enableExpressionEvaluation) { From 3d837f530cceee9c71e54929a4780661ba679b1b Mon Sep 17 00:00:00 2001 From: Jessy Yameogo Date: Wed, 5 Feb 2025 13:38:10 -0500 Subject: [PATCH 5/7] updated docstring --- dwds/lib/src/loaders/strategy.dart | 1 - webdev/lib/src/serve/utils.dart | 1 - 2 files changed, 2 deletions(-) diff --git a/dwds/lib/src/loaders/strategy.dart b/dwds/lib/src/loaders/strategy.dart index 428158efe..8c26a38c5 100644 --- a/dwds/lib/src/loaders/strategy.dart +++ b/dwds/lib/src/loaders/strategy.dart @@ -86,7 +86,6 @@ abstract class LoadStrategy { /// Returns the absolute file path of the `package_config.json` file in the `.dart_tool` /// directory, searching recursively from the current directory hierarchy. - /// If `_packageConfigPath` is already set, it returns the cached value immediately. static String? _findPackageConfigFilePath() { var candidateDir = Directory(DartUri.currentDirectory).absolute; diff --git a/webdev/lib/src/serve/utils.dart b/webdev/lib/src/serve/utils.dart index 8ace79588..e5475d5ab 100644 --- a/webdev/lib/src/serve/utils.dart +++ b/webdev/lib/src/serve/utils.dart @@ -85,7 +85,6 @@ Future _removeDeleted(String from, String to) async { /// Returns the absolute file path of the `package_config.json` file in the `.dart_tool` /// directory, searching recursively from the current directory hierarchy. -/// If `_packageConfigPath` is already set, it returns the cached value immediately. String? findPackageConfigFilePath() { var candidateDir = Directory(p.current).absolute; while (true) { From 4361530212db22365e66e15bcc11a082f2a93dd1 Mon Sep 17 00:00:00 2001 From: Jessy Yameogo Date: Fri, 7 Feb 2025 11:11:48 -0500 Subject: [PATCH 6/7] revert changes to webdev --- webdev/lib/src/serve/utils.dart | 22 ---------------------- webdev/lib/src/serve/webdev_server.dart | 2 -- 2 files changed, 24 deletions(-) diff --git a/webdev/lib/src/serve/utils.dart b/webdev/lib/src/serve/utils.dart index e5475d5ab..962305b59 100644 --- a/webdev/lib/src/serve/utils.dart +++ b/webdev/lib/src/serve/utils.dart @@ -82,25 +82,3 @@ Future _removeDeleted(String from, String to) async { } } } - -/// Returns the absolute file path of the `package_config.json` file in the `.dart_tool` -/// directory, searching recursively from the current directory hierarchy. -String? findPackageConfigFilePath() { - var candidateDir = Directory(p.current).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; - } -} diff --git a/webdev/lib/src/serve/webdev_server.dart b/webdev/lib/src/serve/webdev_server.dart index edcfb848a..bdf632091 100644 --- a/webdev/lib/src/serve/webdev_server.dart +++ b/webdev/lib/src/serve/webdev_server.dart @@ -21,7 +21,6 @@ import '../command/configuration.dart'; import '../util.dart'; import 'chrome.dart'; import 'handlers/favicon_handler.dart'; -import 'utils.dart' show findPackageConfigFilePath; Logger _logger = Logger('WebDevServer'); @@ -142,7 +141,6 @@ class WebDevServer { options.configuration.reload, assetReader, buildSettings, - packageConfigPath: findPackageConfigFilePath(), ).strategy; if (options.configuration.enableExpressionEvaluation) { From 0bb1a44117b0b21f80f198f39fdd7f4ab562fc1d Mon Sep 17 00:00:00 2001 From: Jessy Yameogo Date: Fri, 7 Feb 2025 11:14:47 -0500 Subject: [PATCH 7/7] Set DWDS version to 24.3.5 to prepare for release --- dwds/CHANGELOG.md | 2 +- dwds/lib/src/version.dart | 2 +- dwds/pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 32a9c6458..9f24df85c 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,4 +1,4 @@ -## 24.3.5-wip +## 24.3.5 - Allow clients to specify the `packageConfigPath` in `LoadStrategy` class and associated providers. ## 24.3.4 diff --git a/dwds/lib/src/version.dart b/dwds/lib/src/version.dart index f972c7ba0..a432a47cf 100644 --- a/dwds/lib/src/version.dart +++ b/dwds/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '24.3.5-wip'; +const packageVersion = '24.3.5'; diff --git a/dwds/pubspec.yaml b/dwds/pubspec.yaml index 73ce9f575..423146af7 100644 --- a/dwds/pubspec.yaml +++ b/dwds/pubspec.yaml @@ -1,6 +1,6 @@ name: dwds # Every time this changes you need to run `dart run build_runner build`. -version: 24.3.5-wip +version: 24.3.5 description: >- A service that proxies between the Chrome debug protocol and the Dart VM service protocol.