Skip to content

feat: use @metamask/messenger/generate-action-types CLI#575

Draft
cryptodev-2s wants to merge 5 commits intomainfrom
feat/use-messenger-generate-action-types
Draft

feat: use @metamask/messenger/generate-action-types CLI#575
cryptodev-2s wants to merge 5 commits intomainfrom
feat/use-messenger-generate-action-types

Conversation

@cryptodev-2s
Copy link
Copy Markdown
Contributor

Explanation

Replace the local copy-pasted scripts/generate-method-action-types.ts (759 lines) with the CLI from @metamask/messenger/generate-action-types.

Currently uses a preview build (@metamask-previews/messenger@0.3.0-preview-f11c28cc2) via npm alias. Once MetaMask/core#8264 is merged and released, the dependency should be updated to the released version.

References

Replace local copy-pasted script with the CLI from
@metamask/messenger. Uses preview build until release.
@cryptodev-2s cryptodev-2s force-pushed the feat/use-messenger-generate-action-types branch from 3166d8d to 9626783 Compare March 23, 2026 19:55
Use resolutions to override @metamask/messenger and @metamask/base-controller
with preview builds. This ensures consistent types across all transitive
dependencies and fixes the build.
@socket-security
Copy link
Copy Markdown

socket-security bot commented Mar 23, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​metamask/​base-controller@​9.0.0-preview-a462582100100100100100
Added@​metamask/​messenger@​0.3.0-preview-a462582100100100100100

View full report

@cryptodev-2s cryptodev-2s force-pushed the feat/use-messenger-generate-action-types branch from 5555741 to 7e4a4c9 Compare March 23, 2026 22:14
github-merge-queue bot pushed a commit to MetaMask/core that referenced this pull request Apr 1, 2026
…rt (#8264)

## Explanation

The script `scripts/generate-method-action-types.ts` generates
TypeScript action type files for controllers/services that define
`MESSENGER_EXPOSED_METHODS`. It was a monorepo-local script invoked via
`tsx ../../scripts/generate-method-action-types.ts` from 44 packages.

This PR moves it into `@metamask/messenger` as a CLI tool, keeping the
library lightweight while making the codegen reusable in other
repositories.

**What changed:**

- Add `generate-action-types/` subdirectory under
`packages/messenger/src/` with modular source files (`parse-source.ts`,
`generate-content.ts`, `check.ts`, `fix.ts`, `cli.ts`)
- Add `messenger-generate-action-types` bin entry to
`@metamask/messenger`
- `yargs` is the only runtime dependency; `@metamask/utils`,
`typescript`, and `eslint` are non-optional peer dependencies (required
for the CLI, but provided by the consuming project). The core
`Messenger` library remains lightweight.
- Recursive directory search discovers controllers/services in
subdirectories automatically, removing the need for per-subdirectory
scripts
- Update all 44 consuming packages to invoke the CLI via `tsx
../../packages/messenger/src/generate-action-types/cli.ts`
- Delete old `scripts/generate-method-action-types.ts`
- Functional tests via `execa` + `tsx` verify exact generated output for
controllers and services

**Working examples in external repos:**

- MetaMask/smart-transactions-controller#575
- MetaMask/snaps#3914

## References

- Consumer PRs:
[smart-transactions-controller#575](MetaMask/smart-transactions-controller#575),
[snaps#3914](MetaMask/snaps#3914)

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Mostly build/tooling changes, but it touches many packages and changes
the action-type generation pipeline; failures would surface as broken
scripts or mismatched generated files across the monorepo.
> 
> **Overview**
> Adds a new `@metamask/messenger` codegen CLI
(`messenger-generate-action-types`) that discovers controllers/services
with `MESSENGER_EXPOSED_METHODS` and supports `--fix` and `--check`
workflows, including optional ESLint formatting and extensive
unit/functional tests.
> 
> Migrates dozens of packages’ `generate-method-action-types` scripts to
call the new CLI entrypoint, deletes the legacy
`scripts/generate-method-action-types.ts`, and updates generated
`*-method-action-types.ts` outputs (header/JSDoc normalization and some
regenerated action unions). Also updates repo config to support the new
tooling (ESLint rule exception for the generator folder and Jest module
mapping for `@metamask/utils/node`).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ca19d18. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant