-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: support finder functions for performing complex searches with list and why commands #9946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ist and why commands
…ist and why commands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces finder functions for performing complex searches in pnpm list
and pnpm why
commands. Previously these commands could only search by package name and version, but now they can search by any properties of dependencies using custom finder functions defined in .pnpmfile.cjs
.
Key changes:
- Added
--find-by
CLI option to specify finder functions by name - Implemented finder function support with a context object providing
name
,version
, andreadManifest()
method - Added ability for finders to return additional information as strings to be displayed in output
Reviewed Changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
plugin-commands-listing/src/why.ts | Added --find-by option and updated error message |
plugin-commands-listing/src/list.ts | Added finder support and validation logic |
list/src/renderTree.ts | Added searchMessage display support |
list/src/index.ts | Added finder parameter to list functions |
dependencies-hierarchy/src/createPackagesSearcher.ts | Refactored to support finder functions alongside package name search |
dependencies-hierarchy/src/getTree.ts | Updated to use FinderContext instead of simple package objects |
dependencies-hierarchy/src/getPkgInfo.ts | Added readManifest function to return value |
dependencies-hierarchy/src/buildDependenciesHierarchy.ts | Updated to use FinderContext and handle searchMessage |
dependencies-hierarchy/src/PackageNode.ts | Added searchMessage property |
read-package-json/src/index.ts | Added synchronous package.json reading functions |
types/src/options.ts | Added FinderContext and Finder type definitions |
pnpmfile/src/requirePnpmfile.ts | Added finders property to pnpmfile interface |
pnpmfile/src/requireHooks.ts | Added finder merging and passing to config |
config/src/Config.ts | Added finders property to Config interface |
cli-utils/src/getConfig.ts | Added finder loading from pnpmfile |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Currently,
pnpm list
andpnpm why
can only search for dependencies by name (and optionally version). For example:prints the chain of dependencies to any installed instance of
minimist
:What if we want to search by other properties of a dependency, not just its name? For instance, find all packages that have react@17 in their peer dependencies?
This is currently not possible. You could try to analyze the lockfile manually but it gets really hard with bigger projects. Also, not all information is present in the lockfile.
My suggested solution for this is introducing "finder functions". Finder functions can be declared via
.pnpmfile.cjs
and invoked using the--find-by=<function name>
flag, when usingpnpm list
orpnpm why
.Let's say we want to find any dependencies that have react 17 in peer dependencies. We can add this finder to our
.pnpmfile.cjs
:Now we can use this finder function by running:
pnpm will find all dependencies that have this react in peer dependencies and print their exact locations in the dependency graph.
It is also possible to print out some additional information in the output by returning a string from the finder. For example, with the following funder:
Every matched package will also print out the license from it's
package.json
: