detective-cjs

Get the dependencies of a CommonJS module by traversing its AST

MIT 22 个版本
安装
npm install detective-cjs
yarn add detective-cjs
pnpm add detective-cjs
bun add detective-cjs
README

detective-cjs

CI npm version npm downloads

Get the dependencies of a CommonJS module by traversing its AST

npm install detective-cjs

But 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.

Usage

const fs = require('fs');
const detective = require('detective-cjs');

const mySourceCode = fs.readFileSync('myfile.js', 'utf8');

// Pass in a file's content or an AST
const dependencies = detective(mySourceCode);

// Use skipLazyLoaded to only include top-level requires,
// treating inline (lazy-loaded) requires as intentional and legal
const topLevelOnly = detective(mySourceCode, { skipLazyLoaded: true });

License

MIT

版本列表
7.0.0 2026-05-19
6.1.1 2026-04-20
6.1.0 2026-03-03
6.0.1 2025-02-01
6.0.0 2024-04-14
5.0.1 2023-05-05
5.0.0 2023-05-05
4.1.0 2023-03-19
4.0.0 2022-03-03
3.1.3 2022-02-22
3.1.2 2022-02-21
3.1.1 2018-10-04
3.1.0 2018-09-25
3.0.0 2018-09-03
2.0.1 2018-08-24
2.0.0 2016-06-16
1.0.5 2015-10-24
1.0.4 2015-07-04
1.0.3 2015-06-27
1.0.2 2015-01-08
1.0.1 2014-12-14
1.0.0 2014-12-14