rev-dep 1.0.0-alpha.0 → 1.0.0-alpha.1
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 +48 -8
- package/dist/cli/commonOptions.js +9 -1
- package/dist/cli/entryPoints/index.js +19 -5
- package/dist/cli/files/index.js +8 -2
- package/dist/cli/resolve/formatResults.js +35 -7
- package/dist/cli/resolve/index.js +18 -9
- package/dist/lib/cleanupDpdmDeps.js +7 -1
- package/dist/lib/find.js +3 -9
- package/dist/lib/getDepsTree.js +11 -3
- package/dist/lib/getEntryPoints.js +24 -5
- package/dist/lib/getMaxDepthInGraph.js +21 -0
- package/dist/lib/utils.js +8 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ For example, to support `*.ts` and `*.tsx` implicit extensions in globally insta
|
|
|
117
117
|
|
|
118
118
|
### Command `resolve`
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
Checks if a filePath is required from entryPoint(s) and prints the resolution path
|
|
121
121
|
|
|
122
122
|
#### Usage
|
|
123
123
|
|
|
@@ -127,18 +127,58 @@ rev-dep resolve <filePath> [entryPoints...] [options]
|
|
|
127
127
|
|
|
128
128
|
#### Arguments
|
|
129
129
|
|
|
130
|
-
- `filePath` -
|
|
130
|
+
- `filePath` - Path to a file that should be resolved in entry points (**required**),\* `entryPoints...` - List of entry points to look for file (_optional_)
|
|
131
131
|
|
|
132
132
|
#### Options
|
|
133
133
|
|
|
134
|
+
- `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
|
|
135
|
+
- `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
|
|
136
|
+
- `--rr reexportRewire <value>` - resolve actual dependencies for "export \* from" statements (_optional_)
|
|
137
|
+
- `-i include <globs...>` - A list of globs to determine files included in entry points search (_optional_)
|
|
138
|
+
- `-e exclude <globs...>` - A list of globs to determine files excluded in entry points search (_optional_)
|
|
134
139
|
- `-cs, --compactSummary` - print a compact summary of reverse resolution with a count of found paths (_optional_)
|
|
135
|
-
-
|
|
140
|
+
- `-a, --all` - finds all paths combination of a given dependency. Might work very slow or crash for some projects due to heavy usage of RAM (_optional_)
|
|
141
|
+
|
|
142
|
+
### Command `entry-points`
|
|
143
|
+
|
|
144
|
+
Print list of entry points in current directory
|
|
145
|
+
|
|
146
|
+
#### Usage
|
|
147
|
+
|
|
148
|
+
```sh
|
|
149
|
+
rev-dep entry-points [options]
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Options
|
|
153
|
+
|
|
154
|
+
- `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
|
|
155
|
+
- `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
|
|
156
|
+
- `--rr reexportRewire <value>` - resolve actual dependencies for "export \* from" statements (_optional_)
|
|
157
|
+
- `-i include <globs...>` - A list of globs to determine files included in entry points search (_optional_)
|
|
158
|
+
- `-e exclude <globs...>` - A list of globs to determine files excluded in entry points search (_optional_)
|
|
159
|
+
- `-pdc, --printDependenciesCount` - print count of entry point dependencies (_optional_)
|
|
160
|
+
- `-c, --count` - print just count of found entry points (_optional_)
|
|
161
|
+
|
|
162
|
+
### Command `files`
|
|
163
|
+
|
|
164
|
+
Get list of files required by entry point
|
|
165
|
+
|
|
166
|
+
#### Usage
|
|
167
|
+
|
|
168
|
+
```sh
|
|
169
|
+
rev-dep files <entryPoint> [options]
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### Arguments
|
|
173
|
+
|
|
174
|
+
- `entryPoint` - Path to entry point (**required**)
|
|
175
|
+
|
|
176
|
+
#### Options
|
|
177
|
+
|
|
136
178
|
- `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
|
|
137
|
-
-
|
|
138
|
-
-
|
|
139
|
-
- `-
|
|
140
|
-
- `-pdc, --printDependentCount` - print count of entry point dependencies (_optional_)
|
|
141
|
-
- `-co, --checkOnly` - finds only one path to entry point instead of all (_optional_)
|
|
179
|
+
- `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
|
|
180
|
+
- `--rr reexportRewire <value>` - resolve actual dependencies for "export \* from" statements (_optional_)
|
|
181
|
+
- `-c, --count` - print only count of entry point dependencies (_optional_)
|
|
142
182
|
|
|
143
183
|
### Command `docs`
|
|
144
184
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reexportRewireOption = exports.cwdOption = exports.webpackConfigOption = void 0;
|
|
3
|
+
exports.excludeOption = exports.includeOption = exports.reexportRewireOption = exports.cwdOption = exports.webpackConfigOption = void 0;
|
|
4
4
|
exports.webpackConfigOption = [
|
|
5
5
|
'-wc, --webpackConfig <path>',
|
|
6
6
|
'path to webpack config to enable webpack aliases support'
|
|
@@ -14,3 +14,11 @@ exports.reexportRewireOption = [
|
|
|
14
14
|
'--rr reexportRewire <value>',
|
|
15
15
|
'resolve actual dependencies for "export * from" statements'
|
|
16
16
|
];
|
|
17
|
+
exports.includeOption = [
|
|
18
|
+
'-i include <globs...>',
|
|
19
|
+
'A list of globs to determine files included in entry points search'
|
|
20
|
+
];
|
|
21
|
+
exports.excludeOption = [
|
|
22
|
+
'-e exclude <globs...>',
|
|
23
|
+
'A list of globs to determine files excluded in entry points search'
|
|
24
|
+
];
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const commonOptions_1 = require("../commonOptions");
|
|
4
4
|
const getEntryPoints_1 = require("../../lib/getEntryPoints");
|
|
5
5
|
const buildDepsGraph_1 = require("../../lib/buildDepsGraph");
|
|
6
|
+
const utils_1 = require("../../lib/utils");
|
|
6
7
|
function createEntryPoints(program) {
|
|
7
8
|
program
|
|
8
9
|
.command('entry-points')
|
|
@@ -10,19 +11,32 @@ function createEntryPoints(program) {
|
|
|
10
11
|
.option(...commonOptions_1.webpackConfigOption)
|
|
11
12
|
.option(...commonOptions_1.cwdOption)
|
|
12
13
|
.option(...commonOptions_1.reexportRewireOption)
|
|
13
|
-
.option(
|
|
14
|
+
.option(...commonOptions_1.includeOption)
|
|
15
|
+
.option(...commonOptions_1.excludeOption)
|
|
16
|
+
.option('-pdc, --printDependenciesCount', 'print count of entry point dependencies', false)
|
|
17
|
+
.option('-c, --count', 'print just count of found entry points', false)
|
|
14
18
|
.action(async (data) => {
|
|
15
|
-
const { webpackConfig: webpackConfigPath, cwd,
|
|
19
|
+
const { webpackConfig: webpackConfigPath, cwd, printDependenciesCount, include, exclude, count } = data;
|
|
16
20
|
const [entryPoints, depsTree] = await (0, getEntryPoints_1.getEntryPoints)({
|
|
17
|
-
cwd,
|
|
18
|
-
webpackConfigPath
|
|
21
|
+
cwd: (0, utils_1.resolvePath)(cwd),
|
|
22
|
+
webpackConfigPath,
|
|
23
|
+
exclude,
|
|
24
|
+
include
|
|
19
25
|
});
|
|
20
26
|
let depsCount = null;
|
|
21
|
-
if (
|
|
27
|
+
if (printDependenciesCount) {
|
|
22
28
|
depsCount = entryPoints
|
|
23
29
|
.map((0, buildDepsGraph_1.buildGraphDpdm)(depsTree))
|
|
24
30
|
.map(([_, __, vertices]) => vertices.size);
|
|
25
31
|
}
|
|
32
|
+
if (count) {
|
|
33
|
+
console.log('Found', entryPoints.length, 'entry points.');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (entryPoints.length === 0) {
|
|
37
|
+
console.log('No results found');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
26
40
|
entryPoints.forEach((pathName, idx) => {
|
|
27
41
|
if (depsCount !== null) {
|
|
28
42
|
console.log(pathName, depsCount[idx]);
|
package/dist/cli/files/index.js
CHANGED
|
@@ -6,7 +6,9 @@ const getDepsTree_1 = require("../../lib/getDepsTree");
|
|
|
6
6
|
function createFiles(program) {
|
|
7
7
|
program
|
|
8
8
|
.command('files <entryPoint>')
|
|
9
|
-
.description('Get list of files required by entry point'
|
|
9
|
+
.description('Get list of files required by entry point', {
|
|
10
|
+
entryPoint: 'Path to entry point'
|
|
11
|
+
})
|
|
10
12
|
.option(...commonOptions_1.webpackConfigOption)
|
|
11
13
|
.option(...commonOptions_1.cwdOption)
|
|
12
14
|
.option(...commonOptions_1.reexportRewireOption)
|
|
@@ -14,8 +16,12 @@ function createFiles(program) {
|
|
|
14
16
|
.action(async (entryPoint, data) => {
|
|
15
17
|
const { webpackConfig: webpackConfigPath, cwd, count } = data;
|
|
16
18
|
const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)([entryPoint]);
|
|
17
|
-
const depsTree = await (0, getDepsTree_1.getDepsTree)(cwd, sanitizedEntryPoints, webpackConfigPath);
|
|
19
|
+
const depsTree = await (0, getDepsTree_1.getDepsTree)((0, utils_1.resolvePath)(cwd), sanitizedEntryPoints, webpackConfigPath);
|
|
18
20
|
const filePaths = Object.keys(depsTree);
|
|
21
|
+
if (filePaths.length === 0) {
|
|
22
|
+
console.log('No results found');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
19
25
|
if (count) {
|
|
20
26
|
console.log(filePaths.length);
|
|
21
27
|
}
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.formatResults = void 0;
|
|
27
|
+
const colors = __importStar(require("colorette"));
|
|
4
28
|
const pathToString = (str, filePath, indentation) => {
|
|
5
29
|
return `${str ? `${str}\n` : ''}${' '.repeat(indentation)} ➞ ${filePath}`;
|
|
6
30
|
};
|
|
@@ -10,10 +34,10 @@ function formatResults({ results, filePath, entryPoints, compactSummary }) {
|
|
|
10
34
|
const hasAnyResults = results.some((paths) => paths.length > 0);
|
|
11
35
|
if (!hasAnyResults) {
|
|
12
36
|
formatted = join('No results found for', filePath, 'in', entryPoints);
|
|
13
|
-
return;
|
|
37
|
+
return formatted;
|
|
14
38
|
}
|
|
15
|
-
formatted += join('Results:\n');
|
|
16
39
|
if (compactSummary) {
|
|
40
|
+
formatted += join('Results:\n');
|
|
17
41
|
const maxEntryLength = entryPoints.reduce((maxLength, entryPoint) => {
|
|
18
42
|
return entryPoint.length > maxLength ? entryPoint.length : maxLength;
|
|
19
43
|
}, 0);
|
|
@@ -26,11 +50,15 @@ function formatResults({ results, filePath, entryPoints, compactSummary }) {
|
|
|
26
50
|
}
|
|
27
51
|
else {
|
|
28
52
|
results.forEach((entryPointResults, index) => {
|
|
29
|
-
entryPointResults.
|
|
30
|
-
formatted += join(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
53
|
+
if (entryPointResults.length > 0) {
|
|
54
|
+
formatted += join(colors.bold(entryPoints[index]), ':', '\n');
|
|
55
|
+
entryPointResults.forEach((path, resultsIndex) => {
|
|
56
|
+
const isLast = resultsIndex === entryPointResults.length - 1;
|
|
57
|
+
formatted += join(path.reduce(pathToString, ''), isLast ? '' : '\n');
|
|
58
|
+
});
|
|
59
|
+
if (index < results.length - 1 && entryPointResults.length > 0) {
|
|
60
|
+
formatted += join('_'.repeat(process.stdout.columns)) + '\n';
|
|
61
|
+
}
|
|
34
62
|
}
|
|
35
63
|
});
|
|
36
64
|
}
|
|
@@ -3,27 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const find_1 = require("../../lib/find");
|
|
4
4
|
const formatResults_1 = require("./formatResults");
|
|
5
5
|
const utils_1 = require("../../lib/utils");
|
|
6
|
+
const commonOptions_1 = require("../commonOptions");
|
|
6
7
|
function createResolve(program) {
|
|
7
8
|
program
|
|
8
9
|
.command('resolve <filePath> [entryPoints...]')
|
|
9
|
-
.description('Checks if a filePath is required from entryPoint(s) and prints the resolution path'
|
|
10
|
+
.description('Checks if a filePath is required from entryPoint(s) and prints the resolution path', {
|
|
11
|
+
filePath: 'Path to a file that should be resolved in entry points',
|
|
12
|
+
'entryPoints...': 'List of entry points to look for file'
|
|
13
|
+
})
|
|
14
|
+
.option(...commonOptions_1.webpackConfigOption)
|
|
15
|
+
.option(...commonOptions_1.cwdOption)
|
|
16
|
+
.option(...commonOptions_1.reexportRewireOption)
|
|
17
|
+
.option(...commonOptions_1.includeOption)
|
|
18
|
+
.option(...commonOptions_1.excludeOption)
|
|
10
19
|
.option('-cs, --compactSummary', 'print a compact summary of reverse resolution with a count of found paths')
|
|
11
|
-
.option('-
|
|
12
|
-
.option('-pmd, --printMaxDepth', 'print max depth in the tree', false)
|
|
13
|
-
.option('-a, --all', 'finds all paths combination of a given dependency. Might work very slow and tend to crash for some projects', false)
|
|
20
|
+
.option('-a, --all', 'finds all paths combination of a given dependency. Might work very slow or crash for some projects due to heavy usage of RAM', false)
|
|
14
21
|
.action(async (filePath, entryPoints, data) => {
|
|
15
|
-
const { compactSummary, webpackConfig,
|
|
22
|
+
const { compactSummary, webpackConfig, all, cwd, exclude, include } = data;
|
|
16
23
|
const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)(entryPoints);
|
|
17
|
-
const results = await (0, find_1.resolve)({
|
|
24
|
+
const [results, resolveEntryPoints] = await (0, find_1.resolve)({
|
|
18
25
|
entryPoints: sanitizedEntryPoints,
|
|
19
26
|
filePath,
|
|
20
27
|
webpackConfig,
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
all,
|
|
29
|
+
cwd: (0, utils_1.resolvePath)(cwd),
|
|
30
|
+
exclude,
|
|
31
|
+
include
|
|
23
32
|
});
|
|
24
33
|
const formatted = (0, formatResults_1.formatResults)({
|
|
25
34
|
results,
|
|
26
|
-
entryPoints,
|
|
35
|
+
entryPoints: resolveEntryPoints,
|
|
27
36
|
compactSummary,
|
|
28
37
|
filePath
|
|
29
38
|
});
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.cleanupDpdmDeps = void 0;
|
|
7
|
+
const is_builtin_module_1 = __importDefault(require("is-builtin-module"));
|
|
4
8
|
const cleanupDpdmDeps = (deps) => {
|
|
5
9
|
const newDeps = {};
|
|
6
10
|
Object.entries(deps).forEach(([id, dependencies]) => {
|
|
7
|
-
if (!
|
|
11
|
+
if (!(0, is_builtin_module_1.default)(id) &&
|
|
12
|
+
!id.includes('node_modules') &&
|
|
13
|
+
dependencies !== null) {
|
|
8
14
|
newDeps[id] = dependencies
|
|
9
15
|
.filter(({ id }) => id && !id.includes('node_modules'))
|
|
10
16
|
.map(({ id, request }) => ({
|
package/dist/lib/find.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.resolve = void 0;
|
|
|
4
4
|
const buildDepsGraph_1 = require("./buildDepsGraph");
|
|
5
5
|
const getDepsTree_1 = require("./getDepsTree");
|
|
6
6
|
const getEntryPoints_1 = require("./getEntryPoints");
|
|
7
|
-
const getMaxDepthInGrapth_1 = require("./getMaxDepthInGrapth");
|
|
8
7
|
const utils_1 = require("./utils");
|
|
9
8
|
const resolvePathsToRoot = (node, all = false, resolvedPaths = [[]]) => {
|
|
10
9
|
const newPaths = resolvedPaths.map((resolvedPath) => [
|
|
@@ -21,7 +20,7 @@ const resolvePathsToRoot = (node, all = false, resolvedPaths = [[]]) => {
|
|
|
21
20
|
}
|
|
22
21
|
return resolvePathsToRoot(node.parents[0], false, newPaths);
|
|
23
22
|
};
|
|
24
|
-
const resolve = async ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd = process.cwd(),
|
|
23
|
+
const resolve = async ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd = process.cwd(), all, include, exclude }) => {
|
|
25
24
|
let deps, entryPoints;
|
|
26
25
|
if (_entryPoints.length > 0) {
|
|
27
26
|
entryPoints = _entryPoints;
|
|
@@ -29,16 +28,11 @@ const resolve = async ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd
|
|
|
29
28
|
}
|
|
30
29
|
else {
|
|
31
30
|
;
|
|
32
|
-
[entryPoints, deps] = await (0, getEntryPoints_1.getEntryPoints)({ cwd });
|
|
31
|
+
[entryPoints, deps] = await (0, getEntryPoints_1.getEntryPoints)({ cwd, exclude, include });
|
|
33
32
|
}
|
|
34
33
|
const cleanedEntryPoints = entryPoints.map(utils_1.removeInitialDot);
|
|
35
34
|
const cleanedFilePath = (0, utils_1.removeInitialDot)(filePath);
|
|
36
35
|
const forest = cleanedEntryPoints.map((0, buildDepsGraph_1.buildGraphDpdm)(deps, cleanedFilePath));
|
|
37
|
-
if (printMaxDepth) {
|
|
38
|
-
forest.forEach(([tree]) => {
|
|
39
|
-
console.log('Max depth', ...(0, getMaxDepthInGrapth_1.getMaxDepth)()(tree));
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
36
|
const resolvedPaths = forest.reduce((allPaths, [_, fileNode]) => {
|
|
43
37
|
if (!fileNode) {
|
|
44
38
|
return [...allPaths, []];
|
|
@@ -46,6 +40,6 @@ const resolve = async ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd
|
|
|
46
40
|
const pathsForTree = resolvePathsToRoot(fileNode, all);
|
|
47
41
|
return [...allPaths, pathsForTree];
|
|
48
42
|
}, []);
|
|
49
|
-
return resolvedPaths;
|
|
43
|
+
return [resolvedPaths, entryPoints];
|
|
50
44
|
};
|
|
51
45
|
exports.resolve = resolve;
|
package/dist/lib/getDepsTree.js
CHANGED
|
@@ -5,11 +5,19 @@ const getDepsSetWebpack_1 = require("./getDepsSetWebpack");
|
|
|
5
5
|
const dpdm_1 = require("dpdm");
|
|
6
6
|
const cleanupDpdmDeps_1 = require("./cleanupDpdmDeps");
|
|
7
7
|
async function getDepsTree(cwd, entryPoints, webpackConfigPath) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
let deps;
|
|
9
|
+
if (webpackConfigPath) {
|
|
10
|
+
deps = (0, getDepsSetWebpack_1.getDepsSetWebpack)(entryPoints, webpackConfigPath, cwd);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
// dpdm does not support custom search directory :/
|
|
14
|
+
const oldProcessCwd = process.cwd;
|
|
15
|
+
process.cwd = () => cwd;
|
|
16
|
+
deps = (0, cleanupDpdmDeps_1.cleanupDpdmDeps)(await (0, dpdm_1.parseDependencyTree)(entryPoints, {
|
|
11
17
|
context: cwd
|
|
12
18
|
}));
|
|
19
|
+
process.cwd = oldProcessCwd;
|
|
20
|
+
}
|
|
13
21
|
return deps;
|
|
14
22
|
}
|
|
15
23
|
exports.getDepsTree = getDepsTree;
|
|
@@ -9,6 +9,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
const getDepsTree_1 = require("./getDepsTree");
|
|
12
|
+
const ignore_1 = __importDefault(require("ignore"));
|
|
12
13
|
const getDirectoriesForEntryPointsSearch = async (dir) => {
|
|
13
14
|
const entries = await promises_1.default.readdir(dir);
|
|
14
15
|
const directories = await (0, utils_1.asyncFilter)(entries, async (pathName) => {
|
|
@@ -25,7 +26,7 @@ const getDirectoriesForEntryPointsSearch = async (dir) => {
|
|
|
25
26
|
];
|
|
26
27
|
};
|
|
27
28
|
exports.getDirectoriesForEntryPointsSearch = getDirectoriesForEntryPointsSearch;
|
|
28
|
-
const findEntryPointsInDepsTree = (deps, exclude = []) => {
|
|
29
|
+
const findEntryPointsInDepsTree = (deps, exclude = [], include = undefined) => {
|
|
29
30
|
const referencedIds = new Set();
|
|
30
31
|
Object.values(deps).forEach((entry) => {
|
|
31
32
|
if (entry !== null) {
|
|
@@ -36,17 +37,35 @@ const findEntryPointsInDepsTree = (deps, exclude = []) => {
|
|
|
36
37
|
.filter((id) => /\.(ts|tsx|mjs|js|jsx)$/.test(id) &&
|
|
37
38
|
!/node_modules/.test(id) &&
|
|
38
39
|
!referencedIds.has(id))
|
|
39
|
-
.filter((id) => exclude.reduce((result, pattern) => result && !(0, minimatch_1.default)(id, pattern), true))
|
|
40
|
+
.filter((id) => exclude.reduce((result, pattern) => result && !(0, minimatch_1.default)(id, pattern), true))
|
|
41
|
+
.filter((id) => include
|
|
42
|
+
? include.reduce((result, pattern) => result || (0, minimatch_1.default)(id, pattern), false)
|
|
43
|
+
: true)
|
|
44
|
+
.sort();
|
|
40
45
|
};
|
|
41
46
|
exports.findEntryPointsInDepsTree = findEntryPointsInDepsTree;
|
|
42
|
-
const getEntryPoints = async ({ cwd, exclude, webpackConfigPath }) => {
|
|
47
|
+
const getEntryPoints = async ({ cwd, exclude, include, webpackConfigPath }) => {
|
|
43
48
|
const dirs = await (0, exports.getDirectoriesForEntryPointsSearch)(cwd);
|
|
44
49
|
const globs = dirs
|
|
45
50
|
.map((dirName) => path_1.default.relative(cwd, dirName))
|
|
46
51
|
.map((dirName) => `${dirName}/*`);
|
|
47
52
|
const globsWithRoot = ['*', ...globs];
|
|
48
53
|
const depsTree = await (0, getDepsTree_1.getDepsTree)(cwd, globsWithRoot, webpackConfigPath);
|
|
49
|
-
const possibleEntryPoints = (0, exports.findEntryPointsInDepsTree)(depsTree, exclude);
|
|
50
|
-
|
|
54
|
+
const possibleEntryPoints = (0, exports.findEntryPointsInDepsTree)(depsTree, exclude, include);
|
|
55
|
+
const ignoreInstance = (0, ignore_1.default)();
|
|
56
|
+
let gitignore = '';
|
|
57
|
+
try {
|
|
58
|
+
gitignore = (await promises_1.default.readFile(path_1.default.join(cwd, '.gitignore'))).toString();
|
|
59
|
+
const lines = gitignore.split('\n');
|
|
60
|
+
const nonCommentedNonEmptyLines = lines
|
|
61
|
+
.filter((line) => !/^(\s*)#/.test(line))
|
|
62
|
+
.filter((line) => !/^(\s*)$/.test(line));
|
|
63
|
+
gitignore = nonCommentedNonEmptyLines.join('\n');
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
e;
|
|
67
|
+
}
|
|
68
|
+
ignoreInstance.add(gitignore);
|
|
69
|
+
return [ignoreInstance.filter(possibleEntryPoints), depsTree];
|
|
51
70
|
};
|
|
52
71
|
exports.getEntryPoints = getEntryPoints;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMaxDepth = void 0;
|
|
4
|
+
const getMaxDepth = (depth = 1, path = [], vertices = new Map()) => {
|
|
5
|
+
return (tree) => {
|
|
6
|
+
const depthFromCache = vertices.get(tree.path);
|
|
7
|
+
if (depthFromCache) {
|
|
8
|
+
return depthFromCache;
|
|
9
|
+
}
|
|
10
|
+
const newPath = [...path, tree.path];
|
|
11
|
+
if (tree.children.length === 0) {
|
|
12
|
+
return [depth, newPath];
|
|
13
|
+
}
|
|
14
|
+
const results = tree.children.map((0, exports.getMaxDepth)(depth + 1, newPath, vertices));
|
|
15
|
+
const maxChildDepth = Math.max(...results.map(([depth]) => depth));
|
|
16
|
+
const itemWithMaxDepth = results.find(([depth]) => depth === maxChildDepth);
|
|
17
|
+
vertices.set(tree.path, itemWithMaxDepth);
|
|
18
|
+
return itemWithMaxDepth;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
exports.getMaxDepth = getMaxDepth;
|
package/dist/lib/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sanitizeUserEntryPoints = exports.asyncFilter = exports.createResolveAbsolutePath = exports.removeInitialDot = void 0;
|
|
6
|
+
exports.resolvePath = exports.sanitizeUserEntryPoints = exports.asyncFilter = exports.createResolveAbsolutePath = exports.removeInitialDot = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const glob_escape_1 = __importDefault(require("glob-escape"));
|
|
9
9
|
const removeInitialDot = (path) => path.replace(/^\.\//, '');
|
|
@@ -20,3 +20,10 @@ const sanitizeUserEntryPoints = (entryPoints) => {
|
|
|
20
20
|
return globEscapedEntryPoints;
|
|
21
21
|
};
|
|
22
22
|
exports.sanitizeUserEntryPoints = sanitizeUserEntryPoints;
|
|
23
|
+
const resolvePath = (p) => {
|
|
24
|
+
if (!p || path_1.default.isAbsolute(p)) {
|
|
25
|
+
return p;
|
|
26
|
+
}
|
|
27
|
+
return path_1.default.resolve(p);
|
|
28
|
+
};
|
|
29
|
+
exports.resolvePath = resolvePath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rev-dep",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
4
|
"description": "Reverse dependency resolution tool built with dependency-cruiser",
|
|
5
5
|
"main": "lib/find.js",
|
|
6
6
|
"bin": "bin.js",
|
|
@@ -32,11 +32,14 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@types/dedent": "^0.7.0",
|
|
35
|
+
"colorette": "^2.0.16",
|
|
35
36
|
"commander": "^6.1.0",
|
|
36
37
|
"dedent": "^0.7.0",
|
|
37
38
|
"dependency-cruiser": "9.23.0",
|
|
38
39
|
"dpdm": "^3.8.0",
|
|
39
40
|
"glob-escape": "^0.0.2",
|
|
41
|
+
"ignore": "^5.2.0",
|
|
42
|
+
"is-builtin-module": "^3.1.0",
|
|
40
43
|
"minimatch": "^5.0.1"
|
|
41
44
|
},
|
|
42
45
|
"devDependencies": {
|