rev-dep 1.2.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
@@ -438,6 +438,27 @@ rev-dep files <entryPoint> [options]
438
438
  - `-c, --count` - print only count of entry point dependencies (_optional_)
439
439
  - `-iti --ignoreTypesImports` - Use this flag to not follow type imports when resolving modules (_optional_)
440
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_)
461
+
441
462
  ### Command `docs`
442
463
 
443
464
  Generate documentation of available commands into md file.
@@ -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;
@@ -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>')
@@ -16,9 +15,12 @@ function createFiles(program) {
16
15
  .option(...commonOptions_1.ignoreTypesImports)
17
16
  .action(async (entryPoint, data) => {
18
17
  const { webpackConfig: webpackConfigPath, cwd, count, ignoreTypesImports } = data;
19
- const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)([entryPoint]);
20
- const depsTree = await (0, getDepsTree_1.getDepsTree)((0, utils_1.resolvePath)(cwd), sanitizedEntryPoints, webpackConfigPath, ignoreTypesImports);
21
- const filePaths = Object.keys(depsTree);
18
+ const filePaths = await (0, getFilesForEntryPoint_1.getFilesForEntryPoint)({
19
+ cwd,
20
+ entryPoint,
21
+ webpackConfigPath,
22
+ ignoreTypesImports
23
+ });
22
24
  if (filePaths.length === 0) {
23
25
  console.log('No results found');
24
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 });
@@ -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.2.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",