@aiready/change-amplification 0.1.6 → 0.1.8
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/.turbo/turbo-build.log +13 -13
- package/.turbo/turbo-lint.log +5 -0
- package/.turbo/turbo-test.log +4 -4
- package/dist/chunk-MARO4FT6.mjs +112 -0
- package/dist/chunk-V5J3BP4N.mjs +117 -0
- package/dist/cli.js +12 -18
- package/dist/cli.mjs +1 -1
- package/dist/index.js +12 -18
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/src/analyzer.ts +18 -29
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @aiready/change-amplification@0.1.
|
|
3
|
+
> @aiready/change-amplification@0.1.8 build /Users/pengcao/projects/aiready/packages/change-amplification
|
|
4
4
|
> tsup src/index.ts src/cli.ts --format cjs,esm --dts
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: src/cli.ts, src/index.ts
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
|
|
13
|
-
[90m[[
|
|
13
|
+
[90m[[90m12:55:24 AM[90m][39m [43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe condition "types" here will never be used as it comes after both "import" and "require"[0m [package.json]
|
|
14
14
|
|
|
15
15
|
package.json:33:6:
|
|
16
16
|
[37m 33 │ [32m"types"[37m: "./dist/index.d.ts"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
[90m[[
|
|
34
|
+
[90m[[90m12:55:24 AM[90m][39m [43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe condition "types" here will never be used as it comes after both "import" and "require"[0m [package.json]
|
|
35
35
|
|
|
36
36
|
package.json:38:6:
|
|
37
37
|
[37m 38 │ [32m"types"[37m: "./dist/cli.d.ts"
|
|
@@ -51,8 +51,12 @@
|
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m110.00 B[39m
|
|
55
|
+
[32mESM[39m [1mdist/cli.mjs [22m[32m2.78 KB[39m
|
|
56
|
+
[32mESM[39m [1mdist/chunk-MARO4FT6.mjs [22m[32m3.52 KB[39m
|
|
57
|
+
[32mESM[39m ⚡️ Build success in 440ms
|
|
54
58
|
|
|
55
|
-
[90m[[
|
|
59
|
+
[90m[[90m12:55:25 AM[90m][39m [43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe condition "types" here will never be used as it comes after both "import" and "require"[0m [package.json]
|
|
56
60
|
|
|
57
61
|
package.json:33:6:
|
|
58
62
|
[37m 33 │ [32m"types"[37m: "./dist/index.d.ts"
|
|
@@ -73,7 +77,7 @@
|
|
|
73
77
|
|
|
74
78
|
|
|
75
79
|
|
|
76
|
-
[90m[[
|
|
80
|
+
[90m[[90m12:55:25 AM[90m][39m [43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe condition "types" here will never be used as it comes after both "import" and "require"[0m [package.json]
|
|
77
81
|
|
|
78
82
|
package.json:38:6:
|
|
79
83
|
[37m 38 │ [32m"types"[37m: "./dist/cli.d.ts"
|
|
@@ -93,15 +97,11 @@
|
|
|
93
97
|
|
|
94
98
|
|
|
95
99
|
|
|
96
|
-
[32mCJS[39m [1mdist/
|
|
97
|
-
[32mCJS[39m [1mdist/
|
|
98
|
-
[32mCJS[39m ⚡️ Build success in
|
|
99
|
-
[32mESM[39m [1mdist/cli.mjs [22m[32m2.78 KB[39m
|
|
100
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m110.00 B[39m
|
|
101
|
-
[32mESM[39m [1mdist/chunk-A5ACPWWO.mjs [22m[32m3.92 KB[39m
|
|
102
|
-
[32mESM[39m ⚡️ Build success in 146ms
|
|
100
|
+
[32mCJS[39m [1mdist/index.js [22m[32m4.79 KB[39m
|
|
101
|
+
[32mCJS[39m [1mdist/cli.js [22m[32m7.65 KB[39m
|
|
102
|
+
[32mCJS[39m ⚡️ Build success in 631ms
|
|
103
103
|
DTS Build start
|
|
104
|
-
DTS ⚡️ Build success in
|
|
104
|
+
DTS ⚡️ Build success in 10596ms
|
|
105
105
|
DTS dist/cli.d.ts 152.00 B
|
|
106
106
|
DTS dist/index.d.ts 999.00 B
|
|
107
107
|
DTS dist/cli.d.mts 152.00 B
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @aiready/change-amplification@0.1.
|
|
3
|
+
> @aiready/change-amplification@0.1.8 test /Users/pengcao/projects/aiready/packages/change-amplification
|
|
4
4
|
> vitest run
|
|
5
5
|
|
|
6
6
|
[?25l
|
|
7
7
|
[1m[46m RUN [49m[22m [36mv4.0.18 [39m[90m/Users/pengcao/projects/aiready/packages/change-amplification[39m
|
|
8
8
|
|
|
9
|
-
[32m✓[39m src/__tests__/dummy.test.ts [2m([22m[2m1 test[22m[2m)[22m[32m
|
|
9
|
+
[32m✓[39m src/__tests__/dummy.test.ts [2m([22m[2m1 test[22m[2m)[22m[32m 13[2mms[22m[39m
|
|
10
10
|
|
|
11
11
|
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
12
12
|
[2m Tests [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
13
|
-
[2m Start at [22m
|
|
14
|
-
[2m Duration [22m
|
|
13
|
+
[2m Start at [22m 00:56:24
|
|
14
|
+
[2m Duration [22m 1.16s[2m (transform 306ms, setup 0ms, import 474ms, tests 13ms, environment 0ms)[22m
|
|
15
15
|
|
|
16
16
|
[?25h
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/analyzer.ts
|
|
9
|
+
import * as fs from "fs";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import {
|
|
12
|
+
scanFiles,
|
|
13
|
+
calculateChangeAmplification,
|
|
14
|
+
getParser
|
|
15
|
+
} from "@aiready/core";
|
|
16
|
+
async function analyzeChangeAmplification(options) {
|
|
17
|
+
const rootDir = path.resolve(options.rootDir || ".");
|
|
18
|
+
const files = await scanFiles({
|
|
19
|
+
...options,
|
|
20
|
+
include: options.include || ["**/*.{ts,tsx,js,jsx,py,go}"]
|
|
21
|
+
});
|
|
22
|
+
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
23
|
+
const reverseGraph = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const file of files) {
|
|
25
|
+
dependencyGraph.set(file, []);
|
|
26
|
+
reverseGraph.set(file, []);
|
|
27
|
+
}
|
|
28
|
+
let processed = 0;
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
processed++;
|
|
31
|
+
options.onProgress?.(
|
|
32
|
+
processed,
|
|
33
|
+
files.length,
|
|
34
|
+
`change-amplification: analyzing files`
|
|
35
|
+
);
|
|
36
|
+
try {
|
|
37
|
+
const parser = getParser(file);
|
|
38
|
+
if (!parser) continue;
|
|
39
|
+
const content = fs.readFileSync(file, "utf8");
|
|
40
|
+
const parseResult = parser.parse(content, file);
|
|
41
|
+
const dependencies = parseResult.imports.map((i) => i.source);
|
|
42
|
+
for (const dep of dependencies) {
|
|
43
|
+
const depDir = path.dirname(file);
|
|
44
|
+
const resolvedPath = files.find((f) => {
|
|
45
|
+
if (dep.startsWith(".")) {
|
|
46
|
+
return f.startsWith(path.resolve(depDir, dep));
|
|
47
|
+
} else {
|
|
48
|
+
return f.includes(dep);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
if (resolvedPath) {
|
|
52
|
+
dependencyGraph.get(file)?.push(resolvedPath);
|
|
53
|
+
reverseGraph.get(resolvedPath)?.push(file);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
void err;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const fileMetrics = files.map((file) => {
|
|
61
|
+
const fanOut = dependencyGraph.get(file)?.length || 0;
|
|
62
|
+
const fanIn = reverseGraph.get(file)?.length || 0;
|
|
63
|
+
return { file, fanOut, fanIn };
|
|
64
|
+
});
|
|
65
|
+
const riskResult = calculateChangeAmplification({ files: fileMetrics });
|
|
66
|
+
const results = [];
|
|
67
|
+
for (const hotspot of riskResult.hotspots) {
|
|
68
|
+
const issues = [];
|
|
69
|
+
if (hotspot.amplificationFactor > 20) {
|
|
70
|
+
issues.push({
|
|
71
|
+
type: "change-amplification",
|
|
72
|
+
severity: hotspot.amplificationFactor > 40 ? "critical" : "major",
|
|
73
|
+
message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
|
|
74
|
+
location: { file: hotspot.file, line: 1 },
|
|
75
|
+
suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (hotspot.amplificationFactor > 5) {
|
|
79
|
+
results.push({
|
|
80
|
+
fileName: hotspot.file,
|
|
81
|
+
issues,
|
|
82
|
+
metrics: {
|
|
83
|
+
aiSignalClarityScore: 100 - hotspot.amplificationFactor
|
|
84
|
+
// Just a rough score
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
summary: {
|
|
91
|
+
totalFiles: files.length,
|
|
92
|
+
totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
|
|
93
|
+
criticalIssues: results.reduce(
|
|
94
|
+
(sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length,
|
|
95
|
+
0
|
|
96
|
+
),
|
|
97
|
+
majorIssues: results.reduce(
|
|
98
|
+
(sum, r) => sum + r.issues.filter((i) => i.severity === "major").length,
|
|
99
|
+
0
|
|
100
|
+
),
|
|
101
|
+
score: riskResult.score,
|
|
102
|
+
rating: riskResult.rating,
|
|
103
|
+
recommendations: riskResult.recommendations
|
|
104
|
+
},
|
|
105
|
+
results
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
__require,
|
|
111
|
+
analyzeChangeAmplification
|
|
112
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/analyzer.ts
|
|
9
|
+
import * as fs from "fs";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import { globSync } from "glob";
|
|
12
|
+
import { calculateChangeAmplification } from "@aiready/core";
|
|
13
|
+
import { getParser } from "@aiready/core";
|
|
14
|
+
function collectFiles(dir, options) {
|
|
15
|
+
const includePatterns = options.include && options.include.length > 0 ? options.include : ["**/*.{ts,tsx,js,jsx,py,go}"];
|
|
16
|
+
const excludePatterns = options.exclude && options.exclude.length > 0 ? options.exclude : ["**/node_modules/**", "**/dist/**", "**/.git/**"];
|
|
17
|
+
let matchedFiles = [];
|
|
18
|
+
for (const pattern of includePatterns) {
|
|
19
|
+
const files = globSync(pattern, {
|
|
20
|
+
cwd: dir,
|
|
21
|
+
ignore: excludePatterns,
|
|
22
|
+
absolute: true
|
|
23
|
+
});
|
|
24
|
+
matchedFiles = matchedFiles.concat(files);
|
|
25
|
+
}
|
|
26
|
+
return [...new Set(matchedFiles)];
|
|
27
|
+
}
|
|
28
|
+
async function analyzeChangeAmplification(options) {
|
|
29
|
+
const rootDir = path.resolve(options.rootDir || ".");
|
|
30
|
+
const files = collectFiles(rootDir, options);
|
|
31
|
+
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
32
|
+
const reverseGraph = /* @__PURE__ */ new Map();
|
|
33
|
+
for (const file of files) {
|
|
34
|
+
dependencyGraph.set(file, []);
|
|
35
|
+
reverseGraph.set(file, []);
|
|
36
|
+
}
|
|
37
|
+
let processed = 0;
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
processed++;
|
|
40
|
+
options.onProgress?.(processed, files.length, `change-amplification: analyzing ${file.substring(rootDir.length + 1)}`);
|
|
41
|
+
try {
|
|
42
|
+
const parser = getParser(file);
|
|
43
|
+
if (!parser) continue;
|
|
44
|
+
const content = fs.readFileSync(file, "utf8");
|
|
45
|
+
const parseResult = parser.parse(content, file);
|
|
46
|
+
const dependencies = parseResult.imports.map((i) => i.source);
|
|
47
|
+
for (const dep of dependencies) {
|
|
48
|
+
const depDir = path.dirname(file);
|
|
49
|
+
const resolvedPath = files.find((f) => {
|
|
50
|
+
if (dep.startsWith(".")) {
|
|
51
|
+
return f.startsWith(path.resolve(depDir, dep));
|
|
52
|
+
} else {
|
|
53
|
+
return f.includes(dep);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (resolvedPath) {
|
|
57
|
+
dependencyGraph.get(file)?.push(resolvedPath);
|
|
58
|
+
reverseGraph.get(resolvedPath)?.push(file);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} catch (err) {
|
|
62
|
+
void err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const fileMetrics = files.map((file) => {
|
|
66
|
+
const fanOut = dependencyGraph.get(file)?.length || 0;
|
|
67
|
+
const fanIn = reverseGraph.get(file)?.length || 0;
|
|
68
|
+
return { file, fanOut, fanIn };
|
|
69
|
+
});
|
|
70
|
+
const riskResult = calculateChangeAmplification({ files: fileMetrics });
|
|
71
|
+
const results = [];
|
|
72
|
+
for (const hotspot of riskResult.hotspots) {
|
|
73
|
+
const issues = [];
|
|
74
|
+
if (hotspot.amplificationFactor > 20) {
|
|
75
|
+
issues.push({
|
|
76
|
+
type: "change-amplification",
|
|
77
|
+
severity: hotspot.amplificationFactor > 40 ? "critical" : "major",
|
|
78
|
+
message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
|
|
79
|
+
location: { file: hotspot.file, line: 1 },
|
|
80
|
+
suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (hotspot.amplificationFactor > 5) {
|
|
84
|
+
results.push({
|
|
85
|
+
fileName: hotspot.file,
|
|
86
|
+
issues,
|
|
87
|
+
metrics: {
|
|
88
|
+
aiSignalClarityScore: 100 - hotspot.amplificationFactor
|
|
89
|
+
// Just a rough score
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
summary: {
|
|
96
|
+
totalFiles: files.length,
|
|
97
|
+
totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
|
|
98
|
+
criticalIssues: results.reduce(
|
|
99
|
+
(sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length,
|
|
100
|
+
0
|
|
101
|
+
),
|
|
102
|
+
majorIssues: results.reduce(
|
|
103
|
+
(sum, r) => sum + r.issues.filter((i) => i.severity === "major").length,
|
|
104
|
+
0
|
|
105
|
+
),
|
|
106
|
+
score: riskResult.score,
|
|
107
|
+
rating: riskResult.rating,
|
|
108
|
+
recommendations: riskResult.recommendations
|
|
109
|
+
},
|
|
110
|
+
results
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export {
|
|
115
|
+
__require,
|
|
116
|
+
analyzeChangeAmplification
|
|
117
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -42,35 +42,29 @@ var fs2 = __toESM(require("fs"));
|
|
|
42
42
|
// src/analyzer.ts
|
|
43
43
|
var fs = __toESM(require("fs"));
|
|
44
44
|
var path = __toESM(require("path"));
|
|
45
|
-
var import_glob = require("glob");
|
|
46
45
|
var import_core = require("@aiready/core");
|
|
47
|
-
var import_core2 = require("@aiready/core");
|
|
48
|
-
function collectFiles(dir, options) {
|
|
49
|
-
const includePatterns = options.include && options.include.length > 0 ? options.include : ["**/*.{ts,tsx,js,jsx,py,go}"];
|
|
50
|
-
const excludePatterns = options.exclude && options.exclude.length > 0 ? options.exclude : ["**/node_modules/**", "**/dist/**", "**/.git/**"];
|
|
51
|
-
let matchedFiles = [];
|
|
52
|
-
for (const pattern of includePatterns) {
|
|
53
|
-
const files = (0, import_glob.globSync)(pattern, {
|
|
54
|
-
cwd: dir,
|
|
55
|
-
ignore: excludePatterns,
|
|
56
|
-
absolute: true
|
|
57
|
-
});
|
|
58
|
-
matchedFiles = matchedFiles.concat(files);
|
|
59
|
-
}
|
|
60
|
-
return [...new Set(matchedFiles)];
|
|
61
|
-
}
|
|
62
46
|
async function analyzeChangeAmplification(options) {
|
|
63
47
|
const rootDir = path.resolve(options.rootDir || ".");
|
|
64
|
-
const files =
|
|
48
|
+
const files = await (0, import_core.scanFiles)({
|
|
49
|
+
...options,
|
|
50
|
+
include: options.include || ["**/*.{ts,tsx,js,jsx,py,go}"]
|
|
51
|
+
});
|
|
65
52
|
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
66
53
|
const reverseGraph = /* @__PURE__ */ new Map();
|
|
67
54
|
for (const file of files) {
|
|
68
55
|
dependencyGraph.set(file, []);
|
|
69
56
|
reverseGraph.set(file, []);
|
|
70
57
|
}
|
|
58
|
+
let processed = 0;
|
|
71
59
|
for (const file of files) {
|
|
60
|
+
processed++;
|
|
61
|
+
options.onProgress?.(
|
|
62
|
+
processed,
|
|
63
|
+
files.length,
|
|
64
|
+
`change-amplification: analyzing files`
|
|
65
|
+
);
|
|
72
66
|
try {
|
|
73
|
-
const parser = (0,
|
|
67
|
+
const parser = (0, import_core.getParser)(file);
|
|
74
68
|
if (!parser) continue;
|
|
75
69
|
const content = fs.readFileSync(file, "utf8");
|
|
76
70
|
const parseResult = parser.parse(content, file);
|
package/dist/cli.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -37,35 +37,29 @@ module.exports = __toCommonJS(index_exports);
|
|
|
37
37
|
// src/analyzer.ts
|
|
38
38
|
var fs = __toESM(require("fs"));
|
|
39
39
|
var path = __toESM(require("path"));
|
|
40
|
-
var import_glob = require("glob");
|
|
41
40
|
var import_core = require("@aiready/core");
|
|
42
|
-
var import_core2 = require("@aiready/core");
|
|
43
|
-
function collectFiles(dir, options) {
|
|
44
|
-
const includePatterns = options.include && options.include.length > 0 ? options.include : ["**/*.{ts,tsx,js,jsx,py,go}"];
|
|
45
|
-
const excludePatterns = options.exclude && options.exclude.length > 0 ? options.exclude : ["**/node_modules/**", "**/dist/**", "**/.git/**"];
|
|
46
|
-
let matchedFiles = [];
|
|
47
|
-
for (const pattern of includePatterns) {
|
|
48
|
-
const files = (0, import_glob.globSync)(pattern, {
|
|
49
|
-
cwd: dir,
|
|
50
|
-
ignore: excludePatterns,
|
|
51
|
-
absolute: true
|
|
52
|
-
});
|
|
53
|
-
matchedFiles = matchedFiles.concat(files);
|
|
54
|
-
}
|
|
55
|
-
return [...new Set(matchedFiles)];
|
|
56
|
-
}
|
|
57
41
|
async function analyzeChangeAmplification(options) {
|
|
58
42
|
const rootDir = path.resolve(options.rootDir || ".");
|
|
59
|
-
const files =
|
|
43
|
+
const files = await (0, import_core.scanFiles)({
|
|
44
|
+
...options,
|
|
45
|
+
include: options.include || ["**/*.{ts,tsx,js,jsx,py,go}"]
|
|
46
|
+
});
|
|
60
47
|
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
61
48
|
const reverseGraph = /* @__PURE__ */ new Map();
|
|
62
49
|
for (const file of files) {
|
|
63
50
|
dependencyGraph.set(file, []);
|
|
64
51
|
reverseGraph.set(file, []);
|
|
65
52
|
}
|
|
53
|
+
let processed = 0;
|
|
66
54
|
for (const file of files) {
|
|
55
|
+
processed++;
|
|
56
|
+
options.onProgress?.(
|
|
57
|
+
processed,
|
|
58
|
+
files.length,
|
|
59
|
+
`change-amplification: analyzing files`
|
|
60
|
+
);
|
|
67
61
|
try {
|
|
68
|
-
const parser = (0,
|
|
62
|
+
const parser = (0, import_core.getParser)(file);
|
|
69
63
|
if (!parser) continue;
|
|
70
64
|
const content = fs.readFileSync(file, "utf8");
|
|
71
65
|
const parseResult = parser.parse(content, file);
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/change-amplification",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "AI-Readiness: Change Amplification Detection",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"commander": "^14.0.0",
|
|
11
11
|
"glob": "^13.0.0",
|
|
12
12
|
"chalk": "^5.3.0",
|
|
13
|
-
"@aiready/core": "0.9.
|
|
13
|
+
"@aiready/core": "0.9.35"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/node": "^24.0.0",
|
package/src/analyzer.ts
CHANGED
|
@@ -1,45 +1,26 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
scanFiles,
|
|
5
|
+
calculateChangeAmplification,
|
|
6
|
+
getParser,
|
|
7
|
+
} from '@aiready/core';
|
|
5
8
|
import type {
|
|
6
9
|
ChangeAmplificationOptions,
|
|
7
10
|
ChangeAmplificationReport,
|
|
8
11
|
FileChangeAmplificationResult,
|
|
9
12
|
ChangeAmplificationIssue,
|
|
10
13
|
} from './types';
|
|
11
|
-
import { getParser } from '@aiready/core';
|
|
12
|
-
|
|
13
|
-
function collectFiles(
|
|
14
|
-
dir: string,
|
|
15
|
-
options: ChangeAmplificationOptions
|
|
16
|
-
): string[] {
|
|
17
|
-
const includePatterns =
|
|
18
|
-
options.include && options.include.length > 0
|
|
19
|
-
? options.include
|
|
20
|
-
: ['**/*.{ts,tsx,js,jsx,py,go}'];
|
|
21
|
-
const excludePatterns =
|
|
22
|
-
options.exclude && options.exclude.length > 0
|
|
23
|
-
? options.exclude
|
|
24
|
-
: ['**/node_modules/**', '**/dist/**', '**/.git/**'];
|
|
25
|
-
|
|
26
|
-
let matchedFiles: string[] = [];
|
|
27
|
-
for (const pattern of includePatterns) {
|
|
28
|
-
const files = globSync(pattern, {
|
|
29
|
-
cwd: dir,
|
|
30
|
-
ignore: excludePatterns,
|
|
31
|
-
absolute: true,
|
|
32
|
-
});
|
|
33
|
-
matchedFiles = matchedFiles.concat(files);
|
|
34
|
-
}
|
|
35
|
-
return [...new Set(matchedFiles)];
|
|
36
|
-
}
|
|
37
14
|
|
|
38
15
|
export async function analyzeChangeAmplification(
|
|
39
16
|
options: ChangeAmplificationOptions
|
|
40
17
|
): Promise<ChangeAmplificationReport> {
|
|
41
18
|
const rootDir = path.resolve(options.rootDir || '.');
|
|
42
|
-
|
|
19
|
+
// Use core scanFiles which respects .gitignore recursively
|
|
20
|
+
const files = await scanFiles({
|
|
21
|
+
...options,
|
|
22
|
+
include: options.include || ['**/*.{ts,tsx,js,jsx,py,go}'],
|
|
23
|
+
});
|
|
43
24
|
|
|
44
25
|
// Compute graph metrics: fanIn and fanOut
|
|
45
26
|
const dependencyGraph = new Map<string, string[]>(); // key: file, value: imported files
|
|
@@ -52,7 +33,15 @@ export async function analyzeChangeAmplification(
|
|
|
52
33
|
}
|
|
53
34
|
|
|
54
35
|
// Parse files to build dependency graph
|
|
36
|
+
let processed = 0;
|
|
55
37
|
for (const file of files) {
|
|
38
|
+
processed++;
|
|
39
|
+
options.onProgress?.(
|
|
40
|
+
processed,
|
|
41
|
+
files.length,
|
|
42
|
+
`change-amplification: analyzing files`
|
|
43
|
+
);
|
|
44
|
+
|
|
56
45
|
try {
|
|
57
46
|
const parser = getParser(file);
|
|
58
47
|
if (!parser) continue;
|