Skip to content

Commit ffdeaa1

Browse files
authored
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 flutter/flutter#150196
1 parent b2b0a75 commit ffdeaa1

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

packages/flutter_tools/lib/src/dart/package_map.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:isolate';
56
import 'dart:typed_data';
67

78
import 'package:package_config/package_config.dart';
@@ -10,6 +11,11 @@ import '../base/common.dart';
1011
import '../base/file_system.dart';
1112
import '../base/logger.dart';
1213

14+
/// Loads the package configuration of the current isolate.
15+
Future<PackageConfig> currentPackageConfig() async {
16+
return loadPackageConfigUri(Isolate.packageConfigSync!);
17+
}
18+
1319
/// Load the package configuration from [file] or throws a [ToolExit]
1420
/// if the operation would fail.
1521
///

packages/flutter_tools/lib/src/isolated/devfs_web.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,14 +1222,7 @@ void log(logging.LogRecord event) {
12221222

12231223
Future<Directory> _loadDwdsDirectory(
12241224
FileSystem fileSystem, Logger logger) async {
1225-
final String toolPackagePath =
1226-
fileSystem.path.join(Cache.flutterRoot!, 'packages', 'flutter_tools');
1227-
final String packageFilePath =
1228-
fileSystem.path.join(toolPackagePath, '.dart_tool', 'package_config.json');
1229-
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
1230-
fileSystem.file(packageFilePath),
1231-
logger: logger,
1232-
);
1225+
final PackageConfig packageConfig = await currentPackageConfig();
12331226
return fileSystem.directory(packageConfig['dwds']!.packageUriRoot);
12341227
}
12351228

packages/flutter_tools/lib/src/test/flutter_web_platform.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,7 @@ class FlutterWebPlatform extends PlatformPlugin {
175175
}) async {
176176
final shelf.Server server = await serverFactory();
177177
if (testPackageUri == null) {
178-
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
179-
fileSystem.file(fileSystem.path.join(
180-
Cache.flutterRoot!,
181-
'packages',
182-
'flutter_tools',
183-
'.dart_tool',
184-
'package_config.json',
185-
)),
186-
logger: logger,
187-
);
178+
final PackageConfig packageConfig = await currentPackageConfig();
188179
testPackageUri = packageConfig['test']!.packageUriRoot;
189180
}
190181
final File testDartJs = fileSystem.file(fileSystem.path.join(

0 commit comments

Comments
 (0)