rev-dep 1.0.7 → 1.2.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 +4 -0
- package/dist/babel/index.js +64 -16
- package/dist/babel/transform.d.ts +1 -0
- package/dist/babel/transform.js +52 -0
- package/dist/cli/commonOptions.d.ts +5 -1
- package/dist/cli/commonOptions.js +6 -1
- package/dist/cli/entryPoints/index.js +5 -3
- package/dist/cli/files/index.js +3 -2
- package/dist/cli/resolve/index.js +6 -2
- package/dist/cli/resolve/types.d.ts +1 -0
- package/dist/lib/buildDepsGraph.d.ts +1 -1
- package/dist/lib/buildDepsGraph.js +10 -4
- package/dist/lib/getDepsTree.d.ts +1 -1
- package/dist/lib/getDepsTree.js +3 -2
- package/dist/lib/getEntryPoints.d.ts +2 -1
- package/dist/lib/getEntryPoints.js +3 -3
- package/dist/lib/resolve.d.ts +4 -2
- package/dist/lib/resolve.js +11 -5
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -394,6 +394,8 @@ rev-dep resolve <filePath> [entryPoints...] [options]
|
|
|
394
394
|
- `-e --exclude <globs...>` - A list of globs to determine files excluded in entry points search (_optional_)
|
|
395
395
|
- `-cs, --compactSummary` - print a compact summary of reverse resolution with a count of found paths (_optional_)
|
|
396
396
|
- `-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_)
|
|
397
|
+
- `-ntp --notTraversePaths <paths...>` - Specify file paths relative to resolution root, that should not be traversed when finding dependency path (_optional_)
|
|
398
|
+
- `-iti --ignoreTypesImports` - Use this flag to not follow type imports when resolving modules (_optional_)
|
|
397
399
|
|
|
398
400
|
### Command `entry-points`
|
|
399
401
|
|
|
@@ -413,6 +415,7 @@ rev-dep entry-points [options]
|
|
|
413
415
|
- `-e --exclude <globs...>` - A list of globs to determine files excluded in entry points search (_optional_)
|
|
414
416
|
- `-pdc, --printDependenciesCount` - print count of entry point dependencies (_optional_)
|
|
415
417
|
- `-c, --count` - print just count of found entry points (_optional_)
|
|
418
|
+
- `-iti --ignoreTypesImports` - Use this flag to not follow type imports when resolving modules (_optional_)
|
|
416
419
|
|
|
417
420
|
### Command `files`
|
|
418
421
|
|
|
@@ -433,6 +436,7 @@ rev-dep files <entryPoint> [options]
|
|
|
433
436
|
- `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
|
|
434
437
|
- `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
|
|
435
438
|
- `-c, --count` - print only count of entry point dependencies (_optional_)
|
|
439
|
+
- `-iti --ignoreTypesImports` - Use this flag to not follow type imports when resolving modules (_optional_)
|
|
436
440
|
|
|
437
441
|
### Command `docs`
|
|
438
442
|
|
package/dist/babel/index.js
CHANGED
|
@@ -7,13 +7,38 @@ const parser = require('@babel/parser');
|
|
|
7
7
|
const template = require('@babel/template').default;
|
|
8
8
|
const utils_1 = require("../lib/utils");
|
|
9
9
|
const SKIP = Symbol('SKIP');
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* TODO
|
|
13
|
+
* - support imports from baseUrl from TS config
|
|
14
|
+
* - persist the original import alias
|
|
15
|
+
* - group named imports from the same file
|
|
16
|
+
* - handle type imports properly - we don't preserve the import was a type import
|
|
17
|
+
* - If that has to be used as a codemod, we have to refactor to make sure we don't change structure of other parts of the code and we preserve imports order
|
|
18
|
+
*/
|
|
10
19
|
module.exports = function plugin({ types }, { tsConfigPath = (0, utils_1.findTsConfig)() }) {
|
|
11
|
-
const
|
|
20
|
+
const root = tsConfigPath.replace('/tsconfig.json', '');
|
|
21
|
+
const tsConfigContent = fs.readFileSync(tsConfigPath).toString();
|
|
22
|
+
const tsConfigContentCleaned = tsConfigContent
|
|
23
|
+
// remove comments
|
|
24
|
+
.replace(/^(\s)*\/\//gm, '')
|
|
25
|
+
.replace(/\/\*.+?\*\//gm, '');
|
|
26
|
+
const tsConfig = JSON.parse(tsConfigContentCleaned);
|
|
12
27
|
const aliases = tsConfig.compilerOptions.paths;
|
|
13
28
|
const aliasesKeys = Object.keys(aliases);
|
|
14
29
|
const aliasesRegexes = Object.keys(aliases).map((alias) => {
|
|
15
30
|
return new RegExp(`^${alias.replace('*', '(.)+')}$`);
|
|
16
31
|
});
|
|
32
|
+
let baseUrlDirs = [];
|
|
33
|
+
const baseUrl = tsConfig.compilerOptions.baseUrl;
|
|
34
|
+
if (baseUrl) {
|
|
35
|
+
const baseDirPath = node_path.join(root, baseUrl);
|
|
36
|
+
const dirNames = fs
|
|
37
|
+
.readdirSync(baseDirPath, { withFileTypes: true })
|
|
38
|
+
.filter((dirent) => dirent.isDirectory())
|
|
39
|
+
.map((dirent) => dirent.name + '/');
|
|
40
|
+
baseUrlDirs = dirNames;
|
|
41
|
+
}
|
|
17
42
|
const cache = new Map();
|
|
18
43
|
const getFile = (original, paths) => {
|
|
19
44
|
if (paths.length === 0) {
|
|
@@ -27,10 +52,12 @@ module.exports = function plugin({ types }, { tsConfigPath = (0, utils_1.findTsC
|
|
|
27
52
|
return getFile(original, paths.slice(1));
|
|
28
53
|
}
|
|
29
54
|
};
|
|
30
|
-
const
|
|
55
|
+
const isPathNotANodeModule = (path) => {
|
|
31
56
|
const aliasRegexIdx = aliasesRegexes.findIndex((aliasRegex) => aliasRegex.test(path));
|
|
32
57
|
const isRelative = path.startsWith('./') || path.startsWith('../');
|
|
33
|
-
|
|
58
|
+
const isAbsolute = path.startsWith('/');
|
|
59
|
+
const isBaseUrlPath = baseUrlDirs.some((dir) => path.startsWith(dir));
|
|
60
|
+
return aliasRegexIdx > -1 || isRelative || isAbsolute || isBaseUrlPath;
|
|
34
61
|
};
|
|
35
62
|
const cacheKey = (identifier, filePath) => `${identifier}-${filePath}`;
|
|
36
63
|
const lookup = (identifier, filePath, cwd) => {
|
|
@@ -71,10 +98,22 @@ module.exports = function plugin({ types }, { tsConfigPath = (0, utils_1.findTsC
|
|
|
71
98
|
const toLookup = [];
|
|
72
99
|
let resolvedAs = null;
|
|
73
100
|
ast.program.body.forEach((declaration) => {
|
|
74
|
-
var _a;
|
|
101
|
+
var _a, _b, _c;
|
|
75
102
|
if (resolvedAs === null) {
|
|
76
103
|
if (types.isExportNamedDeclaration(declaration)) {
|
|
77
|
-
if (
|
|
104
|
+
if (((_a = declaration.declaration) === null || _a === void 0 ? void 0 : _a.type.startsWith('TS')) &&
|
|
105
|
+
((_b = declaration.declaration) === null || _b === void 0 ? void 0 : _b.type.endsWith('Declaration'))) {
|
|
106
|
+
const typeName = declaration.declaration.id.name;
|
|
107
|
+
if (typeName === identifier) {
|
|
108
|
+
resolvedAs = {
|
|
109
|
+
// This should be 'type' of something else, but ESLint would handle that
|
|
110
|
+
type: 'named',
|
|
111
|
+
identifier,
|
|
112
|
+
source: filePath
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (types.isVariableDeclaration(declaration.declaration)) {
|
|
78
117
|
const hasIdentifier = declaration.declaration.declarations.find((declarator) => {
|
|
79
118
|
return declarator.id.name === identifier;
|
|
80
119
|
});
|
|
@@ -97,7 +136,7 @@ module.exports = function plugin({ types }, { tsConfigPath = (0, utils_1.findTsC
|
|
|
97
136
|
}
|
|
98
137
|
}
|
|
99
138
|
else {
|
|
100
|
-
const source = (
|
|
139
|
+
const source = (_c = declaration.source) === null || _c === void 0 ? void 0 : _c.value;
|
|
101
140
|
declaration.specifiers.forEach((specifier) => {
|
|
102
141
|
if (types.isExportSpecifier(specifier)) {
|
|
103
142
|
if (specifier.exported.name === identifier) {
|
|
@@ -115,9 +154,9 @@ module.exports = function plugin({ types }, { tsConfigPath = (0, utils_1.findTsC
|
|
|
115
154
|
source: filePath
|
|
116
155
|
};
|
|
117
156
|
}
|
|
118
|
-
else if (
|
|
157
|
+
else if (isPathNotANodeModule(source)) {
|
|
119
158
|
toLookup.push({
|
|
120
|
-
identifier: specifier.
|
|
159
|
+
identifier: specifier.local.name,
|
|
121
160
|
source: getModulePath(source, resolvedFilePath, cwd)
|
|
122
161
|
});
|
|
123
162
|
}
|
|
@@ -127,7 +166,7 @@ module.exports = function plugin({ types }, { tsConfigPath = (0, utils_1.findTsC
|
|
|
127
166
|
}
|
|
128
167
|
}
|
|
129
168
|
else if (types.isExportAllDeclaration(declaration) &&
|
|
130
|
-
|
|
169
|
+
isPathNotANodeModule(declaration.source.value)) {
|
|
131
170
|
toLookup.push({
|
|
132
171
|
identifier,
|
|
133
172
|
source: getModulePath(declaration.source.value, resolvedFilePath, cwd)
|
|
@@ -149,6 +188,7 @@ module.exports = function plugin({ types }, { tsConfigPath = (0, utils_1.findTsC
|
|
|
149
188
|
const relativeFileName = node_path.relative(cwd, fileName);
|
|
150
189
|
const aliasKey = aliasesKeys[aliasRegexIdx];
|
|
151
190
|
const alias = (_a = aliases[aliasKey]) === null || _a === void 0 ? void 0 : _a[0];
|
|
191
|
+
const isAbsoluteToBaseDir = baseUrlDirs.some((baseUrlDir) => sourcePath.startsWith(baseUrlDir));
|
|
152
192
|
let modulePath = '';
|
|
153
193
|
if (alias) {
|
|
154
194
|
let relative = alias;
|
|
@@ -158,35 +198,43 @@ module.exports = function plugin({ types }, { tsConfigPath = (0, utils_1.findTsC
|
|
|
158
198
|
}
|
|
159
199
|
modulePath = node_path.resolve(cwd, relative);
|
|
160
200
|
}
|
|
201
|
+
else if (isAbsoluteToBaseDir) {
|
|
202
|
+
modulePath = node_path.join(cwd, sourcePath);
|
|
203
|
+
}
|
|
161
204
|
else {
|
|
162
205
|
// we need ../ to skip current file name
|
|
163
|
-
modulePath = node_path.
|
|
206
|
+
modulePath = node_path.join(cwd, relativeFileName, '../' + sourcePath);
|
|
164
207
|
}
|
|
165
208
|
return modulePath;
|
|
166
209
|
};
|
|
167
210
|
return {
|
|
168
211
|
visitor: {
|
|
169
|
-
|
|
212
|
+
Program() {
|
|
213
|
+
// console.log('Cache size', cache.size)
|
|
214
|
+
},
|
|
215
|
+
ImportDeclaration(path, { filename }) {
|
|
170
216
|
const sourceRelative = (source) => {
|
|
171
217
|
const rel = node_path.relative(node_path.dirname(filename), source);
|
|
172
|
-
|
|
218
|
+
const whatever = rel.startsWith('.') ? rel : './' + rel;
|
|
219
|
+
// remove file extension
|
|
220
|
+
return whatever.replace(/\.(ts|js|tsx|jsx|cjs|mjs)$/, '');
|
|
173
221
|
};
|
|
174
222
|
const node = path.node;
|
|
175
223
|
const source = node.source;
|
|
176
224
|
if (source.type !== 'StringLiteral') {
|
|
177
225
|
return;
|
|
178
226
|
}
|
|
179
|
-
const shouldSkip = node[SKIP] || !
|
|
227
|
+
const shouldSkip = node[SKIP] || !isPathNotANodeModule(source.value);
|
|
180
228
|
if (shouldSkip) {
|
|
181
229
|
return;
|
|
182
230
|
}
|
|
183
|
-
const modulePath = getModulePath(source.value, filename,
|
|
231
|
+
const modulePath = getModulePath(source.value, filename, root);
|
|
184
232
|
const defaultSpecifier = node.specifiers.find((specifier) => specifier.type === 'ImportDefaultSpecifier');
|
|
185
233
|
const namespaceSpecifier = node.specifiers.find((specifier) => specifier.type === 'ImportNamespaceSpecifier');
|
|
186
234
|
const specifiers = node.specifiers.filter((specifier) => specifier.type === 'ImportSpecifier');
|
|
187
235
|
const results = specifiers.map((specifier) => {
|
|
188
236
|
const importedName = specifier.imported.name;
|
|
189
|
-
const result = lookup(importedName, modulePath,
|
|
237
|
+
const result = lookup(importedName, modulePath, root);
|
|
190
238
|
if (!result) {
|
|
191
239
|
return {
|
|
192
240
|
identifier: importedName,
|
|
@@ -202,7 +250,7 @@ module.exports = function plugin({ types }, { tsConfigPath = (0, utils_1.findTsC
|
|
|
202
250
|
};
|
|
203
251
|
});
|
|
204
252
|
const defaultResult = defaultSpecifier
|
|
205
|
-
? lookup('default', modulePath,
|
|
253
|
+
? lookup('default', modulePath, root)
|
|
206
254
|
: null;
|
|
207
255
|
if (defaultResult) {
|
|
208
256
|
cache.set(cacheKey('default', modulePath), defaultResult);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*eslint-disable @typescript-eslint/no-var-requires */
|
|
3
|
+
const { getFilesList } = require('@codeque/core');
|
|
4
|
+
const babelCore = require('@babel/core');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const rootPath = process.argv[2];
|
|
8
|
+
const inputFilePath = process.argv[3];
|
|
9
|
+
if (!rootPath) {
|
|
10
|
+
console.error('Please provide correct transformation root');
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
;
|
|
14
|
+
(async () => {
|
|
15
|
+
const root = path.resolve(rootPath);
|
|
16
|
+
const resolvedInputFilePath = inputFilePath
|
|
17
|
+
? path.join(root, inputFilePath)
|
|
18
|
+
: undefined;
|
|
19
|
+
console.log('root', root);
|
|
20
|
+
const filesList = resolvedInputFilePath
|
|
21
|
+
? [path.resolve(resolvedInputFilePath)]
|
|
22
|
+
: await getFilesList({
|
|
23
|
+
searchRoot: root,
|
|
24
|
+
extensionTester: /\.(ts|tsx)$/
|
|
25
|
+
});
|
|
26
|
+
const errors = [];
|
|
27
|
+
let progressCount = 0;
|
|
28
|
+
for (const filePath of filesList) {
|
|
29
|
+
try {
|
|
30
|
+
const fileName = path.parse(filePath).name;
|
|
31
|
+
const result = babelCore.transformFileSync(filePath, {
|
|
32
|
+
plugins: [
|
|
33
|
+
['./babel.js', { tsConfigPath: path.join(root, 'tsconfig.json') }]
|
|
34
|
+
],
|
|
35
|
+
parserOpts: {
|
|
36
|
+
plugins: ['typescript', 'jsx']
|
|
37
|
+
},
|
|
38
|
+
filename: fileName
|
|
39
|
+
});
|
|
40
|
+
fs.writeFileSync(filePath, result.code);
|
|
41
|
+
progressCount++;
|
|
42
|
+
if (progressCount % 100 === 0) {
|
|
43
|
+
console.log(`${progressCount}+${errors.length}/${filesList.length}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
errors.push(e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.log(errors);
|
|
51
|
+
console.log(`Done: ${progressCount}/${filesList.length}; Failed: ${errors.length}`);
|
|
52
|
+
})();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare type OptionMeta2 = [string, string];
|
|
2
|
-
declare type OptionMeta3 = [string, string, string];
|
|
2
|
+
declare type OptionMeta3 = [string, string, string | boolean];
|
|
3
3
|
export declare const webpackConfigOption: OptionMeta2;
|
|
4
4
|
export declare type WebpackConfigOptionType = {
|
|
5
5
|
webpackConfig?: string;
|
|
@@ -20,4 +20,8 @@ export declare const excludeOption: OptionMeta2;
|
|
|
20
20
|
export declare type ExcludeOptionType = {
|
|
21
21
|
exclude?: string[];
|
|
22
22
|
};
|
|
23
|
+
export declare const ignoreTypesImports: OptionMeta3;
|
|
24
|
+
export declare type IgnoreTypesImportsOptionType = {
|
|
25
|
+
ignoreTypesImports: boolean;
|
|
26
|
+
};
|
|
23
27
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.excludeOption = exports.includeOption = exports.reexportRewireOption = exports.cwdOption = exports.webpackConfigOption = void 0;
|
|
3
|
+
exports.ignoreTypesImports = 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'
|
|
@@ -22,3 +22,8 @@ exports.excludeOption = [
|
|
|
22
22
|
'-e --exclude <globs...>',
|
|
23
23
|
'A list of globs to determine files excluded in entry points search'
|
|
24
24
|
];
|
|
25
|
+
exports.ignoreTypesImports = [
|
|
26
|
+
'-iti --ignoreTypesImports',
|
|
27
|
+
'Use this flag to not follow type imports when resolving modules',
|
|
28
|
+
false
|
|
29
|
+
];
|
|
@@ -15,18 +15,20 @@ function createEntryPoints(program) {
|
|
|
15
15
|
.option(...commonOptions_1.excludeOption)
|
|
16
16
|
.option('-pdc, --printDependenciesCount', 'print count of entry point dependencies', false)
|
|
17
17
|
.option('-c, --count', 'print just count of found entry points', false)
|
|
18
|
+
.option(...commonOptions_1.ignoreTypesImports)
|
|
18
19
|
.action(async (data) => {
|
|
19
|
-
const { webpackConfig: webpackConfigPath, cwd, printDependenciesCount, include, exclude, count } = data;
|
|
20
|
+
const { webpackConfig: webpackConfigPath, cwd, printDependenciesCount, include, exclude, count, ignoreTypesImports } = data;
|
|
20
21
|
const [entryPoints, depsTree] = await (0, getEntryPoints_1.getEntryPoints)({
|
|
21
22
|
cwd: (0, utils_1.resolvePath)(cwd),
|
|
22
23
|
webpackConfigPath,
|
|
23
24
|
exclude,
|
|
24
|
-
include
|
|
25
|
+
include,
|
|
26
|
+
ignoreTypesImports
|
|
25
27
|
});
|
|
26
28
|
let depsCount = null;
|
|
27
29
|
if (printDependenciesCount) {
|
|
28
30
|
depsCount = entryPoints
|
|
29
|
-
.map((0, buildDepsGraph_1.
|
|
31
|
+
.map((0, buildDepsGraph_1.buildDepsGraph)(depsTree))
|
|
30
32
|
.map(([_, __, vertices]) => vertices.size);
|
|
31
33
|
}
|
|
32
34
|
if (count) {
|
package/dist/cli/files/index.js
CHANGED
|
@@ -13,10 +13,11 @@ function createFiles(program) {
|
|
|
13
13
|
.option(...commonOptions_1.cwdOption)
|
|
14
14
|
// .option(...reexportRewireOption)
|
|
15
15
|
.option('-c, --count', 'print only count of entry point dependencies', false)
|
|
16
|
+
.option(...commonOptions_1.ignoreTypesImports)
|
|
16
17
|
.action(async (entryPoint, data) => {
|
|
17
|
-
const { webpackConfig: webpackConfigPath, cwd, count } = data;
|
|
18
|
+
const { webpackConfig: webpackConfigPath, cwd, count, ignoreTypesImports } = data;
|
|
18
19
|
const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)([entryPoint]);
|
|
19
|
-
const depsTree = await (0, getDepsTree_1.getDepsTree)((0, utils_1.resolvePath)(cwd), sanitizedEntryPoints, webpackConfigPath);
|
|
20
|
+
const depsTree = await (0, getDepsTree_1.getDepsTree)((0, utils_1.resolvePath)(cwd), sanitizedEntryPoints, webpackConfigPath, ignoreTypesImports);
|
|
20
21
|
const filePaths = Object.keys(depsTree);
|
|
21
22
|
if (filePaths.length === 0) {
|
|
22
23
|
console.log('No results found');
|
|
@@ -18,8 +18,10 @@ function createResolve(program) {
|
|
|
18
18
|
.option(...commonOptions_1.excludeOption)
|
|
19
19
|
.option('-cs, --compactSummary', 'print a compact summary of reverse resolution with a count of found paths')
|
|
20
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)
|
|
21
|
+
.option('-ntp --notTraversePaths <paths...>', 'Specify file paths relative to resolution root, that should not be traversed when finding dependency path')
|
|
22
|
+
.option(...commonOptions_1.ignoreTypesImports)
|
|
21
23
|
.action(async (filePath, entryPoints, data) => {
|
|
22
|
-
const { compactSummary, webpackConfig, all, cwd, exclude, include } = data;
|
|
24
|
+
const { compactSummary, webpackConfig, all, cwd, exclude, include, notTraversePaths, ignoreTypesImports } = data;
|
|
23
25
|
const [results, resolveEntryPoints] = await (0, resolve_1.resolve)({
|
|
24
26
|
entryPoints,
|
|
25
27
|
filePath,
|
|
@@ -27,7 +29,9 @@ function createResolve(program) {
|
|
|
27
29
|
all,
|
|
28
30
|
cwd: (0, utils_1.resolvePath)(cwd),
|
|
29
31
|
exclude,
|
|
30
|
-
include
|
|
32
|
+
include,
|
|
33
|
+
notTraversePaths,
|
|
34
|
+
ignoreTypesImports
|
|
31
35
|
});
|
|
32
36
|
const formatted = (0, formatResults_1.formatResults)({
|
|
33
37
|
results,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Node, MinimalDependencyTree } from './types';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const buildDepsGraph: (deps: MinimalDependencyTree, filePath?: string | undefined, notTraversePath?: string[] | undefined) => (entryPoint: string) => [Node, Node | null, Map<string, Node>];
|
|
@@ -1,7 +1,11 @@
|
|
|
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
|
-
exports.
|
|
4
|
-
const
|
|
6
|
+
exports.buildDepsGraph = void 0;
|
|
7
|
+
const minimatch_1 = __importDefault(require("minimatch"));
|
|
8
|
+
const buildDepsGraph = (deps, filePath, notTraversePath) => (entryPoint) => {
|
|
5
9
|
const vertices = new Map();
|
|
6
10
|
let fileNode = null;
|
|
7
11
|
const inner = (path, visited = new Set(), depth = 1, parent = null) => {
|
|
@@ -30,7 +34,9 @@ const buildGraphDpdm = (deps, filePath) => (entryPoint) => {
|
|
|
30
34
|
};
|
|
31
35
|
node.children = (dep || [])
|
|
32
36
|
.map((d) => d.id)
|
|
33
|
-
.filter((path) => path !== null &&
|
|
37
|
+
.filter((path) => path !== null &&
|
|
38
|
+
!path.includes('node_modules') &&
|
|
39
|
+
!(notTraversePath === null || notTraversePath === void 0 ? void 0 : notTraversePath.some((pathToNotTraverse) => (0, minimatch_1.default)(path, pathToNotTraverse))))
|
|
34
40
|
.map((path) => inner(path, localVisited, depth + 1, node));
|
|
35
41
|
vertices.set(path, node);
|
|
36
42
|
if (path === filePath) {
|
|
@@ -40,4 +46,4 @@ const buildGraphDpdm = (deps, filePath) => (entryPoint) => {
|
|
|
40
46
|
};
|
|
41
47
|
return [inner(entryPoint), fileNode, vertices];
|
|
42
48
|
};
|
|
43
|
-
exports.
|
|
49
|
+
exports.buildDepsGraph = buildDepsGraph;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getDepsTree(cwd: string, entryPoints: string[], webpackConfigPath?: string): Promise<import("./types").MinimalDependencyTree>;
|
|
1
|
+
export declare function getDepsTree(cwd: string, entryPoints: string[], webpackConfigPath?: string, ignoreTypesImports?: boolean): Promise<import("./types").MinimalDependencyTree>;
|
package/dist/lib/getDepsTree.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.getDepsTree = void 0;
|
|
|
4
4
|
const getDepsSetWebpack_1 = require("./getDepsSetWebpack");
|
|
5
5
|
const dpdm_1 = require("dpdm");
|
|
6
6
|
const cleanupDpdmDeps_1 = require("./cleanupDpdmDeps");
|
|
7
|
-
async function getDepsTree(cwd, entryPoints, webpackConfigPath) {
|
|
7
|
+
async function getDepsTree(cwd, entryPoints, webpackConfigPath, ignoreTypesImports = false) {
|
|
8
8
|
let deps;
|
|
9
9
|
if (webpackConfigPath) {
|
|
10
10
|
deps = (0, getDepsSetWebpack_1.getDepsSetWebpack)(entryPoints, webpackConfigPath, cwd);
|
|
@@ -14,7 +14,8 @@ async function getDepsTree(cwd, entryPoints, webpackConfigPath) {
|
|
|
14
14
|
const oldProcessCwd = process.cwd;
|
|
15
15
|
process.cwd = () => cwd;
|
|
16
16
|
deps = (0, cleanupDpdmDeps_1.cleanupDpdmDeps)(await (0, dpdm_1.parseDependencyTree)(entryPoints, {
|
|
17
|
-
context: cwd
|
|
17
|
+
context: cwd,
|
|
18
|
+
transform: ignoreTypesImports
|
|
18
19
|
}));
|
|
19
20
|
process.cwd = oldProcessCwd;
|
|
20
21
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MinimalDependencyTree } from './types';
|
|
2
2
|
export declare const getDirectoriesForEntryPointsSearch: (dir: string) => Promise<string[]>;
|
|
3
3
|
export declare const findEntryPointsInDepsTree: (deps: MinimalDependencyTree, exclude?: string[], include?: string[] | undefined) => string[];
|
|
4
|
-
export declare const getEntryPoints: ({ cwd, exclude, include, webpackConfigPath }: {
|
|
4
|
+
export declare const getEntryPoints: ({ cwd, exclude, include, webpackConfigPath, ignoreTypesImports }: {
|
|
5
5
|
cwd: string;
|
|
6
6
|
exclude?: string[] | undefined;
|
|
7
7
|
include?: string[] | undefined;
|
|
8
8
|
webpackConfigPath?: string | undefined;
|
|
9
|
+
ignoreTypesImports?: boolean | undefined;
|
|
9
10
|
}) => Promise<[string[], MinimalDependencyTree]>;
|
|
@@ -35,7 +35,7 @@ const findEntryPointsInDepsTree = (deps, exclude = [], include = undefined) => {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
return Object.keys(deps)
|
|
38
|
-
.filter((id) => /\.(ts|tsx|mjs|js|jsx)$/.test(id) &&
|
|
38
|
+
.filter((id) => /\.(ts|tsx|mjs|cjs|js|jsx)$/.test(id) &&
|
|
39
39
|
!/node_modules/.test(id) &&
|
|
40
40
|
!referencedIds.has(id))
|
|
41
41
|
.filter((id) => exclude.reduce((result, pattern) => result && !(0, minimatch_1.default)(id, pattern), true))
|
|
@@ -45,13 +45,13 @@ const findEntryPointsInDepsTree = (deps, exclude = [], include = undefined) => {
|
|
|
45
45
|
.sort();
|
|
46
46
|
};
|
|
47
47
|
exports.findEntryPointsInDepsTree = findEntryPointsInDepsTree;
|
|
48
|
-
const getEntryPoints = async ({ cwd, exclude, include, webpackConfigPath }) => {
|
|
48
|
+
const getEntryPoints = async ({ cwd, exclude, include, webpackConfigPath, ignoreTypesImports }) => {
|
|
49
49
|
const dirs = await (0, exports.getDirectoriesForEntryPointsSearch)(cwd);
|
|
50
50
|
const globs = dirs
|
|
51
51
|
.map((dirName) => path_1.default.relative(cwd, dirName))
|
|
52
52
|
.map((dirName) => `${(0, glob_escape_1.default)(dirName)}/*`);
|
|
53
53
|
const globsWithRoot = ['*', ...globs];
|
|
54
|
-
const depsTree = await (0, getDepsTree_1.getDepsTree)(cwd, globsWithRoot, webpackConfigPath);
|
|
54
|
+
const depsTree = await (0, getDepsTree_1.getDepsTree)(cwd, globsWithRoot, webpackConfigPath, ignoreTypesImports);
|
|
55
55
|
const possibleEntryPoints = (0, exports.findEntryPointsInDepsTree)(depsTree, exclude, include);
|
|
56
56
|
const ignoreInstance = (0, ignore_1.default)();
|
|
57
57
|
let gitignore = '';
|
package/dist/lib/resolve.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
declare type ResolveParams = {
|
|
2
|
-
entryPoints
|
|
2
|
+
entryPoints?: string[];
|
|
3
3
|
filePath: string;
|
|
4
4
|
webpackConfig?: string;
|
|
5
5
|
cwd?: string;
|
|
6
6
|
all: boolean;
|
|
7
7
|
exclude?: string[];
|
|
8
8
|
include?: string[];
|
|
9
|
+
notTraversePaths?: string[];
|
|
10
|
+
ignoreTypesImports?: boolean;
|
|
9
11
|
};
|
|
10
|
-
export declare const resolve: ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd, all, include, exclude }: ResolveParams) => Promise<[string[][][], string[]]>;
|
|
12
|
+
export declare const resolve: ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd, all, include, exclude, notTraversePaths, ignoreTypesImports }: ResolveParams) => Promise<[string[][][], string[]]>;
|
|
11
13
|
export {};
|
package/dist/lib/resolve.js
CHANGED
|
@@ -27,20 +27,26 @@ const resolvePathsToRoot = (node, all = false, resolvedPaths = [[]]) => {
|
|
|
27
27
|
}
|
|
28
28
|
return resolvePathsToRoot(node.parents[0], false, newPaths);
|
|
29
29
|
};
|
|
30
|
-
const resolve = async ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd = process.cwd(), all, include, exclude }) => {
|
|
30
|
+
const resolve = async ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd = process.cwd(), all, include, exclude, notTraversePaths, ignoreTypesImports }) => {
|
|
31
31
|
let deps, entryPoints;
|
|
32
|
-
if (_entryPoints.length > 0) {
|
|
32
|
+
if (_entryPoints && (_entryPoints === null || _entryPoints === void 0 ? void 0 : _entryPoints.length) > 0) {
|
|
33
33
|
entryPoints = _entryPoints;
|
|
34
34
|
const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)(entryPoints);
|
|
35
|
-
deps = await (0, getDepsTree_1.getDepsTree)(cwd, sanitizedEntryPoints, webpackConfig);
|
|
35
|
+
deps = await (0, getDepsTree_1.getDepsTree)(cwd, sanitizedEntryPoints, webpackConfig, ignoreTypesImports);
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
;
|
|
39
|
-
[entryPoints, deps] = await (0, getEntryPoints_1.getEntryPoints)({
|
|
39
|
+
[entryPoints, deps] = await (0, getEntryPoints_1.getEntryPoints)({
|
|
40
|
+
cwd,
|
|
41
|
+
exclude,
|
|
42
|
+
include,
|
|
43
|
+
webpackConfigPath: webpackConfig,
|
|
44
|
+
ignoreTypesImports
|
|
45
|
+
});
|
|
40
46
|
}
|
|
41
47
|
const cleanedEntryPoints = entryPoints.map(utils_1.removeInitialDot);
|
|
42
48
|
const cleanedFilePath = (0, utils_1.removeInitialDot)(filePath);
|
|
43
|
-
const forest = cleanedEntryPoints.map((0, buildDepsGraph_1.
|
|
49
|
+
const forest = cleanedEntryPoints.map((0, buildDepsGraph_1.buildDepsGraph)(deps, cleanedFilePath, notTraversePaths));
|
|
44
50
|
const resolvedPaths = forest.reduce((allPaths, [_, fileNode]) => {
|
|
45
51
|
if (!fileNode) {
|
|
46
52
|
return [...allPaths, []];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rev-dep",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Dependency debugging tool for JavaScript and TypeScript projects",
|
|
5
5
|
"main": "dist/module.js",
|
|
6
6
|
"bin": "bin.js",
|
|
@@ -33,8 +33,10 @@
|
|
|
33
33
|
"typecheck": "tsc --noEmit"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@babel/core": "^7.20.12",
|
|
36
37
|
"@babel/parser": "^7.17.8",
|
|
37
38
|
"@babel/template": "^7.16.7",
|
|
39
|
+
"@codeque/core": "^0.4.0",
|
|
38
40
|
"@types/dedent": "^0.7.0",
|
|
39
41
|
"colorette": "^2.0.16",
|
|
40
42
|
"commander": "^6.1.0",
|
|
@@ -58,7 +60,7 @@
|
|
|
58
60
|
"jest": "^26.5.3",
|
|
59
61
|
"mock-fs": "^4.13.0",
|
|
60
62
|
"prettier": "^2.1.2",
|
|
61
|
-
"release-it": "
|
|
63
|
+
"release-it": "16.2.1",
|
|
62
64
|
"typescript": "^4.6.2"
|
|
63
65
|
},
|
|
64
66
|
"keywords": [
|