rev-dep 1.1.0 → 1.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/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,28 @@ 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_)
440
+
441
+ ### Command `node-modules`
442
+
443
+ Get list of node modules required by entry point
444
+
445
+ #### Usage
446
+
447
+ ```sh
448
+ rev-dep node-modules <entryPoint> [options]
449
+ ```
450
+
451
+ #### Arguments
452
+
453
+ - `entryPoint` - Path to entry point (**required**)
454
+
455
+ #### Options
456
+
457
+ - `-wc, --webpackConfig <path>` - path to webpack config to enable webpack aliases support (_optional_)
458
+ - `--cwd <path>` - path to a directory that should be used as a resolution root (_optional_)
459
+ - `-c, --count` - print only count of entry point dependencies (_optional_)
460
+ - `-iti --ignoreTypesImports` - Use this flag to not follow type imports when resolving modules (_optional_)
436
461
 
437
462
  ### Command `docs`
438
463
 
@@ -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 tsConfig = require(tsConfigPath);
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 isPathRelativeOrAliased = (path) => {
55
+ const isPathNotANodeModule = (path) => {
31
56
  const aliasRegexIdx = aliasesRegexes.findIndex((aliasRegex) => aliasRegex.test(path));
32
57
  const isRelative = path.startsWith('./') || path.startsWith('../');
33
- return aliasRegexIdx > -1 || isRelative;
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 (types.isVariableDeclaration(declaration.declaration)) {
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 = (_a = declaration.source) === null || _a === void 0 ? void 0 : _a.value;
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 (isPathRelativeOrAliased(source)) {
157
+ else if (isPathNotANodeModule(source)) {
119
158
  toLookup.push({
120
- identifier: specifier.exported.local,
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
- isPathRelativeOrAliased(declaration.source.value)) {
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.resolve(relativeFileName, '../' + sourcePath);
206
+ modulePath = node_path.join(cwd, relativeFileName, '../' + sourcePath);
164
207
  }
165
208
  return modulePath;
166
209
  };
167
210
  return {
168
211
  visitor: {
169
- ImportDeclaration(path, { filename, cwd }) {
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
- return rel.startsWith('.') ? rel : './' + rel;
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] || !isPathRelativeOrAliased(source.value);
227
+ const shouldSkip = node[SKIP] || !isPathNotANodeModule(source.value);
180
228
  if (shouldSkip) {
181
229
  return;
182
230
  }
183
- const modulePath = getModulePath(source.value, filename, cwd);
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, cwd);
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, cwd)
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
+ ];
@@ -8,10 +8,12 @@ const resolve_1 = __importDefault(require("./resolve"));
8
8
  const docs_1 = __importDefault(require("./docs"));
9
9
  const entryPoints_1 = __importDefault(require("./entryPoints"));
10
10
  const files_1 = __importDefault(require("./files"));
11
+ const nodeModules_1 = __importDefault(require("./nodeModules"));
11
12
  function createCommands(program) {
12
13
  (0, resolve_1.default)(program);
13
14
  (0, entryPoints_1.default)(program);
14
15
  (0, files_1.default)(program);
16
+ (0, nodeModules_1.default)(program);
15
17
  (0, docs_1.default)(program);
16
18
  }
17
19
  exports.createCommands = createCommands;
@@ -15,13 +15,15 @@ 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) {
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const commonOptions_1 = require("../commonOptions");
4
- const utils_1 = require("../../lib/utils");
5
- const getDepsTree_1 = require("../../lib/getDepsTree");
4
+ const getFilesForEntryPoint_1 = require("../../lib/getFilesForEntryPoint");
6
5
  function createFiles(program) {
7
6
  program
8
7
  .command('files <entryPoint>')
@@ -13,11 +12,15 @@ function createFiles(program) {
13
12
  .option(...commonOptions_1.cwdOption)
14
13
  // .option(...reexportRewireOption)
15
14
  .option('-c, --count', 'print only count of entry point dependencies', false)
15
+ .option(...commonOptions_1.ignoreTypesImports)
16
16
  .action(async (entryPoint, data) => {
17
- const { webpackConfig: webpackConfigPath, cwd, count } = data;
18
- const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)([entryPoint]);
19
- const depsTree = await (0, getDepsTree_1.getDepsTree)((0, utils_1.resolvePath)(cwd), sanitizedEntryPoints, webpackConfigPath);
20
- const filePaths = Object.keys(depsTree);
17
+ const { webpackConfig: webpackConfigPath, cwd, count, ignoreTypesImports } = data;
18
+ const filePaths = await (0, getFilesForEntryPoint_1.getFilesForEntryPoint)({
19
+ cwd,
20
+ entryPoint,
21
+ webpackConfigPath,
22
+ ignoreTypesImports
23
+ });
21
24
  if (filePaths.length === 0) {
22
25
  console.log('No results found');
23
26
  return;
@@ -0,0 +1,2 @@
1
+ import commander from 'commander';
2
+ export default function createNodeModules(program: commander.Command): void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const commonOptions_1 = require("../commonOptions");
4
+ const getNodeModulesForEntryPoint_1 = require("../../lib/getNodeModulesForEntryPoint");
5
+ function createNodeModules(program) {
6
+ program
7
+ .command('node-modules <entryPoint>')
8
+ .description('Get list of node modules required by entry point', {
9
+ entryPoint: 'Path to entry point'
10
+ })
11
+ .option(...commonOptions_1.webpackConfigOption)
12
+ .option(...commonOptions_1.cwdOption)
13
+ // .option(...reexportRewireOption)
14
+ .option('-c, --count', 'print only count of entry point dependencies', false)
15
+ .option(...commonOptions_1.ignoreTypesImports)
16
+ .action(async (entryPoint, data) => {
17
+ const { webpackConfig: webpackConfigPath, cwd, count, ignoreTypesImports } = data;
18
+ const uniqueNodeModuleImports = await (0, getNodeModulesForEntryPoint_1.getNodeModulesForEntryPoint)({
19
+ cwd,
20
+ entryPoint,
21
+ webpackConfigPath,
22
+ ignoreTypesImports
23
+ });
24
+ if (uniqueNodeModuleImports.length === 0) {
25
+ console.log('No results found');
26
+ return;
27
+ }
28
+ if (count) {
29
+ console.log(uniqueNodeModuleImports.length);
30
+ }
31
+ else {
32
+ uniqueNodeModuleImports.forEach((nodeModuleName) => console.log(nodeModuleName));
33
+ }
34
+ });
35
+ }
36
+ exports.default = createNodeModules;
@@ -0,0 +1,3 @@
1
+ export declare type InputParams = {
2
+ count?: boolean;
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,
@@ -6,4 +6,5 @@ export declare type InputParams = {
6
6
  printMaxDepth?: boolean;
7
7
  printDependentCount?: boolean;
8
8
  all: boolean;
9
+ notTraversePaths?: string[];
9
10
  };
@@ -1,3 +1,3 @@
1
1
  import { DependencyTree } from 'dpdm';
2
2
  import { MinimalDependencyTree } from './types';
3
- export declare const cleanupDpdmDeps: (deps: MinimalDependencyTree | DependencyTree) => MinimalDependencyTree;
3
+ export declare const cleanupDpdmDeps: (deps: MinimalDependencyTree | DependencyTree, includeNodeModules?: boolean) => MinimalDependencyTree;
@@ -5,14 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.cleanupDpdmDeps = void 0;
7
7
  const is_builtin_module_1 = __importDefault(require("is-builtin-module"));
8
- const cleanupDpdmDeps = (deps) => {
8
+ const cleanupDpdmDeps = (deps, includeNodeModules = false) => {
9
9
  const newDeps = {};
10
10
  Object.entries(deps).forEach(([id, dependencies]) => {
11
11
  if (!(0, is_builtin_module_1.default)(id) &&
12
12
  !id.includes('node_modules') &&
13
13
  dependencies !== null) {
14
14
  newDeps[id] = dependencies
15
- .filter(({ id }) => id && !id.includes('node_modules') && !(0, is_builtin_module_1.default)(id))
15
+ .filter(({ id }) => id &&
16
+ (includeNodeModules || !id.includes('node_modules')) &&
17
+ !(0, is_builtin_module_1.default)(id))
16
18
  .map(({ id, request }) => ({
17
19
  id,
18
20
  request
@@ -1 +1 @@
1
- export declare function getDepsTree(cwd: string, entryPoints: string[], webpackConfigPath?: string, ignoreTypesImports?: boolean): Promise<import("./types").MinimalDependencyTree>;
1
+ export declare function getDepsTree(cwd: string, entryPoints: string[], webpackConfigPath?: string, ignoreTypesImports?: boolean, includeNodeModules?: boolean): Promise<import("./types").MinimalDependencyTree>;
@@ -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, ignoreTypesImports = false) {
7
+ async function getDepsTree(cwd, entryPoints, webpackConfigPath, ignoreTypesImports = false, includeNodeModules = false) {
8
8
  let deps;
9
9
  if (webpackConfigPath) {
10
10
  deps = (0, getDepsSetWebpack_1.getDepsSetWebpack)(entryPoints, webpackConfigPath, cwd);
@@ -16,7 +16,7 @@ async function getDepsTree(cwd, entryPoints, webpackConfigPath, ignoreTypesImpor
16
16
  deps = (0, cleanupDpdmDeps_1.cleanupDpdmDeps)(await (0, dpdm_1.parseDependencyTree)(entryPoints, {
17
17
  context: cwd,
18
18
  transform: ignoreTypesImports
19
- }));
19
+ }), includeNodeModules);
20
20
  process.cwd = oldProcessCwd;
21
21
  }
22
22
  return deps;
@@ -1,6 +1,13 @@
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 prepareIgnoreInstance: (cwd: string) => Promise<import("ignore").Ignore>;
5
+ export declare const findEntryPointsInDepsTreeAndFilterOutIgnoredFiles: ({ cwd, depsTree, include, exclude }: {
6
+ depsTree: MinimalDependencyTree;
7
+ exclude: string[] | undefined;
8
+ include: string[] | undefined;
9
+ cwd: string;
10
+ }) => Promise<string[]>;
4
11
  export declare const getEntryPoints: ({ cwd, exclude, include, webpackConfigPath, ignoreTypesImports }: {
5
12
  cwd: string;
6
13
  exclude?: string[] | undefined;
@@ -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.getEntryPoints = exports.findEntryPointsInDepsTree = exports.getDirectoriesForEntryPointsSearch = void 0;
6
+ exports.getEntryPoints = exports.findEntryPointsInDepsTreeAndFilterOutIgnoredFiles = exports.prepareIgnoreInstance = exports.findEntryPointsInDepsTree = exports.getDirectoriesForEntryPointsSearch = void 0;
7
7
  const minimatch_1 = __importDefault(require("minimatch"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const promises_1 = __importDefault(require("fs/promises"));
@@ -45,14 +45,7 @@ const findEntryPointsInDepsTree = (deps, exclude = [], include = undefined) => {
45
45
  .sort();
46
46
  };
47
47
  exports.findEntryPointsInDepsTree = findEntryPointsInDepsTree;
48
- const getEntryPoints = async ({ cwd, exclude, include, webpackConfigPath, ignoreTypesImports }) => {
49
- const dirs = await (0, exports.getDirectoriesForEntryPointsSearch)(cwd);
50
- const globs = dirs
51
- .map((dirName) => path_1.default.relative(cwd, dirName))
52
- .map((dirName) => `${(0, glob_escape_1.default)(dirName)}/*`);
53
- const globsWithRoot = ['*', ...globs];
54
- const depsTree = await (0, getDepsTree_1.getDepsTree)(cwd, globsWithRoot, webpackConfigPath, ignoreTypesImports);
55
- const possibleEntryPoints = (0, exports.findEntryPointsInDepsTree)(depsTree, exclude, include);
48
+ const prepareIgnoreInstance = async (cwd) => {
56
49
  const ignoreInstance = (0, ignore_1.default)();
57
50
  let gitignore = '';
58
51
  try {
@@ -67,6 +60,24 @@ const getEntryPoints = async ({ cwd, exclude, include, webpackConfigPath, ignore
67
60
  e;
68
61
  }
69
62
  ignoreInstance.add(gitignore);
70
- return [ignoreInstance.filter(possibleEntryPoints), depsTree];
63
+ return ignoreInstance;
64
+ };
65
+ exports.prepareIgnoreInstance = prepareIgnoreInstance;
66
+ const findEntryPointsInDepsTreeAndFilterOutIgnoredFiles = async ({ cwd, depsTree, include = undefined, exclude = [] }) => {
67
+ const possibleEntryPoints = (0, exports.findEntryPointsInDepsTree)(depsTree, exclude, include).sort();
68
+ const ignoreInstance = await (0, exports.prepareIgnoreInstance)(cwd);
69
+ const entryPointsWithoutIgnoredFiles = ignoreInstance.filter(possibleEntryPoints);
70
+ return entryPointsWithoutIgnoredFiles;
71
+ };
72
+ exports.findEntryPointsInDepsTreeAndFilterOutIgnoredFiles = findEntryPointsInDepsTreeAndFilterOutIgnoredFiles;
73
+ const getEntryPoints = async ({ cwd, exclude, include, webpackConfigPath, ignoreTypesImports }) => {
74
+ const dirs = await (0, exports.getDirectoriesForEntryPointsSearch)(cwd);
75
+ const globs = dirs
76
+ .map((dirName) => path_1.default.relative(cwd, dirName))
77
+ .map((dirName) => `${(0, glob_escape_1.default)(dirName)}/*`);
78
+ const globsWithRoot = ['*', ...globs];
79
+ const depsTree = await (0, getDepsTree_1.getDepsTree)(cwd, globsWithRoot, webpackConfigPath, ignoreTypesImports);
80
+ const entryPointsWithoutIgnoredFiles = await (0, exports.findEntryPointsInDepsTreeAndFilterOutIgnoredFiles)({ cwd, include, exclude, depsTree });
81
+ return [entryPointsWithoutIgnoredFiles, depsTree];
71
82
  };
72
83
  exports.getEntryPoints = getEntryPoints;
@@ -0,0 +1,8 @@
1
+ import { MinimalDependencyTree } from './types';
2
+ export declare function getFilesForEntryPoint({ cwd, entryPoint, webpackConfigPath, ignoreTypesImports, depsTree: initDepsTree }: {
3
+ cwd: string;
4
+ entryPoint: string;
5
+ ignoreTypesImports: boolean;
6
+ webpackConfigPath?: string;
7
+ depsTree?: MinimalDependencyTree;
8
+ }): Promise<string[]>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFilesForEntryPoint = void 0;
4
+ const utils_1 = require("./utils");
5
+ const getDepsTree_1 = require("./getDepsTree");
6
+ async function getFilesForEntryPoint({ cwd, entryPoint, webpackConfigPath, ignoreTypesImports, depsTree: initDepsTree }) {
7
+ const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)([entryPoint]);
8
+ const depsTree = initDepsTree !== null && initDepsTree !== void 0 ? initDepsTree : (await (0, getDepsTree_1.getDepsTree)((0, utils_1.resolvePath)(cwd), sanitizedEntryPoints, webpackConfigPath, ignoreTypesImports));
9
+ const filePaths = Object.keys(depsTree);
10
+ return filePaths.sort();
11
+ }
12
+ exports.getFilesForEntryPoint = getFilesForEntryPoint;
@@ -0,0 +1,8 @@
1
+ import { MinimalDependencyTree } from './types';
2
+ export declare function getNodeModulesForEntryPoint({ cwd, entryPoint, webpackConfigPath, ignoreTypesImports, depsTree: initDepsTree }: {
3
+ cwd: string;
4
+ entryPoint: string;
5
+ ignoreTypesImports: boolean;
6
+ webpackConfigPath?: string;
7
+ depsTree?: MinimalDependencyTree;
8
+ }): Promise<(string | undefined)[]>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNodeModulesForEntryPoint = void 0;
4
+ const utils_1 = require("./utils");
5
+ const getDepsTree_1 = require("./getDepsTree");
6
+ async function getNodeModulesForEntryPoint({ cwd, entryPoint, webpackConfigPath, ignoreTypesImports, depsTree: initDepsTree }) {
7
+ const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)([entryPoint]);
8
+ const depsTree = initDepsTree !== null && initDepsTree !== void 0 ? initDepsTree : (await (0, getDepsTree_1.getDepsTree)((0, utils_1.resolvePath)(cwd), sanitizedEntryPoints, webpackConfigPath, ignoreTypesImports, true));
9
+ const nodeModuleImports = Object.values(depsTree)
10
+ .filter((depsTree) => depsTree !== null)
11
+ .flat(2)
12
+ .filter((dep) => (dep === null || dep === void 0 ? void 0 : dep.id) && dep.id.includes('node_modules'))
13
+ .map((dep) => dep === null || dep === void 0 ? void 0 : dep.request)
14
+ .filter(Boolean);
15
+ const uniqueNodeModuleImports = [...new Set(nodeModuleImports)].sort();
16
+ return uniqueNodeModuleImports;
17
+ }
18
+ exports.getNodeModulesForEntryPoint = getNodeModulesForEntryPoint;
@@ -1,3 +1,4 @@
1
+ import { MinimalDependencyTree } from './types';
1
2
  declare type ResolveParams = {
2
3
  entryPoints?: string[];
3
4
  filePath: string;
@@ -9,5 +10,5 @@ declare type ResolveParams = {
9
10
  notTraversePaths?: string[];
10
11
  ignoreTypesImports?: boolean;
11
12
  };
12
- export declare const resolve: ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd, all, include, exclude, notTraversePaths, ignoreTypesImports }: ResolveParams) => Promise<[string[][][], string[]]>;
13
+ export declare const resolve: ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd, all, include, exclude, notTraversePaths, ignoreTypesImports }: ResolveParams) => Promise<[string[][][], string[], MinimalDependencyTree]>;
13
14
  export {};
@@ -54,6 +54,6 @@ const resolve = async ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd
54
54
  const pathsForTree = resolvePathsToRoot(fileNode, all);
55
55
  return [...allPaths, pathsForTree];
56
56
  }, []);
57
- return [resolvedPaths, entryPoints];
57
+ return [resolvedPaths, entryPoints, deps];
58
58
  };
59
59
  exports.resolve = resolve;
@@ -1,10 +1,12 @@
1
- import { Dependency } from 'dpdm';
2
1
  export declare type Node = {
3
2
  path: string;
4
3
  children: Node[];
5
4
  parents: Node[];
6
5
  };
7
- export declare type MinimalDependency = Pick<Dependency, 'id' | 'request'>;
6
+ export declare type MinimalDependency = {
7
+ id: string | null;
8
+ request: string;
9
+ };
8
10
  export declare type MinimalDependencyTree = {
9
11
  [key: string]: readonly MinimalDependency[] | null;
10
12
  };
package/dist/module.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  export { resolve } from './lib/resolve';
2
- export { getEntryPoints } from './lib/getEntryPoints';
2
+ export { getEntryPoints, findEntryPointsInDepsTreeAndFilterOutIgnoredFiles, findEntryPointsInDepsTree } from './lib/getEntryPoints';
3
+ export { getFilesForEntryPoint } from './lib/getFilesForEntryPoint';
4
+ export { getNodeModulesForEntryPoint } from './lib/getNodeModulesForEntryPoint';
5
+ export * from './lib/types';
package/dist/module.js CHANGED
@@ -1,7 +1,28 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEntryPoints = exports.resolve = void 0;
17
+ exports.getNodeModulesForEntryPoint = exports.getFilesForEntryPoint = exports.findEntryPointsInDepsTree = exports.findEntryPointsInDepsTreeAndFilterOutIgnoredFiles = exports.getEntryPoints = exports.resolve = void 0;
4
18
  var resolve_1 = require("./lib/resolve");
5
19
  Object.defineProperty(exports, "resolve", { enumerable: true, get: function () { return resolve_1.resolve; } });
6
20
  var getEntryPoints_1 = require("./lib/getEntryPoints");
7
21
  Object.defineProperty(exports, "getEntryPoints", { enumerable: true, get: function () { return getEntryPoints_1.getEntryPoints; } });
22
+ Object.defineProperty(exports, "findEntryPointsInDepsTreeAndFilterOutIgnoredFiles", { enumerable: true, get: function () { return getEntryPoints_1.findEntryPointsInDepsTreeAndFilterOutIgnoredFiles; } });
23
+ Object.defineProperty(exports, "findEntryPointsInDepsTree", { enumerable: true, get: function () { return getEntryPoints_1.findEntryPointsInDepsTree; } });
24
+ var getFilesForEntryPoint_1 = require("./lib/getFilesForEntryPoint");
25
+ Object.defineProperty(exports, "getFilesForEntryPoint", { enumerable: true, get: function () { return getFilesForEntryPoint_1.getFilesForEntryPoint; } });
26
+ var getNodeModulesForEntryPoint_1 = require("./lib/getNodeModulesForEntryPoint");
27
+ Object.defineProperty(exports, "getNodeModulesForEntryPoint", { enumerable: true, get: function () { return getNodeModulesForEntryPoint_1.getNodeModulesForEntryPoint; } });
28
+ __exportStar(require("./lib/types"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rev-dep",
3
- "version": "1.1.0",
3
+ "version": "1.3.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": "^14.2.1",
63
+ "release-it": "16.2.1",
62
64
  "typescript": "^4.6.2"
63
65
  },
64
66
  "keywords": [