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.
- package/controllers/summary.js +2 -2
- package/package.json +1 -1
- package/utils/summary.js +71 -50
package/controllers/summary.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
11
|
+
}
|
|
12
|
+
return { deadLinks, aliveLinks };
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function getTotalImageSize(graph) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
21
|
+
}
|
|
22
|
+
return totalSize;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function getTotalCodeSize(graph) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
};
|
|
93
|
+
getDeadLinks,
|
|
94
|
+
getTotalImageSize,
|
|
95
|
+
getTotalCodeSize,
|
|
96
|
+
getTop10LargestImages,
|
|
97
|
+
getTop10LargestCodeFiles,
|
|
98
|
+
findCodeFilesAbove100KB,
|
|
99
|
+
getTop10FilesWithHeavyDependencies,
|
|
100
|
+
getTop10FilesWithLightDependencies,
|
|
101
|
+
getTop10FilesHotspots,
|
|
102
|
+
};
|