Get the dependencies of a CommonJS module by traversing its AST
npm install detective-cjsBut dude, substack already built this: node-detective. Yes, but I needed the capability to reuse an AST and this was unlikely to be merged timely. I can also support jsx and other syntactic constructs faster.
constfs=require('fs');constdetective=require('detective-cjs');constmySourceCode=fs.readFileSync('myfile.js','utf8');// Pass in a file's content or an ASTconstdependencies=detective(mySourceCode);- Supports JSX, ES7, and any other features that node-source-walk supports.