• Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    JavaScript
  • Created over 13 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Determine the set of requirements for a given node.js file, directory tree, or module

require-analyzer

Determine dependencies for a given node.js file, directory tree, or module in code or on the command line

Status

Build Status

Installation

Installing npm (node package manager)

  curl http://npmjs.org/install.sh | sh

Installing require-analyzer

  [sudo] npm install require-analyzer

NOTE: If you're using npm >= 1.0 then you need to add the -g parameter to install require-analyzer globally.

Usage

There are two distinct ways to use the require-analyzer library: from the command line or through code. The command line tool is designed to work with package.json files so make sure that you have created one for your project first. Checkout jitsu for a quick and easy way to create a package.json.

For more information read our blog post at blog.nodejitsu.com.

Command-line usage

Using require-analyzer from the command line is easy. The binary will attempt to read the package.json file in the current directory, then analyze the dependencies and cross reference the result.

  $ require-analyzer --help
  usage: require-analyzer [options] [directory]

  Analyzes the node.js requirements for the target directory. If no directory
  is supplied then the current directory is used

  options:
    --update     Update versions for existing dependencies
    -h, --help   You're staring at it

Here's a sample of require-analyzer analyzing its own dependencies:

  $ require-analyzer
  info:  require-analyzer starting in /Users/Charlie/Nodejitsu/require-analyzer
  warn:  No dependencies found
  info:  Analyzing dependencies...
  info:  Done analyzing raw dependencies
  info:  Retrieved packages from npm
  info:  Additional dependencies found
  data:  {
  data:    findit: '>= 0.0.3',
  data:    npm: '>= 0.3.18'
  data:  }
  info:  Updating /Users/Charlie/Nodejitsu/require-analyzer/package.json
  info:  require-analyzer updated package.json dependencies

Programmatic usage

The easiest way to use require-analyzer programmatically is through the .analyze() method. This method will use fs.stat() on the path supplied and attempt one of three options:

  1. If it is a directory that has a package.json, analyze require statements from package.main
  2. If it is a directory with no package.json analyze every .js or .coffee file in the directory tree
  3. If it is a file, then analyze require statements from that individual file.

Lets dive into a quick sample usage:

  var analyzer = require('require-analyzer');

  var options = {
    target: 'path/to/your/dependency' // e.g /Users/some-user/your-package
    reduce: true
  };

  var deps = analyzer.analyze(options, function (err, pkgs) {
    //
    // Log all packages that were discovered
    //
    console.dir(pkgs);
  });

  //
  // The call the `.analyze()` returns an `EventEmitter` which outputs
  // data at various stages of the analysis operation.
  //
  deps.on('dependencies', function (raw) {
    //
    // Log the raw list of dependencies (no versions)
    //
    console.dir(raw);
  });

  deps.on('search', function (pkgs) {
    //
    // Log the results from the npm search operation with the current
    // active version for each dependency
    //
    console.dir(pkgs);
  });

  deps.on('reduce', function (reduced) {
    //
    // Logs the dependencies after they have been cross-referenced with
    // sibling dependencies. (i.e. if 'foo' requires 'bar', 'bar' will be removed).
    //
    console.dir(reduced);
  });

Further analyzing dependencies

Sometimes when dealing with dependencies it is necessary to further analyze the dependencies that are returned. require-analyzer has a convenience method for doing just this:

  var analyzer = require('require-analyzer');

  var current = {
    'foo': '>= 0.1.0'
  };

  var updated = {
    'foo': '>= 0.2.0',
    'bar': '>= 0.1.0'
  };

  var updates = analyzer.updates(current, updated);

  //
  // This will return an object literal with the differential
  // updates between the two sets of dependencies:
  //
  // {
  //   added: { 'bar': '>= 0.1.0' },
  //   updated: { 'foo': '>= 0.2.0' }
  // }
  //

Tests

  npm test

Author: Charlie Robbins

More Repositories

1

haibu

[Deprecated] a node.js application server - spawn your own node.js clouds, on your own hardware
JavaScript
722
star
2

jitsu

Flawless command line deployment of your Node.js apps to the cloud
JavaScript
648
star
3

handbook

A gentle introduction to the art of Nodejitsu
JavaScript
473
star
4

nexpect

spawn and control child processes in node.js with ease
JavaScript
290
star
5

godot

Godot is a streaming real-time event processor based on Riemann written in Node.js
JavaScript
265
star
6

docs

Community powered rocket fuel for node.js
JavaScript
194
star
7

node-cloudservers

A client implementation for Rackspace CloudServers in node.js
JavaScript
159
star
8

node-cloudfiles

A client implementation for Rackspace CloudFIles in node.js
JavaScript
151
star
9

kohai

I am kohai. I am a pluggable irc bot for managing real-time data events.
JavaScript
91
star
10

prenup

A collaborative bdd project planning tool for node. uses kyuri and VowsJS
JavaScript
83
star
11

module-foundry

A web service for building node.js modules that runs on Linux, SmartOS and Windows.
JavaScript
80
star
12

mock-request

A simple testing tool for mocking HTTP sequences of request / response pairs in node.js
JavaScript
77
star
13

haibu-carapace

The application host used by the haibu node.js application deployment / management server.
JavaScript
69
star
14

txn

Process and update CouchDB data in atomic, all-or-nothing transactions
JavaScript
65
star
15

nodejitsu-api

a collection of client wrappers for nodejitsu's core api
JavaScript
47
star
16

browsenpm.org

Browse packages, users, code, stats and more the public npm registry in style.
JavaScript
44
star
17

forza

A lightweight agent for Godot
C
36
star
18

jitsu-ui

A terminal interface for jitsu.
JavaScript
34
star
19

aeternum

A process monitor in libuv
C
31
star
20

module-smith

A simple extensible npm build bot that works on Linux, SmartOS, and Windows.
JavaScript
19
star
21

solenoid

Jump start an application
JavaScript
19
star
22

overwatch

A deterministic couchdb replication watcher
JavaScript
19
star
23

persistent-ghost

Wrapper to deploy the Ghost blog on Nodejitsu
JavaScript
18
star
24

haibu-api

A collection of client wrappers for haibu's core api
JavaScript
11
star
25

defaultable

Transparent, drop-in helper for overridable, inheritable defaults in CommonJS modules
JavaScript
9
star
26

contour

Collection of BigPipe Pagelets for fast prototyping and scaffold of templates
CSS
8
star
27

npm-pkg-top

Lists the top binary packages by npm stars and github stars
JavaScript
7
star
28

npm-ev-source

The transform module or daemon that takes a `skimdb` based couch and turns it into an `event-sourced` complete npm
JavaScript
7
star
29

packages-pagelet

A pagelet for rendering a npm package page.
JavaScript
4
star
30

npm-package-json-pagelet

An interactive guide for package.json
HTML
3
star
31

npm-search-pagelet

Search the npm registry.
JavaScript
2
star
32

nodejitsu-npm

A simple command line utility to get started with a Nodejitsu Private npm!
JavaScript
2
star
33

npm-dependencies-pagelet

Pagelet for the dependencies UI for a single package
JavaScript
1
star
34

registry-status-pagelet

Pagelet for visual overview of npm registry statuses
JavaScript
1
star
35

service-select

Service selector pagelet for selecting
JavaScript
1
star
36

npm-documentation-pagelet

Display documentation of npm
CSS
1
star