🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

detective-cjs

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detective-cjs

Get the dependencies of a CommonJS module by traversing its AST

latest
Source
npmnpm
Version
6.1.1
Version published
Weekly downloads
4.3M
-0.03%
Maintainers
3
Weekly downloads
 
Created
Source

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 });
  • Supports JSX, ES7, and any other features that node-source-walk supports.

License

MIT

Keywords

detective

FAQs

Package last updated on 20 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts