Skip to content

jaebradley/npm-list-problems

Repository files navigation

npm-list-problems

Introduction

npm list essentially outputs your dependency tree structure.

It also outputs any errors associated with your dependency tree like extraneous or missing dependencies.

Sometimes, it would be useful to programmatically retrieve this list of problems (for example, failing a build if any extraneous errors are found).

Installation

npm install npm-list-problems --save

API

getProblems(relativePath = null)

  • Takes an optional relativePath argument. If unspecified, the method will identify problems for the current directory
  • Returns an array of problem objects

Problem objects

  • There are 6 types of errors that npm list returns (defined in the getLite method in npm's ls.js)

    1. Extraneous dependency
    2. Missing dependency
    3. Missing peer dependency
    4. Invalid dependency
    5. Dependency error
  • Each of these error types will produce differently formatted Problem objects

Extraneous dependency

{
  package: 'some package name',
  version: 'some package version',
  path: 'some path to package',
  type: 'EXTRANEOUS_DEPENDENCY',
}

Missing dependency

{
  package: 'some package name',
  version: 'some package version',
  requiredBy: {
    package: 'some other package',
    version: 'some other package version',
  },
  type: 'MISSING_DEPENDENCY',
}

Missing peer dependency

{
  package: 'some package name',
  version: 'some package version',
  requiredBy: {
    package: 'some other package',
    version: 'some other package version',
  },
  type: 'MISSING_PEER_DEPENDENCY',
}

Invalid dependency

{
  package: 'some package name',
  version: 'some package version',
  path: 'some path to package',
  type: 'INVALID_DEPENDENCY',
}

Dependency error

{
  path: 'some path to package',
  message: 'some error message'
  type: 'DEPENDENCY_ERROR',
}

Usage

import getProblems from 'npm-list-problems';

// defaults to current directory
getProblems().then(problems => console.log(problems));

// get dependency problems for relative path
getProblems('../some/relative/directory').then(problems => console.log(problems));

// both could output something like
// [
//   { package: 'object-assign',
//     version: '4.1.1',
//     requiredBy: { package: 'react-dom', version: '16.2.0' },
//     type: 'MISSING_DEPENDENCY' },
//   { package: 'prop-types',
//     version: '15.6.0',
//     requiredBy: { package: 'react-dom', version: '16.2.0' },
//     type: 'MISSING_DEPENDENCY' }
// ]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published