1.2.0 • Published 8 years ago

get-wanted-dependencies v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

get-wanted-dependencies NPM version

Get a list of NPM package dependencies that are "wanted", based on the contents of package.json and what is currently installed in /node_modules.

Installation

Install the package with NPM:

$ npm install -g get-wanted-dependencies

The -g flag is recommended for easy CLI usage, but completely optional.

API

The package exposes a function with the signature (dir, callback), where dir is the directory containing package.json and callback is a typical Node.js-style callback function.

Example:

import getWantedDependencies from "get-wanted-dependencies";

getWantedDependencies(__dirname, (err, wantedDependencies) => {
  if (err) {
    console.error(err);
    return;
  }

  wantedDependencies.forEach(dependency => {
    console.log(dependency.name);
    console.log(dependency.installedVersion);
    console.log(dependency.wantedVersion);
  });
});

CLI

Run get-wanted-dependencies from the command line to output a list of wanted dependencies for the current directory:

$ get-wanted-dependencies

Tip

When working on a team, one can sometimes forget to run npm install after pulling in dependency changes made by others. Solution – integrate the package into your automated build system!

Example gulp task:

gulp.task("check-dependencies", done => {
  getWantedDependencies(__dirname).then(wantedDependencies => {
    if (wantedDependencies.length > 0) {
      console.error("Wanted dependencies not installed. Run `npm install`.");
      process.exit(1);
    }

    done();
  }).catch(err => done(err));
});