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
This commit is contained in:
Sigurd Meldgaard 2024-06-26 09:49:44 +02:00 committed by GitHub
parent b2b0a751ff
commit ffdeaa1995
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 18 deletions

View File

@ -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<PackageConfig> currentPackageConfig() async {
return loadPackageConfigUri(Isolate.packageConfigSync!);
}
/// Load the package configuration from [file] or throws a [ToolExit]
/// if the operation would fail.
///

View File

@ -1222,14 +1222,7 @@ void log(logging.LogRecord event) {
Future<Directory> _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);
}

View File

@ -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(