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 24 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
|
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.
|
@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?
There was a problem hiding this comment.
yargs probably, but TypeScript should probably be a peer dependency?
There was a problem hiding this comment.
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.
| // 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?
packages/messenger/src/generate-action-types/generate-content.ts
Outdated
Show resolved
Hide resolved
Recursive search makes per-subdirectory scripts unnecessary in assets-controllers, notification-services-controller, and profile-sync-controller.
## 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 -->
…te-action-types-package
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.
| }, | ||
| "yargs": { | ||
| "optional": true | ||
| } |
There was a problem hiding this comment.
Required codegen dependencies missing from dependencies
High Severity
yargs, @metamask/utils, and typescript are directly imported (top-level, no try/catch) in cli.ts and parse-source.ts, but all are only in devDependencies and marked as optional peer dependencies. When the package is published, devDependencies aren't installed and optional peers won't trigger warnings. The bin entry messenger-generate-action-types and the ./generate-action-types subpath export will crash at runtime for external consumers. Per the PR discussion, yargs belongs in dependencies and typescript/eslint should be non-optional peer dependencies, but this wasn't implemented.
Additional Locations (2)
No consumers import programmatically. The tool is CLI-only.
## 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 -->


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
Medium risk because it replaces a widely-used monorepo script with a new CLI entrypoint and updates many package scripts, so any behavioral mismatch or optional peer dependency resolution issues could break codegen/CI.
Overview
Moves the
generate-method-action-typescodegen fromscripts/generate-method-action-types.tsinto@metamask/messengeras a newsrc/generate-action-typesmodule with ayargs-based CLI that can--checkor--fix, optionally running ESLint formatting.Updates all consuming packages to invoke the new tool (now also published as the
messenger-generate-action-typesbin) and adjusts@metamask/messengerpackaging/peers to keep codegen deps optional. Regenerates some*-method-action-types.tsoutputs and tweaks lint/jest config to accommodate the new CLI.Written by Cursor Bugbot for commit 646a812. This will update automatically on new commits. Configure here.