Skip to content

[flutter_tools] Inject dependencies into bundle, web asset server, and web targets - #194053

Merged
auto-submit[bot] merged 16 commits into
flutter:masterfrom
bkonyi:di/28g-bundle-and-web-asset-server
Oct 21, 2026
Merged

auto-submit[bot] merged 16 commits into
flutter:masterfrom
bkonyi:di/28g-bundle-and-web-asset-server

Conversation

@bkonyi

@bkonyi bkonyi commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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 #47161

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

…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
@bkonyi
bkonyi requested a review from a team as a code owner October 9, 2026 01:43
@bkonyi bkonyi added the CICD Run CI/CD label Oct 9, 2026
@bkonyi
bkonyi requested a review from a team as a code owner October 9, 2026 01:43
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. team-ios Owned by iOS platform team team-macos Owned by the macOS platform team labels Oct 9, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bkonyi
bkonyi marked this pull request as draft October 9, 2026 16:46
…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.
@github-actions github-actions Bot added platform-ios iOS applications specifically team-android Owned by Android platform team labels Oct 15, 2026
…back

Keep Logger required on Device, pass logger: toolContext.logger from CustomDevice and FlutterTesterDevice, and thread Analytics, BuildSystem, and BuildTargets through CustomDevices to CustomDevice.
@github-actions github-actions Bot removed platform-ios iOS applications specifically team-android Owned by Android platform team labels Oct 15, 2026
…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
@bkonyi
bkonyi marked this pull request as ready for review October 19, 2026 19:49
@bkonyi
bkonyi requested a review from chingjun October 19, 2026 19:49

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 20, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 20, 2026
@auto-submit

auto-submit Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

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.

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 20, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Oct 21, 2026
Merged via the queue into flutter:master with commit d59b911 Oct 21, 2026
22 of 23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 21, 2026
LongCatIsLooong pushed a commit to LongCatIsLooong/flutter that referenced this pull request Oct 22, 2026
…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.
auto-submit Bot pushed a commit that referenced this pull request Oct 26, 2026
…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.
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD team-ios Owned by iOS platform team team-macos Owned by the macOS platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants