-
-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recategorize controller dependencies as devDependencies if only imports are messaging system-related types #3607
Conversation
@metamask/{keyring-controller,snap-controllers}
as deps
@metamask/{keyring-controller,snap-controllers}
as deps@metamask/{keyring-controller,snaps-controllers}
as deps
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.
One thing but otherwise looks good!
@legobeat Thanks for reminding me about that issue, I will take a closer look at it tomorrow. |
26ccef1
to
4f99106
Compare
@@ -33,6 +33,8 @@ | |||
"@metamask/base-controller": "^4.0.0", | |||
"@metamask/eth-snap-keyring": "^2.0.0", | |||
"@metamask/keyring-api": "^1.1.0", | |||
"@metamask/keyring-controller": "^10.0.0", |
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.
Would it be a sufficient compromise to add them as peerDependencies
+ devDependencies
, and drop them as direct dependencies?
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.
That sounds like a better idea to me as well. This is better represented as a peerDependency
because we're using it via the messaging system. A peerDependency
is an expectation we have of the user of this package, which is the situation we're in here (we're expecting the user of this package to have a messaging system that includes a specific version of the KeyringController
).
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.
Thanks for explaining this! Applied here: b3be687
Also made the same changes to queued-request-controller
(9b79604), and a few others (0e731b7) that we can revert if unnecessary.
queued-request-controller
seems like an appropriate change though, since the controllers dependencies are only being used to import messaging types that are used in the middleware and not the controller itself.
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.
Great! Maybe we can go even further but makes sense to not do everything in one go.
4f99106
to
024b7ce
Compare
…ricted to messaging system-related types
024b7ce
to
0e731b7
Compare
@metamask/{keyring-controller,snaps-controllers}
as depsThere 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.
Upon a second review of this PR, does it make sense to do this? In all of these cases, dependencies are imported to use types from those dependencies. We want to make sure that those dependencies come along for the ride and aren't merely dev or peer dependencies, otherwise consumers that attempt to import these packages will get TypeScript compilation errors.
@mcmire That was my understanding going into this PR (packages from which we're only importing types can still be dependencies), which is why I initially recategorized |
We've been doing this a long time now. This is what this constraint is meant to enforce: Line 342 in 509e580
|
I'm not sure I follow. If the client is using a function or constructor from a library that expects an argument of a certain shape, and that shape comes from a dependency that the library loads, and the client passes an object that is of a different version of that shape because the library it uses is of a different version, TypeScript should fail.
Have we? I know we've been using |
This would be true if Generally though you're right, these
That's exactly the situation here though, it's no different. The types aren't just being used for some unrelated purpose, they're used to represent the expected shape of the controller that the types come from.
We need to ensure the types are present if they're referenced in the types bundled with the package itself, otherwise those types would be invalid. But We're not asking users to manually install additional code to get the types to work in this case. That's already required. These controllers won't work correctly if the controller referenced in the type isn't present, and integrated via the messenger system/controller constructor parameters. |
Oh, though I am noticing now that I have misremembered the constraint we have for controllers. It only checks that controller Edit: While I don't recall why these controllers had each other as dependencies, it does make sense that we wouldn't have this constraint for |
To recap:
Does that make sense? |
I think so, yes. I'm on board. |
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!
* origin/main: Recategorize controller dependencies as devDependencies if only imports are messaging system-related types (#3607)
I've updated some of the changelogs to simplify them (no need to explain `devDependency` changes, those aren't public) and to clarify that the one peer dependency addition is breaking.
Explanation
peerDependencies
to ensure that we see warnings for incompatible versions.peerDependencies
controller that is not invoked directly at runtime shouldn't be included underdependencies
. Any type imports will still resolve because we can assume the controller package will be installed.References
Changelog
@metamask/accounts-controller
Fixed
@metamask/snaps-controllers
as a peer dependency in addition to a dev dependency (#3607)@metamask/ens-controller
Fixed
@metamask/network-controller
as a dev dependency and peer dependency (#3607)@metamask/keyring-controller
Fixed
@metamask/preferences-controller
as a dev dependency and peer dependency (#3607)@metamask/permission-controller
Fixed
@metamask/approval-controller
as a dev dependency and peer dependency (#3607)@metamask/queued-request-controller
Fixed
@metamask/approval-controller
,@metamask/network-controller
,@metamask/selected-network-controller
as dev dependencies (#3607)Checklist