dep-brain 0.1.4 → 0.2.1

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/README.md CHANGED
@@ -41,6 +41,7 @@ dep-brain analyze
41
41
 
42
42
  npx dep-brain analyze
43
43
  npx dep-brain analyze --json
44
+ npx dep-brain analyze --md
44
45
  npx dep-brain analyze ./path-to-project
45
46
  npx dep-brain analyze --config depbrain.config.json
46
47
  npx dep-brain analyze --min-score 90 --fail-on-risks
@@ -90,6 +91,12 @@ Suggestions:
90
91
  dep-brain analyze --json
91
92
  ```
92
93
 
94
+ ## Markdown Output
95
+
96
+ ```bash
97
+ dep-brain analyze --md
98
+ ```
99
+
93
100
  ## Config File
94
101
 
95
102
  Create a `depbrain.config.json` file in the project root:
@@ -107,6 +114,12 @@ Create a `depbrain.config.json` file in the project root:
107
114
  },
108
115
  "report": {
109
116
  "maxSuggestions": 3
117
+ },
118
+ "scoring": {
119
+ "duplicateWeight": 5,
120
+ "outdatedWeight": 1,
121
+ "unusedWeight": 2,
122
+ "riskWeight": 6
110
123
  }
111
124
  }
112
125
  ```
@@ -125,6 +138,10 @@ Supported sections:
125
138
  - `policy.failOnOutdated`
126
139
  - `policy.failOnRisks`
127
140
  - `report.maxSuggestions`
141
+ - `scoring.duplicateWeight`
142
+ - `scoring.outdatedWeight`
143
+ - `scoring.unusedWeight`
144
+ - `scoring.riskWeight`
128
145
 
129
146
  Sample config file:
130
147
 
@@ -16,5 +16,11 @@
16
16
  },
17
17
  "report": {
18
18
  "maxSuggestions": 5
19
+ },
20
+ "scoring": {
21
+ "duplicateWeight": 5,
22
+ "outdatedWeight": 3,
23
+ "unusedWeight": 4,
24
+ "riskWeight": 10
19
25
  }
20
26
  }
@@ -33,6 +33,16 @@
33
33
  "properties": {
34
34
  "maxSuggestions": { "type": "number" }
35
35
  }
36
+ },
37
+ "scoring": {
38
+ "type": "object",
39
+ "additionalProperties": false,
40
+ "properties": {
41
+ "duplicateWeight": { "type": "number" },
42
+ "outdatedWeight": { "type": "number" },
43
+ "unusedWeight": { "type": "number" },
44
+ "riskWeight": { "type": "number" }
45
+ }
36
46
  }
37
47
  }
38
48
  }
package/dist/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { analyzeProject } from "./core/analyzer.js";
3
3
  import { renderConsoleReport } from "./reporters/console.js";
4
4
  import { renderJsonReport } from "./reporters/json.js";
5
+ import { renderMarkdownReport } from "./reporters/markdown.js";
5
6
  import { promises as fs } from "node:fs";
6
7
  import path from "node:path";
7
8
  async function main() {
@@ -80,6 +81,9 @@ async function main() {
80
81
  if (flags.has("--json")) {
81
82
  process.stdout.write(`${renderJsonReport(result)}\n`);
82
83
  }
84
+ else if (flags.has("--md")) {
85
+ process.stdout.write(`${renderMarkdownReport(result)}\n`);
86
+ }
83
87
  else {
84
88
  const output = renderConsoleReport(result);
85
89
  if (!output || output.trim().length === 0) {
@@ -144,13 +148,14 @@ function printHelp() {
144
148
  console.log("Dependency Brain");
145
149
  console.log("");
146
150
  console.log("Usage:");
147
- console.log(" dep-brain analyze [path] [--json] [--config path] [--min-score n] [--fail-on-risks] [--fail-on-outdated] [--fail-on-unused] [--fail-on-duplicates]");
151
+ console.log(" dep-brain analyze [path] [--json] [--md] [--config path] [--min-score n] [--fail-on-risks] [--fail-on-outdated] [--fail-on-unused] [--fail-on-duplicates]");
148
152
  console.log(" dep-brain config [path] [--config path]");
149
153
  console.log(" dep-brain help");
150
154
  console.log(" dep-brain --version");
151
155
  console.log("");
152
156
  console.log("Options:");
153
157
  console.log(" --json Output JSON for analysis");
158
+ console.log(" --md Output Markdown report");
154
159
  console.log(" --config <path> Path to depbrain.config.json");
155
160
  console.log(" --min-score <n> Minimum score required to pass");
156
161
  console.log(" --fail-on-risks Fail when risky dependencies exist");
@@ -33,6 +33,7 @@ export interface RiskDependency {
33
33
  export interface AnalysisResult {
34
34
  rootDir: string;
35
35
  score: number;
36
+ scoreBreakdown: ScoreBreakdown;
36
37
  policy: PolicyResult;
37
38
  duplicates: DuplicateDependency[];
38
39
  unused: UnusedDependency[];
@@ -50,6 +51,7 @@ export interface PackageAnalysisResult {
50
51
  name: string;
51
52
  rootDir: string;
52
53
  score: number;
54
+ scoreBreakdown: ScoreBreakdown;
53
55
  policy: PolicyResult;
54
56
  duplicates: DuplicateDependency[];
55
57
  unused: UnusedDependency[];
@@ -57,4 +59,17 @@ export interface PackageAnalysisResult {
57
59
  risks: RiskDependency[];
58
60
  suggestions: string[];
59
61
  }
62
+ export interface ScoreBreakdown {
63
+ baseScore: number;
64
+ duplicates: number;
65
+ outdated: number;
66
+ unused: number;
67
+ risks: number;
68
+ weights: {
69
+ duplicateWeight: number;
70
+ outdatedWeight: number;
71
+ unusedWeight: number;
72
+ riskWeight: number;
73
+ };
74
+ }
60
75
  export declare function analyzeProject(options?: AnalysisOptions): Promise<AnalysisResult>;
@@ -32,8 +32,18 @@ export async function analyzeProject(options = {}) {
32
32
  duplicates: duplicates.length,
33
33
  unused: unused.length,
34
34
  outdated: outdated.length,
35
- risks: risks.length
35
+ risks: risks.length,
36
+ duplicateWeight: config.scoring.duplicateWeight,
37
+ outdatedWeight: config.scoring.outdatedWeight,
38
+ unusedWeight: config.scoring.unusedWeight,
39
+ riskWeight: config.scoring.riskWeight
36
40
  });
41
+ const scoreBreakdown = buildScoreBreakdown({
42
+ duplicates: duplicates.length,
43
+ unused: unused.length,
44
+ outdated: outdated.length,
45
+ risks: risks.length
46
+ }, config);
37
47
  const suggestions = [
38
48
  ...packages.flatMap((pkg) => pkg.suggestions.map((suggestion) => `[${pkg.name}] ${suggestion}`))
39
49
  ].slice(0, config.report.maxSuggestions);
@@ -47,6 +57,7 @@ export async function analyzeProject(options = {}) {
47
57
  return {
48
58
  rootDir,
49
59
  score,
60
+ scoreBreakdown,
50
61
  policy,
51
62
  duplicates,
52
63
  unused,
@@ -79,6 +90,12 @@ function mergeConfig(base, overrides) {
79
90
  },
80
91
  report: {
81
92
  maxSuggestions: overrides.report?.maxSuggestions ?? base.report.maxSuggestions
93
+ },
94
+ scoring: {
95
+ duplicateWeight: overrides.scoring?.duplicateWeight ?? base.scoring.duplicateWeight,
96
+ outdatedWeight: overrides.scoring?.outdatedWeight ?? base.scoring.outdatedWeight,
97
+ unusedWeight: overrides.scoring?.unusedWeight ?? base.scoring.unusedWeight,
98
+ riskWeight: overrides.scoring?.riskWeight ?? base.scoring.riskWeight
82
99
  }
83
100
  };
84
101
  }
@@ -121,8 +138,18 @@ async function analyzeSingleProject(rootDir, config, options = {}) {
121
138
  duplicates: duplicates.length,
122
139
  unused: unused.length,
123
140
  outdated: outdated.length,
124
- risks: risks.length
141
+ risks: risks.length,
142
+ duplicateWeight: config.scoring.duplicateWeight,
143
+ outdatedWeight: config.scoring.outdatedWeight,
144
+ unusedWeight: config.scoring.unusedWeight,
145
+ riskWeight: config.scoring.riskWeight
125
146
  });
147
+ const scoreBreakdown = buildScoreBreakdown({
148
+ duplicates: duplicates.length,
149
+ unused: unused.length,
150
+ outdated: outdated.length,
151
+ risks: risks.length
152
+ }, config);
126
153
  const suggestions = [
127
154
  ...unused.map((item) => `Remove ${item.name} from ${item.section}`),
128
155
  ...duplicates.map((item) => `Consider consolidating ${item.name} to one version`),
@@ -147,6 +174,7 @@ async function analyzeSingleProject(rootDir, config, options = {}) {
147
174
  return {
148
175
  rootDir,
149
176
  score,
177
+ scoreBreakdown,
150
178
  policy,
151
179
  duplicates,
152
180
  unused: scopedUnused,
@@ -156,3 +184,18 @@ async function analyzeSingleProject(rootDir, config, options = {}) {
156
184
  config
157
185
  };
158
186
  }
187
+ function buildScoreBreakdown(counts, config) {
188
+ return {
189
+ baseScore: 100,
190
+ duplicates: counts.duplicates * config.scoring.duplicateWeight,
191
+ outdated: counts.outdated * config.scoring.outdatedWeight,
192
+ unused: counts.unused * config.scoring.unusedWeight,
193
+ risks: counts.risks * config.scoring.riskWeight,
194
+ weights: {
195
+ duplicateWeight: config.scoring.duplicateWeight,
196
+ outdatedWeight: config.scoring.outdatedWeight,
197
+ unusedWeight: config.scoring.unusedWeight,
198
+ riskWeight: config.scoring.riskWeight
199
+ }
200
+ };
201
+ }
@@ -3,5 +3,9 @@ export interface ScoreInputs {
3
3
  unused: number;
4
4
  outdated: number;
5
5
  risks: number;
6
+ duplicateWeight?: number;
7
+ unusedWeight?: number;
8
+ outdatedWeight?: number;
9
+ riskWeight?: number;
6
10
  }
7
11
  export declare function calculateHealthScore(inputs: ScoreInputs): number;
@@ -1,8 +1,12 @@
1
1
  export function calculateHealthScore(inputs) {
2
+ const duplicateWeight = inputs.duplicateWeight ?? 5;
3
+ const outdatedWeight = inputs.outdatedWeight ?? 3;
4
+ const unusedWeight = inputs.unusedWeight ?? 4;
5
+ const riskWeight = inputs.riskWeight ?? 10;
2
6
  const rawScore = 100 -
3
- inputs.duplicates * 5 -
4
- inputs.outdated * 3 -
5
- inputs.unused * 4 -
6
- inputs.risks * 10;
7
+ inputs.duplicates * duplicateWeight -
8
+ inputs.outdated * outdatedWeight -
9
+ inputs.unused * unusedWeight -
10
+ inputs.risks * riskWeight;
7
11
  return Math.max(0, rawScore);
8
12
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { analyzeProject } from "./core/analyzer.js";
2
- export type { AnalysisOptions, AnalysisResult, DuplicateDependency, OutdatedDependency, PolicyResult, PackageAnalysisResult, RiskDependency, UnusedDependency } from "./core/analyzer.js";
2
+ export type { AnalysisOptions, AnalysisResult, DuplicateDependency, OutdatedDependency, PolicyResult, PackageAnalysisResult, ScoreBreakdown, RiskDependency, UnusedDependency } from "./core/analyzer.js";
3
3
  export type { DepBrainConfig, DepBrainConfigOverrides } from "./utils/config.js";
4
4
  export type { WorkspacePackage } from "./utils/workspaces.js";
@@ -3,6 +3,7 @@ export function renderConsoleReport(result) {
3
3
  lines.push(`Project Health: ${result.score}/100`);
4
4
  lines.push(`Path: ${result.rootDir}`);
5
5
  lines.push(`Policy: ${result.policy.passed ? "PASS" : "FAIL"}`);
6
+ lines.push(`Score Breakdown: base ${result.scoreBreakdown.baseScore} - dup ${result.scoreBreakdown.duplicates} - outdated ${result.scoreBreakdown.outdated} - unused ${result.scoreBreakdown.unused} - risk ${result.scoreBreakdown.risks}`);
6
7
  lines.push("");
7
8
  lines.push(summaryLine("Duplicates", result.duplicates.length));
8
9
  lines.push(summaryLine("Unused", result.unused.length));
@@ -0,0 +1,2 @@
1
+ import type { AnalysisResult } from "../core/analyzer.js";
2
+ export declare function renderMarkdownReport(result: AnalysisResult): string;
@@ -0,0 +1,52 @@
1
+ export function renderMarkdownReport(result) {
2
+ const lines = [];
3
+ lines.push(`# Dependency Brain Report`);
4
+ lines.push("");
5
+ lines.push(`- **Project Health:** ${result.score}/100`);
6
+ lines.push(`- **Path:** ${result.rootDir}`);
7
+ lines.push(`- **Policy:** ${result.policy.passed ? "PASS" : "FAIL"}`);
8
+ lines.push(`- **Score Breakdown:** base ${result.scoreBreakdown.baseScore} - dup ${result.scoreBreakdown.duplicates} - outdated ${result.scoreBreakdown.outdated} - unused ${result.scoreBreakdown.unused} - risk ${result.scoreBreakdown.risks}`);
9
+ lines.push("");
10
+ if (result.packages && result.packages.length > 0) {
11
+ lines.push("## Packages");
12
+ for (const pkg of result.packages) {
13
+ lines.push(`- ${pkg.name}: ${pkg.score}/100 (D:${pkg.duplicates.length} U:${pkg.unused.length} O:${pkg.outdated.length} R:${pkg.risks.length})`);
14
+ }
15
+ lines.push("");
16
+ }
17
+ lines.push("## Summary");
18
+ lines.push(`- Duplicates: ${result.duplicates.length}`);
19
+ lines.push(`- Unused: ${result.unused.length}`);
20
+ lines.push(`- Outdated: ${result.outdated.length}`);
21
+ lines.push(`- Risks: ${result.risks.length}`);
22
+ lines.push("");
23
+ appendSection(lines, "Duplicate dependencies", result.duplicates.map((item) => `${item.name}: ${item.versions.join(", ")}`));
24
+ appendSection(lines, "Unused dependencies", result.unused.map((item) => item.package
25
+ ? `${item.name} (${item.section}) [${item.package}]`
26
+ : `${item.name} (${item.section})`));
27
+ appendSection(lines, "Outdated dependencies", result.outdated.map((item) => item.package
28
+ ? `${item.name}: ${item.current} -> ${item.latest} [${item.updateType}] [${item.package}]`
29
+ : `${item.name}: ${item.current} -> ${item.latest} [${item.updateType}]`));
30
+ appendSection(lines, "Risky dependencies", result.risks.map((item) => item.package
31
+ ? `${item.name}: ${item.reasons.join("; ")} [${item.package}]`
32
+ : `${item.name}: ${item.reasons.join("; ")}`));
33
+ appendSection(lines, "Policy reasons", result.policy.reasons);
34
+ if (result.suggestions.length > 0) {
35
+ lines.push("## Suggestions");
36
+ for (const suggestion of result.suggestions) {
37
+ lines.push(`- ${suggestion}`);
38
+ }
39
+ lines.push("");
40
+ }
41
+ return lines.join("\n");
42
+ }
43
+ function appendSection(lines, title, items) {
44
+ if (items.length === 0) {
45
+ return;
46
+ }
47
+ lines.push(`## ${title}`);
48
+ for (const item of items) {
49
+ lines.push(`- ${item}`);
50
+ }
51
+ lines.push("");
52
+ }
@@ -17,11 +17,18 @@ export interface DepBrainConfig {
17
17
  report: {
18
18
  maxSuggestions: number;
19
19
  };
20
+ scoring: {
21
+ duplicateWeight: number;
22
+ outdatedWeight: number;
23
+ unusedWeight: number;
24
+ riskWeight: number;
25
+ };
20
26
  }
21
27
  export interface DepBrainConfigOverrides {
22
28
  ignore?: Partial<DepBrainConfig["ignore"]>;
23
29
  policy?: Partial<DepBrainConfig["policy"]>;
24
30
  report?: Partial<DepBrainConfig["report"]>;
31
+ scoring?: Partial<DepBrainConfig["scoring"]>;
25
32
  }
26
33
  export declare const defaultConfig: DepBrainConfig;
27
34
  export declare function loadDepBrainConfig(rootDir: string, configPath?: string): Promise<DepBrainConfig>;
@@ -18,6 +18,12 @@ export const defaultConfig = {
18
18
  },
19
19
  report: {
20
20
  maxSuggestions: 5
21
+ },
22
+ scoring: {
23
+ duplicateWeight: 5,
24
+ outdatedWeight: 3,
25
+ unusedWeight: 4,
26
+ riskWeight: 10
21
27
  }
22
28
  };
23
29
  export async function loadDepBrainConfig(rootDir, configPath) {
@@ -49,6 +55,12 @@ function normalizeConfig(loaded) {
49
55
  },
50
56
  report: {
51
57
  maxSuggestions: normalizeNumber(loaded.report?.maxSuggestions, defaultConfig.report.maxSuggestions)
58
+ },
59
+ scoring: {
60
+ duplicateWeight: normalizeNumber(loaded.scoring?.duplicateWeight, defaultConfig.scoring.duplicateWeight),
61
+ outdatedWeight: normalizeNumber(loaded.scoring?.outdatedWeight, defaultConfig.scoring.outdatedWeight),
62
+ unusedWeight: normalizeNumber(loaded.scoring?.unusedWeight, defaultConfig.scoring.unusedWeight),
63
+ riskWeight: normalizeNumber(loaded.scoring?.riskWeight, defaultConfig.scoring.riskWeight)
52
64
  }
53
65
  };
54
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dep-brain",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "CLI and library for dependency health analysis",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",