From e8d2e5814e2ba8ea1f5920265054c6b75fcaeb25 Mon Sep 17 00:00:00 2001 From: Yegor Date: Wed, 7 Aug 2024 11:40:58 -0700 Subject: [PATCH] [web] hide the --web-renderer option in the tool (#152683) Hide the `--web-renderer` option in the Flutter Tool. The defaults already cover all fully supported modes: - `flutter build web` provides canvaskit + dart2js - `flutter build web --wasm` provides skwasm + dart2wasm We do not want to encourage production usage of any other permutations (e.g. `auto` or `html`), in particular those that simply do not work (e.g. `skwasm` + dart2js). Fixes https://github.com/flutter/flutter/issues/140096 Fixes https://github.com/flutter/flutter/issues/151786 --- .../lib/src/runner/flutter_command.dart | 19 +++++++++- .../hermetic/build_web_test.dart | 38 +++++++++++++++++++ .../test/general.shard/args_test.dart | 24 ++++++++++-- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index 4249210c53..997fdb0311 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -707,11 +707,28 @@ abstract class FlutterCommand extends Command { ); } + // This option is deprecated and is no longer publicly supported, and + // therefore is hidden. + // + // The option still exists for internal testing, and to give existing users + // time to migrate off the HTML renderer, but it is no longer advertised as a + // supported mode. + // + // See also: + // * https://github.com/flutter/flutter/issues/151786 + // * https://github.com/flutter/flutter/issues/145954 void usesWebRendererOption() { argParser.addOption( + hide: true, FlutterOptions.kWebRendererFlag, allowed: WebRendererMode.values.map((WebRendererMode e) => e.name), - help: 'The renderer implementation to use when building for the web.', + help: 'This option is deprecated and will be removed in a future Flutter ' + 'release.\n' + 'Selects the renderer implementation to use when building for the ' + 'web. The supported renderers are "canvaskit" when compiling to ' + 'JavaScript, and "skwasm" when compiling to WebAssembly. Other ' + 'renderer and compiler combinations are no longer supported. ' + 'Consider migrating your app to a supported renderer.', allowedHelp: CliEnum.allowedHelp(WebRendererMode.values) ); } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart index 0c2cb70056..35d10bb5b0 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart @@ -377,6 +377,44 @@ void main() { FileSystem: () => fileSystem, ProcessManager: () => processManager, }); + + testUsingContext('flutter build web option visibility', () async { + final TestWebBuildCommand buildCommand = TestWebBuildCommand(fileSystem: fileSystem); + createTestCommandRunner(buildCommand); + final BuildWebCommand command = buildCommand.subcommands.values.single as BuildWebCommand; + + void expectVisible(String option) { + expect(command.argParser.options.keys, contains(option)); + expect(command.argParser.options[option]!.hide, isFalse); + expect(command.usage, contains(option)); + } + + void expectHidden(String option) { + expect(command.argParser.options.keys, contains(option)); + expect(command.argParser.options[option]!.hide, isTrue); + expect(command.usage, isNot(contains(option))); + } + + expectVisible('pwa-strategy'); + expectVisible('web-resources-cdn'); + expectVisible('optimization-level'); + expectVisible('source-maps'); + expectVisible('csp'); + expectVisible('dart2js-optimization'); + expectVisible('dump-info'); + expectVisible('no-frequency-based-minification'); + expectVisible('wasm'); + expectVisible('strip-wasm'); + expectVisible('base-href'); + + expectHidden('web-renderer'); + }, overrides: { + Platform: () => fakePlatform, + FileSystem: () => fileSystem, + FeatureFlags: () => TestFeatureFlags(isWebEnabled: true), + ProcessManager: () => processManager, + }); + } void setupFileSystemForEndToEndTest(FileSystem fileSystem) { diff --git a/packages/flutter_tools/test/general.shard/args_test.dart b/packages/flutter_tools/test/general.shard/args_test.dart index bb04cc8a86..08997eae2a 100644 --- a/packages/flutter_tools/test/general.shard/args_test.dart +++ b/packages/flutter_tools/test/general.shard/args_test.dart @@ -227,10 +227,28 @@ void verifyOptions(String? command, Iterable