Skip to content

[tool] Migrate Web build subcommands and toolchain to modular dependency injection - #190783

Merged
auto-submit[bot] merged 57 commits into
flutter:masterfrom
bkonyi:di/17-web-build-and-toolchain
Sep 29, 2026
Merged

auto-submit[bot] merged 57 commits into
flutter:masterfrom
bkonyi:di/17-web-build-and-toolchain

Conversation

@bkonyi

@bkonyi bkonyi commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part 17 of the modular dependency injection migration.

Note

Stacked on #192462 (di/17a-build-bundle-command), which migrated BuildBundleCommand to modular DI.

  • Migrates Web build subcommand and toolchain components to modular constructor dependency injection:
    • BuildWebCommand({required BuildSystem buildSystem, required FeatureFlags featureFlags, required ToolContext toolContext, required super.verboseHelp, BuildTargets buildTargets = const BuildTargetsImpl(), WebBuilder? webBuilder})
  • Passes ToolContext directly to subcommands, eliminating context.get fallbacks in BuildCommand and WebBuilder.
  • Injects FileSystem into defaultDepfilePath and getAssetBuildDirectory.
  • Migrates unit tests in test/commands.shard/hermetic/build_web_test.dart to hermetic testWithoutContext.

Part of #188471

@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team team-linux Owned by the Linux platform team labels Aug 8, 2026
@bkonyi
bkonyi force-pushed the di/17-web-build-and-toolchain branch 6 times, most recently from c7444cf to 8b68044 Compare August 12, 2026 18:39
@bkonyi
bkonyi force-pushed the di/17-web-build-and-toolchain branch from 8b68044 to bfbe18c Compare September 2, 2026 13:30
@bkonyi
bkonyi marked this pull request as ready for review September 2, 2026 13:30
@bkonyi bkonyi added the CICD Run CI/CD label Sep 2, 2026
@github-actions github-actions Bot removed a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team team-windows Owned by the Windows platform team team-linux Owned by the Linux platform team labels Sep 2, 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 build commands (BuildCommand, BuildBundleCommand, BuildWebCommand) and the WebBuilder class to accept explicit dependencies (such as ToolContext, BuildSystem, and FeatureFlags) instead of relying on global state or context lookups. This allows migrating their respective tests from testUsingContext to testWithoutContext. Feedback suggests typing the terminal parameter, field, and local variable in WebBuilder as Terminal instead of AnsiTerminal to prevent potential runtime TypeErrors when using non-ANSI or mock terminals.

Comment thread packages/flutter_tools/lib/src/web/compile.dart Outdated
Comment thread packages/flutter_tools/lib/src/web/compile.dart Outdated
Comment thread packages/flutter_tools/lib/src/web/compile.dart Outdated
@bkonyi

bkonyi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 build commands, including BuildCommand, BuildBundleCommand, and BuildWebCommand, to explicitly accept ToolContext and FeatureFlags instead of relying on global context. This change allows migrating associated tests from testUsingContext to testWithoutContext. Feedback on the changes suggests avoiding an unnecessary downcast of terminal to AnsiTerminal in build_web.dart to prevent potential runtime errors in tests, and consolidating the duplicated _DefaultFeatureFlags class into a shared location to adhere to the DRY principle.

Comment thread packages/flutter_tools/lib/src/commands/build_web.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/build.dart Outdated
@bkonyi

bkonyi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 the build commands (BuildCommand, BuildBundleCommand, and BuildWebCommand) and related utilities to use modular dependency injection via ToolContext and FeatureFlags instead of relying on global variables, enabling hermetic tests to run without context. The review feedback suggests enhancing this refactoring by avoiding hardcoded fallback paths in bundle.dart (using globals.localFileSystem instead) and fully injecting the Config instance into WebBuilder to avoid any fallback to globals.config when resolving the web build directory.

Comment thread packages/flutter_tools/lib/src/bundle.dart Outdated
Comment thread packages/flutter_tools/lib/src/bundle.dart Outdated
Comment thread packages/flutter_tools/lib/src/bundle.dart Outdated
Comment thread packages/flutter_tools/lib/src/web/compile.dart
Comment thread packages/flutter_tools/lib/src/web/compile.dart Outdated
Comment thread packages/flutter_tools/lib/src/web/compile.dart
Comment thread packages/flutter_tools/lib/src/commands/build_web.dart Outdated
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team labels Sep 18, 2026
…-toolchain

# Conflicts:
#	packages/flutter_tools/lib/src/commands/build.dart
#	packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart
… fallback

- WebBuilder now has a single constructor with all dependencies
  required (artifacts, build targets, cache, config, platform, terminal
  added to the existing parameters). BuildWebCommand builds it from its
  ToolContext; the non-migrated ResidentWebRunner passes its
  dependencies explicitly at the call site.
- getWebBuildDirectory now requires Config and FileSystem instead of
  falling back to globals.fs.
- Remove the unused test-only webBuilder/buildTargets injection points
  from BuildWebCommand.
- Revert unrelated formatting and renames (web_ui embedding strategy,
  BuildCommand android builder local, WebBuilder field names, and
  compile_web_test setup) to reduce the diff.
@github-actions github-actions Bot removed engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team labels Sep 24, 2026
@bkonyi
bkonyi requested a review from dcharkes September 28, 2026 12:09
dcharkes
dcharkes previously approved these changes Sep 28, 2026
fileSystem: globals.fs,
flutterVersion: globals.flutterVersion,
analytics: globals.analytics,
logger: logger,

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.

Does WebBuilder need to be migrated to tool context, instead of all the params? Edit: Yes you already have a TODO. sgtm!

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 28, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Sep 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Sep 28, 2026
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 28, 2026
…-toolchain

# Conflicts:
#	packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 29, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Sep 29, 2026
Merged via the queue into flutter:master with commit 3a8e191 Sep 29, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD 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