rev-dep 1.3.0 → 1.4.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
@@ -378,12 +378,12 @@ Checks if a filePath is required from entryPoint(s) and prints the resolution pa
378
378
  #### Usage
379
379
 
380
380
  ```sh
381
- rev-dep resolve <filePath> [entryPoints...] [options]
381
+ rev-dep resolve <filePathOrNodeModuleName> [entryPoints...] [options]
382
382
  ```
383
383
 
384
384
  #### Arguments
385
385
 
386
- - `filePath` - Path to a file that should be resolved in entry points (**required**)
386
+ - `filePathOrNodeModuleName` - undefined (**required**)
387
387
  - `entryPoints...` - List of entry points to look for file (_optional_)
388
388
 
389
389
  #### Options
@@ -395,6 +395,7 @@ rev-dep resolve <filePath> [entryPoints...] [options]
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
397
  - `-ntp --notTraversePaths <paths...>` - Specify file paths relative to resolution root, that should not be traversed when finding dependency path (_optional_)
398
+ - `-inm --includeNodeModules` - Whether to include node modules in dependency graph. Has to be provided to resolve node module. (_optional_)
398
399
  - `-iti --ignoreTypesImports` - Use this flag to not follow type imports when resolving modules (_optional_)
399
400
 
400
401
  ### Command `entry-points`
@@ -1,9 +1,9 @@
1
1
  import { InputParams } from './types';
2
2
  declare type Results = Array<Array<Array<string>>>;
3
- export declare function formatResults({ results, filePath, entryPoints, compactSummary }: {
3
+ export declare function formatResults({ results, filePathOrNodeModuleName, entryPoints, compactSummary }: {
4
4
  results: Results;
5
5
  compactSummary: InputParams['compactSummary'];
6
6
  entryPoints: string[];
7
- filePath: string;
7
+ filePathOrNodeModuleName: string;
8
8
  }): string;
9
9
  export {};
@@ -29,11 +29,11 @@ const pathToString = (str, filePath, indentation) => {
29
29
  return `${str ? `${str}\n` : ''}${' '.repeat(indentation)} ➞ ${filePath}`;
30
30
  };
31
31
  const join = (...args) => args.join(' ') + '\n';
32
- function formatResults({ results, filePath, entryPoints, compactSummary }) {
32
+ function formatResults({ results, filePathOrNodeModuleName, entryPoints, compactSummary }) {
33
33
  let formatted = '';
34
34
  const hasAnyResults = results.some((paths) => paths.length > 0);
35
35
  if (!hasAnyResults) {
36
- formatted = join('No results found for', filePath, 'in the following entry points list:\n' + entryPoints.join('\n'));
36
+ formatted = join('No results found for', filePathOrNodeModuleName, 'in the following entry points list:\n' + entryPoints.join('\n'));
37
37
  return formatted;
38
38
  }
39
39
  if (compactSummary) {
@@ -6,7 +6,7 @@ const utils_1 = require("../../lib/utils");
6
6
  const commonOptions_1 = require("../commonOptions");
7
7
  function createResolve(program) {
8
8
  program
9
- .command('resolve <filePath> [entryPoints...]')
9
+ .command('resolve <filePathOrNodeModuleName> [entryPoints...]')
10
10
  .description('Checks if a filePath is required from entryPoint(s) and prints the resolution path', {
11
11
  filePath: 'Path to a file that should be resolved in entry points',
12
12
  'entryPoints...': 'List of entry points to look for file'
@@ -19,25 +19,27 @@ function createResolve(program) {
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
21
  .option('-ntp --notTraversePaths <paths...>', 'Specify file paths relative to resolution root, that should not be traversed when finding dependency path')
22
+ .option('-inm --includeNodeModules', 'Whether to include node modules in dependency graph. Has to be provided to resolve node module.', true)
22
23
  .option(...commonOptions_1.ignoreTypesImports)
23
- .action(async (filePath, entryPoints, data) => {
24
- const { compactSummary, webpackConfig, all, cwd, exclude, include, notTraversePaths, ignoreTypesImports } = data;
24
+ .action(async (filePathOrNodeModuleName, entryPoints, data) => {
25
+ const { compactSummary, webpackConfig, all, cwd, exclude, include, notTraversePaths, ignoreTypesImports, includeNodeModules } = data;
25
26
  const [results, resolveEntryPoints] = await (0, resolve_1.resolve)({
26
27
  entryPoints,
27
- filePath,
28
+ filePathOrNodeModuleName,
28
29
  webpackConfig,
29
30
  all,
30
31
  cwd: (0, utils_1.resolvePath)(cwd),
31
32
  exclude,
32
33
  include,
33
34
  notTraversePaths,
34
- ignoreTypesImports
35
+ ignoreTypesImports,
36
+ includeNodeModules
35
37
  });
36
38
  const formatted = (0, formatResults_1.formatResults)({
37
39
  results,
38
40
  entryPoints: resolveEntryPoints,
39
41
  compactSummary,
40
- filePath
42
+ filePathOrNodeModuleName
41
43
  });
42
44
  console.log(formatted);
43
45
  });
@@ -7,4 +7,5 @@ export declare type InputParams = {
7
7
  printDependentCount?: boolean;
8
8
  all: boolean;
9
9
  notTraversePaths?: string[];
10
+ includeNodeModules?: boolean;
10
11
  };
@@ -1,2 +1,2 @@
1
1
  import { Node, MinimalDependencyTree } from './types';
2
- export declare const buildDepsGraph: (deps: MinimalDependencyTree, filePath?: string | undefined, notTraversePath?: string[] | undefined) => (entryPoint: string) => [Node, Node | null, Map<string, Node>];
2
+ export declare const buildDepsGraph: (deps: MinimalDependencyTree, filePathOrNodeModuleName?: string | undefined, notTraversePath?: string[] | undefined) => (entryPoint: string) => [Node, Node | null, Map<string, Node>];
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.buildDepsGraph = void 0;
7
7
  const minimatch_1 = __importDefault(require("minimatch"));
8
- const buildDepsGraph = (deps, filePath, notTraversePath) => (entryPoint) => {
8
+ const buildDepsGraph = (deps, filePathOrNodeModuleName, notTraversePath) => (entryPoint) => {
9
9
  const vertices = new Map();
10
- let fileNode = null;
10
+ let fileOrNodeModuleNode = null;
11
11
  const inner = (path, visited = new Set(), depth = 1, parent = null) => {
12
12
  const vertex = vertices.get(path);
13
13
  if (vertex) {
@@ -39,11 +39,11 @@ const buildDepsGraph = (deps, filePath, notTraversePath) => (entryPoint) => {
39
39
  !(notTraversePath === null || notTraversePath === void 0 ? void 0 : notTraversePath.some((pathToNotTraverse) => (0, minimatch_1.default)(path, pathToNotTraverse))))
40
40
  .map((path) => inner(path, localVisited, depth + 1, node));
41
41
  vertices.set(path, node);
42
- if (path === filePath) {
43
- fileNode = node;
42
+ if (path === filePathOrNodeModuleName) {
43
+ fileOrNodeModuleNode = node;
44
44
  }
45
45
  return node;
46
46
  };
47
- return [inner(entryPoint), fileNode, vertices];
47
+ return [inner(entryPoint), fileOrNodeModuleNode, vertices];
48
48
  };
49
49
  exports.buildDepsGraph = buildDepsGraph;
@@ -8,6 +8,7 @@ const is_builtin_module_1 = __importDefault(require("is-builtin-module"));
8
8
  const cleanupDpdmDeps = (deps, includeNodeModules = false) => {
9
9
  const newDeps = {};
10
10
  Object.entries(deps).forEach(([id, dependencies]) => {
11
+ const nodeModules = [];
11
12
  if (!(0, is_builtin_module_1.default)(id) &&
12
13
  !id.includes('node_modules') &&
13
14
  dependencies !== null) {
@@ -15,10 +16,22 @@ const cleanupDpdmDeps = (deps, includeNodeModules = false) => {
15
16
  .filter(({ id }) => id &&
16
17
  (includeNodeModules || !id.includes('node_modules')) &&
17
18
  !(0, is_builtin_module_1.default)(id))
18
- .map(({ id, request }) => ({
19
- id,
20
- request
21
- }));
19
+ .map(({ id, request }) => {
20
+ const shouldAddNodeModule = includeNodeModules && (id === null || id === void 0 ? void 0 : id.includes('node_modules'));
21
+ const idToAdd = shouldAddNodeModule ? request : id;
22
+ if (shouldAddNodeModule && idToAdd) {
23
+ nodeModules.push(idToAdd);
24
+ }
25
+ return {
26
+ id: idToAdd,
27
+ request
28
+ };
29
+ });
30
+ }
31
+ if (includeNodeModules) {
32
+ nodeModules.forEach((nodeModuleName) => {
33
+ newDeps[nodeModuleName] = [];
34
+ });
22
35
  }
23
36
  });
24
37
  return newDeps;
@@ -8,10 +8,11 @@ export declare const findEntryPointsInDepsTreeAndFilterOutIgnoredFiles: ({ cwd,
8
8
  include: string[] | undefined;
9
9
  cwd: string;
10
10
  }) => Promise<string[]>;
11
- export declare const getEntryPoints: ({ cwd, exclude, include, webpackConfigPath, ignoreTypesImports }: {
11
+ export declare const getEntryPoints: ({ cwd, exclude, include, webpackConfigPath, ignoreTypesImports, includeNodeModules }: {
12
12
  cwd: string;
13
13
  exclude?: string[] | undefined;
14
14
  include?: string[] | undefined;
15
15
  webpackConfigPath?: string | undefined;
16
16
  ignoreTypesImports?: boolean | undefined;
17
+ includeNodeModules?: boolean | undefined;
17
18
  }) => Promise<[string[], MinimalDependencyTree]>;
@@ -70,13 +70,13 @@ const findEntryPointsInDepsTreeAndFilterOutIgnoredFiles = async ({ cwd, depsTree
70
70
  return entryPointsWithoutIgnoredFiles;
71
71
  };
72
72
  exports.findEntryPointsInDepsTreeAndFilterOutIgnoredFiles = findEntryPointsInDepsTreeAndFilterOutIgnoredFiles;
73
- const getEntryPoints = async ({ cwd, exclude, include, webpackConfigPath, ignoreTypesImports }) => {
73
+ const getEntryPoints = async ({ cwd, exclude, include, webpackConfigPath, ignoreTypesImports, includeNodeModules }) => {
74
74
  const dirs = await (0, exports.getDirectoriesForEntryPointsSearch)(cwd);
75
75
  const globs = dirs
76
76
  .map((dirName) => path_1.default.relative(cwd, dirName))
77
77
  .map((dirName) => `${(0, glob_escape_1.default)(dirName)}/*`);
78
78
  const globsWithRoot = ['*', ...globs];
79
- const depsTree = await (0, getDepsTree_1.getDepsTree)(cwd, globsWithRoot, webpackConfigPath, ignoreTypesImports);
79
+ const depsTree = await (0, getDepsTree_1.getDepsTree)(cwd, globsWithRoot, webpackConfigPath, ignoreTypesImports, includeNodeModules);
80
80
  const entryPointsWithoutIgnoredFiles = await (0, exports.findEntryPointsInDepsTreeAndFilterOutIgnoredFiles)({ cwd, include, exclude, depsTree });
81
81
  return [entryPointsWithoutIgnoredFiles, depsTree];
82
82
  };
@@ -1,7 +1,7 @@
1
1
  import { MinimalDependencyTree } from './types';
2
2
  declare type ResolveParams = {
3
3
  entryPoints?: string[];
4
- filePath: string;
4
+ filePathOrNodeModuleName: string;
5
5
  webpackConfig?: string;
6
6
  cwd?: string;
7
7
  all: boolean;
@@ -9,6 +9,7 @@ declare type ResolveParams = {
9
9
  include?: string[];
10
10
  notTraversePaths?: string[];
11
11
  ignoreTypesImports?: boolean;
12
+ includeNodeModules?: boolean;
12
13
  };
13
- export declare const resolve: ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd, all, include, exclude, notTraversePaths, ignoreTypesImports }: ResolveParams) => Promise<[string[][][], string[], MinimalDependencyTree]>;
14
+ export declare const resolve: ({ entryPoints: _entryPoints, filePathOrNodeModuleName, webpackConfig, cwd, all, include, exclude, notTraversePaths, ignoreTypesImports, includeNodeModules }: ResolveParams) => Promise<[string[][][], string[], MinimalDependencyTree]>;
14
15
  export {};
@@ -27,12 +27,12 @@ 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, notTraversePaths, ignoreTypesImports }) => {
30
+ const resolve = async ({ entryPoints: _entryPoints, filePathOrNodeModuleName, webpackConfig, cwd = process.cwd(), all, include, exclude, notTraversePaths, ignoreTypesImports, includeNodeModules }) => {
31
31
  let deps, entryPoints;
32
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, ignoreTypesImports);
35
+ deps = await (0, getDepsTree_1.getDepsTree)(cwd, sanitizedEntryPoints, webpackConfig, ignoreTypesImports, includeNodeModules);
36
36
  }
37
37
  else {
38
38
  ;
@@ -41,12 +41,13 @@ const resolve = async ({ entryPoints: _entryPoints, filePath, webpackConfig, cwd
41
41
  exclude,
42
42
  include,
43
43
  webpackConfigPath: webpackConfig,
44
- ignoreTypesImports
44
+ ignoreTypesImports,
45
+ includeNodeModules
45
46
  });
46
47
  }
47
48
  const cleanedEntryPoints = entryPoints.map(utils_1.removeInitialDot);
48
- const cleanedFilePath = (0, utils_1.removeInitialDot)(filePath);
49
- const forest = cleanedEntryPoints.map((0, buildDepsGraph_1.buildDepsGraph)(deps, cleanedFilePath, notTraversePaths));
49
+ const cleanedFilePathOrNodeModuleName = (0, utils_1.removeInitialDot)(filePathOrNodeModuleName);
50
+ const forest = cleanedEntryPoints.map((0, buildDepsGraph_1.buildDepsGraph)(deps, cleanedFilePathOrNodeModuleName, notTraversePaths));
50
51
  const resolvedPaths = forest.reduce((allPaths, [_, fileNode]) => {
51
52
  if (!fileNode) {
52
53
  return [...allPaths, []];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rev-dep",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Dependency debugging tool for JavaScript and TypeScript projects",
5
5
  "main": "dist/module.js",
6
6
  "bin": "bin.js",