{"name":"dependency-tree","version":"11.1.0","keywords":["dependency","tree","graph","module","ast","requirejs","AMD","commonjs","es6","sass","stylus","less","typescript"],"author":{"name":"Joel Kemp","email":"joel@mrjoelkemp.com"},"license":"MIT","_id":"dependency-tree@11.1.0","maintainers":[{"name":"pahen","email":"patrik.henningsson@gmail.com"},{"name":"mrjoelkemp","email":"mrjoelkemp@gmail.com"},{"name":"xhmikosr","email":"xhmikosr@gmail.com"}],"homepage":"https://github.com/dependents/node-dependency-tree","bugs":{"url":"https://github.com/dependents/node-dependency-tree/issues"},"xo":{"rules":{"curly":["error","multi-line"],"camelcase":["error",{"properties":"never"}],"comma-dangle":["error","never"],"prefer-template":"error","arrow-body-style":"off","operator-linebreak":["error","after"],"capitalized-comments":"off","object-curly-spacing":["error","always"],"unicorn/prefer-module":"off","space-before-function-paren":["error","never"],"unicorn/prevent-abbreviations":"off","unicorn/prefer-top-level-await":"off","unicorn/no-anonymous-default-export":"off"},"space":true,"ignores":["index.d.ts","test/fixtures/*"]},"bin":{"dependency-tree":"bin/cli.js"},"dist":{"shasum":"910490f397fa936a95da072c64a5ccf136a0a588","tarball":"http://registry-npm.ywwl.com/dependency-tree/download/dependency-tree-11.1.0.tgz","fileCount":7,"integrity":"sha512-Qu3zvy2JrcSFtvB1gf1iVnbm+PWoVtTKxgs5Lc6+QCs8FPkxe8ezAVnp8O6a2/qMg0yrVNdy2f7oV4DsVUJdUA==","signatures":[{"sig":"MEQCIHAK7pCTwLHyk3oDarDGA2L7kaIITOWQQynxZntdwxgsAiB5ReyVY0P3qf5GiwMQrAwtkK4McBddY4PGtAua9IecfQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":21078,"size":7385,"noattachment":false,"key":"/dependency-tree/-/dependency-tree-11.1.0.tgz"},"main":"index.js","types":"index.d.ts","engines":{"node":">=18"},"gitHead":"f4f3844ca504ff148ec2c32d7b79c996dbd10ad8","scripts":{"fix":"xo --fix","lint":"xo","test":"npm run lint && npm run mocha","mocha":"mocha","test:ci":"c8 npm run mocha"},"_npmUser":{"name":"xhmikosr","email":"xhmikosr@gmail.com"},"repository":{"url":"git+https://github.com/dependents/node-dependency-tree.git","type":"git"},"_npmVersion":"10.8.2","description":"Get the dependency tree of a module","directories":{},"_nodeVersion":"20.18.2","dependencies":{"precinct":"^12.2.0","commander":"^12.1.0","typescript":"^5.7.3","filing-cabinet":"^5.0.3"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.3","xo":"^0.60.0","debug":"^4.4.0","mocha":"^11.1.0","sinon":"^19.0.2","mock-fs":"^5.4.1","resolve":"^1.22.10"},"_npmOperationalInternal":{"tmp":"tmp/dependency-tree_11.1.0_1738859795035_0.9967436080594905","host":"s3://npm-registry-packages-npm-production"},"readme":"# dependency-tree\n\n[![CI](https://img.shields.io/github/actions/workflow/status/dependents/node-dependency-tree/ci.yml?branch=main&label=CI&logo=github)](https://github.com/dependents/node-dependency-tree/actions/workflows/ci.yml?query=branch%3Amain)\n[![npm version](https://img.shields.io/npm/v/dependency-tree?logo=npm&logoColor=fff)](https://www.npmjs.com/package/dependency-tree)\n[![npm downloads](https://img.shields.io/npm/dm/dependency-tree)](https://www.npmjs.com/package/dependency-tree)\n\n> Get the dependency tree of a module\n\n```sh\nnpm install dependency-tree\n```\n\n* Supports JS (AMD, CommonJS, ES6), TypeScript, and CSS preprocessors (PostCSS, Sass, Stylus, Less) - any type handled by [precinct](https://github.com/dependents/node-precinct)\n  - CommonJS: third-party (npm) dependencies are included by default\n  - Path resolution is handled by [filing-cabinet](https://github.com/dependents/node-filing-cabinet); RequireJS and webpack loaders are supported\n* Core Node built-ins (assert, path, fs, etc.) are excluded by default\n\n## Usage\n\n```js\n// ESM\nimport dependencyTree from 'dependency-tree';\n// CommonJS\nconst { default: dependencyTree } = require('dependency-tree');\n\n// Returns a nested dependency tree object for the given file\nconst tree = dependencyTree({\n  filename: 'path/to/a/file',\n  directory: 'path/to/all/files',\n  requireConfig: 'path/to/requirejs/config', // optional\n  webpackConfig: 'path/to/webpack/config', // optional\n  tsConfig: 'path/to/typescript/config', // optional\n  nodeModulesConfig: {\n    entry: 'module'\n  }, // optional\n  filter: (dependencyPath, parentPath) => !dependencyPath.includes('node_modules'), // optional\n  nonExistent: [], // optional\n  noTypeDefinitions: false // optional\n});\n\n// Returns a post-order flat list of absolute paths (dependencies before dependents).\n// Useful as a concatenation order for bundling.\nconst list = dependencyTree.toList({\n  filename: 'path/to/a/file',\n  directory: 'path/to/all/files'\n});\n```\n\n### Options\n\n| Option | Type | Default | Description |\n|---|---|---|---|\n| `filename` | `string` | - | **Required.** Absolute path to the entry file |\n| `directory` | `string` | - | **Required.** Root directory used to resolve relative paths |\n| `root` | `string` | `undefined` | Alias for `directory` |\n| `requireConfig` | `string` | `undefined` | Path to a RequireJS config for AMD modules (resolves aliased paths) |\n| `config` | `string` | `undefined` | Alias for `requireConfig` |\n| `webpackConfig` | `string` | `undefined` | Path to a webpack config for aliased modules |\n| `tsConfig` | `string \\| object` | `undefined` | Path to a TypeScript config file, or a preloaded config object |\n| `tsConfigPath` | `string` | `undefined` | Virtual path for the TypeScript config when `tsConfig` is an object. Required for [Path Mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping); ignored when `tsConfig` is a string path |\n| `nodeModulesConfig` | `object` | `undefined` | Config for resolving `node_modules` entry files (e.g. `{ entry: 'module' }`) |\n| `visited` | `object` | `{}` | Memoization cache (filename to subtree) to skip already-processed files |\n| `nonExistent` | `string[]` | `[]` | Array populated with partial paths that could not be resolved |\n| `isListForm` | `boolean` | `false` | Return a flat post-order list of paths instead of a nested tree (same as calling `dependencyTree.toList()`) |\n| `filter` | `(dependencyPath: string, parentPath: string) => boolean` | `undefined` | Return `true` to include a dependency (and its subtree) in the tree |\n| `detectiveConfig` | `object` | `{}` | Options passed to [precinct](https://github.com/dependents/node-precinct#usage) for dependency extraction - e.g. `{ amd: { skipLazyLoaded: true } }`, `{ ts: { skipTypeImports: true } }` |\n| `detective` | `object` | `{}` | Alias for `detectiveConfig` |\n| `noTypeDefinitions` | `boolean` | `false` | Resolve TypeScript imports to `*.js` instead of `*.d.ts` |\n\n### Output format\n\nThe default output is a nested object where every key is an absolute file path and the value is its own subtree:\n\n```js\n{\n  '/path/to/a.js': {\n    '/path/to/b.js': {\n      '/path/to/d.js': {},\n      '/path/to/e.js': {}\n    },\n    '/path/to/c.js': {\n      '/path/to/f.js': {},\n      '/path/to/g.js': {}\n    }\n  }\n}\n```\n\nThis format was designed for visual representation in the [Dependents](https://github.com/mrjoelkemp/sublime-dependents) plugin.\n\n### CLI\n\nRequires a global install: `npm install -g dependency-tree`\n\n```\ndependency-tree --directory=path/to/files [--list-form] [--es6-mixed-imports] [-c path/to/require/config] [-w path/to/webpack/config] filename\n```\n\nPrints the dependency tree as JSON. Use `--list-form` to print one path per line instead.\n\n## How it works\n\ndependency-tree passes the entry file to [precinct](https://github.com/dependents/node-precinct/) to extract raw dependency strings, then passes each to [filing-cabinet](https://github.com/dependents/node-filing-cabinet) to resolve them to real filesystem paths, and recurses until the full tree is built.\n\nPrecinct generates an AST via [node-source-walk](https://github.com/dependents/node-source-walk), detects the module format (CommonJS, AMD, or ES6), and delegates to the appropriate detective to extract dependency declarations.\n\nFiling-cabinet reuses that AST to detect the module format again, then delegates to the right resolver - necessary because AMD supports path aliasing via a RequireJS config, while CommonJS has its own resolution algorithm. The resolver returns an absolute path, which dependency-tree then recurses into.\n\n## FAQ\n\n### Why aren't some dependencies being detected?\n\nBugs in [precinct](https://github.com/dependents/node-precinct) or an incomplete `requireConfig`/`webpackConfig`/`tsConfig` are the most common causes. Any path that could not be resolved is appended to the array passed as `nonExistent`.\n\nFor detailed resolution logs, set `NODE_DEBUG=*` when using the CLI:\n\n```sh\nNODE_DEBUG=* dependency-tree -w path/to/webpack.config.json path/to/a/file\n```\n","publish_time":1738859795251,"_cnpm_publish_time":1738859795251,"dist-tags":{"latest":"12.0.1"}}