<commit_before># module-deps

walk the dependency graph to generate json output that can be fed into
[browser-pack](https://github.com/substack/browser-pack)

[![build status](https://secure.travis-ci.org/substack/module-deps.png)](http://travis-ci.org/substack/module-deps)

# example

``` js
var mdeps = require('module-deps');
var JSONStream = require('JSONStream');

var stringify = JSONStream.stringify();
stringify.pipe(process.stdout);

var file = __dirname + '/files/main.js';
mdeps(file).pipe(stringify);
```

output:

```
$ node example/deps.js
[
{"id":"/home/substack/projects/module-deps/example/files/main.js","source":"var foo = require('./foo');\nconsole.log('main: ' + foo(5));\n","entry":true,"deps":{"./foo":"/home/substack/projects/module-deps/example/files/foo.js"}}
,
{"id":"/home/substack/projects/module-deps/example/files/foo.js","source":"var bar = require('./bar');\n\nmodule.exports = function (n) {\n    return n * 111 + bar(n);\n};\n","deps":{"./bar":"/home/substack/projects/module-deps/example/files/bar.js"}}
,
{"id":"/home/substack/projects/module-deps/example/files/bar.js","source":"module.exports = function (n) {\n    return n * 100;\n};\n","deps":{}}
]
```

and you can feed this json data into
[browser-pack](https://github.com/substack/browser-pack):

```
$ node example/deps.js | browser-pack | node
main: 1055
```

# usage

```
usage: module-deps [files]

  generate json output from each entry file

```

# methods

``` js
var mdeps = require('module-deps')
```

## mdeps(files, opts={})

Return a readable stream of javascript objects from an array of filenames
`files`.

Optionally pass in some `opts`:

* opts.transform - a string or array of string transforms (see below)

* opts.transformKey - an array path of strings showing where to look in the
package.json for source transformations. If falsy, don't look at the
package.json at all.

* opts.resolve - custom resolve function using the
`opts.resolve(id, parent, cb)` signature that
[browser-resolve](https://github.com/shtylman/node-browser-resolve) has

* opts.filter - a function (id) to skip resolution of some module `id` strings.
If defined, `opts.filter(id)` should return truthy for all the ids to include
and falsey for all the ids to skip.

* opts.packageFilter - transform the parsed package.json contents before using
the values. `opts.packageFilter(pkg)` should return the new `pkg` object to use.

* opts.noParse - an array of absolute paths to not parse for dependencies. Use
this for large dependencies like jquery or threejs which take forever to parse.

* opts.cache - an object mapping filenames to file objects to skip costly io

# transforms

module-deps can be configured to run source transformations on files before
parsing them for `require()` calls. These transforms are useful if you want to
compile a language like [coffeescript](http://coffeescript.org/) on the fly or<commit_msg>document stream behavior<commit_after># module-deps

walk the dependency graph to generate json output that can be fed into
[browser-pack](https://github.com/substack/browser-pack)

[![build status](https://secure.travis-ci.org/substack/module-deps.png)](http://travis-ci.org/substack/module-deps)

# example

``` js
var mdeps = require('module-deps');
var JSONStream = require('JSONStream');

var stringify = JSONStream.stringify();
stringify.pipe(process.stdout);

var file = __dirname + '/files/main.js';
mdeps(file).pipe(stringify);
```

output:

```
$ node example/deps.js
[
{"id":"/home/substack/projects/module-deps/example/files/main.js","source":"var foo = require('./foo');\nconsole.log('main: ' + foo(5));\n","entry":true,"deps":{"./foo":"/home/substack/projects/module-deps/example/files/foo.js"}}
,
{"id":"/home/substack/projects/module-deps/example/files/foo.js","source":"var bar = require('./bar');\n\nmodule.exports = function (n) {\n    return n * 111 + bar(n);\n};\n","deps":{"./bar":"/home/substack/projects/module-deps/example/files/bar.js"}}
,
{"id":"/home/substack/projects/module-deps/example/files/bar.js","source":"module.exports = function (n) {\n    return n * 100;\n};\n","deps":{}}
]
```

and you can feed this json data into
[browser-pack](https://github.com/substack/browser-pack):

```
$ node example/deps.js | browser-pack | node
main: 1055
```

# usage

```
usage: module-deps [files]

  generate json output from each entry file

```

# methods

``` js
var mdeps = require('module-deps')
```

## mdeps(files, opts={})

Return a readable stream of javascript objects from an array of filenames
`files`.

Each file in `files` can be a string filename or a stream.

Optionally pass in some `opts`:

* opts.transform - a string or array of string transforms (see below)

* opts.transformKey - an array path of strings showing where to look in the
package.json for source transformations. If falsy, don't look at the
package.json at all.

* opts.resolve - custom resolve function using the
`opts.resolve(id, parent, cb)` signature that
[browser-resolve](https://github.com/shtylman/node-browser-resolve) has

* opts.filter - a function (id) to skip resolution of some module `id` strings.
If defined, `opts.filter(id)` should return truthy for all the ids to include
and falsey for all the ids to skip.

* opts.packageFilter - transform the parsed package.json contents before using
the values. `opts.packageFilter(pkg)` should return the new `pkg` object to use.

* opts.noParse - an array of absolute paths to not parse for dependencies. Use
this for large dependencies like jquery or threejs which take forever to parse.

* opts.cache - an object mapping filenames to file objects to skip costly io

# transforms

module-deps can be configured to run source transformations on files before
parsing them for `require()` calls. These transforms are useful if you want to
compile a language like [coffeescript](http://coffeescript.org/) on the fly or
{'fraction_non_alphanumeric': 0.1471736547275505, 'fraction_numerical': 0.003734510269903242, 'mean_word_length': 4.55325164938737, 'pattern_counts': {'":': 24, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7508694', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1795, 'n_words': 573}