You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Drop Node.js < 14 support
* Remove debug dependency
* Fix tests on Windows
* Switch to GitHub Actions CI
* Add c8 for coverage
* Update dependencies
* Remove rewire and esm, update mocha and switch to ESM for tests
* Works for JS (AMD, CommonJS, ES6 modules), Typescript, and CSS preprocessors (CSS (PostCSS), Sass, Stylus, and Less); basically, any module type supported by [Precinct](https://github.com/mrjoelkemp/node-precinct).
13
+
* Works for JS (AMD, CommonJS, ES6 modules), Typescript, and CSS preprocessors (CSS (PostCSS), Sass, Stylus, and Less); basically, any module type supported by [Precinct](https://github.com/dependents/node-precinct).
8
14
- For CommonJS modules, 3rd party dependencies (npm installed dependencies) are included in the tree by default
9
-
- Dependency path resolutions are handled by [filing-cabinet](https://github.com/mrjoelkemp/node-filing-cabinet)
15
+
- Dependency path resolutions are handled by [filing-cabinet](https://github.com/dependents/node-filing-cabinet)
10
16
- Supports RequireJS and Webpack loaders
11
17
* All core Node modules (assert, path, fs, etc) are removed from the dependency list by default
12
18
13
-
###Usage
19
+
## Usage
14
20
15
21
```js
16
-
var dependencyTree =require('dependency-tree');
22
+
constdependencyTree=require('dependency-tree');
17
23
18
24
// Returns a dependency tree object for the given file
// Returns a post-order traversal (list form) of the tree with duplicate sub-trees pruned.
34
40
// This is useful for bundling source files, because the list gives the concatenation order.
35
41
// Note: you can pass the same arguments as you would to dependencyTree()
36
-
var list =dependencyTree.toList({
42
+
constlist=dependencyTree.toList({
37
43
filename:'path/to/a/file',
38
44
directory:'path/to/all/files'
39
45
});
40
46
```
41
47
42
-
####Options
48
+
### Options
43
49
44
50
*`requireConfig`: path to a requirejs config for AMD modules (allows for the result of aliased module paths)
45
51
*`webpackConfig`: path to a webpack config for aliased modules
@@ -54,7 +60,7 @@ var list = dependencyTree.toList({
54
60
- See [precinct's usage docs](https://github.com/dependents/node-precinct#usage) for the list of module types you can pass options to.
55
61
*`noTypeDefinitions`: For TypeScript imports, whether to resolve to `*.js` instead of `*.d.ts`.
56
62
57
-
####Format Details
63
+
### Format Details
58
64
59
65
The object form is a mapping of the dependency tree to the filesystem –
60
66
where every key is an absolute filepath and the value is another object/subtree.
@@ -79,7 +85,7 @@ Example:
79
85
This structure was chosen to serve as a visual representation of the dependency tree
80
86
for use in the [Dependents](https://github.com/mrjoelkemp/sublime-dependents) plugin.
81
87
82
-
#####CLI version
88
+
### CLI version
83
89
84
90
* Assumes a global install: `npm install -g dependency-tree`
85
91
@@ -91,9 +97,9 @@ Prints the dependency tree of the given filename as stringified json (by default
91
97
92
98
* You can alternatively print out the list form one element per line using the `--list-form` option.
93
99
94
-
###How does this work?
100
+
## How does this work?
95
101
96
-
Dependency tree takes in a starting file, extracts its declared dependencies via [precinct](https://github.com/dependents/node-precinct/), resolves each of those dependencies to a file on the filesystem via [filing-cabinet](https://github.com/dependents/node-filing-cabinet), then recursively performs those steps until there are no more dependencies to process.
102
+
Dependency tree takes in a starting file, extracts its declared dependencies via [precinct](https://github.com/dependents/node-precinct/), resolves each of those dependencies to a file on the filesystem via [filing-cabinet](https://github.com/dependents/node-filing-cabinet), then recursively performs those steps until there are no more dependencies to process.
97
103
98
104
In more detail, the starting file is passed to precinct to extract dependencies. Dependency-tree doesn't care about how to extract dependencies, so it delegates that work to precinct: which is a multi-language dependency extractor; we'll focus on JavaScript tree generation for this example. To do the extraction, precinct delegates the abstract-syntax-tree (AST) generation to the default parser for [node-source-walk](https://github.com/dependents/node-source-walk). Precinct uses the AST to determine what type of JS module the file is (Commonjs, AMD, or ES6) and then delegates to the "detective" that's appropriate for that module type. The "detective" contains the logic for how to extract dependencies based on the module syntax format; i.e., the way dependencies are declared in commonjs is different than in AMD (which has 4 ways of doing that, for example).
99
105
@@ -105,13 +111,13 @@ So after the appropriate resolver finds the file on the filesystem, filing-cabin
105
111
106
112
At the end of traversing every file (in a depth-first fashion), we have a fully populated dependency tree. :dancers:
107
113
108
-
###FAQ
114
+
## FAQ
109
115
110
-
####Why aren't some some dependencies being detected?
116
+
### Why aren't some some dependencies being detected?
111
117
112
118
If there are bugs in [precinct](https://github.com/dependents/node-precinct) or if the `requireConfig`/`webpackConfig`/`tsConfig` options are incomplete,
113
119
some dependencies may not be resolved. The optional array passed to the `nonExistent` option will be populated with paths
114
120
that could not be resolved. You can check this array to see where problems might exist.
115
121
116
-
You can also use the `DEBUG=*` env variable along with the cli version to see debugging information explaining where resolution went wrong.
0 commit comments