@deplens/mcp 0.1.7 → 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.
@@ -0,0 +1,145 @@
1
+ /**
2
+ * diff.mjs - Main entry point for package version diff
3
+ * Combines version resolution, diff analysis, and changelog parsing
4
+ */
5
+
6
+ import {
7
+ downloadVersionPair,
8
+ resolveVersion,
9
+ clearCache,
10
+ getCacheStats,
11
+ } from "./version-resolver.mjs";
12
+ import {
13
+ compareVersions,
14
+ formatDiffAsText,
15
+ formatDiffAsJson,
16
+ } from "./diff-analyzer.mjs";
17
+ import {
18
+ findChangelog,
19
+ parseChangelogFile,
20
+ getChangesBetweenVersions,
21
+ formatChangelogDiff,
22
+ } from "./changelog-parser.mjs";
23
+
24
+ /**
25
+ * Run a complete diff between two package versions
26
+ */
27
+ export async function runDiff(options = {}) {
28
+ const {
29
+ package: packageName,
30
+ from = "installed",
31
+ to = "latest",
32
+ projectDir = process.cwd(),
33
+ includeSource = false,
34
+ includeChangelog = true,
35
+ filter,
36
+ format = "text", // "text" | "json"
37
+ verbose = false,
38
+ colors = true,
39
+ } = options;
40
+
41
+ if (!packageName) {
42
+ throw new Error("Package name is required");
43
+ }
44
+
45
+ const output = [];
46
+ const log = (msg) => output.push(msg);
47
+
48
+ try {
49
+ // Resolve and download versions
50
+ log(`🔍 Resolving versions for ${packageName}...`);
51
+
52
+ const versionPair = await downloadVersionPair(packageName, from, to, {
53
+ projectDir,
54
+ });
55
+
56
+ log(
57
+ ` From: ${versionPair.from.version}${versionPair.from.cached ? " (cached)" : ""}`,
58
+ );
59
+ log(
60
+ ` To: ${versionPair.to.version}${versionPair.to.cached ? " (cached)" : ""}`,
61
+ );
62
+ log("");
63
+
64
+ // Run semantic diff
65
+ log(`📊 Analyzing differences...`);
66
+ const diff = await compareVersions(
67
+ versionPair.from.packageDir,
68
+ versionPair.to.packageDir,
69
+ { filter, includeSource },
70
+ );
71
+ log("");
72
+
73
+ // Parse changelog if available
74
+ let changelogDiff = null;
75
+ if (includeChangelog) {
76
+ const changelogPath = findChangelog(versionPair.to.packageDir);
77
+ if (changelogPath) {
78
+ log(`📜 Parsing changelog...`);
79
+ const changelog = parseChangelogFile(changelogPath);
80
+ changelogDiff = getChangesBetweenVersions(
81
+ changelog,
82
+ versionPair.from.version,
83
+ versionPair.to.version,
84
+ );
85
+ }
86
+ }
87
+
88
+ // Format output
89
+ if (format === "json") {
90
+ return {
91
+ output: formatDiffAsJson({
92
+ ...diff,
93
+ changelog: changelogDiff,
94
+ meta: {
95
+ package: packageName,
96
+ from: versionPair.from.version,
97
+ to: versionPair.to.version,
98
+ analyzedAt: new Date().toISOString(),
99
+ },
100
+ }),
101
+ diff,
102
+ changelog: changelogDiff,
103
+ };
104
+ }
105
+
106
+ if (format === "object") {
107
+ return {
108
+ output: null,
109
+ diff,
110
+ changelog: changelogDiff,
111
+ };
112
+ }
113
+
114
+ // Text format
115
+ log(formatDiffAsText(diff, { colors, verbose }));
116
+
117
+ if (changelogDiff) {
118
+ log("");
119
+ log(formatChangelogDiff(changelogDiff));
120
+ }
121
+
122
+ return {
123
+ output: output.join("\n"),
124
+ diff,
125
+ changelog: changelogDiff,
126
+ };
127
+ } catch (error) {
128
+ return {
129
+ output: `❌ Error: ${error.message}`,
130
+ error: error.message,
131
+ };
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Get available versions for a package
137
+ */
138
+ export { resolveVersion, clearCache, getCacheStats };
139
+
140
+ export default {
141
+ runDiff,
142
+ resolveVersion,
143
+ clearCache,
144
+ getCacheStats,
145
+ };