Add validation that the extension name matches the package name - #9965
Add validation that the extension name matches the package name#9965johnpryan wants to merge 2 commits into
Conversation
Ensure that an extension's name in config.yaml matches the package name in pubspec.yaml
There was a problem hiding this comment.
Code Review
This pull request introduces validation during DevTools extension discovery and validation to ensure that an extension's declared name in config.yaml matches its containing package name. If there is a mismatch, the extension is ignored (with a warning) or validation fails. This is implemented across devtools_shared and devtools_extensions, with corresponding tests added.
Feedback on the changes highlights two potential runtime issues:
- In
extension_manager.dart, if thenamefield inconfig.yamlis missing or not a string, the extension will be silently ignored with a mismatch warning instead of throwing a more descriptive parsing error. It is suggested to only perform the mismatch check ifextensionNameis aString. - In
_validate.dart, castingpubspecYaml['name']andconfigYaml['name']directly usingas String?can cause a runtimeTypeErrorif the fields are parsed as non-string types. Safe type checking should be used instead.
kenzieschmoll
left a comment
There was a problem hiding this comment.
The actually breaks an intentional feature of DevTools extensions that allows you to develop your extension in a different package than the one where you ship it. See https://github.com/rrousselGit/provider/tree/master/packages for an example. This is necessary because many package authors want to decouple their Flutter Web project (DevTools extension) from their package that users import as a direct dependency. Developing the devtools extension in another package allows the Flutter web code and deps to be kept separate from the package users depend on.
|
I didn't realize that was the intended behavior. I'm not sure how exactly to proceed. Here here are some alternatives we could consider:
|
This ensures that packages can't provide extensions for package with a different name.
To test this behavior, create a new package under
packages/devtools_extensions/example/test_validation_pkg:devtools/config.yaml:
pubspec.yaml:
Run the validator: