# module-graph

> Utility for obtaining the dependency graph from ES6 modules

Latest version **0.1.2** (published 2014-05-29) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install module-graph
pnpm add module-graph
yarn add module-graph
bun add module-graph
```

Provides the command `module-graph`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2014-05-29 |
| First published | 2014-05-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.x |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 29 |
| Author | Juan Dopazo |
| Maintainers | juandopazo |
| Keywords | ecmascript, es6, AST, dependency, dependencies, analizer |

## Links

- npm: https://www.npmjs.com/package/module-graph
- Repository: https://github.com/juandopazo/module-graph
- Issues: https://github.com/juandopazo/module-graph/issues
- npm.io page: https://npm.io/package/module-graph

## Dependencies (4)

- [extend](https://npm.io/package/extend.md) ^1.2.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.0
- [nomnom](https://npm.io/package/nomnom.md) ^1.6.2
- [esprima-fb](https://npm.io/package/esprima-fb.md) 4001.1.0-dev-harmony-fb

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2014-05-29
- 0.1.1 — 2014-05-29
- 0.1.0 — 2014-05-29

## README

module-graph
============

[![Build Status](https://travis-ci.org/juandopazo/module-graph.svg?branch=master)](https://travis-ci.org/juandopazo/module-graph)
[![Dependency Status](https://gemnasium.com/juandopazo/module-graph.svg)](https://gemnasium.com/juandopazo/module-graph)
[![NPM version](https://badge.fury.io/js/module-graph.svg)](http://badge.fury.io/js/module-graph)

Utility for obtaining the dependency graph from ES6 modules.

Limitations
-----------

`module-graph` only works for source code that the Esprima parser can parse.
This does not include the whole ES6 syntax at the moment. Consider this module
experimental.


API
---

### graph(source, [options])

`module-graph` exports a single function that takes a string with source code
and returns an array of the dependencies in that module:

```js
var graph = require('module-graph');

var result = graph('import foo from "bar"; export default foo;');
// returns an array like ['bar']
```

If the `includeBindings` option is set to `true`, then the graph function
will return an object containing all the imported and exported names of the
module:

```js
var graph = require('module-graph');

var result = graph('import foo from "bar"; export default foo;', {
    includeBindings: true
});
/* result looks like this:
{
    imports: {
        'foo': ['bar']
    },
    exports: ['default']
}
*/
```

Optionally, if you're already dealing with an AST that contains ES6 imports
or exports, you can pass that AST object to the `graph` function:

```
var esprima = require('esprima'); // Make sure your Esprima version supports ES6!
var graph   = require('module-graph');

var ast = esprima.parse('import foo from "bar"; export default foo;');
var result = graph(ast);
```

Note: none of the dependency names are normalized. It's up to you to decide how
to normalize them.

CLI
---

If installed with `npm install module-graph -g` it can be used as a global
command `module-graph paths... [options]` which will generate a JSON file with
all the dependency information. Try `module-graph --help` for more information.

License
-------

This software is free to use under the Yahoo Inc. BSD license.
See the [LICENSE file][] for license text and copyright information.

Contribute
----------

See the [CONTRIBUTING file][] for info.


[CONTRIBUTING file]: https://github.com/juandopazo/module-graph/blob/master/CONTRIBUTING.md
[LICENSE file]: https://github.com/juandopazo/module-graph/blob/master/LICENSE.md

---
_Source: https://npm.io/package/module-graph · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
