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 17 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
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).
|
@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. |
…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.
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.
|
@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. |
|
@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. |
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.
|
@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. |
| "typedoc-plugin-missing-exports": "^2.0.0", | ||
| "typescript": "~5.3.3" | ||
| "typescript": "~5.3.3", | ||
| "yargs": "^17.7.2" |
There was a problem hiding this comment.
Should these be in dependencies, since they're being referred to in code that we are publishing?
| @@ -0,0 +1,6 @@ | |||
| export { checkActionTypesFiles } from './check'; | |||
There was a problem hiding this comment.
Do we need to expose an API? I know that we do this for auto-changelog so we can programmatically parse changelogs, but maybe we don't need one in this case?
| // The display name when running multiple projects | ||
| displayName, | ||
|
|
||
| coveragePathIgnorePatterns: ['./src/generate-action-types/cli.ts'], |
There was a problem hiding this comment.
Instead of ignoring this file, what are your thoughts on writing functional tests that run the CLI for real on a set of example files?
| const sourceImportPath = `./${baseFileName}`; | ||
|
|
||
| let content = `/** | ||
| * This file is auto generated by \`@metamask/messenger/generate-action-types\`. |
There was a problem hiding this comment.
Maybe we shouldn't mention the tool that created this file so that if we change the tool later we don't need to update these files?
| * This file is auto generated by \`@metamask/messenger/generate-action-types\`. | |
| * This file is auto-generated. |

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 subpath export (@metamask/messenger/generate-action-types), 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)./generate-action-typessubpath export andmessenger-generate-action-typesbin entry to@metamask/messenger@metamask/utils,typescript,yargs,eslint) are optional peer dependencies — only needed when using the codegen tool. The coreMessengerlibrary remains truly zero-dependency.tsx ../../packages/messenger/src/generate-action-types/cli.tsscripts/generate-method-action-types.ts*-method-action-types.tsfiles with updated headerReferences
Checklist
Note
Medium Risk
Adds a new published CLI/subpath export in
@metamask/messengerand rewires many packages’ codegen scripts to use it, which could impact build/codegen workflows if packaging or optional peer deps are misconfigured. Runtime controller logic is unaffected; most changes are tooling and regenerated type files.Overview
Moves the monorepo’s
generate-method-action-typescodegen fromscripts/generate-method-action-types.tsinto@metamask/messengeras a newgenerate-action-typesmodule, including a CLI (messenger-generate-action-types) and programmatic exports.Updates dozens of packages to call the new CLI entrypoint and regenerates
*-method-action-types.tsheaders/content accordingly, while deleting the old script. Also adjusts@metamask/messengerpackaging (subpath export,bin, optional peer deps fortypescript/yargs/eslint/@metamask/utils) and adds lint/test config tweaks to support the new generator code.Written by Cursor Bugbot for commit a462582. This will update automatically on new commits. Configure here.