Skip to content

feat: extract generate-action-types CLI into @metamask/messenger-cli#8377

Closed
cryptodev-2s wants to merge 44 commits intomainfrom
feat/messenger-cli-package
Closed

feat: extract generate-action-types CLI into @metamask/messenger-cli#8377
cryptodev-2s wants to merge 44 commits intomainfrom
feat/messenger-cli-package

Conversation

@cryptodev-2s
Copy link
Copy Markdown
Contributor

@cryptodev-2s cryptodev-2s commented Apr 3, 2026

Explanation

The generate-action-types CLI 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 the messenger-generate-action-types binary works out of the box.

Changes

  • New @metamask/messenger-cli package with all CLI source files (check.ts, fix.ts, generate-content.ts, parse-source.ts, cli.ts) and tests (100% coverage).
  • All dependencies are regular (eslint, typescript, yargs, @metamask/utils) — no peer deps, no configuration burden on consumers.
  • Deprecated the CLI in @metamask/messenger (non-breaking) — existing users get a deprecation warning pointing to the new package.
  • Removed per-package generate-method-action-types scripts from ~47 consumer packages. The binary messenger-generate-action-types is now invoked directly.
  • Updated root scripts to use yarn workspaces foreach exec messenger-generate-action-types instead of run generate-method-action-types.
  • Updated CI, docs, and metadata (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

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
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 messenger action-type generation CLI into a new publishable package, @metamask/messenger-cli, providing the messenger-generate-action-types binary 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-workspace generate-method-action-types scripts across many packages.

Keeps a deprecated messenger-generate-action-types binary in @metamask/messenger that now emits a deprecation warning pointing consumers to @metamask/messenger-cli, while also updating docs/ESLint/Jest config and regenerating some *-method-action-types.ts outputs to match the new generator format.

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

cryptodev-2s and others added 30 commits March 23, 2026 19:31
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.
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)
…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.
- 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
@cryptodev-2s cryptodev-2s requested review from a team as code owners April 3, 2026 09:35
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.

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.

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

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

}

return sources;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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).

Additional Locations (2)
Fix in Cursor Fix in Web

@cryptodev-2s cryptodev-2s deleted the feat/messenger-cli-package branch April 3, 2026 09:40
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