Usage |
Credits
Retrieves the (flat) list of package dependencies from the package manager lock file.
Currently, we support these package managers:
Usage
First, install the library with:
npm i @h4ad/dependency-extractor
Then, you need to read and parse the package-lock.json
:
import { NpmExtractor } from '@h4ad/dependency-extractor';
import { readFileSync } from 'fs';
const extractor = new NpmExtractor();
const packageLock = readFileSync('package-lock.json').toString('utf-8');
const dependencyContainer = extractor.parse(packageLock);
Then, you can use the information collected from your dependencies with:
const allDependencies = dependencyContainer.getAllDependencies();
const productionDependencies = dependencyContainer.getProductionDependencies();
const developmentDependencies = dependencyContainer.getDevelopmentDependencies();
const peerDependencies = dependencyContainer.getPeerDependencies();
const optionalDependencies = dependencyContainer.getOptionalDependencies();
const firstDependency = allDependencies[0];
console.log(firstDependency.name);
console.log(firstDependency.version);
console.log(firstDependency.isProduction);
console.log(firstDependency.isDevelopment);
console.log(firstDependency.isOptional);
console.log(firstDependency.isPeer);
Credits
This library was based on npm-dependencies-extractor.