es6-import-list
Utility for obtaining the dependency list from ES6 modules.
This module only analyzes imports declared using the ES module syntax.
Installation
npm install -g es6-import-list
CLI
$ es6-import-list -d src/
// Output:
┌────────────────────────┬─────────────────────────┐
│ Modules │ Import List │
├────────────────────────┼─────────────────────────┤
│ megadraft │ MegadraftEditor │
│ │ MegadraftIcons │
│ │ editorStateFromRaw │
├────────────────────────┼─────────────────────────┤
│ react │ Component │
│ │ React │
├────────────────────────┼─────────────────────────┤
│ react-dom │ render │
└────────────────────────┴─────────────────────────┘
Generate a JSON output with all the dependency information
$ es6-import-list -d src/ --json
// Output:
{
"megadraft": [
"MegadraftEditor",
"MegadraftIcons",
"editorStateFromRaw"
],
"react": [
"Component",
"React"
],
"react-dom": [
"render"
]
}
Try es6-import-list --help
for more information.
API
getImports(dir, [options], callback)
Examples
const getImports = require('es6-import-list');
getImports('my-directory', importsList => {
console.log(importsList);
});
Default options:
const options = {
match: /.js$/,
exclude: [/^\./],
}
es6-import-list uses node-dir, so you can pass additional options
parameter to match or ignore files, for example.
const getImports = require('es6-import-list');
const options = {
match: /.js$/,
exclude: [/^\./],
excludeDir: ['dist', 'lib', 'node_modules'],
};
getImports('my-directory', options, importList => {
console.log(importList);
});