feat(messenger): add generate-action-types CLI tool as subpath export#8264
feat(messenger): add generate-action-types CLI tool as subpath export#8264cryptodev-2s wants to merge 43 commits intomainfrom
generate-action-types CLI tool as subpath export#8264Conversation
@metamask/messenger-generate-action-types packagegenerate-action-types CLI tool as subpath export
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
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`
89da66f to
0202e79
Compare
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)
mcmire
left a comment
There was a problem hiding this comment.
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.', |
There was a problem hiding this comment.
Does this command need to be updated?
There was a problem hiding this comment.
That`s the root package.json script, do you prefer to rename it ?
There was a problem hiding this comment.
I'm just thinking that if people are running the CLI in a different project (not within core) then yarn generate-method-action-types won't work. They'd have to run yarn messenger-generate-action-types instead.
Maybe we can capture the name of the script in cli.ts and pass it down so we can use it here? The name of the script is usually present as the first or second item in the process.argv array.
…te-action-types-package
…te-action-types-package
…te-action-types-package
Move `@metamask/utils` from peerDependencies to dependencies in the messenger package since it is a required runtime dependency. Also replace `globalThis.process.exitCode` with `process.exitCode` to fix an ESLint violation.
Apply the same ESLint fix as in fix.ts — use `process.exitCode` directly instead of `globalThis.process.exitCode`.
Already listed under dependencies, so the devDependencies entry is redundant.
…perps action types Update base-data-service and phishing-controller to point their generate-method-action-types script at the new messenger CLI. Regenerate PerpsController action types to reflect current API.
…ion-types tests Replace manual mkdtemp/rm temp directory management with the createSandbox utility from @metamask/utils/node across all 4 test files. Add @metamask/utils/node subpath mapping to the shared jest.config.packages.js so all packages can resolve it.
Return boolean from checkActionTypesFiles and generateAllActionTypesFiles instead of setting process.exitCode directly. Only cli.ts now sets the exit code, keeping the global side effect in a single location.
Replace the wrapped outputFixes/getErrorResults functions with an eslintClass reference so callers use the static methods directly, making it clear these are class-level operations.
… load failure Add directory exclusions (node_modules, dist, .git, coverage) to the recursive file walker to avoid traversing irrelevant trees. Also log a warning when ESLint fails to load instead of silently skipping formatting.
…te-action-types-package
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| 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.', | ||
| ); |
There was a problem hiding this comment.
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |


Explanation
The script
scripts/generate-method-action-types.tsgenerates TypeScript action type files for controllers/services that defineMESSENGER_EXPOSED_METHODS. It was a monorepo-local script invoked viatsx ../../scripts/generate-method-action-types.tsfrom 44 packages.This PR moves it into
@metamask/messengeras a CLI tool, keeping the library lightweight while making the codegen reusable in other repositories.What changed:
generate-action-types/subdirectory underpackages/messenger/src/with modular source files (parse-source.ts,generate-content.ts,check.ts,fix.ts,cli.ts)messenger-generate-action-typesbin entry to@metamask/messengeryargsis the only runtime dependency;@metamask/utils,typescript, andeslintare non-optional peer dependencies (required for the CLI, but provided by the consuming project). The coreMessengerlibrary remains lightweight.tsx ../../packages/messenger/src/generate-action-types/cli.tsscripts/generate-method-action-types.tsexeca+tsxverify exact generated output for controllers and servicesWorking examples in external repos:
References
Checklist
Note
Medium Risk
Mostly build/tooling changes, but they touch many packages’ codegen scripts and regenerate action-type output, so CI/build consistency could break if the new CLI behavior diverges from the old script.
Overview
Introduces a new
packages/messenger/src/generate-action-typesCLI (published asmessenger-generate-action-types) that discoversMESSENGER_EXPOSED_METHODS, generates*-method-action-types.ts, and supports--fix/--checkwith optional ESLint formatting.Migrates all packages’
generate-method-action-typesscripts from the deleted rootscripts/generate-method-action-types.tsto the new messenger CLI, and adjusts repo config to support it (ESLint override for the new directory, Jest mapper for@metamask/utils/node, messenger deps/peers, and coverage ignore forcli.ts).Regenerates/updates a few generated action-type files (e.g.,
PerpsControlleradds the auto-generated header, backticktypeliterals, and additional exposed actions; minor doc tweaks in other generated files).Written by Cursor Bugbot for commit 16512b7. This will update automatically on new commits. Configure here.