rev-dep 0.2.1 → 0.3.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/cli.js +6 -3
- package/find.js +40 -3
- package/package.json +4 -2
package/cli.js
CHANGED
|
@@ -26,9 +26,10 @@ program
|
|
|
26
26
|
'-tc, --typescriptConfig <path>',
|
|
27
27
|
'path to TypeScript config to enable TS aliases support'
|
|
28
28
|
)
|
|
29
|
-
.action((filePath, entryPoints, data) => {
|
|
29
|
+
.action(async (filePath, entryPoints, data) => {
|
|
30
30
|
const { compactSummary, verbose, webpackConfig, typescriptConfig } = data
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
const results = await find({
|
|
32
33
|
entryPoints,
|
|
33
34
|
filePath,
|
|
34
35
|
verbose,
|
|
@@ -54,13 +55,15 @@ program
|
|
|
54
55
|
} else {
|
|
55
56
|
results.forEach((entryPointResults, index) => {
|
|
56
57
|
entryPointResults.forEach((path) => {
|
|
57
|
-
console.log(path.reduce(pathToString, ''))
|
|
58
|
+
console.log(path.reduce(pathToString, ''), '\n')
|
|
58
59
|
})
|
|
59
60
|
if (index < results.length - 1) {
|
|
60
61
|
console.log('_'.repeat(process.stdout.columns))
|
|
61
62
|
}
|
|
62
63
|
})
|
|
63
64
|
}
|
|
65
|
+
|
|
66
|
+
|
|
64
67
|
})
|
|
65
68
|
|
|
66
69
|
program.parse(process.argv)
|
package/find.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
const getDepsSet = require('./getDepsSet')
|
|
3
|
+
const { parseDependencyTree } = require('dpdm');
|
|
4
|
+
const escapeGlob = require('glob-escape');
|
|
3
5
|
|
|
4
6
|
const buildTree = (deps) => (entryPoint) => {
|
|
5
7
|
const inner = (path) => {
|
|
@@ -21,6 +23,39 @@ const buildTree = (deps) => (entryPoint) => {
|
|
|
21
23
|
return inner(entryPoint)
|
|
22
24
|
}
|
|
23
25
|
|
|
26
|
+
const buildTreeDpdm = (_deps) => (entryPoint) => {
|
|
27
|
+
|
|
28
|
+
const deps = Object.entries(_deps).reduce((deps, [id, data]) => {
|
|
29
|
+
if (!id.includes('node_modules')) {
|
|
30
|
+
return Object.assign({}, deps, { [id]: data ? data.filter(({ id }) => id && !id.includes('node_modules')) : data })
|
|
31
|
+
}
|
|
32
|
+
return deps
|
|
33
|
+
}, {})
|
|
34
|
+
|
|
35
|
+
const inner = (path, visited = new Set()) => {
|
|
36
|
+
if (visited.has(path)) {
|
|
37
|
+
return {
|
|
38
|
+
path,
|
|
39
|
+
children: []
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
visited.add(path);
|
|
43
|
+
const dep = deps[path]
|
|
44
|
+
if (dep === undefined) {
|
|
45
|
+
throw new Error(`Dependency '${path}' not found!`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
path,
|
|
50
|
+
children: (dep || [])
|
|
51
|
+
.map(d => d.id)
|
|
52
|
+
.filter(path => path && !path.includes('node_modules'))
|
|
53
|
+
.map((path) => inner(path, visited))
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return inner(entryPoint)
|
|
57
|
+
}
|
|
58
|
+
|
|
24
59
|
const traverse = (file) => (tree) => {
|
|
25
60
|
if (tree.path === file) {
|
|
26
61
|
return [[file]]
|
|
@@ -40,7 +75,7 @@ const removeInitialDot = (path) => path.replace(/^\.\//, '')
|
|
|
40
75
|
|
|
41
76
|
const _resolveAbsolutePath = (cwd) => (p) => typeof p === 'string' ? path.resolve(cwd, p) : p
|
|
42
77
|
|
|
43
|
-
const find = ({
|
|
78
|
+
const find = async ({
|
|
44
79
|
entryPoints,
|
|
45
80
|
filePath,
|
|
46
81
|
skipRegex,
|
|
@@ -51,24 +86,26 @@ const find = ({
|
|
|
51
86
|
}) => {
|
|
52
87
|
const resolveAbsolutePath = _resolveAbsolutePath(cwd)
|
|
53
88
|
const absoluteEntryPoints = entryPoints.map(resolveAbsolutePath)
|
|
89
|
+
const globEscapedEntryPoints = entryPoints.map(escapeGlob);
|
|
54
90
|
|
|
55
91
|
if (verbose) {
|
|
56
92
|
console.log('Entry points:')
|
|
57
93
|
console.log(absoluteEntryPoints)
|
|
58
94
|
console.log('Getting dependency set for entry points...')
|
|
59
95
|
}
|
|
60
|
-
const deps = getDepsSet(
|
|
96
|
+
const deps = typescriptConfig ? await parseDependencyTree(globEscapedEntryPoints, { context: process.cwd() }) : getDepsSet(
|
|
61
97
|
absoluteEntryPoints,
|
|
62
98
|
skipRegex,
|
|
63
99
|
resolveAbsolutePath(webpackConfig),
|
|
64
100
|
resolveAbsolutePath(typescriptConfig)
|
|
65
101
|
)
|
|
102
|
+
|
|
66
103
|
const cleanedEntryPoints = entryPoints.map(removeInitialDot)
|
|
67
104
|
const cleanedFilePath = removeInitialDot(filePath)
|
|
68
105
|
if (verbose) {
|
|
69
106
|
console.log('Building dependency trees for entry points...')
|
|
70
107
|
}
|
|
71
|
-
const forest = cleanedEntryPoints.map(buildTree(deps))
|
|
108
|
+
const forest = cleanedEntryPoints.map(typescriptConfig ? buildTreeDpdm(deps) : buildTree(deps))
|
|
72
109
|
if (verbose) {
|
|
73
110
|
console.log('Finding paths in dependency trees...')
|
|
74
111
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rev-dep",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Reverse dependency resolution tool built with dependency-cruiser",
|
|
5
5
|
"main": "find.js",
|
|
6
6
|
"bin": "cli.js",
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"commander": "^6.1.0",
|
|
33
|
-
"dependency-cruiser": "9.23.0"
|
|
33
|
+
"dependency-cruiser": "9.23.0",
|
|
34
|
+
"dpdm": "^3.8.0",
|
|
35
|
+
"glob-escape": "^0.0.2"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"eslint": "^7.11.0",
|