mcbain
Find `require()` calls and report the dependencies they refer to.
Last updated 5 years ago by jmm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mcbain 
SYNC missed versions from official npm registry.

Find require() calls and report the dependencies they refer to.

This is like, and adapted from, detective, but conducts its investigation with extreme prejudice (scope awareness). (Note: the scope awareness makes this significantly slower than detective.) That is, when this hits a scope that defines a require binding (e.g. as a var or a function parameter) it considers require() calls in that scope to no longer be the require() it's looking for and eliminates them from the output. Example:

Input:

require("x");

(function (require) {
  require("y");
})();

Output (detective): ["x", "y"]

Output (mcbain): ["x"]

Why would scope awareness matter or be desirable? See substack/node-browserify#1151 for an example. If you create a standalone bundle with browserify, then require() it into a subsequent browserify bundle without taking special measures to eliminate or ignore require() calls in the standalone bundle, detective will report modules that are already in the first bundle as dependencies that browserify (module-deps) will try to resolve and choke on. mcbain detects that the require() calls are nested in scopes that have defined require and eliminates them. Indeed, browserify has already resolved and packaged the dependencies they refer to and defined its own require to retrieve them.

Aside from that difference, this should mostly be able to function as a drop-in replacement for detective (albeit slower) in the sense that it has the same export profile and mostly the same API as detective. See its README for documentation. This does not use acorn and does not support opts.parse. This passes detective's tests with the exception of those involving opts.parse.

Current Tags

  • 0.1.2                                ...           latest (5 years ago)

1 Versions

  • 0.1.2                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (2)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |