{"name":"dependency-tree","version":"12.0.1","description":"Get the dependency tree of a module","type":"module","exports":{".":{"types":"./types/index.d.ts","default":"./index.js"}},"bin":{"dependency-tree":"bin/cli.js"},"scripts":{"generate:types":"tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types index.js","check:types":"npm run generate:types && git diff HEAD --exit-code types/index.d.ts","lint":"xo","fix":"xo --fix","vitest":"vitest","test":"npm run lint && npm run check:types && vitest run","test:ci":"vitest run --coverage"},"repository":{"type":"git","url":"git+https://github.com/dependents/node-dependency-tree.git"},"keywords":["dependency","tree","graph","module","ast","requirejs","AMD","commonjs","es6","sass","stylus","less","typescript"],"author":{"name":"Joel Kemp","email":"joel@mrjoelkemp.com"},"license":"MIT","bugs":{"url":"https://github.com/dependents/node-dependency-tree/issues"},"homepage":"https://github.com/dependents/node-dependency-tree","engines":{"node":">=20.19.0 || >=22.12.0"},"dependencies":{"@discoveryjs/json-ext":"^1.1.0","commander":"^14.0.3","filing-cabinet":"^6.0.0","precinct":"^13.0.0","typescript":"^6.0.3"},"devDependencies":{"@vitest/coverage-v8":"^4.1.7","debug":"^4.4.3","vitest":"^4.1.7","xo":"^2.0.2"},"gitHead":"a33fcfad8ecf52629123db3a435fd79a0a8e24f2","_id":"dependency-tree@12.0.1","_nodeVersion":"24.16.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-82JYm4VjLvHC5rDYNIhLtoxaV2aPlB5tlvkXqVVKp/20+Y4lux30lAUoYxhJ5gH/WzeNmYo7IsAOUJtPEYw5Rg==","shasum":"be47c5c590a9eccec9248ff9afec86f03990ecad","tarball":"http://registry-npm.ywwl.com/dependency-tree/download/dependency-tree-12.0.1.tgz","fileCount":8,"unpackedSize":25525,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHH/+fsENmTV/3+/9U4n1A+6o0zd/Un1iZFxPaZcePeWAiEAiT++MeCMk4QZMo+sGdMgNMREo2e5nIflFR+E2knc7sE="}],"size":7368,"noattachment":false,"key":"/dependency-tree/-/dependency-tree-12.0.1.tgz"},"_npmUser":{"name":"xhmikosr","email":"xhmikosr@gmail.com"},"directories":{},"maintainers":[{"name":"pahen","email":"patrik.henningsson@gmail.com"},{"name":"mrjoelkemp","email":"mrjoelkemp@gmail.com"},{"name":"xhmikosr","email":"xhmikosr@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/dependency-tree_12.0.1_1780813048967_0.04475115575922284"},"_hasShrinkwrap":false,"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":1780813049104,"_cnpm_publish_time":1780813049104,"dist-tags":{"latest":"12.0.1"}}