Repository navigation
fix(@angular/cli): resolve installed @angular/core version in list_projects MCP tool - #34772
FlorinAsavoaie wants to merge 1 commit into
Conversation
…ojects MCP tool The `list_projects` MCP tool determined `frameworkVersion` by walking up from the workspace directory to the first `package.json` that declared `@angular/core` and passing the declared value to `semver.minVersion`. Declared values that are not semver ranges, such as pnpm/yarn catalogs (`catalog:`, `catalog:angular`), `workspace:*` or `npm:` aliases, made `semver.minVersion` throw. The tool then reported a versioning error for the workspace (e.g. `Invalid comparator: catalog:`) and left `frameworkVersion` unset. The version is now read from the installed `@angular/core/package.json`, resolved with `createRequire` in the same way as the `get_best_practices` tool, so the way the dependency is declared no longer matters. The resolution starts from the workspace's `angular.json` file rather than its directory, because `createRequire` searches from the parent directory of the given path and would otherwise skip the `node_modules` of nested workspaces such as `apps/web`. When `@angular/core` is not installed or its version cannot be read, `frameworkVersion` is left unset and no error is reported. The upward `package.json` search and its cache are removed; the output schema is unchanged.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request refactors how the major version of @angular/core is determined for a workspace. It replaces a custom upward directory traversal and caching mechanism with Node.js module resolution via createRequire relative to the angular.json file. This change simplifies the code, robustly handles various dependency declaration formats (such as pnpm/yarn catalogs), and removes the reporting of versioning errors when the package is not installed. Additionally, comprehensive unit tests have been added to verify these resolution behaviors. I have no further feedback to provide as the implementation is clean and well-tested.
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The
list_projectsMCP tool works outframeworkVersionby walking up from the workspace directory to the firstpackage.jsonthat declares@angular/core, then passing the declared value tosemver.minVersion. If the declared value isn't a semver range,semver.minVersionthrows. That happens with pnpm/yarn catalogs (catalog:,catalog:angular),workspace:*andnpm:aliases. The tool then reports a versioning error for the workspace (e.g.Invalid comparator: catalog:) and leavesframeworkVersionunset.Issue Number: N/A
What is the new behavior?
The version now comes from the installed
@angular/core/package.json, resolved withcreateRequirethe same way theget_best_practicestool does it. How the dependency is declared no longer matters.angular.jsonfile rather than its directory.createRequiresearches from the parent directory of the path it's given, so starting from the directory would skip thenode_modulesof nested workspaces such asapps/web.@angular/coreisn't installed or its version can't be read,frameworkVersionis left unset and no error is reported.package.jsonsearch and its cache are removed.Does this PR introduce a breaking change?
Other information