pkgscan
Version:
Retrieve information on installed packages across npm, pnpm and yarn
115 lines (85 loc) • 4.09 kB
Markdown
[](https://github.com/nguyenngoclongdev/pkgscan/actions/workflows/ci.yml)
[](https://github.com/nguyenngoclongdev/pkgscan/)
[](https://www.npmjs.org/package/pkgscan)
[](https://gitpod.io/#https://github.com/nguyenngoclongdev/pkgscan)
[](https://packagephobia.now.sh/result?p=pkgscan)
[](https://bundlephobia.com/package/pkgscan@latest)
[](https://npm-stat.com/charts.html?package=pkgscan)
# pkgscan
`pkgscan` is a simple and efficient tool to get detailed information about the packages installed in your project. With support from popular package managers such as `npm`, `pnpm`, and `yarn`, you can easily retrieve information about package versions, dependencies, and other relevant information related to installed packages.

If you find this package useful for your projects, please consider supporting me by [Buy Me a Coffee](https://ko-fi.com/D1D2LBPX9). It's a great way to help me maintain and improve this package in the future. Your support is truly appreciated!
<a href='https://ko-fi.com/D1D2LBPX9' target='_blank'>
<img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi3.png?v=3' border='0' alt='Buy Me a Coffee' />
</a>
## Installation
**npm**
```sh
# Try with npx
npx pkgscan [options]
# Locally in your project.
npm install pkgscan
# Or globally (use as cli)
npm install -g pkgscan
```
## CLI
### Usage
```
pkgscan [options]
Options:
-p, --pkg The name of the package to retrieve information for.
-c, --cwd The current working directory of the project.
-h, --help Show help
```
### Examples
```sh
# Get details about the installed package with automatic package manager detection.
pkgscan --pkg typescript
# Get details about the installed package with a user-specified package manager.
pkgscan --pkg typescript --cwd ./project-directory-path
```
## API
```typescript
import { getInstalledPackageDetails } from 'pkgscan';
// Get details about the installed package with automatic package manager detection.
const installedPackage = await getInstalledPackageDetails('typescript');
console.log(installedPackage);
/*
[
{
name: 'typescript',
version: '5.1.3',
isDirectProjectDependency: true,
dev: true,
license: 'Apache-2.0',
engines: { node: '>=14.17' }
}
]
*/
// Get details about the installed package with a user-specified package manager.
const cwd = __dirname;
const installedPackage = await getInstalledPackageDetails('typescript', cwd);
console.log(installedPackage);
/*
[
{
name: 'typescript',
version: '5.1.3',
isDirectProjectDependency: true,
dev: true,
license: 'Apache-2.0',
engines: { node: '>=14.17' }
}
]
*/
```
> `isDirectProjectDependency` used to determine whether a package is a direct dependency of a project or not. By using this variable, you can check whether a package is directly listed in the dependencies section of the project's package.json file or not.
## Supported package managers:
- [x] npm (lock file versions 1, 2, 3)
- [x] pnpm (all versions of lock files)
- [x] yarn (all versions of lock files)
## Feedback
If you discover a bug, or have a suggestion for a feature request, please
submit an [issue](https://github.com/nguyenngoclongdev/pkgscan/issues).
## LICENSE
This extension is licensed under the [MIT License](LICENSE)