-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Allow skipping webOnlyInitializePlatform in Flutter for Web #40301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow skipping webOnlyInitializePlatform in Flutter for Web #40301
Conversation
|
Works like a charm! This will make my job incrementally porting from dart:html much easier! |
| import "${path.url.basename(buildStep.inputId.path)}" as entrypoint; | ||
| Future<void> main() async { | ||
| registerPlugins(webPluginRegistry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this hasWebPlugins line an unrelated bug fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
jacob314
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: probably would be cleaner if your integration test could check for an
if (false) { initalizeWebOnlyPlatform(); }
jacob314
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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