find-installed-packages
v4.0.1
Published
Find installed packages
Readme
find-installed-packages
Find installed packages.
ESM only, Node >= 20.19.
Usage
import { findByKeywords } from 'find-installed-packages'
(async () => {
const packages = await findByKeywords(['some-keyword']) // ['pkg-a', 'pkg-b']
// or from somewhere other than the current directory
await findByKeywords(['some-keyword'], { cwd: './packages/app' })
}())A package is returned when its package.json declares every keyword you ask for.
How packages are found
Packages are located by walking the declared dependency graph from cwd and asking
the host runtime's module resolver where each one lives, rather than scanning
node_modules folders.
That keeps results correct across layouts a node_modules scan gets wrong:
| Layout | Scanning node_modules | Resolving |
| --- | --- | --- |
| npm / yarn / bun, single package | works | works |
| pnpm, bun --linker=isolated | relies on undocumented store internals | works |
| Workspaces (tree hoisted to the repo root) | finds nothing | works |
| Yarn Plug'n'Play (no node_modules at all) | finds nothing | works |
Two consequences worth knowing:
- Only declared dependencies are reported. A package present in
node_modulesthat nothing depends on is not returned. - Under Yarn PnP this must run inside the PnP-enabled process (the normal case for
a library loaded by your app). Shelling out to a plain
nodewill find nothing.
If cwd has no readable package.json, or one that declares no dependencies, the
node_modules scan is used as a fallback.
Cache
Results are cached in the temp folder, keyed by cwd plus keywords, and invalidated
when the lockfile, package.json, or top-level node_modules changes. Lockfiles are
looked up from cwd upwards, so workspaces are handled.
The lockfile names come from
package-manager-detector,
so a new package manager arrives with a dependency bump rather than a bug report.
Yarn PnP's .pnp.cjs and .pnp.data.json are watched too, since they change with the
installed tree even though they are not lockfiles.
Contribute
# after fork and clone
npm install
# begin making changes
git checkout -b <branch>
npm run watch
# after making change(s)
git commit -m "<commit message>"
git push
# create PR