@rowanmanning/npm-dependencies
v1.1.1
Published
Get a list of all the dependencies found in a package file
Downloads
17
Readme
@rowanmanning/npm-dependencies
Get a resolved list of dependencies found in a package.json
or package-lock.json
file.
Requirements
This library requires the following to run:
- Node.js 18+
Usage
Install with npm:
npm install @rowanmanning/npm-dependencies
Load one of the methods into your code with import
or require
:
import { getPackageDependencies } from '@rowanmanning/npm-dependencies';
// or
const { getPackageDependencies } = require('@rowanmanning/npm-dependencies');
The following exports are available.
getPackageDependencies()
A function to list the npm dependencies that a package.json
or package-lock.json
file installs. This function has the following signature:
(packageJson: PackageJson, options?: object) => Dependency[]
Returned dependencies have the following signature:
{
name: string;
version: string;
isBundled: boolean;
isDev: boolean;
isOptional: boolean;
isPeer: boolean;
}
PackageJson
must be a JavaScript object that is a valid package.json
or package-lock.json
file. We recommend using @rowanmanning/package-json or @npmcli/package-json.
The options
argument is optional and can be used to change the way the method works. The following options are available:
workspace
: Astring
option defaulting to""
. This is used to specify which workspace in apackage-lock.json
file to get dependencies for, defaulting to the root workspace. This option has no effect forpackage.json
files.
const dependencies = getPackageDependencies(require('./package.json'));
// or
const dependencies = getPackageDependencies(require('./package-lock.json'));
getAllWorkspaceDependencies()
A function to list dependencies for all workspaces defined in a package-lock.json
file. This function has the following signature:
(packageJson: PackageJson) => Workspace[]
Returned workspaces have the following signature:
{
workspace: string;
name: string;
version: string;
dependencies: [
{
name: string;
version: string;
isBundled: boolean;
isDev: boolean;
isOptional: boolean;
isPeer: boolean;
}
]
}
PackageJson
must be a JavaScript object that is a valid package-lock.json
file. We recommend using @rowanmanning/package-json.
Contributing
See the central README for a contribution guide and code of conduct.
License
Licensed under the MIT license. Copyright © 2024, Rowan Manning