{"name":"detective-amd","version":"4.1.0","description":"Find all dependencies within a JavaScript file using AMD module syntax","main":"index.js","bin":{"detective-amd":"bin/cli.js"},"scripts":{"lint":"eslint bin index.js \"test/*.js\"","fix":"npm run lint -- --fix","mocha":"mocha","test":"npm run lint && npm run mocha","test:ci":"c8 npm run mocha"},"repository":{"type":"git","url":"git+https://github.com/dependents/node-detective-amd.git"},"keywords":["amd","detective","dependencies","ast","static analysis","requirejs","jsx","module"],"author":{"name":"Joel Kemp","email":"joel@mrjoelkemp.com"},"license":"MIT","bugs":{"url":"https://github.com/dependents/node-detective-amd/issues"},"homepage":"https://github.com/dependents/node-detective-amd","engines":{"node":">=12"},"dependencies":{"ast-module-types":"^4.0.0","escodegen":"^2.0.0","get-amd-module-type":"^4.1.0","node-source-walk":"^5.0.1"},"devDependencies":{"c8":"^7.13.0","eslint":"^8.36.0","mocha":"^9.2.2"},"gitHead":"d90c6d44c21ec3ba1c27bc9cdbec2324f1b79441","_id":"detective-amd@4.1.0","_nodeVersion":"18.15.0","_npmVersion":"9.5.0","dist":{"integrity":"sha512-XlQrGjGEnMFjKbep0/S/T7XICxf25LFMP6Ug+Iw/Ww/MHUBzfy8QETCzamO1JlAMYPmkChDh21/NS/csG0FwGg==","shasum":"d3402df4d06a1e7078965482d120a85095147746","tarball":"http://registry-npm.ywwl.com/detective-amd/download/detective-amd-4.1.0.tgz","fileCount":5,"unpackedSize":9295,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH9I5OurANj5k7JTBvgXaoMZru4ehV57b5MhL8tjx2OZAiBJcOb2qipPRTzOmvyBI73En4sdGrHG0ZpfKEZiUQsGtA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkFr7NACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrU3w//Vskcu+mpJdIZawtCeDYt/ZIMWypCFktyF2XyaXO4N7Epcs1c\r\nnCFr/vp9t0J3jMGTSB7qVAOfkzfnVaHZp5beawqDe9gfpqwnMeMeriuoEZ6b\r\nEDkLmqNhtR4QRoZteC1/n7B3ftN9wp7+DI3tOv+qgXLiWMspx+XvMRsiD5p0\r\nd3/vux4pTrz8+ZtfMsEgmKK+KtwCOMtHi8iFRo5l41b+djnHpy4zaYpU6KN7\r\nPYd+GcqatwwHzC4hlvtXkRDx0C1WmwK6VSCFgWxvRUrbrN7rfbIt2QYr9Vu8\r\nl3NSa76jneUQWy5gnhPBLGm1Yhhu8T1zvobtuPL8yUm/CSzWemp2B94PutQK\r\nOjDWXJqlOG27Utw3PuzBY6JD0M5hivcIitC3/C5Q8nTTguw14BDyvf304aqF\r\npENm+M+oXO+0PG09qiLZIrj66fgm/Hp4pbn9dfft27L1uSFnf2zGvgJ/1tT8\r\nOmiVtf2DLsj35WS9rio8zW4ig28GOdob/HjJTw60kggkFQULtZUOoHPsdoCg\r\nPyB/ELGebOvb3+c8+Evh5sjBXLvcYKWTyZC1nhA72yIsXm9rQnNb2jC+LzdL\r\nj2CJA6RkU6X0F0ehYBlP9fnnMycfXc8VF3KecbEwnEAD+vR1nhWyy2vhIRS6\r\nCf45g7ee3LB+RmLcDdLU68nNEnISPqsvfIE=\r\n=w9Vv\r\n-----END PGP SIGNATURE-----\r\n","size":3876,"noattachment":false,"key":"/detective-amd/-/detective-amd-4.1.0.tgz"},"_npmUser":{"name":"xhmikosr","email":"xhmikosr@gmail.com"},"directories":{},"maintainers":[{"name":"pahen","email":"patrik.henningsson@gmail.com"},{"name":"xhmikosr","email":"xhmikosr@gmail.com"},{"name":"mrjoelkemp","email":"mrjoelkemp@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/detective-amd_4.1.0_1679212236848_0.15207171615537174"},"_hasShrinkwrap":false,"readme":"# detective-amd\n\n[![CI](https://img.shields.io/github/actions/workflow/status/dependents/node-detective-amd/ci.yml?branch=main&label=CI&logo=github)](https://github.com/dependents/node-detective-amd/actions/workflows/ci.yml?query=branch%3Amain)\n[![npm version](https://img.shields.io/npm/v/detective-amd?logo=npm&logoColor=fff)](https://www.npmjs.com/package/detective-amd)\n[![npm downloads](https://img.shields.io/npm/dm/detective-amd)](https://www.npmjs.com/package/detective-amd)\n\nReturns a list of dependencies for a given JavaScript file or AST using any of the AMD module syntaxes.\n\n*Inspired by substack/node-detective but built for AMD.*\n\n```sh\nnpm install detective-amd\n```\n\n* Supports JSX code via [node-source-walk](https://github.com/dependents/node-source-walk).\n\n## Usage\n\nLet's say we have the following file definitions:\n\n```js\n\n// a.js\ndefine(['./b', './c'], function (b, c) {\n  console.log(b, c);\n});\n\n// b.js\ndefine({\n  name: 'foo'\n});\n\n// c.js\ndefine(function () {\n  return 'bar';\n});\n\n```\n\nHere's how you can grab the list of dependencies of `a.js` **synchronously**.\n\n```js\nconst fs = require('fs');\nconst detective = require('detective-amd');\n\nconst srcA = fs.readFileSync('a.js', 'utf8');\n\n// Pass in the source code or an AST (if you've already parsed the file)\nconsole.log(detective(srcA)); // prints ['./b', './c']\n```\n\nYou may also (optionally) configure the detective via a second object argument `detective(src, options)` that supports the following options:\n\n* `skipLazyLoaded`: (Boolean) whether or not to omit inner requires in the list of extracted dependencies.\n  * Note: this does not affect the REM form since those inner requires are not \"lazily\" fetched.\n\n## Syntax Support\n\n**Supports the 4 forms of AMD module syntax:**\n\n* \"named\": `define('name', [deps], func)`\n* \"dependency list\": `define([deps], func)`\n* \"factory\": `define(func(require))`\n* \"no dependencies\": `define({})`\n\n**Extra forms:**\n\n* \"driver script\" (or entry-point) syntax: `require([deps], func)`\n* \"REM\" (or CommonJS-like) form: `define(function(require, exports, module) {})`.\n\nAlso handles dynamically loaded dependencies (ex: inner requires).\n\n**Supports driver scripts**\n\nYou can also find the dependencies from a script that has a top-level require (an app initialization/driver/entry-point script):\n\n```js\nrequire([\n  './a'\n], function (a) {\n  // My app will get booted up from here\n});\n```\n\n**Expression-based requires**\n\nIf there's a require call that doesn't have a string literal but an expression, a string (escodegen-generated) representation will be returned.\n\nFor example, if `a.js` was of the \"factory\" form and contained a dynamic module name:\n\n```js\n// a.js\n\ndefine(function (require) {\n  // Assume str is some variable that gets set to a string dynamically\n  // const str = ...\n\n  const b = require('./' + str);\n  const c = require('./c');\n\n  console.log(b, c);\n});\n```\n\nThe dependency list will be: `[ '\\'./\\' + str', './c' ]`\n\n* Even though that string representation isn't incredibly useful, it's still added to the list to represent/count that dependency\n\n## License\n\n[MIT](LICENSE)\n","publish_time":1679212237007,"_cnpm_publish_time":1679212237007,"dist-tags":{"latest":"7.0.0"}}