Skip to content

feat(messenger): add generate-action-types CLI tool as subpath export#8264

Open
cryptodev-2s wants to merge 29 commits intomainfrom
feat/messenger-generate-action-types-package
Open

feat(messenger): add generate-action-types CLI tool as subpath export#8264
cryptodev-2s wants to merge 29 commits intomainfrom
feat/messenger-generate-action-types-package

Conversation

@cryptodev-2s
Copy link
Copy Markdown
Contributor

@cryptodev-2s cryptodev-2s commented Mar 20, 2026

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:

References

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
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Moderate risk because it changes the codegen entrypoint across many packages and introduces optional ESLint-driven formatting, which could affect generated file output and CI checks if environments differ.

Overview
Adds a new @metamask/messenger codegen CLI (messenger-generate-action-types) that discovers controllers/services with MESSENGER_EXPOSED_METHODS, generates *-method-action-types.ts files, and supports --fix/--check with optional ESLint formatting.

Migrates the repo to the new tool by deleting scripts/generate-method-action-types.ts, updating ~44 packages’ generate-method-action-types scripts to invoke the new packages/messenger/src/generate-action-types/cli.ts, and adjusting ESLint config to allow Node built-ins in the new generator sources. A few generated action-type files change slightly (header/template string usage and JSDoc wording) to match the new generator output.

Written by Cursor Bugbot for commit f24ab34. This will update automatically on new commits. Configure here.

@cryptodev-2s cryptodev-2s changed the title feat: create @metamask/messenger-generate-action-types package feat(messenger): add generate-action-types CLI tool as subpath export Mar 20, 2026
@cryptodev-2s
Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@5.0.1-preview-f11c28cc2
@metamask-previews/accounts-controller@37.0.0-preview-f11c28cc2
@metamask-previews/address-book-controller@7.1.0-preview-f11c28cc2
@metamask-previews/ai-controllers@0.4.0-preview-f11c28cc2
@metamask-previews/analytics-controller@1.0.0-preview-f11c28cc2
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-f11c28cc2
@metamask-previews/announcement-controller@8.0.0-preview-f11c28cc2
@metamask-previews/app-metadata-controller@2.0.0-preview-f11c28cc2
@metamask-previews/approval-controller@9.0.0-preview-f11c28cc2
@metamask-previews/assets-controller@3.0.0-preview-f11c28cc2
@metamask-previews/assets-controllers@101.0.1-preview-f11c28cc2
@metamask-previews/base-controller@9.0.0-preview-f11c28cc2
@metamask-previews/base-data-service@0.0.0-preview-f11c28cc2
@metamask-previews/bridge-controller@69.1.1-preview-f11c28cc2
@metamask-previews/bridge-status-controller@70.0.0-preview-f11c28cc2
@metamask-previews/build-utils@3.0.4-preview-f11c28cc2
@metamask-previews/chain-agnostic-permission@1.4.0-preview-f11c28cc2
@metamask-previews/claims-controller@0.4.3-preview-f11c28cc2
@metamask-previews/client-controller@1.0.0-preview-f11c28cc2
@metamask-previews/compliance-controller@1.0.1-preview-f11c28cc2
@metamask-previews/composable-controller@12.0.0-preview-f11c28cc2
@metamask-previews/config-registry-controller@0.1.1-preview-f11c28cc2
@metamask-previews/connectivity-controller@0.1.0-preview-f11c28cc2
@metamask-previews/controller-utils@11.19.0-preview-f11c28cc2
@metamask-previews/core-backend@6.2.0-preview-f11c28cc2
@metamask-previews/delegation-controller@2.0.2-preview-f11c28cc2
@metamask-previews/earn-controller@11.1.2-preview-f11c28cc2
@metamask-previews/eip-5792-middleware@3.0.1-preview-f11c28cc2
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.0-preview-f11c28cc2
@metamask-previews/eip1193-permission-middleware@1.0.3-preview-f11c28cc2
@metamask-previews/ens-controller@19.1.0-preview-f11c28cc2
@metamask-previews/error-reporting-service@3.0.1-preview-f11c28cc2
@metamask-previews/eth-block-tracker@15.0.1-preview-f11c28cc2
@metamask-previews/eth-json-rpc-middleware@23.1.0-preview-f11c28cc2
@metamask-previews/eth-json-rpc-provider@6.0.0-preview-f11c28cc2
@metamask-previews/foundryup@1.0.1-preview-f11c28cc2
@metamask-previews/gas-fee-controller@26.1.0-preview-f11c28cc2
@metamask-previews/gator-permissions-controller@2.1.1-preview-f11c28cc2
@metamask-previews/geolocation-controller@0.1.1-preview-f11c28cc2
@metamask-previews/json-rpc-engine@10.2.3-preview-f11c28cc2
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-f11c28cc2
@metamask-previews/keyring-controller@25.1.0-preview-f11c28cc2
@metamask-previews/logging-controller@8.0.0-preview-f11c28cc2
@metamask-previews/message-manager@14.1.0-preview-f11c28cc2
@metamask-previews/messenger@0.3.0-preview-f11c28cc2
@metamask-previews/multichain-account-service@7.1.0-preview-f11c28cc2
@metamask-previews/multichain-api-middleware@1.2.7-preview-f11c28cc2
@metamask-previews/multichain-network-controller@3.0.5-preview-f11c28cc2
@metamask-previews/multichain-transactions-controller@7.0.2-preview-f11c28cc2
@metamask-previews/name-controller@9.1.0-preview-f11c28cc2
@metamask-previews/network-controller@30.0.0-preview-f11c28cc2
@metamask-previews/network-enablement-controller@5.0.0-preview-f11c28cc2
@metamask-previews/notification-services-controller@23.0.0-preview-f11c28cc2
@metamask-previews/permission-controller@12.2.1-preview-f11c28cc2
@metamask-previews/permission-log-controller@5.0.0-preview-f11c28cc2
@metamask-previews/perps-controller@1.3.0-preview-f11c28cc2
@metamask-previews/phishing-controller@17.0.0-preview-f11c28cc2
@metamask-previews/polling-controller@16.0.3-preview-f11c28cc2
@metamask-previews/preferences-controller@23.0.0-preview-f11c28cc2
@metamask-previews/profile-metrics-controller@3.1.1-preview-f11c28cc2
@metamask-previews/profile-sync-controller@28.0.0-preview-f11c28cc2
@metamask-previews/ramps-controller@12.0.0-preview-f11c28cc2
@metamask-previews/rate-limit-controller@7.0.0-preview-f11c28cc2
@metamask-previews/react-data-query@0.0.0-preview-f11c28cc2
@metamask-previews/remote-feature-flag-controller@4.1.0-preview-f11c28cc2
@metamask-previews/sample-controllers@4.0.3-preview-f11c28cc2
@metamask-previews/seedless-onboarding-controller@9.0.0-preview-f11c28cc2
@metamask-previews/selected-network-controller@26.0.3-preview-f11c28cc2
@metamask-previews/shield-controller@5.0.2-preview-f11c28cc2
@metamask-previews/signature-controller@39.1.0-preview-f11c28cc2
@metamask-previews/storage-service@1.0.0-preview-f11c28cc2
@metamask-previews/subscription-controller@6.0.2-preview-f11c28cc2
@metamask-previews/transaction-controller@63.0.0-preview-f11c28cc2
@metamask-previews/transaction-pay-controller@18.0.0-preview-f11c28cc2
@metamask-previews/user-operation-controller@41.1.0-preview-f11c28cc2

Extract `scripts/generate-method-action-types.ts` into a publishable
CLI package so it can be reused across repositories.

- Scaffold `@metamask/messenger-generate-action-types` with bin entry
- Split script into modular source files (parse, generate, check, fix)
- Use named TypeScript imports, optional ESLint peer dependency
- Update 44 consuming packages to use the new binary
- Update package template, CODEOWNERS, teams.json, eslint config
- Add ESLint config exception for Node.js module imports
- Regenerate all action type files with updated header
- Delete old `scripts/generate-method-action-types.ts`
The binary requires a build step before it can be used. Using tsx
to run the source TypeScript directly avoids this dependency.
Move the CLI tool into @metamask/messenger as a subpath export
instead of a separate package. This keeps the library lightweight
while making the codegen available via optional peer dependencies.

- Move source files to packages/messenger/src/generate-action-types/
- Add ./generate-action-types subpath export and bin entry
- typescript, yargs, eslint are optional peerDependencies
- @metamask/utils added as dependency (needed by codegen)
- Remove standalone @metamask/messenger-generate-action-types package
- Update 44 consuming packages to point to new location
- Revert CODEOWNERS, teams.json, tsconfig, README changes
- Remove unused `MethodInfo.signature` field
- Remove redundant `ControllerInfo.exposedMethods` (derivable from methods)
- Extract shared ESLint types to `types.ts`, deduplicate across check/fix
- Combine eslint/eslintStatic params into single `ESLint | null` object
- Inline single-use `capitalize()` helper
- Remove unused `Identifier` type import and `extractMethodSignature`
@cryptodev-2s cryptodev-2s force-pushed the feat/messenger-generate-action-types-package branch from 89da66f to 0202e79 Compare March 23, 2026 18:35
@cryptodev-2s cryptodev-2s self-assigned this Mar 23, 2026
@cryptodev-2s cryptodev-2s marked this pull request as ready for review March 23, 2026 18:50
@cryptodev-2s cryptodev-2s requested review from a team as code owners March 23, 2026 18:50
@cryptodev-2s
Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@5.0.1-preview-74da211
@metamask-previews/accounts-controller@37.0.0-preview-74da211
@metamask-previews/address-book-controller@7.1.0-preview-74da211
@metamask-previews/ai-controllers@0.5.0-preview-74da211
@metamask-previews/analytics-controller@1.0.0-preview-74da211
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-74da211
@metamask-previews/announcement-controller@8.0.0-preview-74da211
@metamask-previews/app-metadata-controller@2.0.0-preview-74da211
@metamask-previews/approval-controller@9.0.0-preview-74da211
@metamask-previews/assets-controller@3.0.0-preview-74da211
@metamask-previews/assets-controllers@101.0.1-preview-74da211
@metamask-previews/base-controller@9.0.0-preview-74da211
@metamask-previews/base-data-service@0.0.0-preview-74da211
@metamask-previews/bridge-controller@69.2.0-preview-74da211
@metamask-previews/bridge-status-controller@70.0.0-preview-74da211
@metamask-previews/build-utils@3.0.4-preview-74da211
@metamask-previews/chain-agnostic-permission@1.4.0-preview-74da211
@metamask-previews/claims-controller@0.4.3-preview-74da211
@metamask-previews/client-controller@1.0.0-preview-74da211
@metamask-previews/compliance-controller@1.0.1-preview-74da211
@metamask-previews/composable-controller@12.0.0-preview-74da211
@metamask-previews/config-registry-controller@0.1.1-preview-74da211
@metamask-previews/connectivity-controller@0.1.0-preview-74da211
@metamask-previews/controller-utils@11.19.0-preview-74da211
@metamask-previews/core-backend@6.2.0-preview-74da211
@metamask-previews/delegation-controller@2.0.2-preview-74da211
@metamask-previews/earn-controller@11.1.2-preview-74da211
@metamask-previews/eip-5792-middleware@3.0.1-preview-74da211
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.0-preview-74da211
@metamask-previews/eip1193-permission-middleware@1.0.3-preview-74da211
@metamask-previews/ens-controller@19.1.0-preview-74da211
@metamask-previews/error-reporting-service@3.0.1-preview-74da211
@metamask-previews/eth-block-tracker@15.0.1-preview-74da211
@metamask-previews/eth-json-rpc-middleware@23.1.0-preview-74da211
@metamask-previews/eth-json-rpc-provider@6.0.0-preview-74da211
@metamask-previews/foundryup@1.0.1-preview-74da211
@metamask-previews/gas-fee-controller@26.1.0-preview-74da211
@metamask-previews/gator-permissions-controller@2.1.1-preview-74da211
@metamask-previews/geolocation-controller@0.1.1-preview-74da211
@metamask-previews/json-rpc-engine@10.2.3-preview-74da211
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-74da211
@metamask-previews/keyring-controller@25.1.0-preview-74da211
@metamask-previews/logging-controller@8.0.0-preview-74da211
@metamask-previews/message-manager@14.1.0-preview-74da211
@metamask-previews/messenger@0.3.0-preview-74da211
@metamask-previews/multichain-account-service@7.1.0-preview-74da211
@metamask-previews/multichain-api-middleware@1.2.7-preview-74da211
@metamask-previews/multichain-network-controller@3.0.5-preview-74da211
@metamask-previews/multichain-transactions-controller@7.0.2-preview-74da211
@metamask-previews/name-controller@9.1.0-preview-74da211
@metamask-previews/network-controller@30.0.0-preview-74da211
@metamask-previews/network-enablement-controller@5.0.0-preview-74da211
@metamask-previews/notification-services-controller@23.0.0-preview-74da211
@metamask-previews/permission-controller@12.2.1-preview-74da211
@metamask-previews/permission-log-controller@5.0.0-preview-74da211
@metamask-previews/perps-controller@1.3.0-preview-74da211
@metamask-previews/phishing-controller@17.0.0-preview-74da211
@metamask-previews/polling-controller@16.0.3-preview-74da211
@metamask-previews/preferences-controller@23.0.0-preview-74da211
@metamask-previews/profile-metrics-controller@3.1.1-preview-74da211
@metamask-previews/profile-sync-controller@28.0.0-preview-74da211
@metamask-previews/ramps-controller@12.0.1-preview-74da211
@metamask-previews/rate-limit-controller@7.0.0-preview-74da211
@metamask-previews/react-data-query@0.0.0-preview-74da211
@metamask-previews/remote-feature-flag-controller@4.1.0-preview-74da211
@metamask-previews/sample-controllers@4.0.3-preview-74da211
@metamask-previews/seedless-onboarding-controller@9.0.0-preview-74da211
@metamask-previews/selected-network-controller@26.0.3-preview-74da211
@metamask-previews/shield-controller@5.0.2-preview-74da211
@metamask-previews/signature-controller@39.1.0-preview-74da211
@metamask-previews/storage-service@1.0.0-preview-74da211
@metamask-previews/subscription-controller@6.0.2-preview-74da211
@metamask-previews/transaction-controller@63.1.0-preview-74da211
@metamask-previews/transaction-pay-controller@18.0.0-preview-74da211
@metamask-previews/user-operation-controller@41.1.0-preview-74da211

Recursively search subdirectories for source files, matching the
snaps repo implementation. This allows packages with controllers
or services in nested directories to be discovered automatically.
@cryptodev-2s cryptodev-2s requested a review from Mrtenz March 23, 2026 21:52
@cryptodev-2s
Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@5.0.1-preview-a462582
@metamask-previews/accounts-controller@37.0.0-preview-a462582
@metamask-previews/address-book-controller@7.1.0-preview-a462582
@metamask-previews/ai-controllers@0.5.0-preview-a462582
@metamask-previews/analytics-controller@1.0.0-preview-a462582
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-a462582
@metamask-previews/announcement-controller@8.0.0-preview-a462582
@metamask-previews/app-metadata-controller@2.0.0-preview-a462582
@metamask-previews/approval-controller@9.0.0-preview-a462582
@metamask-previews/assets-controller@3.0.0-preview-a462582
@metamask-previews/assets-controllers@101.0.1-preview-a462582
@metamask-previews/base-controller@9.0.0-preview-a462582
@metamask-previews/base-data-service@0.0.0-preview-a462582
@metamask-previews/bridge-controller@69.2.0-preview-a462582
@metamask-previews/bridge-status-controller@70.0.0-preview-a462582
@metamask-previews/build-utils@3.0.4-preview-a462582
@metamask-previews/chain-agnostic-permission@1.4.0-preview-a462582
@metamask-previews/claims-controller@0.4.3-preview-a462582
@metamask-previews/client-controller@1.0.0-preview-a462582
@metamask-previews/compliance-controller@1.0.1-preview-a462582
@metamask-previews/composable-controller@12.0.0-preview-a462582
@metamask-previews/config-registry-controller@0.1.1-preview-a462582
@metamask-previews/connectivity-controller@0.1.0-preview-a462582
@metamask-previews/controller-utils@11.19.0-preview-a462582
@metamask-previews/core-backend@6.2.0-preview-a462582
@metamask-previews/delegation-controller@2.0.2-preview-a462582
@metamask-previews/earn-controller@11.1.2-preview-a462582
@metamask-previews/eip-5792-middleware@3.0.1-preview-a462582
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.0-preview-a462582
@metamask-previews/eip1193-permission-middleware@1.0.3-preview-a462582
@metamask-previews/ens-controller@19.1.0-preview-a462582
@metamask-previews/error-reporting-service@3.0.1-preview-a462582
@metamask-previews/eth-block-tracker@15.0.1-preview-a462582
@metamask-previews/eth-json-rpc-middleware@23.1.0-preview-a462582
@metamask-previews/eth-json-rpc-provider@6.0.0-preview-a462582
@metamask-previews/foundryup@1.0.1-preview-a462582
@metamask-previews/gas-fee-controller@26.1.0-preview-a462582
@metamask-previews/gator-permissions-controller@2.1.1-preview-a462582
@metamask-previews/geolocation-controller@0.1.1-preview-a462582
@metamask-previews/json-rpc-engine@10.2.3-preview-a462582
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-a462582
@metamask-previews/keyring-controller@25.1.0-preview-a462582
@metamask-previews/logging-controller@8.0.0-preview-a462582
@metamask-previews/message-manager@14.1.0-preview-a462582
@metamask-previews/messenger@0.3.0-preview-a462582
@metamask-previews/multichain-account-service@7.1.0-preview-a462582
@metamask-previews/multichain-api-middleware@1.2.7-preview-a462582
@metamask-previews/multichain-network-controller@3.0.5-preview-a462582
@metamask-previews/multichain-transactions-controller@7.0.2-preview-a462582
@metamask-previews/name-controller@9.1.0-preview-a462582
@metamask-previews/network-controller@30.0.0-preview-a462582
@metamask-previews/network-enablement-controller@5.0.0-preview-a462582
@metamask-previews/notification-services-controller@23.0.0-preview-a462582
@metamask-previews/permission-controller@12.2.1-preview-a462582
@metamask-previews/permission-log-controller@5.0.0-preview-a462582
@metamask-previews/perps-controller@1.3.0-preview-a462582
@metamask-previews/phishing-controller@17.0.0-preview-a462582
@metamask-previews/polling-controller@16.0.3-preview-a462582
@metamask-previews/preferences-controller@23.0.0-preview-a462582
@metamask-previews/profile-metrics-controller@3.1.1-preview-a462582
@metamask-previews/profile-sync-controller@28.0.0-preview-a462582
@metamask-previews/ramps-controller@12.0.1-preview-a462582
@metamask-previews/rate-limit-controller@7.0.0-preview-a462582
@metamask-previews/react-data-query@0.0.0-preview-a462582
@metamask-previews/remote-feature-flag-controller@4.1.0-preview-a462582
@metamask-previews/sample-controllers@4.0.3-preview-a462582
@metamask-previews/seedless-onboarding-controller@9.0.0-preview-a462582
@metamask-previews/selected-network-controller@26.0.3-preview-a462582
@metamask-previews/shield-controller@5.0.2-preview-a462582
@metamask-previews/signature-controller@39.1.0-preview-a462582
@metamask-previews/storage-service@1.0.0-preview-a462582
@metamask-previews/subscription-controller@6.0.2-preview-a462582
@metamask-previews/transaction-controller@63.1.0-preview-a462582
@metamask-previews/transaction-pay-controller@18.0.0-preview-a462582
@metamask-previews/user-operation-controller@41.1.0-preview-a462582

"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3"
"typescript": "~5.3.3",
"yargs": "^17.7.2"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be in dependencies, since they're being referred to in code that we are publishing?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yargs probably, but TypeScript should probably be a peer dependency?

Copy link
Copy Markdown
Contributor

@mcmire mcmire Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you say it, yes, that would probably make more sense. I guess we want a peer dependency on ESLint for the same reason. They're tools that the project should already have, and we don't want to use a different version of them.

So 1) typescript and eslint should be in peer dependencies, but they should not be optional peer dependencies (we need them or else this script won't work) and 2) only yargs/@types/yargs needs to be in dependencies.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done here ff21843

Recursive search makes per-subdirectory scripts unnecessary in
assets-controllers, notification-services-controller, and
profile-sync-controller.
github-merge-queue bot pushed a commit that referenced this pull request Mar 24, 2026
## Explanation

The auto-generated method action type files previously referenced the
generator script path in their header comment (`This file is auto
generated by scripts/generate-method-action-types.ts`). This simplifies
it to just `This file is auto generated.`.

For context why we are making this change
#8264 (comment)

## References

N/A

## 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
- [ ] 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]
> **Low Risk**
> Only changes a comment string in generated `*-method-action-types.ts`
files and the generator script; no runtime logic or types are modified
beyond file header text.
> 
> **Overview**
> **Simplifies the header comment** across all auto-generated
`*-method-action-types.ts` files by removing the explicit generator
script path reference and leaving `This file is auto generated.` plus
`Do not edit manually.`
> 
> Updates `scripts/generate-method-action-types.ts` so future
generations produce the new header format.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
472e809. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
No consumers import programmatically. The tool is CLI-only.
micaelae pushed a commit that referenced this pull request Mar 24, 2026
## Explanation

The auto-generated method action type files previously referenced the
generator script path in their header comment (`This file is auto
generated by scripts/generate-method-action-types.ts`). This simplifies
it to just `This file is auto generated.`.

For context why we are making this change
#8264 (comment)

## References

N/A

## 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
- [ ] 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]
> **Low Risk**
> Only changes a comment string in generated `*-method-action-types.ts`
files and the generator script; no runtime logic or types are modified
beyond file header text.
> 
> **Overview**
> **Simplifies the header comment** across all auto-generated
`*-method-action-types.ts` files by removing the explicit generator
script path reference and leaving `This file is auto generated.` plus
`Do not edit manually.`
> 
> Updates `scripts/generate-method-action-types.ts` so future
generations produce the new header format.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
472e809. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
- Refactor cli.ts: export main(args), parseCommandLineArguments(args),
  loadESLint() for testability; simplify auto-invocation guard
- Add functional tests verifying exact generated output for controllers
  and services (file names and full type content)
- Test variations: multiple methods with/without JSDoc, @param/@returns,
  controller+service in same dir, nested subdirectories, empty directory
- Cover --check mode: up-to-date, out-of-date, and missing files
- Remove coveragePathIgnorePatterns for cli.ts — now fully covered
- 127 total tests, 100% coverage
Spawn the CLI as a subprocess via tsx + execa (same pattern as
create-release-branch). Tests verify exact generated output given
source files for controllers and services.

- File name conventions: {ClassName}-method-action-types.ts
- Full type content: action types, handler references, union types
- Variations: multiple methods with/without JSDoc, @param/@returns,
  single-method service, controller+service in same dir, nested
  subdirectories, empty dir
- --check mode: up-to-date, out-of-date, missing files
- Argument validation: exits 1 without --check or --fix
Per review feedback:
- yargs: moved to dependencies (runtime dep of the CLI)
- typescript, eslint, @metamask/utils: non-optional peerDependencies
  (required for the CLI to work, but provided by the consuming project)
- Removed peerDependenciesMeta (no optional peers remaining)
@cryptodev-2s cryptodev-2s requested a review from mcmire March 25, 2026 13:44
} catch {
return null;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required peer dependency failure silently swallowed

Medium Severity

loadESLint silently returns null when ESLint fails to load, even though eslint is a required (non-optional) peer dependency. The old script instantiated ESLint directly and would crash immediately on failure. Now, if ESLint has a broken installation or version mismatch, the CLI silently skips all formatting with no warning — producing unformatted output files in --fix mode and potentially false pass/fail results in --check mode.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! Left some more comments, mostly minor.

if (hasErrors) {
console.error('\n💥 Some action type files are out of date or missing.');
console.error(
'Run `yarn generate-method-action-types --fix` to update them.',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this command need to be updated?

let tmpDir: string;

beforeEach(async () => {
tmpDir = await fs.promises.mkdtemp(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: @metamask/utils provides a createSandbox function if it's useful. Each test needs to be wrapped though: https://github.com/MetaMask/utils/blob/main/src/fs.ts#L243

- Add `generate-action-types` CLI tool ([#8264](https://github.com/MetaMask/core/pull/8264))
- Generates TypeScript action type files for controllers and services that define `MESSENGER_EXPOSED_METHODS`.
- Available as a CLI binary (`messenger-generate-action-types`).
- `@metamask/utils`, `typescript`, `yargs`, and `eslint` are optional peer dependencies, only required when using the codegen tool.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be updated to read:

Suggested change
- `@metamask/utils`, `typescript`, `yargs`, and `eslint` are optional peer dependencies, only required when using the codegen tool.
- `typescript` and `eslint` are peer dependencies.

"typescript": "~5.3.3"
},
"peerDependencies": {
"@metamask/utils": "^11.9.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a regular dependency as well? I think we can allow this to be whatever version works for this use case, we don't need to require that the consuming project uses this exact version.

const errors = eslint.getErrorResults(results);
if (errors.length > 0) {
console.error('❌ ESLint errors:', errors);
globalThis.process.exitCode = 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use globalThis. here? process is already a global in Node.

Suggested change
globalThis.process.exitCode = 1;
process.exitCode = 1;

Copy link
Copy Markdown
Contributor

@mcmire mcmire Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Having seen the @metamask/messenger-docs package I am now curious whether there is some package can we use that would allow us to simplify this file (particularly extracting the JSDoc). It's out of scope for this PR but we might want to think about this.

const originalExitCode = globalThis.process.exitCode;

beforeEach(async () => {
tmpDir = await fs.promises.mkdtemp(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as cli.test.ts — we might consider using createSandbox from @metamask/utils.


afterEach(async () => {
await fs.promises.rm(tmpDir, { recursive: true, force: true });
globalThis.process.exitCode = originalExitCode;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Instead of allowing this file to set the exit code, you might consider only allowing cli.ts to do this. That way you don't need to save and restore the exit code here. (The exit code is global to the entire process so it seems worth it to limit its scope.)

@@ -0,0 +1,115 @@
import * as fs from 'node:fs';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Is it necessary to use node: qualifiers when importing built-in modules? We don't really do this elsewhere so it would be inconsistent with our existing code style.

});
return {
instance,
outputFixes: ESLintClass.outputFixes.bind(ESLintClass),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of wrapping these methods? I'm curious if it would be better to simply return the ESLint instance from this function, and then where we want to call outputFixes we use ESLint.outputFixes. As it is, by bundling outputFixes and getErrorResults with the ESLint instance it makes it seem like these are class (instance) methods, when in fact they are static methods.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

There are 3 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

"@metamask/utils": "^11.9.0",
"eslint": ">=8",
"typescript": "~5.3.3"
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peer dependencies not marked optional despite documentation claiming so

Medium Severity

The peerDependencies for @metamask/utils, eslint, and typescript are declared as required, but the CHANGELOG states they are "optional peer dependencies, only required when using the codegen tool." Without a peerDependenciesMeta section marking each as optional: true, npm/yarn will emit missing-peer-dependency warnings for every consumer of @metamask/messenger — even those that only use the core Messenger class and never invoke the CLI.

Additional Locations (1)
Fix in Cursor Fix in Web

},
"dependencies": {
"yargs": "^17.7.2"
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime yargs dependency shipped to all library consumers

Medium Severity

yargs is listed as a production dependency of @metamask/messenger, meaning every consumer of the package — including those only importing the core Messenger class — will install yargs and its transitive dependencies. This contradicts the PR goal that "the core Messenger library remains lightweight," since yargs is only needed by the CLI codegen tool.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants