feat: extract generate-action-types CLI into @metamask/messenger-cli#8377
feat: extract generate-action-types CLI into @metamask/messenger-cli#8377cryptodev-2s wants to merge 44 commits intomainfrom
Conversation
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`
The module parses both controllers and services, not just controllers.
@metamask/utils is only used by the generate-action-types subpath, not the core Messenger library. Keep it consistent with the other codegen-only dependencies (typescript, yargs, eslint).
…action-types Rename types, functions, params, and variables to be neutral: ControllerInfo → SourceInfo, parseControllerFile → parseSourceFile, findControllersWithExposedMethods → findSourcesWithExposedMethods. The tool works for both controllers and services.
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.
Recursive search makes per-subdirectory scripts unnecessary in assets-controllers, notification-services-controller, and profile-sync-controller.
…te-action-types-package
No consumers import programmatically. The tool is CLI-only.
- 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)
…te-action-types-package
…te-action-types-package
…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
- New @metamask/messenger-cli package with all CLI source and tests - All deps (eslint, typescript, yargs) as regular dependencies - Deprecation warning added to @metamask/messenger CLI - Removed per-package generate-method-action-types scripts - Root scripts renamed to messenger-generate-action-types using exec
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| 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.
Deprecated check.ts references removed command name
Medium Severity
The error message in the deprecated @metamask/messenger version of check.ts tells users to run yarn generate-method-action-types --fix, but this script has been removed from both the root package.json and all per-package package.json files. Users encountering this error would be given a non-functional remediation command. The messenger-cli copy correctly says messenger-generate-action-types --fix.
| } | ||
|
|
||
| return sources; | ||
| } |
There was a problem hiding this comment.
Full CLI source duplicated across two packages
Medium Severity
The entire CLI implementation (~700 lines across parse-source.ts, check.ts, fix.ts, generate-content.ts, types.ts, plus all tests) is fully copy-pasted between packages/messenger/src/generate-action-types/ and packages/messenger-cli/src/. The deprecated @metamask/messenger version could import from @metamask/messenger-cli and just add the deprecation wrapper in cli.ts, avoiding maintaining two identical codebases where bug fixes must be applied in both places (as the stale error message already demonstrates).


Explanation
The
generate-action-typesCLI tool currently lives inside@metamask/messenger. This causes issues for consumers who use different ESLint or TypeScript versions, since these are peer dependencies of the messenger package. This PR extracts the CLI into its own dedicated package (@metamask/messenger-cli) where all dependencies are regular (not peer), so consumers just install it as a devDependency and themessenger-generate-action-typesbinary works out of the box.Changes
@metamask/messenger-clipackage with all CLI source files (check.ts,fix.ts,generate-content.ts,parse-source.ts,cli.ts) and tests (100% coverage).eslint,typescript,yargs,@metamask/utils) — no peer deps, no configuration burden on consumers.@metamask/messenger(non-breaking) — existing users get a deprecation warning pointing to the new package.generate-method-action-typesscripts from ~47 consumer packages. The binarymessenger-generate-action-typesis now invoked directly.yarn workspaces foreach exec messenger-generate-action-typesinstead ofrun generate-method-action-types.lint-build-test.yml,controller-guidelines.md,teams.json,eslint.config.mjs).This package will also serve as the home for
@metamask/messenger-docs(PR #8012) in a follow-up, consolidating all messenger CLI tooling in one place.References
generate-action-typesCLI tool as subpath export #8264@metamask/messenger-docs) will merge into this packageChecklist
Note
Medium Risk
Medium risk because it changes repo-wide lint/CI tooling and introduces a new CLI package/binary that many workspaces will rely on; failures would primarily surface as generation/check breaks rather than runtime behavior.
Overview
Moves the
messengeraction-type generation CLI into a new publishable package,@metamask/messenger-cli, providing themessenger-generate-action-typesbinary with its own dependencies and a full Jest test suite.Updates repo tooling to use the new command name (
messenger-generate-action-types) in root scripts and CI, and removes per-workspacegenerate-method-action-typesscripts across many packages.Keeps a deprecated
messenger-generate-action-typesbinary in@metamask/messengerthat now emits a deprecation warning pointing consumers to@metamask/messenger-cli, while also updating docs/ESLint/Jest config and regenerating some*-method-action-types.tsoutputs to match the new generator format.Written by Cursor Bugbot for commit 360cc4d. This will update automatically on new commits. Configure here.