A tool gets the package info of node modules.
Install from the NPM repository using yarn or npm:
yarn add fetch-pkgs-info
npm install fetch-pkgs-info
Create a js file:
import GetPackageJsonProcess from 'fetch-pkgs-info'
const config = {
modules: [
{ name: 'react', version: '16.0.0' },
{ name: 'redux', version: '4.0.0' }
]
}
new GetPackageJsonProcess(config).run()
.then(result => {})
.catch(err => {})
Or you can pass the second parameter to the constructor GetPackageJsonProcess to specify the attributes what need to be returned.
import GetPackageJsonProcess, { retrievePkgs } from 'fetch-pkgs-info'
const config = {
modules: [
{ name: 'react', version: '16.0.0' },
{ name: 'redux', version: '4.0.0' }
],
attributes: ['name', 'version', 'dependencies'],
installPkgTool: 'npm'
}
// method 1:
new GetPackageJsonProcess(config).run()
.then(result => {})
.catch(err => {})
// method 2:
retrievePkgs(config)
.then(result => {})
.catch(err => {})
Array: [{ name: 'react', version: '16.0.0' }] Object: { name: 'react', version: '16.0.0' }
Array: ['name', 'version'] String: 'name'
Notice: If you don't offer installPkgTool's value, it will detect the yarn.lock file to check using yarn or npm.