-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[flutter_plugin_tools] Split common.dart #4057
[flutter_plugin_tools] Split common.dart #4057
Conversation
common.dart is a large-and-growing file containing all shared code, which makes it hard to navigate. To make maintenance easier, this splits the file (and its test file) into separate files for each major component or category.
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
const String kPlatformFlagWindows = 'windows'; | ||
|
||
/// Key for macos platform. | ||
const String kPlatformFlagMacos = 'macos'; | ||
|
||
/// Key for linux platform. | ||
const String kPlatformFlagLinux = 'linux'; | ||
|
||
/// Key for IPA (iOS) platform. | ||
const String kPlatformFlagIos = 'ios'; | ||
|
||
/// Key for APK (Android) platform. | ||
const String kPlatformFlagAndroid = 'android'; | ||
|
||
/// Key for Web platform. | ||
const String kPlatformFlagWeb = 'web'; | ||
|
||
/// Key for enable experiment. | ||
const String kEnableExperiment = 'enable-experiment'; |
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.
nits: maybe we can refactor all these to a file called constants.dart?
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 wanted to hold off on making a "constants" file until tool refactoring is further along; I think in most cases there will be a more specific home that makes sense. (Even these are a bit iffy in that they are used multiple ways which might be better managed via usage-specific enums, so I'm not sure they will survive as-is.)
bool isFlutterPackage(FileSystemEntity entity) { | ||
if (entity is! Directory) { | ||
return false; | ||
} | ||
|
||
try { | ||
final File pubspecFile = entity.childFile('pubspec.yaml'); | ||
final YamlMap pubspecYaml = | ||
loadYaml(pubspecFile.readAsStringSync()) as YamlMap; | ||
final YamlMap? dependencies = pubspecYaml['dependencies'] as YamlMap?; | ||
if (dependencies == null) { | ||
return false; | ||
} | ||
return dependencies.containsKey('flutter'); | ||
} on FileSystemException { | ||
return false; | ||
} on YamlException { | ||
return false; | ||
} | ||
} | ||
|
||
/// Prints `errorMessage` in red. | ||
void printError(String errorMessage) { | ||
final Colorize redError = Colorize(errorMessage)..red(); | ||
print(redError); | ||
} |
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.
What makes these methods not in the plugin_util.dart?
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.
They aren't related to plugins. One of the goals of the overall refactoring is to stop using "plugin" to mean "package" in most places in this tool, since it's used for both flutter/plugins and flutter/packages.
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.
Ah I see. So I think a future refactoring that updates the class PluginCommand
to a different name is coming?
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, and flag renaming, and various other things.
Landing on red to trigger a re-run of postsubmit since I believe the docker build error there was flake, and this is both approved and relatively low-risk. |
common.dart is a large-and-growing file containing all shared code, which makes it hard to navigate. To make maintenance easier, this splits the file (and its test file) into separate files for each major component or category.
common.dart is a large-and-growing file containing all shared code,
which makes it hard to navigate. To make maintenance easier, this splits
the file (and its test file) into separate files for each major
component or category.
All code is moved exacty as-is, with the exception of test fixture setups
being edited down to just the pieces that each test suite uses. By
design, no actual changes are made to any functionality, comments,
etc. so that no actual changes will be masked by the move.
Pre-launch Checklist
dart format
.)[shared_preferences]
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.