rev-dep 1.5.4 → 2.0.0-alpha-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/Readme.md +5 -0
  2. package/bin.js +66 -1
  3. package/package.json +6 -49
  4. package/README.md +0 -558
  5. package/babel.js +0 -1
  6. package/dist/babel/babelParsingOptions.d.ts +0 -5
  7. package/dist/babel/babelParsingOptions.js +0 -15
  8. package/dist/babel/groupBy.d.ts +0 -1
  9. package/dist/babel/groupBy.js +0 -14
  10. package/dist/babel/index.d.ts +0 -1
  11. package/dist/babel/index.js +0 -449
  12. package/dist/babel/processCodeTextModificationsArray.d.ts +0 -30
  13. package/dist/babel/processCodeTextModificationsArray.js +0 -55
  14. package/dist/babel/template.d.ts +0 -1
  15. package/dist/babel/template.js +0 -13
  16. package/dist/babel/transform.d.ts +0 -6
  17. package/dist/babel/transform.js +0 -66
  18. package/dist/babel/transformCli.d.ts +0 -1
  19. package/dist/babel/transformCli.js +0 -18
  20. package/dist/cli/commonOptions.d.ts +0 -27
  21. package/dist/cli/commonOptions.js +0 -29
  22. package/dist/cli/createCommands.d.ts +0 -2
  23. package/dist/cli/createCommands.js +0 -19
  24. package/dist/cli/docs/generate.d.ts +0 -20
  25. package/dist/cli/docs/generate.js +0 -90
  26. package/dist/cli/docs/index.d.ts +0 -3
  27. package/dist/cli/docs/index.js +0 -18
  28. package/dist/cli/docs/template.d.ts +0 -3
  29. package/dist/cli/docs/template.js +0 -51
  30. package/dist/cli/entryPoints/index.d.ts +0 -2
  31. package/dist/cli/entryPoints/index.js +0 -52
  32. package/dist/cli/entryPoints/types.d.ts +0 -4
  33. package/dist/cli/entryPoints/types.js +0 -2
  34. package/dist/cli/files/index.d.ts +0 -2
  35. package/dist/cli/files/index.js +0 -36
  36. package/dist/cli/files/types.d.ts +0 -3
  37. package/dist/cli/files/types.js +0 -2
  38. package/dist/cli/index.d.ts +0 -1
  39. package/dist/cli/index.js +0 -10
  40. package/dist/cli/nodeModules/index.d.ts +0 -2
  41. package/dist/cli/nodeModules/index.js +0 -36
  42. package/dist/cli/nodeModules/types.d.ts +0 -3
  43. package/dist/cli/nodeModules/types.js +0 -2
  44. package/dist/cli/resolve/formatResults.d.ts +0 -9
  45. package/dist/cli/resolve/formatResults.js +0 -67
  46. package/dist/cli/resolve/index.d.ts +0 -2
  47. package/dist/cli/resolve/index.js +0 -47
  48. package/dist/cli/resolve/types.d.ts +0 -11
  49. package/dist/cli/resolve/types.js +0 -2
  50. package/dist/lib/buildDepsGraph.d.ts +0 -2
  51. package/dist/lib/buildDepsGraph.js +0 -49
  52. package/dist/lib/cleanupDpdmDeps.d.ts +0 -3
  53. package/dist/lib/cleanupDpdmDeps.js +0 -39
  54. package/dist/lib/getDepsSetWebpack.d.ts +0 -6
  55. package/dist/lib/getDepsSetWebpack.js +0 -44
  56. package/dist/lib/getDepsTree.d.ts +0 -1
  57. package/dist/lib/getDepsTree.js +0 -24
  58. package/dist/lib/getEntryPoints.d.ts +0 -18
  59. package/dist/lib/getEntryPoints.js +0 -83
  60. package/dist/lib/getFilesForEntryPoint.d.ts +0 -8
  61. package/dist/lib/getFilesForEntryPoint.js +0 -12
  62. package/dist/lib/getMaxDepthInGraph.d.ts +0 -4
  63. package/dist/lib/getMaxDepthInGraph.js +0 -21
  64. package/dist/lib/getNodeModulesForEntryPoint.d.ts +0 -8
  65. package/dist/lib/getNodeModulesForEntryPoint.js +0 -18
  66. package/dist/lib/resolve.d.ts +0 -15
  67. package/dist/lib/resolve.js +0 -60
  68. package/dist/lib/types.d.ts +0 -12
  69. package/dist/lib/types.js +0 -2
  70. package/dist/lib/utils.d.ts +0 -6
  71. package/dist/lib/utils.js +0 -44
  72. package/dist/module.d.ts +0 -5
  73. package/dist/module.js +0 -28
@@ -1,49 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildDepsGraph = void 0;
7
- const minimatch_1 = __importDefault(require("minimatch"));
8
- const buildDepsGraph = (deps, filePathOrNodeModuleName, notTraversePath) => (entryPoint) => {
9
- const vertices = new Map();
10
- let fileOrNodeModuleNode = null;
11
- const inner = (path, visited = new Set(), depth = 1, parent = null) => {
12
- const vertex = vertices.get(path);
13
- if (vertex) {
14
- vertex.parents.push(parent);
15
- return vertex;
16
- }
17
- const localVisited = new Set(visited);
18
- if (localVisited.has(path)) {
19
- // console.error('CIRCULAR DEP', ...localVisited.values(), path)
20
- return {
21
- path: 'CIRCULAR',
22
- parents: parent ? [parent] : [],
23
- children: []
24
- };
25
- }
26
- localVisited.add(path);
27
- const dep = deps[path];
28
- if (dep === undefined) {
29
- throw new Error(`Dependency '${path}' not found!`);
30
- }
31
- const node = {
32
- parents: parent ? [parent] : [],
33
- path
34
- };
35
- node.children = (dep || [])
36
- .map((d) => d.id)
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))))
40
- .map((path) => inner(path, localVisited, depth + 1, node));
41
- vertices.set(path, node);
42
- if (path === filePathOrNodeModuleName) {
43
- fileOrNodeModuleNode = node;
44
- }
45
- return node;
46
- };
47
- return [inner(entryPoint), fileOrNodeModuleNode, vertices];
48
- };
49
- exports.buildDepsGraph = buildDepsGraph;
@@ -1,3 +0,0 @@
1
- import { DependencyTree } from 'dpdm';
2
- import { MinimalDependencyTree } from './types';
3
- export declare const cleanupDpdmDeps: (deps: MinimalDependencyTree | DependencyTree, includeNodeModules?: boolean) => MinimalDependencyTree;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.cleanupDpdmDeps = void 0;
7
- const is_builtin_module_1 = __importDefault(require("is-builtin-module"));
8
- const cleanupDpdmDeps = (deps, includeNodeModules = false) => {
9
- const newDeps = {};
10
- Object.entries(deps).forEach(([id, dependencies]) => {
11
- const nodeModules = [];
12
- if (!(0, is_builtin_module_1.default)(id) &&
13
- !id.includes('node_modules') &&
14
- dependencies !== null) {
15
- newDeps[id] = dependencies
16
- .filter(({ id }) => id &&
17
- (includeNodeModules || !id.includes('node_modules')) &&
18
- !(0, is_builtin_module_1.default)(id))
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
- });
35
- }
36
- });
37
- return newDeps;
38
- };
39
- exports.cleanupDpdmDeps = cleanupDpdmDeps;
@@ -1,6 +0,0 @@
1
- export declare const getDepsSetWebpack: (entryPoints: string[], webpackConfigPath: string, cwd: string, skipRegex?: RegExp | undefined) => {
2
- [key: string]: {
3
- id: string;
4
- request: string;
5
- }[];
6
- };
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDepsSetWebpack = void 0;
4
- const dependency_cruiser_1 = require("dependency-cruiser");
5
- const utils_1 = require("./utils");
6
- // eslint-disable-next-line
7
- const resolveWebpackConfig = require('dependency-cruiser/config-utl/extract-webpack-resolve-config');
8
- const normalizeDepsTree = (modules) => {
9
- const normalized = {};
10
- const nonResolvableDeps = [];
11
- modules.forEach((mod) => {
12
- const { source, dependencies } = mod;
13
- if (!nonResolvableDeps.includes(source)) {
14
- normalized[source] = dependencies
15
- .filter(({ couldNotResolve, resolved: id }) => {
16
- if (couldNotResolve) {
17
- nonResolvableDeps.push(id);
18
- }
19
- return !couldNotResolve;
20
- })
21
- .map(({ resolved, module }) => ({
22
- id: resolved,
23
- request: module
24
- }));
25
- }
26
- });
27
- return normalized;
28
- };
29
- const getDepsSetWebpack = (entryPoints, webpackConfigPath, cwd, skipRegex) => {
30
- const skip = skipRegex || '(node_modules|/__tests__|/__test__|/__mockContent__|.scss)';
31
- const webpackResolveOptions = webpackConfigPath
32
- ? resolveWebpackConfig((0, utils_1.createResolveAbsolutePath)(cwd)(webpackConfigPath))
33
- : null;
34
- const result = (0, dependency_cruiser_1.cruise)(entryPoints, {
35
- //@ts-ignore
36
- exclude: skip,
37
- //@ts-ignore
38
- doNotFollow: { path: skip },
39
- tsPreCompilationDeps: true,
40
- baseDir: cwd
41
- }, webpackResolveOptions);
42
- return normalizeDepsTree(result.output.modules);
43
- };
44
- exports.getDepsSetWebpack = getDepsSetWebpack;
@@ -1 +0,0 @@
1
- export declare function getDepsTree(cwd: string, entryPoints: string[], webpackConfigPath?: string, ignoreTypesImports?: boolean, includeNodeModules?: boolean): Promise<import("./types").MinimalDependencyTree>;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDepsTree = void 0;
4
- const getDepsSetWebpack_1 = require("./getDepsSetWebpack");
5
- const dpdm_1 = require("dpdm");
6
- const cleanupDpdmDeps_1 = require("./cleanupDpdmDeps");
7
- async function getDepsTree(cwd, entryPoints, webpackConfigPath, ignoreTypesImports = false, includeNodeModules = false) {
8
- let deps;
9
- if (webpackConfigPath) {
10
- deps = (0, getDepsSetWebpack_1.getDepsSetWebpack)(entryPoints, webpackConfigPath, cwd);
11
- }
12
- else {
13
- // dpdm does not support custom search directory :/
14
- const oldProcessCwd = process.cwd;
15
- process.cwd = () => cwd;
16
- deps = (0, cleanupDpdmDeps_1.cleanupDpdmDeps)(await (0, dpdm_1.parseDependencyTree)(entryPoints, {
17
- context: cwd,
18
- transform: ignoreTypesImports
19
- }), includeNodeModules);
20
- process.cwd = oldProcessCwd;
21
- }
22
- return deps;
23
- }
24
- exports.getDepsTree = getDepsTree;
@@ -1,18 +0,0 @@
1
- import { MinimalDependencyTree } from './types';
2
- export declare const getDirectoriesForEntryPointsSearch: (dir: string) => Promise<string[]>;
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[]>;
11
- export declare const getEntryPoints: ({ cwd, exclude, include, webpackConfigPath, ignoreTypesImports, includeNodeModules }: {
12
- cwd: string;
13
- exclude?: string[] | undefined;
14
- include?: string[] | undefined;
15
- webpackConfigPath?: string | undefined;
16
- ignoreTypesImports?: boolean | undefined;
17
- includeNodeModules?: boolean | undefined;
18
- }) => Promise<[string[], MinimalDependencyTree]>;
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getEntryPoints = exports.findEntryPointsInDepsTreeAndFilterOutIgnoredFiles = exports.prepareIgnoreInstance = exports.findEntryPointsInDepsTree = exports.getDirectoriesForEntryPointsSearch = void 0;
7
- const minimatch_1 = __importDefault(require("minimatch"));
8
- const path_1 = __importDefault(require("path"));
9
- const promises_1 = __importDefault(require("fs/promises"));
10
- const utils_1 = require("./utils");
11
- const getDepsTree_1 = require("./getDepsTree");
12
- const ignore_1 = __importDefault(require("ignore"));
13
- const glob_escape_1 = __importDefault(require("glob-escape"));
14
- const getDirectoriesForEntryPointsSearch = async (dir) => {
15
- const entries = await promises_1.default.readdir(dir);
16
- const directories = await (0, utils_1.asyncFilter)(entries, async (pathName) => {
17
- if (pathName === 'node_modules' || pathName.startsWith('.')) {
18
- return false;
19
- }
20
- const stat = await promises_1.default.lstat(path_1.default.resolve(dir, pathName));
21
- return stat.isDirectory();
22
- });
23
- const joinedWithDir = directories.map((pathName) => path_1.default.join(dir, pathName));
24
- return [
25
- ...joinedWithDir,
26
- ...(await Promise.all(joinedWithDir.map(exports.getDirectoriesForEntryPointsSearch))).flat(1)
27
- ];
28
- };
29
- exports.getDirectoriesForEntryPointsSearch = getDirectoriesForEntryPointsSearch;
30
- const findEntryPointsInDepsTree = (deps, exclude = [], include = undefined) => {
31
- const referencedIds = new Set();
32
- Object.values(deps).forEach((entry) => {
33
- if (entry !== null) {
34
- entry.forEach(({ id }) => referencedIds.add(id));
35
- }
36
- });
37
- return Object.keys(deps)
38
- .filter((id) => /\.(ts|tsx|mjs|cjs|js|jsx)$/.test(id) &&
39
- !/node_modules/.test(id) &&
40
- !referencedIds.has(id))
41
- .filter((id) => exclude.reduce((result, pattern) => result && !(0, minimatch_1.default)(id, pattern), true))
42
- .filter((id) => include
43
- ? include.reduce((result, pattern) => result || (0, minimatch_1.default)(id, pattern), false)
44
- : true)
45
- .sort();
46
- };
47
- exports.findEntryPointsInDepsTree = findEntryPointsInDepsTree;
48
- const prepareIgnoreInstance = async (cwd) => {
49
- const ignoreInstance = (0, ignore_1.default)();
50
- let gitignore = '';
51
- try {
52
- gitignore = (await promises_1.default.readFile(path_1.default.join(cwd, '.gitignore'))).toString();
53
- const lines = gitignore.split('\n');
54
- const nonCommentedNonEmptyLines = lines
55
- .filter((line) => !/^(\s*)#/.test(line))
56
- .filter((line) => !/^(\s*)$/.test(line));
57
- gitignore = nonCommentedNonEmptyLines.join('\n');
58
- }
59
- catch (e) {
60
- e;
61
- }
62
- ignoreInstance.add(gitignore);
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, includeNodeModules }) => {
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, includeNodeModules);
80
- const entryPointsWithoutIgnoredFiles = await (0, exports.findEntryPointsInDepsTreeAndFilterOutIgnoredFiles)({ cwd, include, exclude, depsTree });
81
- return [entryPointsWithoutIgnoredFiles, depsTree];
82
- };
83
- exports.getEntryPoints = getEntryPoints;
@@ -1,8 +0,0 @@
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[]>;
@@ -1,12 +0,0 @@
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;
@@ -1,4 +0,0 @@
1
- import { Node } from './types';
2
- declare type MaxDepthMeta = [number, string[]];
3
- export declare const getMaxDepth: (depth?: number, path?: string[], vertices?: Map<any, any>) => (tree: Node) => MaxDepthMeta;
4
- export {};
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMaxDepth = void 0;
4
- const getMaxDepth = (depth = 1, path = [], vertices = new Map()) => {
5
- return (tree) => {
6
- const depthFromCache = vertices.get(tree.path);
7
- if (depthFromCache) {
8
- return depthFromCache;
9
- }
10
- const newPath = [...path, tree.path];
11
- if (tree.children.length === 0) {
12
- return [depth, newPath];
13
- }
14
- const results = tree.children.map((0, exports.getMaxDepth)(depth + 1, newPath, vertices));
15
- const maxChildDepth = Math.max(...results.map(([depth]) => depth));
16
- const itemWithMaxDepth = results.find(([depth]) => depth === maxChildDepth);
17
- vertices.set(tree.path, itemWithMaxDepth);
18
- return itemWithMaxDepth;
19
- };
20
- };
21
- exports.getMaxDepth = getMaxDepth;
@@ -1,8 +0,0 @@
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)[]>;
@@ -1,18 +0,0 @@
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,15 +0,0 @@
1
- import { MinimalDependencyTree } from './types';
2
- declare type ResolveParams = {
3
- entryPoints?: string[];
4
- filePathOrNodeModuleName: string;
5
- webpackConfig?: string;
6
- cwd?: string;
7
- all: boolean;
8
- exclude?: string[];
9
- include?: string[];
10
- notTraversePaths?: string[];
11
- ignoreTypesImports?: boolean;
12
- includeNodeModules?: boolean;
13
- };
14
- export declare const resolve: ({ entryPoints: _entryPoints, filePathOrNodeModuleName, webpackConfig, cwd, all, include, exclude, notTraversePaths, ignoreTypesImports, includeNodeModules }: ResolveParams) => Promise<[string[][][], string[], MinimalDependencyTree]>;
15
- export {};
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolve = void 0;
4
- const buildDepsGraph_1 = require("./buildDepsGraph");
5
- const getDepsTree_1 = require("./getDepsTree");
6
- const getEntryPoints_1 = require("./getEntryPoints");
7
- const utils_1 = require("./utils");
8
- const resolvePathsToRoot = (node, all = false, resolvedPaths = [[]]) => {
9
- const newPaths = resolvedPaths.map((resolvedPath) => [
10
- node.path,
11
- ...resolvedPath
12
- ]);
13
- if (node.parents.length === 0) {
14
- /*
15
- * If there is only one path, and has length of 1, it's file self reference
16
- * It's invalid result, so we return empty paths in that case
17
- */
18
- if (newPaths.length === 1 && newPaths[0].length === 1) {
19
- return [];
20
- }
21
- return newPaths;
22
- }
23
- if (all) {
24
- return node.parents
25
- .map((parentPath) => resolvePathsToRoot(parentPath, all, newPaths))
26
- .flat(1);
27
- }
28
- return resolvePathsToRoot(node.parents[0], false, newPaths);
29
- };
30
- const resolve = async ({ entryPoints: _entryPoints, filePathOrNodeModuleName, webpackConfig, cwd = process.cwd(), all, include, exclude, notTraversePaths, ignoreTypesImports, includeNodeModules }) => {
31
- let deps, entryPoints;
32
- if (_entryPoints && (_entryPoints === null || _entryPoints === void 0 ? void 0 : _entryPoints.length) > 0) {
33
- entryPoints = _entryPoints;
34
- const sanitizedEntryPoints = (0, utils_1.sanitizeUserEntryPoints)(entryPoints);
35
- deps = await (0, getDepsTree_1.getDepsTree)(cwd, sanitizedEntryPoints, webpackConfig, ignoreTypesImports, includeNodeModules);
36
- }
37
- else {
38
- ;
39
- [entryPoints, deps] = await (0, getEntryPoints_1.getEntryPoints)({
40
- cwd,
41
- exclude,
42
- include,
43
- webpackConfigPath: webpackConfig,
44
- ignoreTypesImports,
45
- includeNodeModules
46
- });
47
- }
48
- const cleanedEntryPoints = entryPoints.map(utils_1.removeInitialDot);
49
- const cleanedFilePathOrNodeModuleName = (0, utils_1.removeInitialDot)(filePathOrNodeModuleName);
50
- const forest = cleanedEntryPoints.map((0, buildDepsGraph_1.buildDepsGraph)(deps, cleanedFilePathOrNodeModuleName, notTraversePaths));
51
- const resolvedPaths = forest.reduce((allPaths, [_, fileNode]) => {
52
- if (!fileNode) {
53
- return [...allPaths, []];
54
- }
55
- const pathsForTree = resolvePathsToRoot(fileNode, all);
56
- return [...allPaths, pathsForTree];
57
- }, []);
58
- return [resolvedPaths, entryPoints, deps];
59
- };
60
- exports.resolve = resolve;
@@ -1,12 +0,0 @@
1
- export declare type Node = {
2
- path: string;
3
- children: Node[];
4
- parents: Node[];
5
- };
6
- export declare type MinimalDependency = {
7
- id: string | null;
8
- request: string;
9
- };
10
- export declare type MinimalDependencyTree = {
11
- [key: string]: readonly MinimalDependency[] | null;
12
- };
package/dist/lib/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +0,0 @@
1
- export declare const removeInitialDot: (path: string) => string;
2
- export declare const createResolveAbsolutePath: (cwd: string) => (p: string | undefined) => string | undefined;
3
- export declare const asyncFilter: <T>(arr: T[], predicate: (el: T) => Promise<boolean>) => Promise<T[]>;
4
- export declare const sanitizeUserEntryPoints: (entryPoints: string[]) => string[];
5
- export declare const resolvePath: <P extends string | undefined>(p: P) => string | P;
6
- export declare const findTsConfig: (cwd?: string) => string | undefined;
package/dist/lib/utils.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.findTsConfig = exports.resolvePath = exports.sanitizeUserEntryPoints = exports.asyncFilter = exports.createResolveAbsolutePath = exports.removeInitialDot = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const glob_escape_1 = __importDefault(require("glob-escape"));
10
- const removeInitialDot = (path) => path.replace(/^\.\//, '');
11
- exports.removeInitialDot = removeInitialDot;
12
- const createResolveAbsolutePath = (cwd) => (p) => (typeof p === 'string' ? path_1.default.resolve(cwd, p) : p);
13
- exports.createResolveAbsolutePath = createResolveAbsolutePath;
14
- const asyncFilter = async (arr, predicate) => {
15
- const results = await Promise.all(arr.map(predicate));
16
- return arr.filter((_v, index) => results[index]);
17
- };
18
- exports.asyncFilter = asyncFilter;
19
- const sanitizeUserEntryPoints = (entryPoints) => {
20
- const globEscapedEntryPoints = entryPoints.map(glob_escape_1.default);
21
- return globEscapedEntryPoints;
22
- };
23
- exports.sanitizeUserEntryPoints = sanitizeUserEntryPoints;
24
- const resolvePath = (p) => {
25
- if (!p || path_1.default.isAbsolute(p)) {
26
- return p;
27
- }
28
- return path_1.default.resolve(p);
29
- };
30
- exports.resolvePath = resolvePath;
31
- const findTsConfig = (cwd = process.cwd()) => {
32
- try {
33
- const tsconfig = path_1.default.join(cwd, 'tsconfig.json');
34
- const stat = fs_1.default.statSync(tsconfig);
35
- if (stat.isFile()) {
36
- return tsconfig;
37
- }
38
- }
39
- catch {
40
- /**/
41
- }
42
- return undefined;
43
- };
44
- exports.findTsConfig = findTsConfig;
package/dist/module.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export { resolve } from './lib/resolve';
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 DELETED
@@ -1,28 +0,0 @@
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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getNodeModulesForEntryPoint = exports.getFilesForEntryPoint = exports.findEntryPointsInDepsTree = exports.findEntryPointsInDepsTreeAndFilterOutIgnoredFiles = exports.getEntryPoints = exports.resolve = void 0;
18
- var resolve_1 = require("./lib/resolve");
19
- Object.defineProperty(exports, "resolve", { enumerable: true, get: function () { return resolve_1.resolve; } });
20
- var getEntryPoints_1 = require("./lib/getEntryPoints");
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);