Skip to content

Commit

Permalink
Use `Isolate.packageConfigSync! to locate the packageconfig of flutte…
Browse files Browse the repository at this point in the history
…r 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
  • Loading branch information
sigurdm authored Jun 26, 2024
1 parent b2b0a75 commit ffdeaa1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
6 changes: 6 additions & 0 deletions packages/flutter_tools/lib/src/dart/package_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
///
Expand Down
9 changes: 1 addition & 8 deletions packages/flutter_tools/lib/src/isolated/devfs_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 1 addition & 10 deletions packages/flutter_tools/lib/src/test/flutter_web_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ffdeaa1

Please sign in to comment.