Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
/ babel-visit-cjs-deps Public archive

Babel visitor for extracting CJS dependencies

License

Notifications You must be signed in to change notification settings

jspm/babel-visit-cjs-deps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Babel CJS dependencies extraction plugin

const babylon = require('babylon');
const traverse = require('babel-traverse').default;
const extractCjsDeps = require('babel-visit-cjs-deps');

const resolves = [];
const deps = [];

const ast = babylon.parse(`
require('x');
require('x/' + 'b');
require.resolve('asdf/');
`, { allowReturnOutsideFunction: true });

traverse(ast, extractCjsDeps({ deps, resolves }));

deps;     // ['x', 'x/']
resolves; // ['adsf/']

Currently no support for dynamic requires.

No actual transformations are performed at all.

License

MIT

About

Babel visitor for extracting CJS dependencies

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published