A Babel plugin (versions 5 & 6) that scans the AST for import statements and require() calls, extracting dependency strings and location data. Works with both ESM imports and CommonJS requires, including dynamic expressions. Metadata is stored on the Babel result and can be retrieved via a convenience method. It provides fine-grained filtering via options like `import`, `export`, `require`, and `generated`. Stable version is 2.0.0, which only supports Babel 5/6 (not Babel 7+). Compatible with Node >=0.10.0.
npm install babel-plugin-detectiveVerified import paths — ran on the pinned version, not inferred.
Uses babel-plugin-detective to extract all string module names from import and require statements in a code snippet.
If you need Babel 7, use @babel/traverse with a custom visitor or switch to a different package like detective.
Use Node.js >=12.0.0, but note that the plugin may still work. If it fails, try using @babel/plugin-proposal-detective or a different dependency scanner.
Set import: false and require: true to only capture generated require() calls, or deduplicate manually.
Always pass the result object returned by babel.transform* (e.g., const meta = detective.metadata(transformResult));
Use a static analysis tool like detective (the original) or escodegen to evaluate simple expressions, or accept that dynamic dependencies are not resolved.
Run: npm install babel-core babel-plugin-detective
Use const detective = require('babel-plugin-detective'); instead of import.Upgrade to babel-core version 6.x.x or use a different detective plugin for Babel 7.
No dependency data recorded yet.