detective-amd is a JavaScript utility for statically analyzing JavaScript files or Abstract Syntax Trees (ASTs) to identify dependencies declared using various AMD (Asynchronous Module Definition) module syntaxes. It supports the four core AMD forms ('named', 'dependency list', 'factory', 'no dependencies'), as well as 'driver script' (`require([deps], func)`) and CommonJS-like 'REM' forms (`define(function(require, exports, module) {})`). The package also handles dynamically loaded dependencies and JSX code through `node-source-walk`. The current stable version is 6.0.1. While not on a fixed release schedule, it sees updates to maintain compatibility with modern Node.js versions and dependencies, with major versions primarily driven by Node.js LTS support drops. Its key differentiator is its specialized focus on AMD syntax, offering a robust solution for environments still leveraging RequireJS or similar AMD loaders, distinguishing it from general-purpose CommonJS or ESM dependency analysis tools.
npm install detective-amdVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to synchronously extract AMD dependencies from source code, including standard `define` calls, `require` driver scripts, and expression-based requires.
Upgrade your Node.js environment to version 18 or higher. If unable to upgrade Node.js, remain on `detective-amd@5.x`.
Upgrade your Node.js environment to version 14 or higher (or 18+ for v6+). If unable to upgrade Node.js, remain on `detective-amd@4.x`.
Be aware that dynamically resolved paths cannot be fully analyzed statically. Manual inspection or runtime analysis might be needed for these cases.
In an ESM context, use a dynamic import: `const detectiveModule = await import('detective-amd'); const detective = detectiveModule.default;`This package is CommonJS. If you are in an ES module context (e.g., `"type": "module"` in package.json), you must use dynamic `import()` to load it: `const detectiveModule = await import('detective-amd'); const detective = detectiveModule.default;`Ensure the source code being passed to `detective-amd` exclusively uses AMD or older JavaScript syntax. If you need to detect ES module dependencies, use a different package designed for ESM analysis.
When using `await import('detective-amd')` in ESM, the main function is accessed via the `.default` property: `const detectiveModule = await import('detective-amd'); const detective = detectiveModule.default;`