Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[flutter_plugin_tools] Split common.dart #4057

Merged
merged 2 commits into from
Jun 16, 2021

Conversation

stuartmorgan-g
Copy link
Contributor

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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

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

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +14 to +32
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';
Copy link
Contributor

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?

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 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.)

Comment on lines +35 to +60
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);
}
Copy link
Contributor

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?

Copy link
Contributor Author

@stuartmorgan-g stuartmorgan-g Jun 15, 2021

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.

Copy link
Contributor

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?

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, and flag renaming, and various other things.

@stuartmorgan-g
Copy link
Contributor Author

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.

@stuartmorgan-g stuartmorgan-g merged commit d1ddb68 into flutter:master Jun 16, 2021
@stuartmorgan-g stuartmorgan-g deleted the tool-common-split branch June 16, 2021 19:37
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 16, 2021
fotiDim pushed a commit to fotiDim/plugins that referenced this pull request Sep 13, 2021
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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants