@gld5000-cli/dependency-finder 1.0.8 → 1.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gld5000-cli/dependency-finder",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Finds how many dependents your components have.",
5
5
  "keywords": [
6
6
  "CLI",
@@ -59,7 +59,10 @@ export function findDependentsInTargetPaths(
59
59
  .flatMap((searchTerm) =>
60
60
  searchFileContent(
61
61
  content,
62
- new RegExp(`import [^'"]*${searchTerm}[^a-zA-Z]([^'"]+["']){2}`, "g"),
62
+ new RegExp(
63
+ `import[^'"a-zA-Z]*${searchTerm}[^a-zA-Z]([^'"]+["']){2}`,
64
+ "g",
65
+ ),
63
66
  ),
64
67
  )
65
68
  .filter((currentArray) => currentArray.length > 0);
@@ -1,73 +0,0 @@
1
- import { readFileContent } from "./readFileContent.mjs";
2
- import { searchFileContent } from "./searchFileContent.mjs";
3
- import { findFiles } from "./findFiles.mjs";
4
- import { filterFilesNot } from "./filterFiles.mjs";
5
-
6
- export function findDependentsInTargetPaths(
7
- componentObjectArray,
8
- targetPaths = ["./components/**/*.tsx", "./pages/**/*.tsx"],
9
- ) {
10
- return targetPaths.reduce(targetPathReducer, componentObjectArray);
11
- }
12
- /**
13
- * Finds dependents in each target path and creates a single object to represent them
14
- * @param {*} accumulator
15
- * @param {*} currentTargetPath
16
- * @returns
17
- */
18
- function targetPathReducer(componentObjectArray, currentTargetPath) {
19
- return componentObjectArray.reduce(componentObjectArrayReducer, {
20
- currentTargetPath,
21
- componentObjectArray: [],
22
- }).componentObjectArray;
23
- }
24
- /**
25
- * Traverses componentObjectArray and checks for its exports in all relevant files in the current target path
26
- * @param {*} componentObject
27
- * @returns
28
- */
29
- function componentObjectArrayReducer(acc, componentObject) {
30
- const { matches, filePath, dependents } = componentObject;
31
- const { currentTargetPath } = acc;
32
- const targetFilelist = filterFilesNot(findFiles(currentTargetPath), [
33
- ".test",
34
- ".stories",
35
- ]);
36
- const { dependentsArray } = targetFilelist.reduce(targetFileListReducer, {
37
- matches,
38
- dependentsArray: [],
39
- });
40
- acc.componentObjectArray.push({
41
- matches,
42
- filePath,
43
- dependents:
44
- dependents !== undefined
45
- ? [...dependents, ...dependentsArray]
46
- : dependentsArray,
47
- });
48
- return acc;
49
- }
50
- /**
51
- * For each target file, check against all match items and add details to dependents array if matches are found
52
- * @param {*} acc
53
- * @param {*} curr
54
- * @returns
55
- */
56
- function targetFileListReducer(acc, currentFilePath) {
57
- const content = readFileContent(currentFilePath);
58
- const dependentsCandidates = acc.matches
59
- .flatMap((searchTerm) =>
60
- searchFileContent(
61
- content,
62
- new RegExp(`import [^']*${searchTerm}[^a-zA-Z]([^']+'){2}`, "g"),
63
- ),
64
- )
65
- .filter((currentArray) => currentArray.length > 0);
66
- if (dependentsCandidates && dependentsCandidates.length > 0) {
67
- acc.dependentsArray.push({
68
- filePath: currentFilePath,
69
- matches: dependentsCandidates,
70
- });
71
- }
72
- return acc;
73
- }