whyinstall 0.2.0 → 0.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/dist/analyzer.d.ts +1 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +2 -8
- package/dist/analyzer.js.map +1 -1
- package/dist/cli.js +13 -5
- package/dist/cli.js.map +1 -1
- package/dist/fileFinder.d.ts +0 -8
- package/dist/fileFinder.d.ts.map +1 -1
- package/dist/fileFinder.js +0 -94
- package/dist/fileFinder.js.map +1 -1
- package/dist/formatter.d.ts +3 -2
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +19 -49
- package/dist/formatter.js.map +1 -1
- package/dist/sizeMapAnalyzer.d.ts +3 -0
- package/dist/sizeMapAnalyzer.d.ts.map +1 -0
- package/dist/sizeMapAnalyzer.js +134 -0
- package/dist/sizeMapAnalyzer.js.map +1 -0
- package/dist/types.d.ts +11 -13
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/analyzer.ts +2 -9
- package/src/cli.ts +14 -7
- package/src/fileFinder.ts +0 -111
- package/src/formatter.ts +24 -57
- package/src/sizeMapAnalyzer.ts +145 -0
- package/src/types.ts +13 -15
- package/src/impactAnalyzer.ts +0 -139
package/dist/analyzer.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AnalyzeResult } from './types';
|
|
2
|
-
export declare function analyzePackage(packageName: string, cwd?: string
|
|
2
|
+
export declare function analyzePackage(packageName: string, cwd?: string): AnalyzeResult;
|
|
3
3
|
//# sourceMappingURL=analyzer.d.ts.map
|
package/dist/analyzer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,aAAa,EAAE,MAAM,SAAS,CAAC;AA+LrE,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,GAAE,MAAsB,GAAG,aAAa,CA6D9F"}
|
package/dist/analyzer.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.analyzePackage = analyzePackage;
|
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const fileFinder_1 = require("./fileFinder");
|
|
7
|
-
const impactAnalyzer_1 = require("./impactAnalyzer");
|
|
8
7
|
function readPackageJson(path) {
|
|
9
8
|
try {
|
|
10
9
|
if ((0, fs_1.existsSync)(path)) {
|
|
@@ -161,7 +160,7 @@ function formatSize(bytes) {
|
|
|
161
160
|
return `${(bytes / 1024).toFixed(0)} KB`;
|
|
162
161
|
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
163
162
|
}
|
|
164
|
-
function analyzePackage(packageName, cwd = process.cwd()
|
|
163
|
+
function analyzePackage(packageName, cwd = process.cwd()) {
|
|
165
164
|
const rootPackageJson = (0, path_1.join)(cwd, 'package.json');
|
|
166
165
|
const packageJsonPath = findPackageJsonPath(packageName, cwd);
|
|
167
166
|
if (!packageJsonPath) {
|
|
@@ -202,10 +201,6 @@ function analyzePackage(packageName, cwd = process.cwd(), includeImpact = false)
|
|
|
202
201
|
}
|
|
203
202
|
}
|
|
204
203
|
const sourceFiles = (0, fileFinder_1.findFilesUsingPackage)(packageName, cwd);
|
|
205
|
-
let impact;
|
|
206
|
-
if (includeImpact) {
|
|
207
|
-
impact = (0, impactAnalyzer_1.analyzeImpact)(packageName, cwd);
|
|
208
|
-
}
|
|
209
204
|
return {
|
|
210
205
|
package: {
|
|
211
206
|
name: packageName,
|
|
@@ -213,8 +208,7 @@ function analyzePackage(packageName, cwd = process.cwd(), includeImpact = false)
|
|
|
213
208
|
description,
|
|
214
209
|
size,
|
|
215
210
|
paths,
|
|
216
|
-
sourceFiles: sourceFiles.length > 0 ? sourceFiles : undefined
|
|
217
|
-
impact
|
|
211
|
+
sourceFiles: sourceFiles.length > 0 ? sourceFiles : undefined
|
|
218
212
|
},
|
|
219
213
|
suggestions
|
|
220
214
|
};
|
package/dist/analyzer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":";;AAiMA,wCA6DC;AA9PD,2BAAqE;AACrE,+BAAqC;AAGrC,6CAAqD;AAYrD,SAAS,eAAe,CAAC,IAAY;IACnC,IAAI,CAAC;QACH,IAAI,IAAA,eAAU,EAAC,IAAI,CAAC,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,SAAS;IACX,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,mBAAmB,CAAC,WAAmB,EAAE,GAAW;IAC3D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,WAAW,eAAe,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClF,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,eAAe,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;QAC/E,IAAI,IAAA,eAAU,EAAC,eAAe,CAAC,EAAE,CAAC;YAChC,OAAO,eAAe,CAAC;QACzB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,wBAAwB,CAAC,WAA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AC,WAAW,CAAC,CAAC,CAAC,SAAS;SAC9D;QACD,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -9,15 +9,16 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
9
9
|
const analyzer_1 = require("./analyzer");
|
|
10
10
|
const formatter_1 = require("./formatter");
|
|
11
11
|
const packageManager_1 = require("./packageManager");
|
|
12
|
+
const sizeMapAnalyzer_1 = require("./sizeMapAnalyzer");
|
|
12
13
|
const program = new commander_1.Command();
|
|
13
14
|
program
|
|
14
15
|
.name('whyinstall')
|
|
15
16
|
.description('Find why a dependency exists in your JS/TS project')
|
|
16
|
-
.version('0.
|
|
17
|
+
.version('0.3.0')
|
|
17
18
|
.argument('<package-name>', 'Package name to analyze')
|
|
18
19
|
.option('-j, --json', 'Output as JSON')
|
|
19
20
|
.option('-c, --cwd <path>', 'Working directory', process.cwd())
|
|
20
|
-
.option('--
|
|
21
|
+
.option('-s, --size-map', 'Show bundle size impact breakdown')
|
|
21
22
|
.action((packageName, options) => {
|
|
22
23
|
try {
|
|
23
24
|
const cwd = options.cwd || process.cwd();
|
|
@@ -25,9 +26,16 @@ program
|
|
|
25
26
|
if (!options.json) {
|
|
26
27
|
console.log(`\n${chalk_1.default.gray(`Detected package manager: ${pm}`)}\n`);
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
if (options.sizeMap) {
|
|
30
|
+
const result = (0, sizeMapAnalyzer_1.analyzeSizeMap)(packageName, cwd);
|
|
31
|
+
const output = (0, formatter_1.formatSizeMap)(result, options.json);
|
|
32
|
+
console.log(output);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const result = (0, analyzer_1.analyzePackage)(packageName, cwd);
|
|
36
|
+
const output = (0, formatter_1.formatOutput)(result, options.json);
|
|
37
|
+
console.log(output);
|
|
38
|
+
}
|
|
31
39
|
process.exit(0);
|
|
32
40
|
}
|
|
33
41
|
catch (error) {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,yCAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,yCAA4C;AAC5C,2CAA0D;AAC1D,qDAAwD;AACxD,uDAAmD;AAEnD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,YAAY,CAAC;KAClB,WAAW,CAAC,oDAAoD,CAAC;KACjE,OAAO,CAAC,OAAO,CAAC;KAChB,QAAQ,CAAC,gBAAgB,EAAE,yBAAyB,CAAC;KACrD,MAAM,CAAC,YAAY,EAAE,gBAAgB,CAAC;KACtC,MAAM,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;KAC9D,MAAM,CAAC,gBAAgB,EAAE,mCAAmC,CAAC;KAC7D,MAAM,CAAC,CAAC,WAAmB,EAAE,OAA4D,EAAE,EAAE;IAC5F,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QACzC,MAAM,EAAE,GAAG,IAAA,qCAAoB,EAAC,GAAG,CAAC,CAAC;QAErC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO,CAAC,GAAG,CAAC,KAAK,eAAK,CAAC,IAAI,CAAC,6BAA6B,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,IAAA,gCAAc,EAAC,WAAW,EAAE,GAAG,CAAC,CAAC;YAChD,MAAM,MAAM,GAAG,IAAA,yBAAa,EAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;YACnD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,MAAM,MAAM,GAAG,IAAA,yBAAc,EAAC,WAAW,EAAE,GAAG,CAAC,CAAC;YAChD,MAAM,MAAM,GAAG,IAAA,wBAAY,EAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;YAClD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtB,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC,CAAC;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/fileFinder.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
export declare function findSourceFiles(dir: string, maxDepth?: number, currentDepth?: number): string[];
|
|
2
|
-
export interface FileUsage {
|
|
3
|
-
file: string;
|
|
4
|
-
lines: number[];
|
|
5
|
-
methods: string[];
|
|
6
|
-
context?: string[];
|
|
7
|
-
purpose?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare function analyzeFileUsage(filePath: string, packageName: string, cwd: string): FileUsage | null;
|
|
10
2
|
export declare function findFilesUsingPackage(packageName: string, cwd: string): string[];
|
|
11
3
|
//# sourceMappingURL=fileFinder.d.ts.map
|
package/dist/fileFinder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileFinder.d.ts","sourceRoot":"","sources":["../src/fileFinder.ts"],"names":[],"mappings":"AAcA,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,EAAE,YAAY,GAAE,MAAU,GAAG,MAAM,EAAE,CAgCrG;
|
|
1
|
+
{"version":3,"file":"fileFinder.d.ts","sourceRoot":"","sources":["../src/fileFinder.ts"],"names":[],"mappings":"AAcA,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,EAAE,YAAY,GAAE,MAAU,GAAG,MAAM,EAAE,CAgCrG;AAmBD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAYhF"}
|
package/dist/fileFinder.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findSourceFiles = findSourceFiles;
|
|
4
|
-
exports.analyzeFileUsage = analyzeFileUsage;
|
|
5
4
|
exports.findFilesUsingPackage = findFilesUsingPackage;
|
|
6
5
|
const fs_1 = require("fs");
|
|
7
6
|
const path_1 = require("path");
|
|
@@ -58,99 +57,6 @@ function fileContainsPackage(filePath, packageName) {
|
|
|
58
57
|
return false;
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
function analyzeFileUsage(filePath, packageName, cwd) {
|
|
62
|
-
try {
|
|
63
|
-
const content = (0, fs_1.readFileSync)(filePath, 'utf-8');
|
|
64
|
-
const lines = content.split('\n');
|
|
65
|
-
const relativePath = filePath.replace(cwd + '/', '');
|
|
66
|
-
const importPatterns = [
|
|
67
|
-
new RegExp(`require\\(['"]${packageName}(/.*)?['"]\\)`, 'g'),
|
|
68
|
-
new RegExp(`from\\s+['"]${packageName}(/.*)?['"]`, 'g'),
|
|
69
|
-
new RegExp(`import\\s+.*\\s+from\\s+['"]${packageName}(/.*)?['"]`, 'g'),
|
|
70
|
-
new RegExp(`import\\s+['"]${packageName}(/.*)?['"]`, 'g'),
|
|
71
|
-
];
|
|
72
|
-
const usageLines = [];
|
|
73
|
-
const methods = new Set();
|
|
74
|
-
const context = [];
|
|
75
|
-
// Find import lines
|
|
76
|
-
lines.forEach((line, index) => {
|
|
77
|
-
const lineNum = index + 1;
|
|
78
|
-
if (importPatterns.some(pattern => pattern.test(line))) {
|
|
79
|
-
usageLines.push(lineNum);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
// Find method usage patterns:
|
|
83
|
-
const escapedPackageName = packageName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
84
|
-
// 1. Direct: packageName.method() or packageName.method
|
|
85
|
-
const directMethodPattern = new RegExp('\\b' + escapedPackageName + '\\.(\\w+)', 'g');
|
|
86
|
-
const directMatches = content.matchAll(directMethodPattern);
|
|
87
|
-
for (const match of directMatches) {
|
|
88
|
-
methods.add(match[1]);
|
|
89
|
-
}
|
|
90
|
-
// 2. Destructured imports: const { red, bold } = require('chalk')
|
|
91
|
-
const destructurePattern = new RegExp('(?:const|let|var)\\s*\\{[^}]*\\}\\s*=\\s*(?:require|import)\\s*\\(?[\'"]' + escapedPackageName, 'g');
|
|
92
|
-
if (destructurePattern.test(content)) {
|
|
93
|
-
const destructureMatch = content.match(/(?:const|let|var)\s*\{([^}]+)\}/);
|
|
94
|
-
if (destructureMatch) {
|
|
95
|
-
destructureMatch[1].split(',').forEach(m => {
|
|
96
|
-
const method = m.trim().split(':')[0].trim();
|
|
97
|
-
if (method)
|
|
98
|
-
methods.add(method);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// 3. Default import assigned to variable: const program = new Command(); program.method()
|
|
103
|
-
// Find named imports: import { Command } from 'commander'
|
|
104
|
-
const namedImportMatch = content.match(/import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/i);
|
|
105
|
-
if (namedImportMatch && namedImportMatch[2] === packageName) {
|
|
106
|
-
const namedImports = namedImportMatch[1].split(',').map(i => i.trim().split('as')[0].trim());
|
|
107
|
-
namedImports.forEach(importName => {
|
|
108
|
-
// Find instances: const program = new Command()
|
|
109
|
-
const escapedImportName = importName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
110
|
-
const instancePattern = new RegExp('(?:const|let|var)\\s+([A-Za-z_$][A-Za-z0-9_$]*)\\s*=\\s*new\\s+' + escapedImportName, 'g');
|
|
111
|
-
const instanceMatches = content.matchAll(instancePattern);
|
|
112
|
-
for (const instanceMatch of instanceMatches) {
|
|
113
|
-
const instanceName = instanceMatch[1];
|
|
114
|
-
// Find methods on this instance: program.command()
|
|
115
|
-
const instanceMethodPattern = new RegExp('\\b' + instanceName + '\\.(\\w+)\\s*\\(', 'g');
|
|
116
|
-
const methodMatches = content.matchAll(instanceMethodPattern);
|
|
117
|
-
for (const methodMatch of methodMatches) {
|
|
118
|
-
methods.add(methodMatch[1]);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
// 4. Default import: import Command from 'commander' or const Command = require('commander')
|
|
124
|
-
const defaultImportMatch = content.match(new RegExp('(?:import|const|let|var)\\s+([A-Za-z_$][A-Za-z0-9_$]*)\\s*(?:=|from)\\s*[\'"]' + escapedPackageName, 'i'));
|
|
125
|
-
if (defaultImportMatch) {
|
|
126
|
-
const importedName = defaultImportMatch[1];
|
|
127
|
-
// Find all method calls on this imported name: program.method()
|
|
128
|
-
const instanceMethodPattern = new RegExp('\\b' + importedName + '\\.(\\w+)\\s*\\(', 'g');
|
|
129
|
-
const instanceMatches = content.matchAll(instanceMethodPattern);
|
|
130
|
-
for (const match of instanceMatches) {
|
|
131
|
-
methods.add(match[1]);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// Capture context (lines around usage)
|
|
135
|
-
if (usageLines.length > 0) {
|
|
136
|
-
const firstLine = Math.max(0, usageLines[0] - 3);
|
|
137
|
-
const lastLine = Math.min(lines.length, usageLines[usageLines.length - 1] + 3);
|
|
138
|
-
context.push(...lines.slice(firstLine, lastLine));
|
|
139
|
-
}
|
|
140
|
-
if (usageLines.length > 0) {
|
|
141
|
-
return {
|
|
142
|
-
file: relativePath,
|
|
143
|
-
lines: usageLines,
|
|
144
|
-
methods: Array.from(methods),
|
|
145
|
-
context: context.slice(0, 10) // Limit context
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
catch {
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
60
|
function findFilesUsingPackage(packageName, cwd) {
|
|
155
61
|
const sourceFiles = findSourceFiles(cwd);
|
|
156
62
|
const matchingFiles = [];
|
package/dist/fileFinder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileFinder.js","sourceRoot":"","sources":["../src/fileFinder.ts"],"names":[],"mappings":";;AAcA,0CAgCC;
|
|
1
|
+
{"version":3,"file":"fileFinder.js","sourceRoot":"","sources":["../src/fileFinder.ts"],"names":[],"mappings":";;AAcA,0CAgCC;AAmBD,sDAYC;AA7ED,2BAAyD;AACzD,+BAAqC;AAErC,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACzE,MAAM,WAAW,GAAG,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AAEnF,SAAS,eAAe,CAAC,OAAe;IACtC,OAAO,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,YAAY,CAAC,QAAgB;IACpC,OAAO,iBAAiB,CAAC,QAAQ,CAAC,IAAA,cAAO,EAAC,QAAQ,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AiB,WAAW,eAAe,EAAE,GAAG,CAAC;YAC5D,IAAI,MAAM,CAAC,eAAe,WAAW,YAAY,EAAE,GAAG,CAAC;YACvD,IAAI,MAAM,CAAC,+BAA+B,WAAW,YAAY,EAAE,GAAG,CAAC;YACvE,IAAI,MAAM,CAAC,iBAAiB,WAAW,YAAY,EAAE,GAAG,CAAC;SAC1D,CAAC;QAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAgB,qBAAqB,CAAC,WAAmB,EAAE,GAAW;IACpE,MAAM,WAAW,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,aAAa,GAAa,EAAE,CAAC;IAEnC,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,IAAI,mBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,CAAC;YAC3C,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,EAAE,EAAE,CAAC,CAAC;YACjD,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
package/dist/formatter.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { AnalyzeResult } from './types';
|
|
2
|
-
export declare function formatOutput(result: AnalyzeResult, json?: boolean
|
|
1
|
+
import { AnalyzeResult, SizeMapResult } from './types';
|
|
2
|
+
export declare function formatOutput(result: AnalyzeResult, json?: boolean): string;
|
|
3
|
+
export declare function formatSizeMap(result: SizeMapResult, json?: boolean): string;
|
|
3
4
|
//# sourceMappingURL=formatter.d.ts.map
|
package/dist/formatter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAkB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAkB,aAAa,EAAE,MAAM,SAAS,CAAC;AAwDvE,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,GAAE,OAAe,GAAG,MAAM,CA8CjF;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,GAAE,OAAe,GAAG,MAAM,CAoBlF"}
|
package/dist/formatter.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.formatOutput = formatOutput;
|
|
7
|
+
exports.formatSizeMap = formatSizeMap;
|
|
7
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
9
|
function formatSize(bytes) {
|
|
9
10
|
if (!bytes)
|
|
@@ -58,23 +59,7 @@ function getTypeLabel(type) {
|
|
|
58
59
|
};
|
|
59
60
|
return labels[type] || type;
|
|
60
61
|
}
|
|
61
|
-
function
|
|
62
|
-
const emojis = {
|
|
63
|
-
Low: '🟢',
|
|
64
|
-
Medium: '🟡',
|
|
65
|
-
High: '🔴'
|
|
66
|
-
};
|
|
67
|
-
return emojis[risk] || '⚪';
|
|
68
|
-
}
|
|
69
|
-
function getRiskColor(risk) {
|
|
70
|
-
const colors = {
|
|
71
|
-
Low: chalk_1.default.green,
|
|
72
|
-
Medium: chalk_1.default.yellow,
|
|
73
|
-
High: chalk_1.default.red
|
|
74
|
-
};
|
|
75
|
-
return colors[risk] || chalk_1.default.gray;
|
|
76
|
-
}
|
|
77
|
-
function formatOutput(result, json = false, showImpact = false) {
|
|
62
|
+
function formatOutput(result, json = false) {
|
|
78
63
|
if (json) {
|
|
79
64
|
return JSON.stringify(result, null, 2);
|
|
80
65
|
}
|
|
@@ -106,38 +91,6 @@ function formatOutput(result, json = false, showImpact = false) {
|
|
|
106
91
|
output += ` ${chalk_1.default.blue(file)}\n`;
|
|
107
92
|
});
|
|
108
93
|
}
|
|
109
|
-
if (showImpact && pkg.impact) {
|
|
110
|
-
const impact = pkg.impact;
|
|
111
|
-
output += '\n' + chalk_1.default.bold('Impact analysis:') + '\n\n';
|
|
112
|
-
if (impact.files.length > 0) {
|
|
113
|
-
output += chalk_1.default.bold('Used in ') + chalk_1.default.bold(`${impact.files.length} file${impact.files.length !== 1 ? 's' : ''}:`) + '\n\n';
|
|
114
|
-
impact.files.forEach((file, index) => {
|
|
115
|
-
const fileUsage = file;
|
|
116
|
-
const lineRange = fileUsage.lines.length === 1
|
|
117
|
-
? `Line ${fileUsage.lines[0]}`
|
|
118
|
-
: `Lines ${Math.min(...fileUsage.lines)}–${Math.max(...fileUsage.lines)}`;
|
|
119
|
-
output += `${index + 1}. ${chalk_1.default.blue(fileUsage.file)}\n`;
|
|
120
|
-
output += ` ${chalk_1.default.gray(lineRange)}\n`;
|
|
121
|
-
if (fileUsage.purpose) {
|
|
122
|
-
output += ` ${chalk_1.default.dim(`Purpose: ${fileUsage.purpose}`)}\n`;
|
|
123
|
-
}
|
|
124
|
-
if (fileUsage.methods.length > 0) {
|
|
125
|
-
output += ` ${chalk_1.default.dim(`Methods: ${fileUsage.methods.slice(0, 5).join(', ')}${fileUsage.methods.length > 5 ? '...' : ''}`)}\n`;
|
|
126
|
-
}
|
|
127
|
-
output += '\n';
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
output += chalk_1.default.yellow(' No direct usage found in source files\n\n');
|
|
132
|
-
}
|
|
133
|
-
output += chalk_1.default.bold('Estimated removal impact:') + '\n';
|
|
134
|
-
impact.impacts.forEach((impactText) => {
|
|
135
|
-
output += ` ${chalk_1.default.gray('-')} ${chalk_1.default.gray(impactText)}\n`;
|
|
136
|
-
});
|
|
137
|
-
output += '\n';
|
|
138
|
-
const riskColor = getRiskColor(impact.riskLevel);
|
|
139
|
-
output += chalk_1.default.bold('Risk level: ') + getRiskEmoji(impact.riskLevel) + ' ' + riskColor(impact.riskLevel) + '\n';
|
|
140
|
-
}
|
|
141
94
|
if (suggestions.length > 0) {
|
|
142
95
|
output += '\n' + chalk_1.default.bold('Suggested actions:') + '\n';
|
|
143
96
|
suggestions.forEach((suggestion, index) => {
|
|
@@ -146,4 +99,21 @@ function formatOutput(result, json = false, showImpact = false) {
|
|
|
146
99
|
}
|
|
147
100
|
return output;
|
|
148
101
|
}
|
|
102
|
+
function formatSizeMap(result, json = false) {
|
|
103
|
+
if (json) {
|
|
104
|
+
return JSON.stringify(result, null, 2);
|
|
105
|
+
}
|
|
106
|
+
let output = '';
|
|
107
|
+
output += chalk_1.default.bold.cyan(`Size map for: ${result.packageName}\n\n`);
|
|
108
|
+
output += chalk_1.default.bold(`${result.packageName} total impact: `) + chalk_1.default.green(formatSize(result.totalSize)) + '\n\n';
|
|
109
|
+
output += chalk_1.default.bold('Breakdown:\n');
|
|
110
|
+
for (const item of result.breakdown) {
|
|
111
|
+
const sizeStr = formatSize(item.size);
|
|
112
|
+
output += chalk_1.default.gray('- ') + chalk_1.default.white(item.name) + chalk_1.default.gray(': ') + chalk_1.default.yellow(sizeStr) + '\n';
|
|
113
|
+
}
|
|
114
|
+
if (result.percentOfNodeModules !== undefined && result.percentOfNodeModules > 0) {
|
|
115
|
+
output += '\n' + chalk_1.default.dim(`This package contributes ${result.percentOfNodeModules.toFixed(1)}% of your vendor bundle.\n`);
|
|
116
|
+
}
|
|
117
|
+
return output;
|
|
118
|
+
}
|
|
149
119
|
//# sourceMappingURL=formatter.js.map
|
package/dist/formatter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],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EA,OAAO,EAAE,aAAa,EAAiB,MAAM,SAAS,CAAC;AAmHvD,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,GAAE,MAAsB,GAAG,aAAa,CA0B9F"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyzeSizeMap = analyzeSizeMap;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const JS_EXTENSIONS = new Set(['.js', '.mjs', '.cjs']);
|
|
7
|
+
const EXCLUDE_DIRS = new Set(['test', 'tests', '__tests__', 'docs', 'doc', 'types', '@types', 'typings', '.d.ts']);
|
|
8
|
+
function readPackageJson(path) {
|
|
9
|
+
try {
|
|
10
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
11
|
+
return JSON.parse((0, fs_1.readFileSync)(path, 'utf-8'));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch { }
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
function shouldExclude(name) {
|
|
18
|
+
const lower = name.toLowerCase();
|
|
19
|
+
return EXCLUDE_DIRS.has(lower) || lower.endsWith('.d.ts') || lower.startsWith('.');
|
|
20
|
+
}
|
|
21
|
+
function calculateJsSize(dir) {
|
|
22
|
+
let total = 0;
|
|
23
|
+
try {
|
|
24
|
+
const entries = (0, fs_1.readdirSync)(dir);
|
|
25
|
+
for (const entry of entries) {
|
|
26
|
+
if (shouldExclude(entry))
|
|
27
|
+
continue;
|
|
28
|
+
const fullPath = (0, path_1.join)(dir, entry);
|
|
29
|
+
try {
|
|
30
|
+
const stats = (0, fs_1.statSync)(fullPath);
|
|
31
|
+
if (stats.isDirectory()) {
|
|
32
|
+
if (entry !== 'node_modules') {
|
|
33
|
+
total += calculateJsSize(fullPath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (JS_EXTENSIONS.has((0, path_1.extname)(entry).toLowerCase())) {
|
|
37
|
+
total += stats.size;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch { }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch { }
|
|
44
|
+
return total;
|
|
45
|
+
}
|
|
46
|
+
function getNodeModulesSize(cwd) {
|
|
47
|
+
const nmPath = (0, path_1.join)(cwd, 'node_modules');
|
|
48
|
+
let total = 0;
|
|
49
|
+
function walkDir(dir) {
|
|
50
|
+
try {
|
|
51
|
+
const entries = (0, fs_1.readdirSync)(dir);
|
|
52
|
+
for (const entry of entries) {
|
|
53
|
+
const fullPath = (0, path_1.join)(dir, entry);
|
|
54
|
+
try {
|
|
55
|
+
const stats = (0, fs_1.statSync)(fullPath);
|
|
56
|
+
if (stats.isDirectory()) {
|
|
57
|
+
walkDir(fullPath);
|
|
58
|
+
}
|
|
59
|
+
else if (JS_EXTENSIONS.has((0, path_1.extname)(entry).toLowerCase())) {
|
|
60
|
+
total += stats.size;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch { }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch { }
|
|
67
|
+
}
|
|
68
|
+
walkDir(nmPath);
|
|
69
|
+
return total;
|
|
70
|
+
}
|
|
71
|
+
function findPackagePath(packageName, cwd) {
|
|
72
|
+
const directPath = (0, path_1.join)(cwd, 'node_modules', packageName);
|
|
73
|
+
if ((0, fs_1.existsSync)(directPath))
|
|
74
|
+
return directPath;
|
|
75
|
+
// Handle scoped packages
|
|
76
|
+
if (packageName.startsWith('@')) {
|
|
77
|
+
const parts = packageName.split('/');
|
|
78
|
+
const scopedPath = (0, path_1.join)(cwd, 'node_modules', parts[0], parts[1]);
|
|
79
|
+
if ((0, fs_1.existsSync)(scopedPath))
|
|
80
|
+
return scopedPath;
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
function getDependencyTree(packagePath, cwd, visited = new Set()) {
|
|
85
|
+
const breakdown = [];
|
|
86
|
+
const pkgJsonPath = (0, path_1.join)(packagePath, 'package.json');
|
|
87
|
+
const pkg = readPackageJson(pkgJsonPath);
|
|
88
|
+
if (!pkg?.dependencies)
|
|
89
|
+
return breakdown;
|
|
90
|
+
for (const depName of Object.keys(pkg.dependencies)) {
|
|
91
|
+
if (visited.has(depName))
|
|
92
|
+
continue;
|
|
93
|
+
visited.add(depName);
|
|
94
|
+
// Check nested node_modules first
|
|
95
|
+
let depPath = (0, path_1.join)(packagePath, 'node_modules', depName);
|
|
96
|
+
if (!(0, fs_1.existsSync)(depPath)) {
|
|
97
|
+
depPath = (0, path_1.join)(cwd, 'node_modules', depName);
|
|
98
|
+
}
|
|
99
|
+
if ((0, fs_1.existsSync)(depPath)) {
|
|
100
|
+
const size = calculateJsSize(depPath);
|
|
101
|
+
if (size > 0) {
|
|
102
|
+
breakdown.push({ name: depName, size });
|
|
103
|
+
}
|
|
104
|
+
// Recursively get sub-dependencies
|
|
105
|
+
const subDeps = getDependencyTree(depPath, cwd, visited);
|
|
106
|
+
breakdown.push(...subDeps);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return breakdown;
|
|
110
|
+
}
|
|
111
|
+
function analyzeSizeMap(packageName, cwd = process.cwd()) {
|
|
112
|
+
const packagePath = findPackagePath(packageName, cwd);
|
|
113
|
+
if (!packagePath) {
|
|
114
|
+
throw new Error(`Package "${packageName}" not found in node_modules`);
|
|
115
|
+
}
|
|
116
|
+
const ownSize = calculateJsSize(packagePath);
|
|
117
|
+
const visited = new Set([packageName]);
|
|
118
|
+
const depBreakdown = getDependencyTree(packagePath, cwd, visited);
|
|
119
|
+
const breakdown = [
|
|
120
|
+
{ name: packageName, size: ownSize },
|
|
121
|
+
...depBreakdown.sort((a, b) => b.size - a.size)
|
|
122
|
+
];
|
|
123
|
+
const totalSize = breakdown.reduce((sum, item) => sum + item.size, 0);
|
|
124
|
+
const nodeModulesSize = getNodeModulesSize(cwd);
|
|
125
|
+
const percentOfNodeModules = nodeModulesSize > 0 ? (totalSize / nodeModulesSize) * 100 : 0;
|
|
126
|
+
return {
|
|
127
|
+
packageName,
|
|
128
|
+
totalSize,
|
|
129
|
+
breakdown,
|
|
130
|
+
nodeModulesSize,
|
|
131
|
+
percentOfNodeModules
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=sizeMapAnalyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sizeMapAnalyzer.js","sourceRoot":"","sources":["../src/sizeMapAnalyzer.ts"],"names":[],"mappings":";;AAqHA,wCA0BC;AA/ID,2BAAqE;AACrE,+BAA8C;AAQ9C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACvD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAEnH,SAAS,eAAe,CAAC,IAAY;IACnC,IAAI,CAAC;QACH,IAAI,IAAA,eAAU,EAAC,IAAI,CAAC,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IACV,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,OAAO,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACrF,CAAC;AAED,SAAS,eAAe,CAAC,GAAW;I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K,CAAC,YAAY,WAAW,6BAA6B,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,OAAO,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,IAAI,GAAG,CAAS,CAAC,WAAW,CAAC,CAAC,CAAC;IAC/C,MAAM,YAAY,GAAG,iBAAiB,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAElE,MAAM,SAAS,GAAoB;QACjC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE;QACpC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;KAChD,CAAC;IAEF,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACtE,MAAM,eAAe,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAChD,MAAM,oBAAoB,GAAG,eAAe,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,eAAe,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3F,OAAO;QACL,WAAW;QACX,SAAS;QACT,SAAS;QACT,eAAe;QACf,oBAAoB;KACrB,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -3,18 +3,6 @@ export interface DependencyPath {
|
|
|
3
3
|
type: 'prod' | 'dev' | 'peer' | 'optional';
|
|
4
4
|
packageJsonPath?: string;
|
|
5
5
|
}
|
|
6
|
-
export interface FileUsage {
|
|
7
|
-
file: string;
|
|
8
|
-
lines: number[];
|
|
9
|
-
methods: string[];
|
|
10
|
-
context?: string[];
|
|
11
|
-
purpose?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface ImpactAnalysis {
|
|
14
|
-
files: FileUsage[];
|
|
15
|
-
riskLevel: 'Low' | 'Medium' | 'High';
|
|
16
|
-
impacts: string[];
|
|
17
|
-
}
|
|
18
6
|
export interface PackageInfo {
|
|
19
7
|
name: string;
|
|
20
8
|
version: string;
|
|
@@ -22,11 +10,21 @@ export interface PackageInfo {
|
|
|
22
10
|
size?: number;
|
|
23
11
|
paths: DependencyPath[];
|
|
24
12
|
sourceFiles?: string[];
|
|
25
|
-
impact?: ImpactAnalysis;
|
|
26
13
|
}
|
|
27
14
|
export interface AnalyzeResult {
|
|
28
15
|
package: PackageInfo;
|
|
29
16
|
suggestions: string[];
|
|
30
17
|
}
|
|
31
18
|
export type PackageManager = 'npm' | 'yarn' | 'pnpm';
|
|
19
|
+
export interface SizeBreakdown {
|
|
20
|
+
name: string;
|
|
21
|
+
size: number;
|
|
22
|
+
}
|
|
23
|
+
export interface SizeMapResult {
|
|
24
|
+
packageName: string;
|
|
25
|
+
totalSize: number;
|
|
26
|
+
breakdown: SizeBreakdown[];
|
|
27
|
+
nodeModulesSize?: number;
|
|
28
|
+
percentOfNodeModules?: number;
|
|
29
|
+
}
|
|
32
30
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,CAAC;IAC3C,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,CAAC;IAC3C,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,WAAW,CAAC;IACrB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B"}
|
package/package.json
CHANGED
package/src/analyzer.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { join, dirname } from 'path';
|
|
|
3
3
|
import { PackageInfo, DependencyPath, AnalyzeResult } from './types';
|
|
4
4
|
import { detectPackageManager } from './packageManager';
|
|
5
5
|
import { findFilesUsingPackage } from './fileFinder';
|
|
6
|
-
import { analyzeImpact } from './impactAnalyzer';
|
|
7
6
|
|
|
8
7
|
interface PackageJson {
|
|
9
8
|
name?: string;
|
|
@@ -192,7 +191,7 @@ function formatSize(bytes: number | undefined): string {
|
|
|
192
191
|
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
193
192
|
}
|
|
194
193
|
|
|
195
|
-
export function analyzePackage(packageName: string, cwd: string = process.cwd()
|
|
194
|
+
export function analyzePackage(packageName: string, cwd: string = process.cwd()): AnalyzeResult {
|
|
196
195
|
const rootPackageJson = join(cwd, 'package.json');
|
|
197
196
|
const packageJsonPath = findPackageJsonPath(packageName, cwd);
|
|
198
197
|
if (!packageJsonPath) {
|
|
@@ -242,11 +241,6 @@ export function analyzePackage(packageName: string, cwd: string = process.cwd(),
|
|
|
242
241
|
|
|
243
242
|
const sourceFiles = findFilesUsingPackage(packageName, cwd);
|
|
244
243
|
|
|
245
|
-
let impact;
|
|
246
|
-
if (includeImpact) {
|
|
247
|
-
impact = analyzeImpact(packageName, cwd);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
244
|
return {
|
|
251
245
|
package: {
|
|
252
246
|
name: packageName,
|
|
@@ -254,8 +248,7 @@ export function analyzePackage(packageName: string, cwd: string = process.cwd(),
|
|
|
254
248
|
description,
|
|
255
249
|
size,
|
|
256
250
|
paths,
|
|
257
|
-
sourceFiles: sourceFiles.length > 0 ? sourceFiles : undefined
|
|
258
|
-
impact
|
|
251
|
+
sourceFiles: sourceFiles.length > 0 ? sourceFiles : undefined
|
|
259
252
|
},
|
|
260
253
|
suggestions
|
|
261
254
|
};
|
package/src/cli.ts
CHANGED
|
@@ -3,20 +3,21 @@
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import { analyzePackage } from './analyzer';
|
|
6
|
-
import { formatOutput } from './formatter';
|
|
6
|
+
import { formatOutput, formatSizeMap } from './formatter';
|
|
7
7
|
import { detectPackageManager } from './packageManager';
|
|
8
|
+
import { analyzeSizeMap } from './sizeMapAnalyzer';
|
|
8
9
|
|
|
9
10
|
const program = new Command();
|
|
10
11
|
|
|
11
12
|
program
|
|
12
13
|
.name('whyinstall')
|
|
13
14
|
.description('Find why a dependency exists in your JS/TS project')
|
|
14
|
-
.version('0.
|
|
15
|
+
.version('0.3.0')
|
|
15
16
|
.argument('<package-name>', 'Package name to analyze')
|
|
16
17
|
.option('-j, --json', 'Output as JSON')
|
|
17
18
|
.option('-c, --cwd <path>', 'Working directory', process.cwd())
|
|
18
|
-
.option('--
|
|
19
|
-
.action((packageName: string, options: { json?: boolean; cwd?: string;
|
|
19
|
+
.option('-s, --size-map', 'Show bundle size impact breakdown')
|
|
20
|
+
.action((packageName: string, options: { json?: boolean; cwd?: string; sizeMap?: boolean }) => {
|
|
20
21
|
try {
|
|
21
22
|
const cwd = options.cwd || process.cwd();
|
|
22
23
|
const pm = detectPackageManager(cwd);
|
|
@@ -25,9 +26,15 @@ program
|
|
|
25
26
|
console.log(`\n${chalk.gray(`Detected package manager: ${pm}`)}\n`);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
if (options.sizeMap) {
|
|
30
|
+
const result = analyzeSizeMap(packageName, cwd);
|
|
31
|
+
const output = formatSizeMap(result, options.json);
|
|
32
|
+
console.log(output);
|
|
33
|
+
} else {
|
|
34
|
+
const result = analyzePackage(packageName, cwd);
|
|
35
|
+
const output = formatOutput(result, options.json);
|
|
36
|
+
console.log(output);
|
|
37
|
+
}
|
|
31
38
|
|
|
32
39
|
process.exit(0);
|
|
33
40
|
} catch (error) {
|
package/src/fileFinder.ts
CHANGED
|
@@ -46,14 +46,6 @@ export function findSourceFiles(dir: string, maxDepth: number = 5, currentDepth:
|
|
|
46
46
|
return files;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export interface FileUsage {
|
|
50
|
-
file: string;
|
|
51
|
-
lines: number[];
|
|
52
|
-
methods: string[];
|
|
53
|
-
context?: string[];
|
|
54
|
-
purpose?: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
49
|
function fileContainsPackage(filePath: string, packageName: string): boolean {
|
|
58
50
|
try {
|
|
59
51
|
const content = readFileSync(filePath, 'utf-8');
|
|
@@ -71,109 +63,6 @@ function fileContainsPackage(filePath: string, packageName: string): boolean {
|
|
|
71
63
|
}
|
|
72
64
|
}
|
|
73
65
|
|
|
74
|
-
export function analyzeFileUsage(filePath: string, packageName: string, cwd: string): FileUsage | null {
|
|
75
|
-
try {
|
|
76
|
-
const content = readFileSync(filePath, 'utf-8');
|
|
77
|
-
const lines = content.split('\n');
|
|
78
|
-
const relativePath = filePath.replace(cwd + '/', '');
|
|
79
|
-
|
|
80
|
-
const importPatterns = [
|
|
81
|
-
new RegExp(`require\\(['"]${packageName}(/.*)?['"]\\)`, 'g'),
|
|
82
|
-
new RegExp(`from\\s+['"]${packageName}(/.*)?['"]`, 'g'),
|
|
83
|
-
new RegExp(`import\\s+.*\\s+from\\s+['"]${packageName}(/.*)?['"]`, 'g'),
|
|
84
|
-
new RegExp(`import\\s+['"]${packageName}(/.*)?['"]`, 'g'),
|
|
85
|
-
];
|
|
86
|
-
|
|
87
|
-
const usageLines: number[] = [];
|
|
88
|
-
const methods = new Set<string>();
|
|
89
|
-
const context: string[] = [];
|
|
90
|
-
|
|
91
|
-
// Find import lines
|
|
92
|
-
lines.forEach((line, index) => {
|
|
93
|
-
const lineNum = index + 1;
|
|
94
|
-
if (importPatterns.some(pattern => pattern.test(line))) {
|
|
95
|
-
usageLines.push(lineNum);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// Find method usage patterns:
|
|
100
|
-
const escapedPackageName = packageName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
101
|
-
|
|
102
|
-
// 1. Direct: packageName.method() or packageName.method
|
|
103
|
-
const directMethodPattern = new RegExp('\\b' + escapedPackageName + '\\.(\\w+)', 'g');
|
|
104
|
-
const directMatches = content.matchAll(directMethodPattern);
|
|
105
|
-
for (const match of directMatches) {
|
|
106
|
-
methods.add(match[1]);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// 2. Destructured imports: const { red, bold } = require('chalk')
|
|
110
|
-
const destructurePattern = new RegExp('(?:const|let|var)\\s*\\{[^}]*\\}\\s*=\\s*(?:require|import)\\s*\\(?[\'"]' + escapedPackageName, 'g');
|
|
111
|
-
if (destructurePattern.test(content)) {
|
|
112
|
-
const destructureMatch = content.match(/(?:const|let|var)\s*\{([^}]+)\}/);
|
|
113
|
-
if (destructureMatch) {
|
|
114
|
-
destructureMatch[1].split(',').forEach(m => {
|
|
115
|
-
const method = m.trim().split(':')[0].trim();
|
|
116
|
-
if (method) methods.add(method);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 3. Default import assigned to variable: const program = new Command(); program.method()
|
|
122
|
-
// Find named imports: import { Command } from 'commander'
|
|
123
|
-
const namedImportMatch = content.match(/import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/i);
|
|
124
|
-
if (namedImportMatch && namedImportMatch[2] === packageName) {
|
|
125
|
-
const namedImports = namedImportMatch[1].split(',').map(i => i.trim().split('as')[0].trim());
|
|
126
|
-
namedImports.forEach(importName => {
|
|
127
|
-
// Find instances: const program = new Command()
|
|
128
|
-
const escapedImportName = importName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
129
|
-
const instancePattern = new RegExp('(?:const|let|var)\\s+([A-Za-z_$][A-Za-z0-9_$]*)\\s*=\\s*new\\s+' + escapedImportName, 'g');
|
|
130
|
-
const instanceMatches = content.matchAll(instancePattern);
|
|
131
|
-
for (const instanceMatch of instanceMatches) {
|
|
132
|
-
const instanceName = instanceMatch[1];
|
|
133
|
-
// Find methods on this instance: program.command()
|
|
134
|
-
const instanceMethodPattern = new RegExp('\\b' + instanceName + '\\.(\\w+)\\s*\\(', 'g');
|
|
135
|
-
const methodMatches = content.matchAll(instanceMethodPattern);
|
|
136
|
-
for (const methodMatch of methodMatches) {
|
|
137
|
-
methods.add(methodMatch[1]);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// 4. Default import: import Command from 'commander' or const Command = require('commander')
|
|
144
|
-
const defaultImportMatch = content.match(new RegExp('(?:import|const|let|var)\\s+([A-Za-z_$][A-Za-z0-9_$]*)\\s*(?:=|from)\\s*[\'"]' + escapedPackageName, 'i'));
|
|
145
|
-
if (defaultImportMatch) {
|
|
146
|
-
const importedName = defaultImportMatch[1];
|
|
147
|
-
// Find all method calls on this imported name: program.method()
|
|
148
|
-
const instanceMethodPattern = new RegExp('\\b' + importedName + '\\.(\\w+)\\s*\\(', 'g');
|
|
149
|
-
const instanceMatches = content.matchAll(instanceMethodPattern);
|
|
150
|
-
for (const match of instanceMatches) {
|
|
151
|
-
methods.add(match[1]);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Capture context (lines around usage)
|
|
156
|
-
if (usageLines.length > 0) {
|
|
157
|
-
const firstLine = Math.max(0, usageLines[0] - 3);
|
|
158
|
-
const lastLine = Math.min(lines.length, usageLines[usageLines.length - 1] + 3);
|
|
159
|
-
context.push(...lines.slice(firstLine, lastLine));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (usageLines.length > 0) {
|
|
163
|
-
return {
|
|
164
|
-
file: relativePath,
|
|
165
|
-
lines: usageLines,
|
|
166
|
-
methods: Array.from(methods),
|
|
167
|
-
context: context.slice(0, 10) // Limit context
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return null;
|
|
172
|
-
} catch {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
66
|
export function findFilesUsingPackage(packageName: string, cwd: string): string[] {
|
|
178
67
|
const sourceFiles = findSourceFiles(cwd);
|
|
179
68
|
const matchingFiles: string[] = [];
|
package/src/formatter.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import { AnalyzeResult, DependencyPath } from './types';
|
|
2
|
+
import { AnalyzeResult, DependencyPath, SizeMapResult } from './types';
|
|
3
3
|
|
|
4
4
|
function formatSize(bytes: number | undefined): string {
|
|
5
5
|
if (!bytes) return '';
|
|
@@ -55,25 +55,7 @@ function getTypeLabel(type: DependencyPath['type']): string {
|
|
|
55
55
|
return labels[type] || type;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function
|
|
59
|
-
const emojis = {
|
|
60
|
-
Low: '🟢',
|
|
61
|
-
Medium: '🟡',
|
|
62
|
-
High: '🔴'
|
|
63
|
-
};
|
|
64
|
-
return emojis[risk] || '⚪';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function getRiskColor(risk: 'Low' | 'Medium' | 'High'): (text: string) => string {
|
|
68
|
-
const colors = {
|
|
69
|
-
Low: chalk.green,
|
|
70
|
-
Medium: chalk.yellow,
|
|
71
|
-
High: chalk.red
|
|
72
|
-
};
|
|
73
|
-
return colors[risk] || chalk.gray;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function formatOutput(result: AnalyzeResult, json: boolean = false, showImpact: boolean = false): string {
|
|
58
|
+
export function formatOutput(result: AnalyzeResult, json: boolean = false): string {
|
|
77
59
|
if (json) {
|
|
78
60
|
return JSON.stringify(result, null, 2);
|
|
79
61
|
}
|
|
@@ -111,43 +93,6 @@ export function formatOutput(result: AnalyzeResult, json: boolean = false, showI
|
|
|
111
93
|
});
|
|
112
94
|
}
|
|
113
95
|
|
|
114
|
-
if (showImpact && pkg.impact) {
|
|
115
|
-
const impact = pkg.impact;
|
|
116
|
-
output += '\n' + chalk.bold('Impact analysis:') + '\n\n';
|
|
117
|
-
|
|
118
|
-
if (impact.files.length > 0) {
|
|
119
|
-
output += chalk.bold('Used in ') + chalk.bold(`${impact.files.length} file${impact.files.length !== 1 ? 's' : ''}:`) + '\n\n';
|
|
120
|
-
|
|
121
|
-
impact.files.forEach((file, index) => {
|
|
122
|
-
const fileUsage = file as any;
|
|
123
|
-
const lineRange = fileUsage.lines.length === 1
|
|
124
|
-
? `Line ${fileUsage.lines[0]}`
|
|
125
|
-
: `Lines ${Math.min(...fileUsage.lines)}–${Math.max(...fileUsage.lines)}`;
|
|
126
|
-
|
|
127
|
-
output += `${index + 1}. ${chalk.blue(fileUsage.file)}\n`;
|
|
128
|
-
output += ` ${chalk.gray(lineRange)}\n`;
|
|
129
|
-
if (fileUsage.purpose) {
|
|
130
|
-
output += ` ${chalk.dim(`Purpose: ${fileUsage.purpose}`)}\n`;
|
|
131
|
-
}
|
|
132
|
-
if (fileUsage.methods.length > 0) {
|
|
133
|
-
output += ` ${chalk.dim(`Methods: ${fileUsage.methods.slice(0, 5).join(', ')}${fileUsage.methods.length > 5 ? '...' : ''}`)}\n`;
|
|
134
|
-
}
|
|
135
|
-
output += '\n';
|
|
136
|
-
});
|
|
137
|
-
} else {
|
|
138
|
-
output += chalk.yellow(' No direct usage found in source files\n\n');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
output += chalk.bold('Estimated removal impact:') + '\n';
|
|
142
|
-
impact.impacts.forEach((impactText) => {
|
|
143
|
-
output += ` ${chalk.gray('-')} ${chalk.gray(impactText)}\n`;
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
output += '\n';
|
|
147
|
-
const riskColor = getRiskColor(impact.riskLevel);
|
|
148
|
-
output += chalk.bold('Risk level: ') + getRiskEmoji(impact.riskLevel) + ' ' + riskColor(impact.riskLevel) + '\n';
|
|
149
|
-
}
|
|
150
|
-
|
|
151
96
|
if (suggestions.length > 0) {
|
|
152
97
|
output += '\n' + chalk.bold('Suggested actions:') + '\n';
|
|
153
98
|
suggestions.forEach((suggestion, index) => {
|
|
@@ -157,3 +102,25 @@ export function formatOutput(result: AnalyzeResult, json: boolean = false, showI
|
|
|
157
102
|
|
|
158
103
|
return output;
|
|
159
104
|
}
|
|
105
|
+
|
|
106
|
+
export function formatSizeMap(result: SizeMapResult, json: boolean = false): string {
|
|
107
|
+
if (json) {
|
|
108
|
+
return JSON.stringify(result, null, 2);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let output = '';
|
|
112
|
+
output += chalk.bold.cyan(`Size map for: ${result.packageName}\n\n`);
|
|
113
|
+
output += chalk.bold(`${result.packageName} total impact: `) + chalk.green(formatSize(result.totalSize)) + '\n\n';
|
|
114
|
+
output += chalk.bold('Breakdown:\n');
|
|
115
|
+
|
|
116
|
+
for (const item of result.breakdown) {
|
|
117
|
+
const sizeStr = formatSize(item.size);
|
|
118
|
+
output += chalk.gray('- ') + chalk.white(item.name) + chalk.gray(': ') + chalk.yellow(sizeStr) + '\n';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (result.percentOfNodeModules !== undefined && result.percentOfNodeModules > 0) {
|
|
122
|
+
output += '\n' + chalk.dim(`This package contributes ${result.percentOfNodeModules.toFixed(1)}% of your vendor bundle.\n`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return output;
|
|
126
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { readFileSync, existsSync, readdirSync, statSync } from 'fs';
|
|
2
|
+
import { join, dirname, extname } from 'path';
|
|
3
|
+
import { SizeMapResult, SizeBreakdown } from './types';
|
|
4
|
+
|
|
5
|
+
interface PackageJson {
|
|
6
|
+
name?: string;
|
|
7
|
+
dependencies?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const JS_EXTENSIONS = new Set(['.js', '.mjs', '.cjs']);
|
|
11
|
+
const EXCLUDE_DIRS = new Set(['test', 'tests', '__tests__', 'docs', 'doc', 'types', '@types', 'typings', '.d.ts']);
|
|
12
|
+
|
|
13
|
+
function readPackageJson(path: string): PackageJson | null {
|
|
14
|
+
try {
|
|
15
|
+
if (existsSync(path)) {
|
|
16
|
+
return JSON.parse(readFileSync(path, 'utf-8'));
|
|
17
|
+
}
|
|
18
|
+
} catch {}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function shouldExclude(name: string): boolean {
|
|
23
|
+
const lower = name.toLowerCase();
|
|
24
|
+
return EXCLUDE_DIRS.has(lower) || lower.endsWith('.d.ts') || lower.startsWith('.');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function calculateJsSize(dir: string): number {
|
|
28
|
+
let total = 0;
|
|
29
|
+
try {
|
|
30
|
+
const entries = readdirSync(dir);
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
if (shouldExclude(entry)) continue;
|
|
33
|
+
const fullPath = join(dir, entry);
|
|
34
|
+
try {
|
|
35
|
+
const stats = statSync(fullPath);
|
|
36
|
+
if (stats.isDirectory()) {
|
|
37
|
+
if (entry !== 'node_modules') {
|
|
38
|
+
total += calculateJsSize(fullPath);
|
|
39
|
+
}
|
|
40
|
+
} else if (JS_EXTENSIONS.has(extname(entry).toLowerCase())) {
|
|
41
|
+
total += stats.size;
|
|
42
|
+
}
|
|
43
|
+
} catch {}
|
|
44
|
+
}
|
|
45
|
+
} catch {}
|
|
46
|
+
return total;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getNodeModulesSize(cwd: string): number {
|
|
50
|
+
const nmPath = join(cwd, 'node_modules');
|
|
51
|
+
let total = 0;
|
|
52
|
+
|
|
53
|
+
function walkDir(dir: string): void {
|
|
54
|
+
try {
|
|
55
|
+
const entries = readdirSync(dir);
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
const fullPath = join(dir, entry);
|
|
58
|
+
try {
|
|
59
|
+
const stats = statSync(fullPath);
|
|
60
|
+
if (stats.isDirectory()) {
|
|
61
|
+
walkDir(fullPath);
|
|
62
|
+
} else if (JS_EXTENSIONS.has(extname(entry).toLowerCase())) {
|
|
63
|
+
total += stats.size;
|
|
64
|
+
}
|
|
65
|
+
} catch {}
|
|
66
|
+
}
|
|
67
|
+
} catch {}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
walkDir(nmPath);
|
|
71
|
+
return total;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function findPackagePath(packageName: string, cwd: string): string | null {
|
|
75
|
+
const directPath = join(cwd, 'node_modules', packageName);
|
|
76
|
+
if (existsSync(directPath)) return directPath;
|
|
77
|
+
|
|
78
|
+
// Handle scoped packages
|
|
79
|
+
if (packageName.startsWith('@')) {
|
|
80
|
+
const parts = packageName.split('/');
|
|
81
|
+
const scopedPath = join(cwd, 'node_modules', parts[0], parts[1]);
|
|
82
|
+
if (existsSync(scopedPath)) return scopedPath;
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getDependencyTree(packagePath: string, cwd: string, visited: Set<string> = new Set()): SizeBreakdown[] {
|
|
88
|
+
const breakdown: SizeBreakdown[] = [];
|
|
89
|
+
const pkgJsonPath = join(packagePath, 'package.json');
|
|
90
|
+
const pkg = readPackageJson(pkgJsonPath);
|
|
91
|
+
|
|
92
|
+
if (!pkg?.dependencies) return breakdown;
|
|
93
|
+
|
|
94
|
+
for (const depName of Object.keys(pkg.dependencies)) {
|
|
95
|
+
if (visited.has(depName)) continue;
|
|
96
|
+
visited.add(depName);
|
|
97
|
+
|
|
98
|
+
// Check nested node_modules first
|
|
99
|
+
let depPath = join(packagePath, 'node_modules', depName);
|
|
100
|
+
if (!existsSync(depPath)) {
|
|
101
|
+
depPath = join(cwd, 'node_modules', depName);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (existsSync(depPath)) {
|
|
105
|
+
const size = calculateJsSize(depPath);
|
|
106
|
+
if (size > 0) {
|
|
107
|
+
breakdown.push({ name: depName, size });
|
|
108
|
+
}
|
|
109
|
+
// Recursively get sub-dependencies
|
|
110
|
+
const subDeps = getDependencyTree(depPath, cwd, visited);
|
|
111
|
+
breakdown.push(...subDeps);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return breakdown;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function analyzeSizeMap(packageName: string, cwd: string = process.cwd()): SizeMapResult {
|
|
119
|
+
const packagePath = findPackagePath(packageName, cwd);
|
|
120
|
+
if (!packagePath) {
|
|
121
|
+
throw new Error(`Package "${packageName}" not found in node_modules`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const ownSize = calculateJsSize(packagePath);
|
|
125
|
+
const visited = new Set<string>([packageName]);
|
|
126
|
+
const depBreakdown = getDependencyTree(packagePath, cwd, visited);
|
|
127
|
+
|
|
128
|
+
const breakdown: SizeBreakdown[] = [
|
|
129
|
+
{ name: packageName, size: ownSize },
|
|
130
|
+
...depBreakdown.sort((a, b) => b.size - a.size)
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
const totalSize = breakdown.reduce((sum, item) => sum + item.size, 0);
|
|
134
|
+
const nodeModulesSize = getNodeModulesSize(cwd);
|
|
135
|
+
const percentOfNodeModules = nodeModulesSize > 0 ? (totalSize / nodeModulesSize) * 100 : 0;
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
packageName,
|
|
139
|
+
totalSize,
|
|
140
|
+
breakdown,
|
|
141
|
+
nodeModulesSize,
|
|
142
|
+
percentOfNodeModules
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
package/src/types.ts
CHANGED
|
@@ -4,20 +4,6 @@ export interface DependencyPath {
|
|
|
4
4
|
packageJsonPath?: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export interface FileUsage {
|
|
8
|
-
file: string;
|
|
9
|
-
lines: number[];
|
|
10
|
-
methods: string[];
|
|
11
|
-
context?: string[];
|
|
12
|
-
purpose?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface ImpactAnalysis {
|
|
16
|
-
files: FileUsage[];
|
|
17
|
-
riskLevel: 'Low' | 'Medium' | 'High';
|
|
18
|
-
impacts: string[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
7
|
export interface PackageInfo {
|
|
22
8
|
name: string;
|
|
23
9
|
version: string;
|
|
@@ -25,7 +11,6 @@ export interface PackageInfo {
|
|
|
25
11
|
size?: number;
|
|
26
12
|
paths: DependencyPath[];
|
|
27
13
|
sourceFiles?: string[];
|
|
28
|
-
impact?: ImpactAnalysis;
|
|
29
14
|
}
|
|
30
15
|
|
|
31
16
|
export interface AnalyzeResult {
|
|
@@ -34,3 +19,16 @@ export interface AnalyzeResult {
|
|
|
34
19
|
}
|
|
35
20
|
|
|
36
21
|
export type PackageManager = 'npm' | 'yarn' | 'pnpm';
|
|
22
|
+
|
|
23
|
+
export interface SizeBreakdown {
|
|
24
|
+
name: string;
|
|
25
|
+
size: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SizeMapResult {
|
|
29
|
+
packageName: string;
|
|
30
|
+
totalSize: number;
|
|
31
|
+
breakdown: SizeBreakdown[];
|
|
32
|
+
nodeModulesSize?: number;
|
|
33
|
+
percentOfNodeModules?: number;
|
|
34
|
+
}
|
package/src/impactAnalyzer.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { ImpactAnalysis } from './types';
|
|
2
|
-
import { FileUsage, findSourceFiles, analyzeFileUsage } from './fileFinder';
|
|
3
|
-
|
|
4
|
-
function analyzeUsageContext(usage: FileUsage, content: string): string {
|
|
5
|
-
// Analyze actual usage patterns in THIS codebase, not generic assumptions
|
|
6
|
-
const lines = content.split('\n');
|
|
7
|
-
const contextLines: string[] = [];
|
|
8
|
-
|
|
9
|
-
// Get context around usage lines
|
|
10
|
-
usage.lines.forEach(lineNum => {
|
|
11
|
-
const start = Math.max(0, lineNum - 2);
|
|
12
|
-
const end = Math.min(lines.length, lineNum + 2);
|
|
13
|
-
contextLines.push(...lines.slice(start, end));
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const context = contextLines.join('\n').toLowerCase();
|
|
17
|
-
|
|
18
|
-
// Simple heuristics based on actual code patterns, not package names
|
|
19
|
-
if (context.includes('console.') || context.includes('process.stdout') || context.includes('process.stderr')) {
|
|
20
|
-
return 'Console/output';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (context.includes('response') || context.includes('res.') || context.includes('req.')) {
|
|
24
|
-
return 'HTTP/API';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (context.includes('database') || context.includes('db.') || context.includes('query')) {
|
|
28
|
-
return 'Database';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (context.includes('test') || context.includes('spec') || context.includes('describe')) {
|
|
32
|
-
return 'Testing';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return 'General usage';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function computeRiskLevel(files: FileUsage[], contexts: string[]): 'Low' | 'Medium' | 'High' {
|
|
39
|
-
// Risk assessment based on WHERE it's used, not WHAT package it is
|
|
40
|
-
const hasDatabase = contexts.some(c => c === 'Database');
|
|
41
|
-
const hasHTTP = contexts.some(c => c === 'HTTP/API');
|
|
42
|
-
const hasTesting = contexts.every(c => c === 'Testing');
|
|
43
|
-
const hasConsole = contexts.every(c => c === 'Console/output');
|
|
44
|
-
|
|
45
|
-
// High risk: Database, HTTP/API (core functionality)
|
|
46
|
-
if (hasDatabase || hasHTTP) {
|
|
47
|
-
return 'High';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Low risk: Only in tests, or only console output
|
|
51
|
-
if (hasTesting || (hasConsole && files.length === 1)) {
|
|
52
|
-
return 'Low';
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Medium: Everything else (could be important, needs review)
|
|
56
|
-
return 'Medium';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function generateImpacts(files: FileUsage[], contexts: string[], packageName: string): string[] {
|
|
60
|
-
const impacts: string[] = [];
|
|
61
|
-
const uniqueContexts = [...new Set(contexts)];
|
|
62
|
-
|
|
63
|
-
// Base impacts on actual usage in THIS codebase
|
|
64
|
-
if (files.length === 0) {
|
|
65
|
-
impacts.push(`No direct usage found in source files`);
|
|
66
|
-
impacts.push(`May be a transitive dependency or unused`);
|
|
67
|
-
} else {
|
|
68
|
-
const totalMethods = new Set(files.flatMap(f => f.methods));
|
|
69
|
-
|
|
70
|
-
if (totalMethods.size > 0) {
|
|
71
|
-
impacts.push(`Methods used: ${Array.from(totalMethods).slice(0, 8).join(', ')}${totalMethods.size > 8 ? ` (+${totalMethods.size - 8} more)` : ''}`);
|
|
72
|
-
} else {
|
|
73
|
-
impacts.push(`Package imported but no method calls detected`);
|
|
74
|
-
impacts.push(`May be used as default export or namespace`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
impacts.push(`Used in ${files.length} file${files.length !== 1 ? 's' : ''}: ${uniqueContexts.join(', ')}`);
|
|
78
|
-
|
|
79
|
-
// Context-specific guidance (based on actual usage, not package name)
|
|
80
|
-
if (uniqueContexts.includes('Database')) {
|
|
81
|
-
impacts.push(`⚠️ Used in database operations - removal may break data access`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (uniqueContexts.includes('HTTP/API')) {
|
|
85
|
-
impacts.push(`⚠️ Used in API/HTTP layer - removal may break endpoints`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (uniqueContexts.includes('Testing')) {
|
|
89
|
-
impacts.push(`✓ Only used in tests - safe to remove from production dependencies`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (uniqueContexts.includes('Console/output') && files.length === 1) {
|
|
93
|
-
impacts.push(`✓ Only used for console output - low impact, can be replaced`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
impacts.push(`\n💡 Review the files above to assess actual impact in your codebase`);
|
|
98
|
-
|
|
99
|
-
return impacts;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function analyzeImpact(packageName: string, cwd: string): ImpactAnalysis {
|
|
103
|
-
const sourceFiles = findSourceFiles(cwd);
|
|
104
|
-
const fileUsages: FileUsage[] = [];
|
|
105
|
-
|
|
106
|
-
for (const file of sourceFiles) {
|
|
107
|
-
const usage = analyzeFileUsage(file, packageName, cwd);
|
|
108
|
-
if (usage) {
|
|
109
|
-
fileUsages.push(usage);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Analyze actual usage context in THIS codebase
|
|
114
|
-
const contexts = fileUsages.map(usage => {
|
|
115
|
-
try {
|
|
116
|
-
const fs = require('fs');
|
|
117
|
-
const path = require('path');
|
|
118
|
-
const fullPath = usage.file.startsWith(cwd) ? usage.file : path.join(cwd, usage.file);
|
|
119
|
-
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
120
|
-
return analyzeUsageContext(usage, content);
|
|
121
|
-
} catch {
|
|
122
|
-
return 'Unknown';
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const riskLevel = computeRiskLevel(fileUsages, contexts);
|
|
127
|
-
const impacts = generateImpacts(fileUsages, contexts, packageName);
|
|
128
|
-
|
|
129
|
-
// Add contexts to file usages
|
|
130
|
-
fileUsages.forEach((usage, index) => {
|
|
131
|
-
(usage as any).purpose = contexts[index];
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
return {
|
|
135
|
-
files: fileUsages,
|
|
136
|
-
riskLevel,
|
|
137
|
-
impacts
|
|
138
|
-
};
|
|
139
|
-
}
|