Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

zkochan
Copy link
Member

@zkochan zkochan commented Sep 7, 2025

Currently, pnpm list and pnpm why can only search for dependencies by name (and optionally version). For example:

pnpm why minimist

prints the chain of dependencies to any installed instance of minimist:

verdaccio 5.20.1
├─┬ handlebars 4.7.7
│ └── minimist 1.2.8
└─┬ mv 2.1.1
  └─┬ mkdirp 0.5.6
    └── minimist 1.2.8

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 using pnpm list or pnpm 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:

module.exports = {
  finders: {
    react17: (ctx) => {
      return ctx.readManifest().peerDependencies?.react === '^17.0.0'
    }
  }
}

Now we can use this finder function by running:

pnpm why --find-by=react17

pnpm will find all dependencies that have this react in peer dependencies and print their exact locations in the dependency graph.

@apollo/client 4.0.4
├── @graphql-typed-document-node/core 3.2.0
└── graphql-tag 2.12.6

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:

module.exports = {
  finders: {
    react17: (ctx) => {
      const manifest = ctx.readManifest()
      if (manifest.peerDependencies?.react === '^17.0.0') {
        return `license: ${manifest.license}`
      }
      return false
    }
  }
}

Every matched package will also print out the license from it's package.json:

@apollo/client 4.0.4
├── @graphql-typed-document-node/core 3.2.0
│   license: MIT
└── graphql-tag 2.12.6
    license: MIT

@zkochan zkochan marked this pull request as ready for review September 11, 2025 15:55
@zkochan zkochan requested review from a team and Copilot September 11, 2025 21:46
Copy link

@Copilot Copilot AI left a 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, and readManifest() 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.

@zkochan zkochan requested a review from Copilot September 11, 2025 22:20
Copy link

@Copilot Copilot AI left a 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.

@zkochan zkochan merged commit e792927 into main Sep 12, 2025
9 of 13 checks passed
@zkochan zkochan deleted the find-by branch September 12, 2025 09:46
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.