dependency-tree 7.2.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,7 +26,8 @@ var tree = dependencyTree({
26
26
  entry: 'module'
27
27
  }, // optional
28
28
  filter: path => path.indexOf('node_modules') === -1, // optional
29
- nonExistent: [] // optional
29
+ nonExistent: [], // optional
30
+ noTypeDefinitions: false // optional
30
31
  });
31
32
 
32
33
  // Returns a post-order traversal (list form) of the tree with duplicate sub-trees pruned.
@@ -49,8 +50,9 @@ var list = dependencyTree.toList({
49
50
  * `filter`: a function used to determine if a module (and its subtree) should be included in the dependency tree
50
51
  - The first argument given to the filter is an absolute filepath to the dependency and the second is the filepath to the currently traversed file. Should return a `Boolean`. If it returns `true`, the module is included in the resulting tree.
51
52
  * `detective`: object with configuration specific to detectives used to find dependencies of a file
52
- - for example `detective.amd.skipLazyLoaded: true` tells the AMD detective to omit inner requires
53
- - See [precinct's usage docs](https://github.com/dependents/node-precinct#usage) for the list of module types you can pass options to.
53
+ - for example `detective.amd.skipLazyLoaded: true` tells the AMD detective to omit inner requires
54
+ - See [precinct's usage docs](https://github.com/dependents/node-precinct#usage) for the list of module types you can pass options to.
55
+ * `noTypeDefinitions`: For TypeScript imports, whether to resolve to `*.js` instead of `*.d.ts`.
54
56
 
55
57
  #### Format Details
56
58
 
package/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ declare namespace dependencyTree {
2
+ interface TreeInnerNode {
3
+ [parent: string]: TreeInnerNode | string;
4
+ }
5
+ type Tree = TreeInnerNode | string;
6
+
7
+ interface Options {
8
+ filename: string;
9
+ directory: string;
10
+ visited?: Tree;
11
+ nonExistent?: string[];
12
+ isListForm?: boolean;
13
+ requireConfig?: string;
14
+ webpackConfig?: string;
15
+ nodeModulesConfig?: any;
16
+ detectiveConfig?: any;
17
+ tsConfig?: string | Record<string, any>;
18
+ noTypeDefinitions?: boolean;
19
+ filter?: (path: string) => boolean;
20
+ }
21
+
22
+ interface Config extends Options {
23
+ clone: () => Config;
24
+ }
25
+
26
+ function toList (options: Options): string[];
27
+ function _getDependencies (config: Config): string[];
28
+ }
29
+
30
+ declare function dependencyTree (options: dependencyTree.Options): dependencyTree.Tree;
31
+
32
+ export = dependencyTree;
package/index.js CHANGED
@@ -22,6 +22,7 @@ const Config = require('./lib/Config');
22
22
  * @param {Array} [options.nonExistent] - List of partials that do not exist
23
23
  * @param {Boolean} [options.isListForm=false]
24
24
  * @param {String|Object} [options.tsConfig] Path to a typescript config (or a preloaded one).
25
+ * @param {Boolean} [options.noTypeDefinitions] For TypeScript imports, whether to resolve to `*.js` instead of `*.d.ts`.
25
26
  * @return {Object}
26
27
  */
27
28
  module.exports = function(options) {
@@ -109,7 +110,8 @@ module.exports._getDependencies = function(config) {
109
110
  config: config.requireConfig,
110
111
  webpackConfig: config.webpackConfig,
111
112
  nodeModulesConfig: config.nodeModulesConfig,
112
- tsConfig: config.tsConfig
113
+ tsConfig: config.tsConfig,
114
+ noTypeDefinitions: config.noTypeDefinitions
113
115
  });
114
116
 
115
117
  if (!result) {
package/lib/Config.js CHANGED
@@ -15,6 +15,7 @@ class Config {
15
15
  this.nodeModulesConfig = options.nodeModulesConfig;
16
16
  this.detectiveConfig = options.detective || options.detectiveConfig || {};
17
17
  this.tsConfig = options.tsConfig;
18
+ this.noTypeDefinitions = options.noTypeDefinitions;
18
19
 
19
20
  this.filter = options.filter;
20
21
 
@@ -22,6 +23,14 @@ class Config {
22
23
  if (!this.directory) { throw new Error('directory not given'); }
23
24
  if (this.filter && typeof this.filter !== 'function') { throw new Error('filter must be a function'); }
24
25
 
26
+ if ('string' === typeof this.tsConfig) {
27
+ debug('preparsing the ts config into an object for performance');
28
+ const ts = require('typescript');
29
+ const tsParsedConfig = ts.readJsonConfigFile(this.tsConfig, ts.sys.readFile);
30
+ const obj = ts.parseJsonSourceFileConfigFileContent(tsParsedConfig, ts.sys, path.dirname(this.tsConfig));
31
+ this.tsConfig = obj.raw;
32
+ }
33
+
25
34
  debug('given filename: ' + this.filename);
26
35
 
27
36
  this.filename = path.resolve(process.cwd(), this.filename);
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "dependency-tree",
3
- "version": "7.2.0",
3
+ "version": "8.1.0",
4
4
  "description": "Get the dependency tree of a module",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "scripts": {
7
- "test": "jscs index.js test/test.js && ./node_modules/.bin/mocha --require @babel/register test/test.js"
8
+ "test": "jscs index.js test/test.js && ./node_modules/.bin/mocha --require esm test/test.js"
8
9
  },
9
10
  "bin": {
10
11
  "dependency-tree": "bin/cli.js"
@@ -34,26 +35,24 @@
34
35
  "url": "https://github.com/mrjoelkemp/node-dependency-tree/issues"
35
36
  },
36
37
  "engines": {
37
- "node": ">=6.0.0"
38
+ "node": "^10.13 || ^12 || >=14"
38
39
  },
39
40
  "homepage": "https://github.com/mrjoelkemp/node-dependency-tree",
40
41
  "dependencies": {
41
- "commander": "^2.19.0",
42
- "debug": "^4.1.1",
43
- "filing-cabinet": "^2.5.1",
44
- "precinct": "^6.2.0"
42
+ "commander": "^2.20.3",
43
+ "debug": "^4.3.1",
44
+ "filing-cabinet": "^3.0.0",
45
+ "precinct": "^7.0.0",
46
+ "typescript": "^3.9.7"
45
47
  },
46
48
  "devDependencies": {
47
- "@babel/cli": "^7.2.3",
48
- "@babel/core": "^7.2.2",
49
- "@babel/preset-env": "^7.2.3",
50
- "@babel/register": "^7.0.0",
49
+ "esm": "^3.2.25",
51
50
  "jscs": "^3.0.7",
52
51
  "jscs-preset-mrjoelkemp": "~2.0.0",
53
- "mocha": "^5.0.0",
54
- "mock-fs": "^4.7.0",
55
- "resolve": "^1.9.0",
56
- "rewire": "^4.0.1",
57
- "sinon": "^6.1.5"
52
+ "mocha": "^8.2.1",
53
+ "mock-fs": "^4.13.0",
54
+ "resolve": "^1.19.0",
55
+ "rewire": "^5.0.0",
56
+ "sinon": "^9.2.1"
58
57
  }
59
58
  }
package/.node-version DELETED
@@ -1 +0,0 @@
1
- 8.16.2