Allow skipping webOnlyInitializePlatform in Flutter for Web#40301
Allow skipping webOnlyInitializePlatform in Flutter for Web#40301jonahwilliams merged 7 commits intoflutter:masterfrom
Conversation
|
Works like a charm! This will make my job incrementally porting from dart:html much easier! |
| @@ -383,7 +390,9 @@ import "${path.url.basename(buildStep.inputId.path)}" as entrypoint; | |||
|
|
|||
| Future<void> main() async { | |||
| registerPlugins(webPluginRegistry); | |||
There was a problem hiding this comment.
doesn't matter for my use case but should this initialization line also be inside the if block?
There was a problem hiding this comment.
I'll leave it out for now, plugins are still a WIP
|
|
||
| Future<void> main() async { | ||
| await ui.webOnlyInitializePlatform(); | ||
| if ($initializePlatform) { |
There was a problem hiding this comment.
doesn't really matter as it will be tree shaken anyway but you could write
${initializePlatform ? 'await ui.webOnlyInitializePlatform();' : ''}
to generate code with the initialize line omitted depending on the style you are going for with this generated code.
There was a problem hiding this comment.
To simplify these case I'm going to leave it inline, I think we can revist later on
| .childDirectory('.dart_tool') | ||
| .createSync(); | ||
| final FlutterProject flutterProject = FlutterProject.fromDirectory(projectDirectory); | ||
| final bool hasWebPlugins = findPlugins(flutterProject) |
There was a problem hiding this comment.
is this hasWebPlugins line an unrelated bug fix?
jacob314
left a comment
There was a problem hiding this comment.
lgtm once there is a test.
|
I'm going to change the command line flag name to be |
|
@jonahwilliams guess you can close #40389 with this.. Sorry for the noise. |
|
@cbenhagen no problem! |
| usesTargetOption(); | ||
| usesPubOption(); | ||
| addBuildModeFlags(); | ||
| argParser.addFlag('web-initialize-platform', |
There was a problem hiding this comment.
why prefix a flag to the web tool with web-? Seems less ambiguous in this case than the general case that this flag is only about initializing the web platform.
There was a problem hiding this comment.
I want to keep the flag the same as what is provided as in run.dart. Since that is not web specific, I prefixed it.
|
|
||
| await builder.build(mockBuildStep); | ||
|
|
||
| verify(mockBuildStep.writeAsString(any, argThat(contains('if (false)')))).called(1); |
There was a problem hiding this comment.
nit: probably would be cleaner if your integration test could check for an
if (false) { initalizeWebOnlyPlatform(); }
Codecov Report
@@ Coverage Diff @@
## master #40301 +/- ##
==========================================
+ Coverage 58.56% 59.22% +0.66%
==========================================
Files 192 193 +1
Lines 18595 18712 +117
==========================================
+ Hits 10890 11083 +193
+ Misses 7705 7629 -76
Continue to review full report at Codecov.
|

Description
Allow configuring whether
webOnlyInitializePlatformis invoked by the shell automatically with the flag (--no)--web-initialize-platform to flutter run and build. Also fixes an issue with flutter build not checking for plugins.cc @jacob314 PTAL and let me know if this is sufficient for your usecase
Also fixes #40389