Skip to content

Commit 4a8975c

Browse files
refactor: migrate NameController to @metamask/messenger (#6541)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> This PR migrates `NameController` to the new `@metamask/messenger` message bus, as opposed to the one exported from `@metamask/base-controller`. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> * Related to #5626 ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Migrates `NameController` to the new `@metamask/messenger`, renames metadata `anonymous` to `includeInDebugSnapshot`, and updates imports, tests, and build references. > > - **NameController**: > - Migrate to `@metamask/messenger` (`Messenger`) and replace `RestrictedMessenger`; update generics/types. > - Switch imports to `@metamask/base-controller/next`. > - Rename metadata `anonymous` -> `includeInDebugSnapshot`; update `stateMetadata` and usages. > - Update tests to reflect new metadata key and `deriveStateFromMetadata` import path. > - **Package/Build**: > - Add dependency `@metamask/messenger` and TypeScript project references. > - Update README dependency graph to include `messenger` links. > - **Changelog**: > - Document breaking changes for messenger migration and metadata rename. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit d84e281. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: Michele Esposito <michele@esposito.codes>
1 parent 3e32d72 commit 4a8975c

File tree

8 files changed

+24
-11
lines changed

8 files changed

+24
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ linkStyle default opacity:0.5
280280
multichain_transactions_controller --> keyring_controller;
281281
name_controller --> base_controller;
282282
name_controller --> controller_utils;
283+
name_controller --> messenger;
283284
network_controller --> base_controller;
284285
network_controller --> controller_utils;
285286
network_controller --> eth_block_tracker;

packages/name-controller/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6541](https://github.com/MetaMask/core/pull/6541))
13+
- Previously, `NameController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
14+
- **BREAKING:** Metadata property `anonymous` renamed to `includeInDebugSnapshot` ([#6541](https://github.com/MetaMask/core/pull/6541))
15+
1016
## [8.1.1]
1117

1218
### Changed

packages/name-controller/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"dependencies": {
5151
"@metamask/base-controller": "^8.4.2",
5252
"@metamask/controller-utils": "^11.14.1",
53+
"@metamask/messenger": "^0.3.0",
5354
"@metamask/utils": "^11.8.1",
5455
"async-mutex": "^0.5.0"
5556
},

packages/name-controller/src/NameController.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { deriveStateFromMetadata } from '@metamask/base-controller';
1+
import { deriveStateFromMetadata } from '@metamask/base-controller/next';
22

33
import type {
44
SetNameRequest,
@@ -2765,7 +2765,7 @@ describe('NameController', () => {
27652765
deriveStateFromMetadata(
27662766
controller.state,
27672767
controller.metadata,
2768-
'anonymous',
2768+
'includeInDebugSnapshot',
27692769
),
27702770
).toMatchInlineSnapshot(`Object {}`);
27712771
});

packages/name-controller/src/NameController.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type {
22
ControllerGetStateAction,
33
ControllerStateChangeEvent,
4-
RestrictedMessenger,
5-
} from '@metamask/base-controller';
6-
import { BaseController } from '@metamask/base-controller';
4+
} from '@metamask/base-controller/next';
5+
import { BaseController } from '@metamask/base-controller/next';
76
import { isSafeDynamicKey } from '@metamask/controller-utils';
7+
import type { Messenger } from '@metamask/messenger';
88

99
import type {
1010
NameProvider,
@@ -44,13 +44,13 @@ const stateMetadata = {
4444
names: {
4545
includeInStateLogs: true,
4646
persist: true,
47-
anonymous: false,
47+
includeInDebugSnapshot: false,
4848
usedInUi: true,
4949
},
5050
nameSources: {
5151
includeInStateLogs: true,
5252
persist: true,
53-
anonymous: false,
53+
includeInDebugSnapshot: false,
5454
usedInUi: true,
5555
},
5656
};
@@ -99,12 +99,10 @@ export type NameControllerActions = GetNameState;
9999

100100
export type NameControllerEvents = NameStateChange;
101101

102-
export type NameControllerMessenger = RestrictedMessenger<
102+
export type NameControllerMessenger = Messenger<
103103
typeof controllerName,
104104
NameControllerActions,
105-
NameControllerEvents,
106-
never,
107-
never
105+
NameControllerEvents
108106
>;
109107

110108
export type NameControllerOptions = {

packages/name-controller/tsconfig.build.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"references": [
99
{
1010
"path": "../base-controller/tsconfig.build.json"
11+
},
12+
{
13+
"path": "../messenger/tsconfig.build.json"
1114
}
1215
],
1316
"include": ["../../types", "./src"]

packages/name-controller/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"references": [
77
{
88
"path": "../base-controller"
9+
},
10+
{
11+
"path": "../messenger"
912
}
1013
],
1114
"include": ["../../types", "./src"]

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4221,6 +4221,7 @@ __metadata:
42214221
"@metamask/auto-changelog": "npm:^3.4.4"
42224222
"@metamask/base-controller": "npm:^8.4.2"
42234223
"@metamask/controller-utils": "npm:^11.14.1"
4224+
"@metamask/messenger": "npm:^0.3.0"
42244225
"@metamask/utils": "npm:^11.8.1"
42254226
"@types/jest": "npm:^27.4.1"
42264227
async-mutex: "npm:^0.5.0"

0 commit comments

Comments
 (0)