Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
/packages/error-reporting-service @MetaMask/core-platform
/packages/eth-json-rpc-middleware @MetaMask/core-platform
/packages/messenger @MetaMask/core-platform
/packages/messenger-docs @MetaMask/core-platform
/packages/sample-controllers @MetaMask/core-platform
/packages/polling-controller @MetaMask/core-platform
/packages/preferences-controller @MetaMask/core-platform
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/messenger-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Messenger API Docs

on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
build-docs:
name: Build Messenger API docs
runs-on: ubuntu-latest
steps:
- name: Checkout and setup environment
uses: MetaMask/action-checkout-and-setup@v2
with:
is-high-risk-environment: false

- name: Generate and build Messenger docs
run: yarn docs:messenger:build
env:
DOCS_URL: https://${{ github.repository_owner }}.github.io
DOCS_BASE_URL: /${{ github.event.repository.name }}/

- name: Upload build artifact (PR)
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: messenger-api-docs
path: .messenger-docs/build/
retention-days: 7

- name: Upload Pages artifact (main)
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: actions/upload-pages-artifact@v3
with:
path: .messenger-docs/build/

deploy:
name: Deploy to GitHub Pages
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: build-docs
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ scripts/coverage
# typescript
packages/*/*.tsbuildinfo

# Messenger API docs (generated)
.messenger-docs/

# Emacs
\#*\#
.#*
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Each package in this repository has its own README where you can find installati
- [`@metamask/logging-controller`](packages/logging-controller)
- [`@metamask/message-manager`](packages/message-manager)
- [`@metamask/messenger`](packages/messenger)
- [`@metamask/messenger-docs`](packages/messenger-docs)
- [`@metamask/multichain-account-service`](packages/multichain-account-service)
- [`@metamask/multichain-api-middleware`](packages/multichain-api-middleware)
- [`@metamask/multichain-network-controller`](packages/multichain-network-controller)
Expand Down Expand Up @@ -144,6 +145,7 @@ linkStyle default opacity:0.5
logging_controller(["@metamask/logging-controller"]);
message_manager(["@metamask/message-manager"]);
messenger(["@metamask/messenger"]);
messenger_docs(["@metamask/messenger-docs"]);
multichain_account_service(["@metamask/multichain-account-service"]);
multichain_api_middleware(["@metamask/multichain-api-middleware"]);
multichain_network_controller(["@metamask/multichain-network-controller"]);
Expand Down
13 changes: 12 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const config = createConfig([
'merged-packages/**',
'.yarn/**',
'scripts/create-package/package-template/**',
'.messenger-docs/**',
'packages/messenger-docs/template/**',
],
},
{
Expand Down Expand Up @@ -43,9 +45,18 @@ const config = createConfig([
'**/tests/**/*.{js,ts}',
'scripts/*.ts',
'scripts/create-package/**/*.ts',
'packages/messenger-docs/src/**/*.ts',
],
extends: [nodejs],
},
{
files: ['packages/messenger-docs/src/cli.ts'],
rules: {
// The bin field points to dist/cli.mjs but the source is src/cli.ts.
// Without convertPath, n/hashbang cannot correlate the two.
'n/hashbang': 'off',
},
},
{
files: ['**/*.{js,cjs}'],
languageOptions: {
Expand Down Expand Up @@ -125,7 +136,7 @@ const config = createConfig([
},
},
{
files: ['scripts/*.ts'],
files: ['scripts/**/*.ts'],
rules: {
// Scripts may be self-executable and thus have hashbangs.
'n/hashbang': 'off',
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"changelog:update": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:update",
"changelog:validate": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:validate",
"create-package": "tsx scripts/create-package",
"docs:messenger:build": "yarn workspace @metamask/messenger-docs docs:build",
"docs:messenger:dev": "yarn workspace @metamask/messenger-docs docs:dev",
"docs:messenger:generate": "yarn workspace @metamask/messenger-docs docs:generate",
"docs:messenger:serve": "yarn workspace @metamask/messenger-docs docs:serve",
"generate-method-action-types": "yarn workspaces foreach --all --parallel --interlaced --verbose run generate-method-action-types",
"lint": "yarn lint:eslint && echo && yarn lint:misc --check && yarn constraints && yarn lint:dependencies && yarn lint:teams && yarn generate-method-action-types --check",
"lint:dependencies": "depcheck && yarn dedupe --check",
Expand All @@ -45,7 +49,11 @@
},
"resolutions": {
"elliptic@6.5.4": "^6.5.7",
"eslint-import-resolver-typescript": "3.7.0",
"eslint-plugin-import-x": "4.6.1",
"eslint-plugin-n": "17.15.1",
"fast-xml-parser@^4.3.4": "^4.4.1",
"prettier@npm:^3.3.3": "3.4.2",
"ws@7.4.6": "^7.5.10"
},
"devDependencies": {
Expand Down Expand Up @@ -107,6 +115,8 @@
"@lavamoat/preinstall-always-fail": false,
"@keystonehq/bc-ur-registry-eth>hdkey>secp256k1": true,
"babel-runtime>core-js": false,
"eslint-import-resolver-typescript>unrs-resolver": false,
"eslint-plugin-import-x>unrs-resolver": false,
"simple-git-hooks": false,
"tsx>esbuild": false
}
Expand Down
14 changes: 14 additions & 0 deletions packages/messenger-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Initial release of the messenger-docs package

[Unreleased]: https://github.com/MetaMask/core/
21 changes: 21 additions & 0 deletions packages/messenger-docs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 MetaMask

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
82 changes: 82 additions & 0 deletions packages/messenger-docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# `@metamask/messenger-docs`

Generate and serve Messenger API documentation for MetaMask controller packages.

Scans TypeScript source files and declaration files for messenger action/event types, then generates a searchable Docusaurus site with per-namespace documentation.

## Installation

`yarn add @metamask/messenger-docs`

or

`npm install @metamask/messenger-docs`

## Usage

### Core monorepo

The package includes workspace scripts for development:

```bash
# Generate docs from all packages
yarn workspace @metamask/messenger-docs docs:generate

# Generate + start dev server with hot reload
yarn workspace @metamask/messenger-docs docs:dev

# Generate + build static site
yarn workspace @metamask/messenger-docs docs:build

# Generate + build + serve
yarn workspace @metamask/messenger-docs docs:serve
```

### Client projects (Extension, Mobile)

Add `@metamask/messenger-docs` as a dev dependency, then add a script to your `package.json`:

```json
{
"scripts": {
"docs:messenger": "messenger-docs --serve"
}
}
```

By default, the tool scans `src/` for `.ts` files and `node_modules/@metamask/` for `.d.cts` declaration files. If your project has source files in other directories, configure `scanDirs` in `package.json`:

```json
{
"messenger-docs": {
"scanDirs": ["app", "src"]
}
}
```

Or pass `--scan-dir` flags:

```bash
messenger-docs --scan-dir app --scan-dir shared --serve
```

### CLI options

```
messenger-docs [project-path] [options]

Arguments:
project-path Path to the project to scan (default: current directory)

Options:
--build Generate docs and build static site
--serve Generate docs, build, and serve static site
--dev Generate docs and start dev server with hot reload
--scan-dir <dir> Extra source directory to scan (repeatable)
--output <dir> Output directory (default: <project-path>/.messenger-docs)
--help Show this help message
```

## Contributing

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
29 changes: 29 additions & 0 deletions packages/messenger-docs/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

const merge = require('deepmerge');
const path = require('path');

const baseConfig = require('../../jest.config.packages');

const displayName = path.basename(__dirname);

module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

// Allow running without any test files
passWithNoTests: true,

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 0,
functions: 0,
lines: 0,
statements: 0,
},
},
});
84 changes: 84 additions & 0 deletions packages/messenger-docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"name": "@metamask/messenger-docs",
"version": "0.0.0",
"description": "Generate and serve Messenger API documentation for MetaMask controller packages",
"keywords": [
"MetaMask",
"Ethereum"
],
"homepage": "https://github.com/MetaMask/core/tree/main/packages/messenger-docs#readme",
"bugs": {
"url": "https://github.com/MetaMask/core/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/core.git"
},
"license": "MIT",
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./package.json": "./package.json"
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
"bin": "./dist/cli.mjs",
"files": [
"dist/",
"template/"
],
"scripts": {
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/messenger-docs",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/messenger-docs",
"docs:build": "tsx src/cli.ts ../.. --build",
"docs:dev": "tsx src/cli.ts ../.. --dev",
"docs:generate": "tsx src/cli.ts ../..",
"docs:serve": "tsx src/cli.ts ../.. --serve",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@docusaurus/core": "^3.9.0",
"@docusaurus/preset-classic": "^3.9.0",
"@docusaurus/theme-common": "^3.9.0",
"@easyops-cn/docusaurus-search-local": "^0.55.0",
"@mdx-js/react": "^3.0.0",
"prism-react-renderer": "^2.4.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "~5.3.3"
},
"devDependencies": {
"@docusaurus/types": "^3.9.0",
"@metamask/auto-changelog": "^3.4.4",
"@ts-bridge/cli": "^0.6.4",
"@types/node": "^16.18.54",
"@types/react": "^18.3.0",
"deepmerge": "^4.2.2",
"jest": "^29.7.0",
"ts-jest": "^29.2.5"
},
"engines": {
"node": "^18.18 || >=20"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
Loading