qleaner 1.1.2 → 1.1.3

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.
@@ -168,7 +168,7 @@ function getTop10LargestFiles(chalk) {
168
168
  const totalCodeSize = getTotalCodeSize(codeGraph.graph);
169
169
  const totalImageSize = getTotalImageSize(imageGraph.graph);
170
170
  const top10CodeFiles = getTop10LargestCodeFiles(codeGraph.graph);
171
- const top10ImageFiles = getTop10LargestImages(imageGraph.graph);
171
+ const top10ImageFiles = getTop10LargestImages(imageGraph.graph, false);
172
172
  const codeFilesAbove100KB = findCodeFilesAbove100KB(codeGraph.graph);
173
173
 
174
174
  // Top 10 Largest Code Files
@@ -279,7 +279,7 @@ function dependenciesSummary(chalk) {
279
279
  // image graph
280
280
  const {deadLinks, aliveLinks} = getDeadLinks(imageGraph.graph);
281
281
  const top10FilesHotspotsDeadImage = getTop10FilesHotspots(deadLinks);
282
- const top10FilesHotspotsAliveImage = getTop10FilesHotspots(aliveLinks);
282
+ const top10FilesHotspotsAliveImage = getTop10FilesHotspots(aliveLinks, false);
283
283
 
284
284
  console.log(chalk.green.bold("\nšŸ“Š Dependencies Summary"));
285
285
  console.log(chalk.green("════════════════════════════════════════════════"));
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "qleaner",
3
3
  "description": "A CLI tool for analyzing and identifying unused files, images, imports, and dead code in React, TypeScript, and JavaScript projects to help optimize bundle size and maintain clean codebases",
4
4
  "packageManager": "yarn@4.6.0",
5
- "version": "1.1.2",
5
+ "version": "1.1.3",
6
6
  "license": "MIT",
7
7
  "main": "command.js",
8
8
  "bin": "bin/cli.js",
package/utils/summary.js CHANGED
@@ -1,81 +1,102 @@
1
1
  function getDeadLinks(graph) {
2
- // get the dead links from the graph
3
- const deadLinks = new Map();
4
- const aliveLinks = new Map();
5
- for (const [filePath, node] of graph.entries()) {
6
- if (node.hash === null) {
7
- deadLinks.set(filePath, {...node});
8
- }else{
9
- aliveLinks.set(filePath, {...node});
10
- }
2
+ // get the dead links from the graph
3
+ const deadLinks = new Map();
4
+ const aliveLinks = new Map();
5
+ for (const [filePath, node] of graph.entries()) {
6
+ if (node.hash === null) {
7
+ deadLinks.set(filePath, { ...node });
8
+ } else {
9
+ aliveLinks.set(filePath, { ...node });
11
10
  }
12
- return {deadLinks, aliveLinks};
11
+ }
12
+ return { deadLinks, aliveLinks };
13
13
  }
14
14
 
15
15
  function getTotalImageSize(graph) {
16
- let totalSize = 0;
17
- for (const [filePath, node] of graph.entries()) {
18
- if (node.hash !== null) {
19
- totalSize += node.size;
20
- }
16
+ let totalSize = 0;
17
+ for (const [filePath, node] of graph.entries()) {
18
+ if (node.hash !== null && node.isImage === true) {
19
+ totalSize += node.size;
21
20
  }
22
- return totalSize;
21
+ }
22
+ return totalSize;
23
23
  }
24
24
 
25
25
  function getTotalCodeSize(graph) {
26
- let totalSize = 0;
27
- for (const [filePath, node] of graph.entries()) {
28
- totalSize += node.size;
29
- }
30
- return totalSize;
26
+ let totalSize = 0;
27
+ for (const [filePath, node] of graph.entries()) {
28
+ totalSize += node.size;
29
+ }
30
+ return totalSize;
31
31
  }
32
32
 
33
33
  function getTop10LargestImages(graph) {
34
- const largestImages = new Map();
35
- for (const [filePath, node] of graph.entries()) {
36
- largestImages.set(filePath, node.size);
34
+ const largestImages = new Map();
35
+ for (const [filePath, node] of graph.entries()) {
36
+ if (node.isImage === true && node.hash !== null) {
37
+ largestImages.set(filePath, node.size);
37
38
  }
38
- return Array.from(largestImages.entries()).sort((a, b) => b[1] - a[1]).slice(0, 10);
39
+ }
40
+ return Array.from(largestImages.entries())
41
+ .sort((a, b) => b[1] - a[1])
42
+ .slice(0, 10);
39
43
  }
40
44
 
41
45
  function getTop10LargestCodeFiles(graph) {
42
- const largestCodeFiles = new Map();
43
- for (const [filePath, node] of graph.entries()) {
44
- largestCodeFiles.set(filePath, node.size);
45
- }
46
- return Array.from(largestCodeFiles.entries()).sort((a, b) => b[1] - a[1]).slice(0, 10);
46
+ const largestCodeFiles = new Map();
47
+ for (const [filePath, node] of graph.entries()) {
48
+ largestCodeFiles.set(filePath, node.size);
49
+ }
50
+ return Array.from(largestCodeFiles.entries())
51
+ .sort((a, b) => b[1] - a[1])
52
+ .slice(0, 10);
47
53
  }
48
54
 
49
55
  function findCodeFilesAbove100KB(graph) {
50
- const codeFilesAbove100KB = new Map();
51
- for (const [filePath, node] of graph.entries()) {
52
- if (node.size > 100 * 1024) {
53
- codeFilesAbove100KB.set(filePath, node.size);
54
- }
56
+ const codeFilesAbove100KB = new Map();
57
+ for (const [filePath, node] of graph.entries()) {
58
+ if (node.size > 100 * 1024) {
59
+ codeFilesAbove100KB.set(filePath, node.size);
55
60
  }
56
- return Array.from(codeFilesAbove100KB.entries()).sort((a, b) => b[1] - a[1]).slice(0, 10);
61
+ }
62
+ return Array.from(codeFilesAbove100KB.entries())
63
+ .sort((a, b) => b[1] - a[1])
64
+ .slice(0, 10);
57
65
  }
58
66
 
59
67
  function getTop10FilesWithHeavyDependencies(graph) {
60
- return Array.from(graph.entries()).sort((a, b) => b[1].imports.size - a[1].imports.size).slice(0, 10);
68
+ return Array.from(graph.entries())
69
+ .sort((a, b) => b[1].imports.size - a[1].imports.size)
70
+ .slice(0, 10);
61
71
  }
62
72
 
63
73
  function getTop10FilesWithLightDependencies(graph) {
64
- return Array.from(graph.entries()).sort((a, b) => a[1].imports.size - b[1].imports.size).slice(0, 10);
74
+ return Array.from(graph.entries())
75
+ .sort((a, b) => a[1].imports.size - b[1].imports.size)
76
+ .slice(0, 10);
65
77
  }
66
78
 
67
- function getTop10FilesHotspots(graph) {
68
- return Array.from(graph.entries()).sort((a, b) => b[1].importedBy.size - a[1].importedBy.size).slice(0, 10);
79
+ function getTop10FilesHotspots(graph, isCheck = true) {
80
+ if (isCheck) {
81
+ return Array.from(graph.entries())
82
+ .sort((a, b) => b[1].importedBy.size - a[1].importedBy.size)
83
+ .slice(0, 10);
84
+ } else {
85
+ return Array.from(graph.entries())
86
+ .sort((a, b) => b[1].importedBy.size - a[1].importedBy.size)
87
+ .filter(([filePath, node]) => node.isImage === true)
88
+ .slice(0, 10);
89
+ }
69
90
  }
70
91
 
71
92
  module.exports = {
72
- getDeadLinks,
73
- getTotalImageSize,
74
- getTotalCodeSize,
75
- getTop10LargestImages,
76
- getTop10LargestCodeFiles,
77
- findCodeFilesAbove100KB,
78
- getTop10FilesWithHeavyDependencies,
79
- getTop10FilesWithLightDependencies,
80
- getTop10FilesHotspots
81
- };
93
+ getDeadLinks,
94
+ getTotalImageSize,
95
+ getTotalCodeSize,
96
+ getTop10LargestImages,
97
+ getTop10LargestCodeFiles,
98
+ findCodeFilesAbove100KB,
99
+ getTop10FilesWithHeavyDependencies,
100
+ getTop10FilesWithLightDependencies,
101
+ getTop10FilesHotspots,
102
+ };