[DevTools extensions] Use `Uri.parse` for windows platforms too (#6968)
diff --git a/packages/devtools_shared/CHANGELOG.md b/packages/devtools_shared/CHANGELOG.md index 86fa082..2cc1be5 100644 --- a/packages/devtools_shared/CHANGELOG.md +++ b/packages/devtools_shared/CHANGELOG.md
@@ -4,7 +4,7 @@ argument. * `SemanticVersion` now mixes in `CompareMixin<SemanticVersion>`, and it's `compareTo` method therefore now accepts a `SemanticVersion`. -* Fix an issue parsing file paths on Mac that could prevent extensions from being detected. +* Fix an issue parsing file paths that could prevent extensions from being detected. # 6.0.2 * Fix an issue parsing file paths on Windows that could prevent extensions from being detected.
diff --git a/packages/devtools_shared/lib/src/extensions/extension_manager.dart b/packages/devtools_shared/lib/src/extensions/extension_manager.dart index e7e5ccb..1d4d65c 100644 --- a/packages/devtools_shared/lib/src/extensions/extension_manager.dart +++ b/packages/devtools_shared/lib/src/extensions/extension_manager.dart
@@ -48,32 +48,40 @@ /// [serveAvailableExtensions] is called. final devtoolsExtensions = <DevToolsExtensionConfig>[]; - /// Serves any available DevTools extensions for the given [rootPath], where - /// [rootPath] is the root for a Dart or Flutter project containing the - /// `.dart_tool/` directory. + /// Serves any available DevTools extensions for the given [rootPathFileUri], + /// where [rootPathFileUri] is the root for a Dart or Flutter project + /// containing the `.dart_tool/` directory. + /// + /// [rootPathFileUri] is expected to be a file uri (e.g. starting with + /// 'file://'). /// /// This method first looks up the available extensions using /// package:extension_discovery, and the available extension's /// assets will be copied to the `build/devtools_extensions` directory that /// DevTools server is serving. - Future<void> serveAvailableExtensions(String? rootPath) async { + Future<void> serveAvailableExtensions(String? rootPathFileUri) async { + if (rootPathFileUri != null && !rootPathFileUri.startsWith('file://')) { + throw ArgumentError.value( + rootPathFileUri, + 'rootPathFileUri', + 'must be a file:// URI String', + ); + } + devtoolsExtensions.clear(); - if (rootPath != null) { + if (rootPathFileUri != null) { late final List<Extension> extensions; try { - final packageConfigPath = path.join( - rootPath, - '.dart_tool', - 'package_config.json', - ); - // Only use [Uri.file] for windows platforms (https://github.com/dart-lang/tools/issues/220). - final packageConfigUri = Platform.isWindows - ? Uri.file(packageConfigPath) - : Uri.parse(packageConfigPath); extensions = await findExtensions( 'devtools', - packageConfig: packageConfigUri, + packageConfig: Uri.parse( + path.posix.join( + rootPathFileUri, + '.dart_tool', + 'package_config.json', + ), + ), ); } catch (e) { print('[ERROR] `findExtensions` failed: $e');