flutter / flutter/flutter

Smarter registration of plugin dependencies.

Open
#142,276 7 comments 0 reactions 0 assignees View on GitHub
a: build a: plugins P3 package team-tool tool tool-still-valid triaged-tool
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Use case

In the current implementation of our plugin-related tooling, all compatible plugin dependencies of a plugin are added to the generated plugin registrar of the platform, regardless of the plugin itself actually supports the target platform.

A concrete example:

if I add `firebase_crashlytics` to my pubspec (this is only compatible Android/iOS/MacOS) and compile for the web, our build system will add `firebase_core` to the plugin web registrant (because it *is* web compatible), but will never add `crashlytics` (which is *not* web compatible), hence making all of `firebase_core` unneeded.

What is worse is that the web plugin registrant generates Dart code that will always call the `registerWith` method of the unused plugin(s), so at least parts of it will fail to tree-shake, increasing the binary size ("how much?" depends on the structure of the unnecessary plugins).

Another problem on the web is that this impedes compiling to `--wasm`, **even if** the App code itself has been written correctly (conditional imports, etc...) to never call the plugin code paths when targeting the web.

### Proposal

Modify the generation of the `plugin_registrar` (at least on the web) to **only include dependencies of the plugins that will be `registerWith` for that platform**. Don't include all its plugin dependencies blindly!

Contributor guide

Open the contributing guide

Research direction

Start by tracing the plugin registrar generation in the plugin-related tooling, using the pubspec compatibility information and the firebase_crashlytics/firebase_core example as the case to follow. Done means the generated web registrar includes dependencies only for plugins that register on the target platform, while preserving valid web and wasm builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
build-system, tooling, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.