Skip to content

Commit 14591fd

Browse files
committed
feat: Create new @metamask/messenger package
The `Messenger` class and related code has been copied from the `@metamask/base-controller` package to a new `@metamask/messenger` package. Separating the messenger from the base controller reduces the impact of base controller breaking changes, and aligns well with our plans to use the `Messenger` class more often for non-controllers. This move will also simplify the effort to implement some new breaking changes to the `Messenger` class (the new `delegation` method, see issue #5626). This new package will not be released until the breaking changes have been applied here. Those changes will come in later PRs; for now, the code was copied over with zero changes.
1 parent 5b66cce commit 14591fd

20 files changed

+3184
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
/packages/composable-controller @MetaMask/core-platform
6464
/packages/controller-utils @MetaMask/core-platform
6565
/packages/error-reporting-service @MetaMask/core-platform
66+
/packages/messenger @MetaMask/core-platform
6667
/packages/sample-controllers @MetaMask/core-platform
6768
/packages/polling-controller @MetaMask/core-platform
6869
/packages/preferences-controller @MetaMask/core-platform

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Each package in this repository has its own README where you can find installati
4747
- [`@metamask/keyring-controller`](packages/keyring-controller)
4848
- [`@metamask/logging-controller`](packages/logging-controller)
4949
- [`@metamask/message-manager`](packages/message-manager)
50+
- [`@metamask/messenger`](packages/messenger)
5051
- [`@metamask/multichain-api-middleware`](packages/multichain-api-middleware)
5152
- [`@metamask/multichain-network-controller`](packages/multichain-network-controller)
5253
- [`@metamask/multichain-transactions-controller`](packages/multichain-transactions-controller)
@@ -104,6 +105,7 @@ linkStyle default opacity:0.5
104105
keyring_controller(["@metamask/keyring-controller"]);
105106
logging_controller(["@metamask/logging-controller"]);
106107
message_manager(["@metamask/message-manager"]);
108+
messenger(["@metamask/messenger"]);
107109
multichain_api_middleware(["@metamask/multichain-api-middleware"]);
108110
multichain_network_controller(["@metamask/multichain-network-controller"]);
109111
multichain_transactions_controller(["@metamask/multichain-transactions-controller"]);

packages/messenger/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Migrate `Messenger` class from `@metamask/base-controller` package
13+
14+
[Unreleased]: https://github.com/MetaMask/core/

packages/messenger/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MIT License
2+
3+
Copyright (c) 2025 MetaMask
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

packages/messenger/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# `@metamask/messenger`
2+
3+
A type-safe message bus library.
4+
5+
The `Messenger` class allows registering functions as 'actions' that can be called elsewhere, and it allows publishing and subscribing to events. Both actions and events are identified by namespaced strings.
6+
7+
## Installation
8+
9+
`yarn add @metamask/messenger`
10+
11+
or
12+
13+
`npm install @metamask/messenger`
14+
15+
## Contributing
16+
17+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).

packages/messenger/jest.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
const merge = require('deepmerge');
7+
const path = require('path');
8+
9+
const baseConfig = require('../../jest.config.packages');
10+
11+
const displayName = path.basename(__dirname);
12+
13+
module.exports = merge(baseConfig, {
14+
// The display name when running multiple projects
15+
displayName,
16+
17+
// An object that configures minimum threshold enforcement for coverage results
18+
coverageThreshold: {
19+
global: {
20+
branches: 100,
21+
functions: 100,
22+
lines: 100,
23+
statements: 100,
24+
},
25+
},
26+
});

packages/messenger/package.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"name": "@metamask/messenger",
3+
"version": "0.0.0",
4+
"description": "A type-safe message bus library",
5+
"keywords": [
6+
"MetaMask",
7+
"Ethereum"
8+
],
9+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/messenger#readme",
10+
"bugs": {
11+
"url": "https://github.com/MetaMask/core/issues"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/MetaMask/core.git"
16+
},
17+
"license": "MIT",
18+
"sideEffects": false,
19+
"exports": {
20+
".": {
21+
"import": {
22+
"types": "./dist/index.d.mts",
23+
"default": "./dist/index.mjs"
24+
},
25+
"require": {
26+
"types": "./dist/index.d.cts",
27+
"default": "./dist/index.cjs"
28+
}
29+
},
30+
"./package.json": "./package.json"
31+
},
32+
"main": "./dist/index.cjs",
33+
"types": "./dist/index.d.cts",
34+
"files": [
35+
"dist/"
36+
],
37+
"scripts": {
38+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
39+
"build:docs": "typedoc",
40+
"changelog:update": "../../scripts/update-changelog.sh @metamask/messenger",
41+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/messenger",
42+
"publish:preview": "yarn npm publish --tag preview",
43+
"since-latest-release": "../../scripts/since-latest-release.sh",
44+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
45+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
46+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
47+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
48+
},
49+
"devDependencies": {
50+
"@metamask/auto-changelog": "^3.4.4",
51+
"@types/jest": "^27.4.1",
52+
"deepmerge": "^4.2.2",
53+
"immer": "^9.0.6",
54+
"jest": "^27.5.1",
55+
"sinon": "^9.2.4",
56+
"ts-jest": "^27.1.4",
57+
"typedoc": "^0.24.8",
58+
"typedoc-plugin-missing-exports": "^2.0.0",
59+
"typescript": "~5.2.2"
60+
},
61+
"engines": {
62+
"node": "^18.18 || >=20"
63+
},
64+
"publishConfig": {
65+
"access": "public",
66+
"registry": "https://registry.npmjs.org/"
67+
}
68+
}

0 commit comments

Comments
 (0)