Create a Babel visitor that will find out all the exports and save them into an object ref.
The object ref to save the exports result.
Create a Babel visitor that will find out all the imports and save them into an object ref.
The object ref to save the imports result.
Create a Babel visitor that will find out the dependency relationships between root declarations, and save to an object ref.
The object ref to save the relationships
Extract imports, exports, and root declarations relations from an AST
extractStats( parse( fs.readFileSync('esfile.js', 'utf-8'), { sourceType: 'module' plugins: ['jsx'] } ) );
File AST object
Get ES file imports, exports, and root declaration definitions. Example:
fileStats(
fs.readFileSync('esfile.js', 'utf-8'),
{
plugins: ['jsx']
}
);
File content
Options supported by @babel/parser@^7.7.5
Extract declaration names and its alias from AST declaration nodes. This function only handles VariableDeclaration, FunctionDeclaration, ClassDeclaration.
AST node object
A list of objects contain declaration name and alias
Merge multiple @babel/traverse visitor objects into one. Example:
mergeVisitors(
{
Identifier(node) {
console.log(1);
}
},
{
Identifier(node) {
console.log(2);
}
}
);
@babel/traverse visitors
Generated using TypeDoc
es-stats
Find out import, exports and root declarations' dependency relationships of an ES module file.
Quick start
Intalling via npm:
Extract imports, exports, and root declarations' relationship with default settings:
const esStats = require('es-stats'); const fs = require('fs'); const { imports, exports, relations } = esStats( fs.readFileSync('myfile.js', 'utf-8') ); console.log('Imports:', imports); console.log('Exports:', exports); console.log('Relations:', relations);
To support things like
JSX
,flow
,dynamic imports
, etc.. You will need to enable@babel/parser
plugins:const { imports, exports, relations } = esStats( fs.readFileSync('myfile.js', 'utf-8'), { plugins: ['jsx', 'dynamicImport'], } );
Following plugins are enabled on
.js
|.jsx
|.ts
|.tsx
files by default:dynamicImport
classProperties
flowComments
objectRestSpread
functionBind
jsx
flow
(.js and .jsx only)typescript
(.ts and .tsx only)All the options in the 2nd parameter will be passed to
@babel/parser
directly.@babel/parser
options can be found here.