diff --git a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart index 5eb6a41fccf..b7380fde589 100644 --- a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart +++ b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart @@ -20,8 +20,10 @@ import '../base/net.dart'; import '../base/terminal.dart'; import '../base/utils.dart'; import '../build_info.dart'; +import '../cache.dart'; import '../compile.dart'; import '../convert.dart'; +import '../dart/pub.dart'; import '../devfs.dart'; import '../device.dart'; import '../features.dart'; @@ -403,6 +405,14 @@ class _ResidentWebRunner extends ResidentWebRunner { try { return await asyncGuard(() async { + // Ensure dwds resources are cached. If the .packages file is missing then + // the client.js script cannot be located by the injected handler in dwds. + // This will result in a NoSuchMethodError thrown by injected_handler.darts + await pub.get( + context: PubContext.pubGet, + directory: globals.fs.path.join(Cache.flutterRoot, 'packages', 'flutter_tools') + ); + device.devFS = WebDevFS( hostname: effectiveHostname, port: hostPort, diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart index 1a315bf49bb..9444d43fa2c 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart @@ -10,6 +10,7 @@ import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_system/build_system.dart'; +import 'package:flutter_tools/src/dart/pub.dart'; import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/project.dart'; @@ -54,7 +55,9 @@ void main() { stayResident: true, urlTunneller: null, ) as ResidentWebRunner; - }, + }, overrides: { + Pub: () => MockPub(), + } ); }); @@ -166,3 +169,4 @@ class MockChromeConnection extends Mock implements ChromeConnection {} class MockChromeTab extends Mock implements ChromeTab {} class MockWipConnection extends Mock implements WipConnection {} class MockBuildSystem extends Mock implements BuildSystem {} +class MockPub extends Mock implements Pub {} diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart index c460695c3fb..934e918e1e9 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart @@ -13,6 +13,7 @@ import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_runner/resident_web_runner.dart'; import 'package:flutter_tools/src/compile.dart'; +import 'package:flutter_tools/src/dart/pub.dart'; import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/globals.dart' as globals; @@ -82,6 +83,9 @@ void main() { globals.fs.currentDirectory.childFile('.packages') .writeAsStringSync('\n'); }, + overrides: { + Pub: () => MockPub(), + } ); }); @@ -214,6 +218,10 @@ void main() { verify(mockAppConnection.runMain()).called(1); verify(mockVmService.registerService('reloadSources', 'FlutterTools')).called(1); verify(status.stop()).called(1); + verify(pub.get( + context: PubContext.pubGet, + directory: globals.fs.path.join('packages', 'flutter_tools') + )).called(1); expect(bufferLogger.statusText, contains('Debug service listening on ws://127.0.0.1/abcd/')); expect(debugConnectionInfo.wsUri.toString(), 'ws://127.0.0.1/abcd/'); @@ -978,3 +986,4 @@ class MockWipConnection extends Mock implements WipConnection {} class MockWipDebugger extends Mock implements WipDebugger {} class MockWebServerDevice extends Mock implements WebServerDevice {} class MockDevice extends Mock implements Device {} +class MockPub extends Mock implements Pub {}