From ffdeaa1995efc1fe7d759e13b92eba1ec57beea6 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Wed, 26 Jun 2024 09:49:44 +0200 Subject: [PATCH] Use `Isolate.packageConfigSync! to locate the packageconfig of flutter tools (#150340) This is a small refactor. Using `loadPackageConfigWithLogging` seems wrong. We should be able to assume that the flutter_tool package_config is in place. Warm-up for https://github.com/flutter/flutter/issues/150196 --- packages/flutter_tools/lib/src/dart/package_map.dart | 6 ++++++ .../flutter_tools/lib/src/isolated/devfs_web.dart | 9 +-------- .../lib/src/test/flutter_web_platform.dart | 11 +---------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/packages/flutter_tools/lib/src/dart/package_map.dart b/packages/flutter_tools/lib/src/dart/package_map.dart index 6d85a1a02c46..404583ca7344 100644 --- a/packages/flutter_tools/lib/src/dart/package_map.dart +++ b/packages/flutter_tools/lib/src/dart/package_map.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:isolate'; import 'dart:typed_data'; import 'package:package_config/package_config.dart'; @@ -10,6 +11,11 @@ import '../base/common.dart'; import '../base/file_system.dart'; import '../base/logger.dart'; +/// Loads the package configuration of the current isolate. +Future currentPackageConfig() async { + return loadPackageConfigUri(Isolate.packageConfigSync!); +} + /// Load the package configuration from [file] or throws a [ToolExit] /// if the operation would fail. /// diff --git a/packages/flutter_tools/lib/src/isolated/devfs_web.dart b/packages/flutter_tools/lib/src/isolated/devfs_web.dart index 4b0667547fed..a9cfacec564a 100644 --- a/packages/flutter_tools/lib/src/isolated/devfs_web.dart +++ b/packages/flutter_tools/lib/src/isolated/devfs_web.dart @@ -1222,14 +1222,7 @@ void log(logging.LogRecord event) { Future _loadDwdsDirectory( FileSystem fileSystem, Logger logger) async { - final String toolPackagePath = - fileSystem.path.join(Cache.flutterRoot!, 'packages', 'flutter_tools'); - final String packageFilePath = - fileSystem.path.join(toolPackagePath, '.dart_tool', 'package_config.json'); - final PackageConfig packageConfig = await loadPackageConfigWithLogging( - fileSystem.file(packageFilePath), - logger: logger, - ); + final PackageConfig packageConfig = await currentPackageConfig(); return fileSystem.directory(packageConfig['dwds']!.packageUriRoot); } diff --git a/packages/flutter_tools/lib/src/test/flutter_web_platform.dart b/packages/flutter_tools/lib/src/test/flutter_web_platform.dart index c77231db80da..c319132ed0f9 100644 --- a/packages/flutter_tools/lib/src/test/flutter_web_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_web_platform.dart @@ -175,16 +175,7 @@ class FlutterWebPlatform extends PlatformPlugin { }) async { final shelf.Server server = await serverFactory(); if (testPackageUri == null) { - final PackageConfig packageConfig = await loadPackageConfigWithLogging( - fileSystem.file(fileSystem.path.join( - Cache.flutterRoot!, - 'packages', - 'flutter_tools', - '.dart_tool', - 'package_config.json', - )), - logger: logger, - ); + final PackageConfig packageConfig = await currentPackageConfig(); testPackageUri = packageConfig['test']!.packageUriRoot; } final File testDartJs = fileSystem.file(fileSystem.path.join(