Repository navigation
[flutter_tools] Inject dependencies into bundle, web asset server, and web targets - #194053
Conversation
…d web targets Eliminate `globals.dart` imports and usages from `bundle.dart`, `bundle_builder.dart`, `isolated/web_asset_server.dart`, `isolated/devfs_web.dart`, `web/file_generators/flutter_service_worker_js.dart`, and `build_system/targets/web.dart` by injecting required dependencies directly into constructors and helper functions. Part of flutter#188471
There was a problem hiding this comment.
Code Review
This pull request refactors several components in flutter_tools, including BundleBuilder, WebDevFS, and WebAssetServer, to explicitly inject dependencies such as FileSystem, Artifacts, and Config instead of relying on global variables. Unit tests are updated to match the new constructor and method signatures. The review feedback highlights a potential regression in buildAssets where removing the default fallback for assetDirPath when null may cause runtime issues, suggesting that Config and FileSystem should be passed to safely default this path.
…vice `tester/flutter_tester.dart` no longer imports `globals.dart` after merging `master`, but `FlutterTesterDevice.startApp` still read `analytics`, `buildSystem`, `buildTargets`, `cache`, `config` and `platform` from globals to construct its `BundleBuilder`. Thread the missing dependencies from `ToolDependencies.bootstrap` through `FlutterDeviceManager` and `FlutterTesterDevices` into `FlutterTesterDevice`, and use the already injected `Platform`. `FlutterDeviceManager` only registers `FlutterTesterDevices` when build targets are provided, since the tester device needs them to build the asset bundle. Part of flutter#188471
…eb-asset-server # Conflicts: # packages/flutter_tools/lib/src/isolated/devfs_web.dart # packages/flutter_tools/lib/src/isolated/web_asset_server.dart # packages/flutter_tools/test/general.shard/web/devfs_web_test.dart
Refactor `BundleBuilder`, `BuildBundleCommand`, `CustomDevice`, `FlutterTesterDevice`, `FlutterTesterDevices`, `WebDevFS`, and `WebAssetServer` to accept `ToolContext` instead of individual dependencies. Destructure `ToolContext` in method bodies instead of unpacking fields in constructor initializer lists, register `ToolContext` in `context_runner.dart` fallbacks and `globals.dart`, and update affected tests to pass `FakeToolContext`.
Define ToolContext on Device and PollingDeviceDiscovery and migrate CustomDevice, CustomDevices, FlutterTesterDevice, and FlutterTesterDevices to inherit toolContext from their base classes instead of using globals.toolContext.
…back Keep Logger required on Device, pass logger: toolContext.logger from CustomDevice and FlutterTesterDevice, and thread Analytics, BuildSystem, and BuildTargets through CustomDevices to CustomDevice.
…eb-asset-server # Conflicts: # packages/flutter_tools/test/general.shard/web/web_asset_server_test.dart
…eb-asset-server # Conflicts: # packages/flutter_tools/lib/src/commands/build_bundle.dart # packages/flutter_tools/lib/src/commands/custom_devices.dart # packages/flutter_tools/lib/src/context/tool_dependencies.dart # packages/flutter_tools/lib/src/custom_devices/custom_device.dart # packages/flutter_tools/lib/src/flutter_device_manager.dart # packages/flutter_tools/test/commands.shard/hermetic/custom_devices_test.dart # packages/flutter_tools/test/general.shard/custom_devices/custom_device_test.dart
There was a problem hiding this comment.
Code Review
This pull request refactors several components in flutter_tools—including BundleBuilder, WebBuilder, WebDevFS, and WebAssetServer—to accept and utilize a unified ToolContext instead of passing individual dependencies separately. The feedback suggests further simplifying WebDevFS and WebAssetServer by defining getters for common dependencies (such as fileSystem, logger, and platform) directly from the injected ToolContext to avoid repetitive destructuring boilerplate across multiple methods.
…nd WebAssetServer
|
autosubmit label was removed for flutter/flutter/194053, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
…d web targets (flutter#194053) Eliminates ambient `globals.dart` usage from `bundle.dart`, `bundle_builder.dart`, `isolated/web_asset_server.dart`, `isolated/devfs_web.dart`, `web/file_generators/flutter_service_worker_js.dart`, and `build_system/targets/web.dart` by injecting dependencies via `ToolContext`. Part of flutter#47161 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing.
…s search roots (#195201) Cherry-pick of #194064 to beta (`flutter-3.50-candidate.0`). ### Impact Description: Tightens how the web development server in `flutter_tools` maps request paths to files, so every lookup stays within the directory it is meant to serve from. It also stops some malformed request paths from throwing out of the request handler. This only affects development with `flutter run` on web, not deployed apps. ### Changelog Description: [#194064](#194064) When running a web app with `flutter run`, the development server resolves some request paths incorrectly. ### Workaround: None. ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? ### Validation Steps: In `packages/flutter_tools`, run `test/general.shard/web/devfs_web_test.dart` and `test/general.shard/web/web_asset_server_test.dart`. All tests pass on this branch, and the new tests fail without the fix. Note: `web_asset_server.dart` needed a small manual merge because #194053 isn't on the 3.50 branch. The logic is the same as on master.
…d web targets (flutter#194053) Eliminates ambient `globals.dart` usage from `bundle.dart`, `bundle_builder.dart`, `isolated/web_asset_server.dart`, `isolated/devfs_web.dart`, `web/file_generators/flutter_service_worker_js.dart`, and `build_system/targets/web.dart` by injecting dependencies via `ToolContext`. Part of flutter#47161 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing.
Eliminates ambient
globals.dartusage frombundle.dart,bundle_builder.dart,isolated/web_asset_server.dart,isolated/devfs_web.dart,web/file_generators/flutter_service_worker_js.dart, andbuild_system/targets/web.dartby injecting dependencies viaToolContext.Part of #47161
Pre-launch Checklist
///).