Skip to content

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Sep 12, 2019

Description

Allow configuring whether webOnlyInitializePlatform is 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

@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label Sep 12, 2019
@jonahwilliams jonahwilliams changed the title allow not calling webOnlyInitializePlatform with (--no)--initialize-p… Allow skipping webOnlyInitializePlatform in Flutter for Web Sep 12, 2019
@jonahwilliams jonahwilliams changed the title Allow skipping webOnlyInitializePlatform in Flutter for Web [WIP] Allow skipping webOnlyInitializePlatform in Flutter for Web Sep 12, 2019
@jacob314
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@jacob314 jacob314 left a 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.

@jonahwilliams jonahwilliams changed the title [WIP] Allow skipping webOnlyInitializePlatform in Flutter for Web Allow skipping webOnlyInitializePlatform in Flutter for Web Sep 12, 2019
@jonahwilliams
Copy link
Contributor Author

I'm going to change the command line flag name to be (--no)--web-initialize-platform

@cbenhagen
Copy link
Contributor

@jonahwilliams guess you can close #40389 with this.. Sorry for the noise.

@jonahwilliams
Copy link
Contributor Author

@cbenhagen no problem!

usesTargetOption();
usesPubOption();
addBuildModeFlags();
argParser.addFlag('web-initialize-platform',
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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(); }

Copy link
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm
with a couple small nits. Thanks for implementing this so quickly!

@codecov
Copy link

codecov bot commented Sep 13, 2019

Codecov Report

Merging #40301 into master will increase coverage by 0.66%.
The diff coverage is 75%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#flutter_tool 59.22% <75%> (+0.66%) ⬆️
Impacted Files Coverage Δ
packages/flutter_tools/lib/src/test/runner.dart 0% <ø> (ø) ⬆️
...lib/src/build_runner/web_compilation_delegate.dart 24.24% <0%> (-1.16%) ⬇️
packages/flutter_tools/lib/src/web/compile.dart 84.37% <100%> (ø) ⬆️
...ges/flutter_tools/lib/src/build_runner/web_fs.dart 23.42% <100%> (+1.2%) ⬆️
packages/flutter_tools/lib/src/commands/run.dart 64.56% <100%> (+1.01%) ⬆️
...ools/lib/src/build_runner/resident_web_runner.dart 78.52% <100%> (+0.14%) ⬆️
packages/flutter_tools/lib/src/device.dart 61.76% <100%> (ø) ⬆️
...ages/flutter_tools/lib/src/commands/build_web.dart 73.33% <50%> (+1.9%) ⬆️
...utter_tools/lib/src/build_runner/build_script.dart 20% <66.66%> (ø)
...ackages/flutter_tools/lib/src/commands/doctor.dart 57.14% <0%> (-7.15%) ⬇️
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 576a455...dc00651. Read the comment docs.

@jonahwilliams jonahwilliams merged commit 69a2964 into flutter:master Sep 13, 2019
@jonahwilliams jonahwilliams deleted the secret_no_initialize branch September 13, 2019 17:20
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web] Release build is not registering web plugins

6 participants