depsonar 4.0.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/LICENSE +21 -0
- package/README.md +247 -0
- package/dist/checker.d.ts +14 -0
- package/dist/checker.d.ts.map +1 -0
- package/dist/checker.js +110 -0
- package/dist/checker.js.map +1 -0
- package/dist/constants.d.ts +21 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +136 -0
- package/dist/constants.js.map +1 -0
- package/dist/dashboard.d.ts +3 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +266 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +121 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/index.d.ts +106 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +106 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/services/actions.d.ts +17 -0
- package/dist/services/actions.d.ts.map +1 -0
- package/dist/services/actions.js +125 -0
- package/dist/services/actions.js.map +1 -0
- package/dist/services/audit.d.ts +27 -0
- package/dist/services/audit.d.ts.map +1 -0
- package/dist/services/audit.js +267 -0
- package/dist/services/audit.js.map +1 -0
- package/dist/services/changelog.d.ts +15 -0
- package/dist/services/changelog.d.ts.map +1 -0
- package/dist/services/changelog.js +92 -0
- package/dist/services/changelog.js.map +1 -0
- package/dist/services/cve.d.ts +32 -0
- package/dist/services/cve.d.ts.map +1 -0
- package/dist/services/cve.js +239 -0
- package/dist/services/cve.js.map +1 -0
- package/dist/services/deprecated.d.ts +18 -0
- package/dist/services/deprecated.d.ts.map +1 -0
- package/dist/services/deprecated.js +93 -0
- package/dist/services/deprecated.js.map +1 -0
- package/dist/services/docker.d.ts +17 -0
- package/dist/services/docker.d.ts.map +1 -0
- package/dist/services/docker.js +152 -0
- package/dist/services/docker.js.map +1 -0
- package/dist/services/docs.d.ts +26 -0
- package/dist/services/docs.d.ts.map +1 -0
- package/dist/services/docs.js +203 -0
- package/dist/services/docs.js.map +1 -0
- package/dist/services/envcheck.d.ts +15 -0
- package/dist/services/envcheck.d.ts.map +1 -0
- package/dist/services/envcheck.js +189 -0
- package/dist/services/envcheck.js.map +1 -0
- package/dist/services/formatter.d.ts +105 -0
- package/dist/services/formatter.d.ts.map +1 -0
- package/dist/services/formatter.js +597 -0
- package/dist/services/formatter.js.map +1 -0
- package/dist/services/licenses.d.ts +19 -0
- package/dist/services/licenses.d.ts.map +1 -0
- package/dist/services/licenses.js +142 -0
- package/dist/services/licenses.js.map +1 -0
- package/dist/services/migrate.d.ts +24 -0
- package/dist/services/migrate.d.ts.map +1 -0
- package/dist/services/migrate.js +169 -0
- package/dist/services/migrate.js.map +1 -0
- package/dist/services/osv.d.ts +29 -0
- package/dist/services/osv.d.ts.map +1 -0
- package/dist/services/osv.js +161 -0
- package/dist/services/osv.js.map +1 -0
- package/dist/services/project.d.ts +29 -0
- package/dist/services/project.d.ts.map +1 -0
- package/dist/services/project.js +716 -0
- package/dist/services/project.js.map +1 -0
- package/dist/services/runtimes.d.ts +26 -0
- package/dist/services/runtimes.d.ts.map +1 -0
- package/dist/services/runtimes.js +236 -0
- package/dist/services/runtimes.js.map +1 -0
- package/dist/services/secrets.d.ts +18 -0
- package/dist/services/secrets.d.ts.map +1 -0
- package/dist/services/secrets.js +164 -0
- package/dist/services/secrets.js.map +1 -0
- package/dist/services/toolchain.d.ts +10 -0
- package/dist/services/toolchain.d.ts.map +1 -0
- package/dist/services/toolchain.js +243 -0
- package/dist/services/toolchain.js.map +1 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +1067 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types.d.ts +69 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import { existsSync, readFileSync, readdirSync, writeFileSync, statSync } from "fs";
|
|
3
|
+
import { join, basename, resolve } from "path";
|
|
4
|
+
import { homedir } from "os";
|
|
5
|
+
import { COMMAND_TIMEOUT, ECOSYSTEM_GROUPS, FRAMEWORK_DETECTORS, LANGUAGE_MARKERS, CACHE_FILENAME, CACHE_MAX_AGE_MS, SERVER_VERSION, } from "../constants.js";
|
|
6
|
+
// ─── Config ────────────────────────────────────────────────────────────
|
|
7
|
+
const DEFAULT_PROJECTS_DIRS = [
|
|
8
|
+
join(homedir(), "Cursor", "App"),
|
|
9
|
+
join(homedir(), "Projects"),
|
|
10
|
+
join(homedir(), "Developer"),
|
|
11
|
+
join(homedir(), "Code"),
|
|
12
|
+
join(homedir(), "dev"),
|
|
13
|
+
];
|
|
14
|
+
export function getProjectsDir() {
|
|
15
|
+
const configPaths = [
|
|
16
|
+
join(homedir(), ".depsonarrc.json"),
|
|
17
|
+
join(homedir(), ".config", "depsonar", "config.json"),
|
|
18
|
+
];
|
|
19
|
+
for (const configPath of configPaths) {
|
|
20
|
+
if (existsSync(configPath)) {
|
|
21
|
+
try {
|
|
22
|
+
const config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
23
|
+
if (config.projectsDir && existsSync(config.projectsDir)) {
|
|
24
|
+
return resolve(config.projectsDir);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch { /* ignore */ }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const envDir = process.env.DEPUP_PROJECTS_DIR;
|
|
31
|
+
if (envDir && existsSync(envDir))
|
|
32
|
+
return resolve(envDir);
|
|
33
|
+
for (const dir of DEFAULT_PROJECTS_DIRS) {
|
|
34
|
+
if (existsSync(dir))
|
|
35
|
+
return dir;
|
|
36
|
+
}
|
|
37
|
+
return join(homedir(), "Projects");
|
|
38
|
+
}
|
|
39
|
+
// ─── Shell Execution ───────────────────────────────────────────────────
|
|
40
|
+
export function run(cmd, cwd) {
|
|
41
|
+
try {
|
|
42
|
+
return execSync(cmd, {
|
|
43
|
+
cwd,
|
|
44
|
+
encoding: "utf-8",
|
|
45
|
+
timeout: COMMAND_TIMEOUT,
|
|
46
|
+
shell: "/bin/sh",
|
|
47
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
48
|
+
env: { ...process.env, FORCE_COLOR: "0" },
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
if (err && typeof err === "object" && "stdout" in err) {
|
|
53
|
+
const stdout = err.stdout;
|
|
54
|
+
if (stdout)
|
|
55
|
+
return stdout;
|
|
56
|
+
}
|
|
57
|
+
const message = err instanceof Error ? err.message
|
|
58
|
+
: err && typeof err === "object" && "stderr" in err ? String(err.stderr)
|
|
59
|
+
: String(err);
|
|
60
|
+
throw new Error(`Command failed: ${cmd}\n${message}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function cmdExists(cmd) {
|
|
64
|
+
try {
|
|
65
|
+
execSync(`which ${cmd}`, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// ─── Language Detection ────────────────────────────────────────────────
|
|
73
|
+
export function detectLanguage(dir) {
|
|
74
|
+
for (const [lang, marker] of Object.entries(LANGUAGE_MARKERS)) {
|
|
75
|
+
if (marker.files.some((f) => existsSync(join(dir, f)))) {
|
|
76
|
+
return lang;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return "node"; // default
|
|
80
|
+
}
|
|
81
|
+
export function detectPackageManager(dir) {
|
|
82
|
+
if (existsSync(join(dir, "bun.lockb")) || existsSync(join(dir, "bun.lock")))
|
|
83
|
+
return "bun";
|
|
84
|
+
if (existsSync(join(dir, "pnpm-lock.yaml")))
|
|
85
|
+
return "pnpm";
|
|
86
|
+
if (existsSync(join(dir, "yarn.lock")))
|
|
87
|
+
return "yarn";
|
|
88
|
+
return "npm";
|
|
89
|
+
}
|
|
90
|
+
export function detectFramework(dir) {
|
|
91
|
+
for (const [name, files] of Object.entries(FRAMEWORK_DETECTORS)) {
|
|
92
|
+
if (files.some((f) => {
|
|
93
|
+
// Handle glob patterns for Xcode
|
|
94
|
+
if (f.startsWith("*.")) {
|
|
95
|
+
const ext = f.slice(1);
|
|
96
|
+
try {
|
|
97
|
+
return readdirSync(dir).some((entry) => entry.endsWith(ext));
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return existsSync(join(dir, f));
|
|
104
|
+
}))
|
|
105
|
+
return name;
|
|
106
|
+
}
|
|
107
|
+
const lang = detectLanguage(dir);
|
|
108
|
+
try {
|
|
109
|
+
if (lang === "node") {
|
|
110
|
+
const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
|
|
111
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
112
|
+
// Frameworks (order matters: specific before generic)
|
|
113
|
+
if (allDeps["solid-start"])
|
|
114
|
+
return "SolidStart";
|
|
115
|
+
if (allDeps["solid-js"])
|
|
116
|
+
return "Solid.js";
|
|
117
|
+
if (allDeps["@sveltejs/kit"])
|
|
118
|
+
return "SvelteKit";
|
|
119
|
+
if (allDeps["svelte"])
|
|
120
|
+
return "Svelte";
|
|
121
|
+
if (allDeps["next"])
|
|
122
|
+
return "Next.js";
|
|
123
|
+
if (allDeps["react"])
|
|
124
|
+
return "React";
|
|
125
|
+
if (allDeps["vue"])
|
|
126
|
+
return "Vue";
|
|
127
|
+
if (allDeps["express"])
|
|
128
|
+
return "Express";
|
|
129
|
+
if (allDeps["fastify"])
|
|
130
|
+
return "Fastify";
|
|
131
|
+
if (allDeps["hono"])
|
|
132
|
+
return "Hono";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch { /* ignore */ }
|
|
136
|
+
return LANGUAGE_MARKERS[lang]?.name || "Unknown";
|
|
137
|
+
}
|
|
138
|
+
export function getProjectInfo(dir) {
|
|
139
|
+
const lang = detectLanguage(dir);
|
|
140
|
+
// Must have at least one marker file
|
|
141
|
+
const marker = LANGUAGE_MARKERS[lang];
|
|
142
|
+
if (!marker || !marker.files.some((f) => existsSync(join(dir, f))))
|
|
143
|
+
return null;
|
|
144
|
+
let deps = {};
|
|
145
|
+
let devDeps = {};
|
|
146
|
+
let name = basename(dir);
|
|
147
|
+
let nodeVersion;
|
|
148
|
+
if (lang === "node") {
|
|
149
|
+
try {
|
|
150
|
+
const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
|
|
151
|
+
name = pkg.name || name;
|
|
152
|
+
deps = pkg.dependencies || {};
|
|
153
|
+
devDeps = pkg.devDependencies || {};
|
|
154
|
+
nodeVersion = pkg.engines?.node;
|
|
155
|
+
}
|
|
156
|
+
catch { /* ignore */ }
|
|
157
|
+
}
|
|
158
|
+
else if (lang === "python") {
|
|
159
|
+
// Read requirements.txt or pyproject.toml for dep names
|
|
160
|
+
try {
|
|
161
|
+
if (existsSync(join(dir, "requirements.txt"))) {
|
|
162
|
+
const lines = readFileSync(join(dir, "requirements.txt"), "utf-8").split("\n");
|
|
163
|
+
for (const line of lines) {
|
|
164
|
+
const match = line.trim().match(/^([a-zA-Z0-9_-]+)/);
|
|
165
|
+
if (match && !line.startsWith("#"))
|
|
166
|
+
deps[match[1]] = "*";
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch { /* ignore */ }
|
|
171
|
+
}
|
|
172
|
+
else if (lang === "rust") {
|
|
173
|
+
try {
|
|
174
|
+
const cargo = readFileSync(join(dir, "Cargo.toml"), "utf-8");
|
|
175
|
+
const nameMatch = cargo.match(/name\s*=\s*"([^"]+)"/);
|
|
176
|
+
if (nameMatch)
|
|
177
|
+
name = nameMatch[1];
|
|
178
|
+
}
|
|
179
|
+
catch { /* ignore */ }
|
|
180
|
+
}
|
|
181
|
+
else if (lang === "go") {
|
|
182
|
+
try {
|
|
183
|
+
const gomod = readFileSync(join(dir, "go.mod"), "utf-8");
|
|
184
|
+
const moduleMatch = gomod.match(/module\s+(\S+)/);
|
|
185
|
+
if (moduleMatch)
|
|
186
|
+
name = moduleMatch[1].split("/").pop() || name;
|
|
187
|
+
}
|
|
188
|
+
catch { /* ignore */ }
|
|
189
|
+
}
|
|
190
|
+
else if (lang === "php") {
|
|
191
|
+
try {
|
|
192
|
+
const composer = JSON.parse(readFileSync(join(dir, "composer.json"), "utf-8"));
|
|
193
|
+
name = composer.name || name;
|
|
194
|
+
deps = composer.require || {};
|
|
195
|
+
devDeps = composer["require-dev"] || {};
|
|
196
|
+
}
|
|
197
|
+
catch { /* ignore */ }
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
name,
|
|
201
|
+
path: dir,
|
|
202
|
+
language: lang,
|
|
203
|
+
framework: detectFramework(dir),
|
|
204
|
+
packageManager: lang === "node" ? detectPackageManager(dir) : "npm",
|
|
205
|
+
nodeVersion,
|
|
206
|
+
dependencies: deps,
|
|
207
|
+
devDependencies: devDeps,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
export function discoverProjects(rootDir) {
|
|
211
|
+
const dir = rootDir || getProjectsDir();
|
|
212
|
+
if (!existsSync(dir))
|
|
213
|
+
return [];
|
|
214
|
+
const projects = [];
|
|
215
|
+
try {
|
|
216
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
217
|
+
for (const entry of entries) {
|
|
218
|
+
if (!entry.isDirectory())
|
|
219
|
+
continue;
|
|
220
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
221
|
+
continue;
|
|
222
|
+
const fullPath = join(dir, entry.name);
|
|
223
|
+
const info = getProjectInfo(fullPath);
|
|
224
|
+
if (info)
|
|
225
|
+
projects.push(info);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch { /* ignore */ }
|
|
229
|
+
return projects.sort((a, b) => a.name.localeCompare(b.name));
|
|
230
|
+
}
|
|
231
|
+
// ─── Multi-language Outdated Parsing ───────────────────────────────────
|
|
232
|
+
export function getOutdated(projectPath, info) {
|
|
233
|
+
const marker = LANGUAGE_MARKERS[info.language];
|
|
234
|
+
if (!marker)
|
|
235
|
+
return {};
|
|
236
|
+
switch (marker.parseOutdated) {
|
|
237
|
+
case "npm":
|
|
238
|
+
return getOutdatedNpm(projectPath, info.packageManager);
|
|
239
|
+
case "pip":
|
|
240
|
+
return getOutdatedPip(projectPath);
|
|
241
|
+
case "cargo":
|
|
242
|
+
return getOutdatedCargo(projectPath);
|
|
243
|
+
case "go":
|
|
244
|
+
return getOutdatedGo(projectPath);
|
|
245
|
+
case "composer":
|
|
246
|
+
return getOutdatedComposer(projectPath);
|
|
247
|
+
case "gem":
|
|
248
|
+
return getOutdatedGem(projectPath);
|
|
249
|
+
case "pub":
|
|
250
|
+
return getOutdatedPub(projectPath);
|
|
251
|
+
case "swift":
|
|
252
|
+
return getOutdatedSwift(projectPath);
|
|
253
|
+
case "gradle":
|
|
254
|
+
return getOutdatedGradle(projectPath);
|
|
255
|
+
default:
|
|
256
|
+
return {};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function getOutdatedNpm(projectPath, pm) {
|
|
260
|
+
try {
|
|
261
|
+
const raw = run(`${pm} outdated --json`, projectPath);
|
|
262
|
+
if (!raw.trim())
|
|
263
|
+
return {};
|
|
264
|
+
const parsed = JSON.parse(raw);
|
|
265
|
+
if (Array.isArray(parsed)) {
|
|
266
|
+
const result = {};
|
|
267
|
+
for (const item of parsed) {
|
|
268
|
+
result[item.name || item.package] = {
|
|
269
|
+
current: item.current || "?",
|
|
270
|
+
wanted: item.wanted || item.current || "?",
|
|
271
|
+
latest: item.latest || "?",
|
|
272
|
+
type: item.dependencyType,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
return parsed;
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
return {};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function getOutdatedPip(projectPath) {
|
|
284
|
+
if (!cmdExists("pip") && !cmdExists("pip3"))
|
|
285
|
+
return {};
|
|
286
|
+
try {
|
|
287
|
+
const pipCmd = cmdExists("pip3") ? "pip3" : "pip";
|
|
288
|
+
const raw = run(`${pipCmd} list --outdated --format=json`, projectPath);
|
|
289
|
+
if (!raw.trim())
|
|
290
|
+
return {};
|
|
291
|
+
const parsed = JSON.parse(raw);
|
|
292
|
+
const result = {};
|
|
293
|
+
for (const item of parsed) {
|
|
294
|
+
result[item.name] = {
|
|
295
|
+
current: item.version,
|
|
296
|
+
wanted: item.latest_version,
|
|
297
|
+
latest: item.latest_version,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
return result;
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
return {};
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function getOutdatedCargo(projectPath) {
|
|
307
|
+
if (!cmdExists("cargo"))
|
|
308
|
+
return {};
|
|
309
|
+
// cargo outdated requires cargo-outdated plugin, fallback to cargo update --dry-run
|
|
310
|
+
try {
|
|
311
|
+
if (cmdExists("cargo-outdated")) {
|
|
312
|
+
const raw = run("cargo outdated --format json", projectPath);
|
|
313
|
+
if (!raw.trim())
|
|
314
|
+
return {};
|
|
315
|
+
const parsed = JSON.parse(raw);
|
|
316
|
+
const result = {};
|
|
317
|
+
for (const dep of parsed.dependencies || []) {
|
|
318
|
+
if (dep.project !== dep.latest) {
|
|
319
|
+
result[dep.name] = {
|
|
320
|
+
current: dep.project,
|
|
321
|
+
wanted: dep.compat,
|
|
322
|
+
latest: dep.latest,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return result;
|
|
327
|
+
}
|
|
328
|
+
// Fallback: parse Cargo.lock vs crates.io (simplified)
|
|
329
|
+
return {};
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
return {};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function getOutdatedGo(projectPath) {
|
|
336
|
+
if (!cmdExists("go"))
|
|
337
|
+
return {};
|
|
338
|
+
try {
|
|
339
|
+
const raw = run("go list -m -u -json all", projectPath);
|
|
340
|
+
if (!raw.trim())
|
|
341
|
+
return {};
|
|
342
|
+
// go list outputs multiple JSON objects, not an array
|
|
343
|
+
const result = {};
|
|
344
|
+
const objects = raw.split("\n}\n").filter((s) => s.trim());
|
|
345
|
+
for (let obj of objects) {
|
|
346
|
+
obj = obj.trim();
|
|
347
|
+
if (!obj.endsWith("}"))
|
|
348
|
+
obj += "}";
|
|
349
|
+
try {
|
|
350
|
+
const parsed = JSON.parse(obj);
|
|
351
|
+
if (parsed.Update && parsed.Version) {
|
|
352
|
+
const name = parsed.Path.split("/").slice(-2).join("/");
|
|
353
|
+
result[name] = {
|
|
354
|
+
current: parsed.Version,
|
|
355
|
+
wanted: parsed.Update.Version,
|
|
356
|
+
latest: parsed.Update.Version,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
catch { /* skip malformed */ }
|
|
361
|
+
}
|
|
362
|
+
return result;
|
|
363
|
+
}
|
|
364
|
+
catch {
|
|
365
|
+
return {};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function getOutdatedComposer(projectPath) {
|
|
369
|
+
if (!cmdExists("composer"))
|
|
370
|
+
return {};
|
|
371
|
+
try {
|
|
372
|
+
const raw = run("composer outdated --format=json --direct", projectPath);
|
|
373
|
+
if (!raw.trim())
|
|
374
|
+
return {};
|
|
375
|
+
const parsed = JSON.parse(raw);
|
|
376
|
+
const result = {};
|
|
377
|
+
for (const item of parsed.installed || []) {
|
|
378
|
+
if (item.version !== item.latest) {
|
|
379
|
+
result[item.name] = {
|
|
380
|
+
current: item.version,
|
|
381
|
+
wanted: item.latest,
|
|
382
|
+
latest: item.latest,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return result;
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
return {};
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
function getOutdatedGem(projectPath) {
|
|
393
|
+
if (!cmdExists("bundle"))
|
|
394
|
+
return {};
|
|
395
|
+
try {
|
|
396
|
+
const raw = run("bundle outdated --parseable", projectPath);
|
|
397
|
+
if (!raw.trim())
|
|
398
|
+
return {};
|
|
399
|
+
const result = {};
|
|
400
|
+
for (const line of raw.split("\n")) {
|
|
401
|
+
// Format: gem-name (newest X.Y.Z, installed X.Y.Z)
|
|
402
|
+
const match = line.match(/(\S+)\s+\(newest\s+(\S+),\s+installed\s+(\S+)/);
|
|
403
|
+
if (match) {
|
|
404
|
+
result[match[1]] = {
|
|
405
|
+
current: match[3],
|
|
406
|
+
wanted: match[2],
|
|
407
|
+
latest: match[2],
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return result;
|
|
412
|
+
}
|
|
413
|
+
catch {
|
|
414
|
+
return {};
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function getOutdatedPub(projectPath) {
|
|
418
|
+
if (!cmdExists("dart") && !cmdExists("flutter"))
|
|
419
|
+
return {};
|
|
420
|
+
try {
|
|
421
|
+
const cmd = cmdExists("flutter") ? "flutter pub outdated --json" : "dart pub outdated --json";
|
|
422
|
+
const raw = run(cmd, projectPath);
|
|
423
|
+
if (!raw.trim())
|
|
424
|
+
return {};
|
|
425
|
+
const parsed = JSON.parse(raw);
|
|
426
|
+
const result = {};
|
|
427
|
+
for (const pkg of parsed.packages || []) {
|
|
428
|
+
if (pkg.current?.version && pkg.latest?.version && pkg.current.version !== pkg.latest.version) {
|
|
429
|
+
result[pkg.package] = {
|
|
430
|
+
current: pkg.current.version,
|
|
431
|
+
wanted: pkg.resolvable?.version || pkg.latest.version,
|
|
432
|
+
latest: pkg.latest.version,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return result;
|
|
437
|
+
}
|
|
438
|
+
catch {
|
|
439
|
+
return {};
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function getOutdatedSwift(projectPath) {
|
|
443
|
+
if (!cmdExists("swift"))
|
|
444
|
+
return {};
|
|
445
|
+
try {
|
|
446
|
+
// Swift PM doesn't have a built-in outdated command
|
|
447
|
+
// Parse Package.resolved and compare with latest tags
|
|
448
|
+
const resolvedPath = join(projectPath, "Package.resolved");
|
|
449
|
+
if (!existsSync(resolvedPath))
|
|
450
|
+
return {};
|
|
451
|
+
const resolved = JSON.parse(readFileSync(resolvedPath, "utf-8"));
|
|
452
|
+
const result = {};
|
|
453
|
+
// v2 format
|
|
454
|
+
const pins = resolved.pins || resolved.object?.pins || [];
|
|
455
|
+
for (const pin of pins) {
|
|
456
|
+
const name = pin.identity || pin.package || pin.repositoryURL?.split("/").pop()?.replace(".git", "");
|
|
457
|
+
const version = pin.state?.version || pin.state?.revision?.slice(0, 8);
|
|
458
|
+
if (name && version) {
|
|
459
|
+
result[name] = {
|
|
460
|
+
current: version,
|
|
461
|
+
wanted: version,
|
|
462
|
+
latest: version, // Can't check latest without network calls to each repo
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return result;
|
|
467
|
+
}
|
|
468
|
+
catch {
|
|
469
|
+
return {};
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function getOutdatedGradle(projectPath) {
|
|
473
|
+
// Requires gradle-versions-plugin (com.github.ben-manes.versions)
|
|
474
|
+
const gradlew = join(projectPath, "gradlew");
|
|
475
|
+
if (!existsSync(gradlew) && !cmdExists("gradle"))
|
|
476
|
+
return {};
|
|
477
|
+
try {
|
|
478
|
+
const cmd = existsSync(gradlew)
|
|
479
|
+
? "./gradlew dependencyUpdates -Drevision=release --output-formatter json"
|
|
480
|
+
: "gradle dependencyUpdates -Drevision=release --output-formatter json";
|
|
481
|
+
const raw = run(cmd, projectPath);
|
|
482
|
+
// Look for the JSON report file
|
|
483
|
+
const reportPath = join(projectPath, "build", "dependencyUpdates", "report.json");
|
|
484
|
+
if (!existsSync(reportPath))
|
|
485
|
+
return {};
|
|
486
|
+
const report = JSON.parse(readFileSync(reportPath, "utf-8"));
|
|
487
|
+
const result = {};
|
|
488
|
+
for (const dep of report.outdated?.dependencies || []) {
|
|
489
|
+
const name = dep.group ? `${dep.group}:${dep.name}` : dep.name;
|
|
490
|
+
result[name] = {
|
|
491
|
+
current: dep.version || "?",
|
|
492
|
+
wanted: dep.available?.release || dep.available?.milestone || dep.version,
|
|
493
|
+
latest: dep.available?.release || dep.available?.milestone || dep.version,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
return result;
|
|
497
|
+
}
|
|
498
|
+
catch {
|
|
499
|
+
return {};
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
// ─── Ecosystem Grouping ────────────────────────────────────────────────
|
|
503
|
+
export function groupByEcosystem(outdated) {
|
|
504
|
+
const groups = {};
|
|
505
|
+
for (const [name, info] of Object.entries(outdated)) {
|
|
506
|
+
let matched = false;
|
|
507
|
+
for (const [ecosystem, pattern] of Object.entries(ECOSYSTEM_GROUPS)) {
|
|
508
|
+
if (pattern.test(name)) {
|
|
509
|
+
if (!groups[ecosystem])
|
|
510
|
+
groups[ecosystem] = [];
|
|
511
|
+
groups[ecosystem].push([name, info]);
|
|
512
|
+
matched = true;
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (!matched) {
|
|
517
|
+
if (!groups["other"])
|
|
518
|
+
groups["other"] = [];
|
|
519
|
+
groups["other"].push([name, info]);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return groups;
|
|
523
|
+
}
|
|
524
|
+
export function isMajorUpdate(current, latest) {
|
|
525
|
+
const curMajor = current.replace(/^[^0-9]*/, "").split(".")[0];
|
|
526
|
+
const latMajor = latest.replace(/^[^0-9]*/, "").split(".")[0];
|
|
527
|
+
return curMajor !== latMajor && curMajor !== "" && latMajor !== "";
|
|
528
|
+
}
|
|
529
|
+
export function getFrameworkVersion(info) {
|
|
530
|
+
const allDeps = { ...info.dependencies, ...info.devDependencies };
|
|
531
|
+
switch (info.framework) {
|
|
532
|
+
case "SvelteKit": return allDeps["@sveltejs/kit"] || allDeps["svelte"] || null;
|
|
533
|
+
case "Svelte": return allDeps["svelte"] || null;
|
|
534
|
+
case "Next.js": return allDeps["next"] || null;
|
|
535
|
+
case "React": return allDeps["react"] || null;
|
|
536
|
+
case "Nuxt": return allDeps["nuxt"] || null;
|
|
537
|
+
case "Vue": return allDeps["vue"] || null;
|
|
538
|
+
case "Astro": return allDeps["astro"] || null;
|
|
539
|
+
case "SolidStart": return allDeps["solid-start"] || allDeps["solid-js"] || null;
|
|
540
|
+
case "Solid.js": return allDeps["solid-js"] || null;
|
|
541
|
+
default: return null;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
// ─── Security Audit ────────────────────────────────────────────────────
|
|
545
|
+
export function getSecurityIssues(projectPath, info) {
|
|
546
|
+
const marker = LANGUAGE_MARKERS[info.language];
|
|
547
|
+
if (!marker?.auditCmd)
|
|
548
|
+
return 0;
|
|
549
|
+
try {
|
|
550
|
+
const cmd = marker.auditCmd.replace(/\{pm\}/g, info.packageManager);
|
|
551
|
+
if (!cmdExists(cmd.split(" ")[0]))
|
|
552
|
+
return 0;
|
|
553
|
+
const raw = run(cmd, projectPath);
|
|
554
|
+
const parsed = JSON.parse(raw);
|
|
555
|
+
// npm format
|
|
556
|
+
if (parsed.metadata?.vulnerabilities) {
|
|
557
|
+
const v = parsed.metadata.vulnerabilities;
|
|
558
|
+
return (v.high || 0) + (v.critical || 0) + (v.moderate || 0);
|
|
559
|
+
}
|
|
560
|
+
return 0;
|
|
561
|
+
}
|
|
562
|
+
catch {
|
|
563
|
+
return 0;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
// ─── Health Score ──────────────────────────────────────────────────────
|
|
567
|
+
export function computeHealthReport(info) {
|
|
568
|
+
const outdated = getOutdated(info.path, info);
|
|
569
|
+
const outdatedCount = Object.keys(outdated).length;
|
|
570
|
+
const majorUpdates = Object.entries(outdated).filter(([, pkg]) => isMajorUpdate(pkg.current, pkg.latest)).length;
|
|
571
|
+
const lockfiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lockb",
|
|
572
|
+
"Cargo.lock", "go.sum", "composer.lock", "Gemfile.lock", "pubspec.lock", "Pipfile.lock",
|
|
573
|
+
"Package.resolved", "gradle.lockfile"];
|
|
574
|
+
const lockfileExists = lockfiles.some((lf) => existsSync(join(info.path, lf)));
|
|
575
|
+
let score = 100;
|
|
576
|
+
score -= Math.min(outdatedCount * 3, 40);
|
|
577
|
+
score -= majorUpdates * 10;
|
|
578
|
+
if (!lockfileExists)
|
|
579
|
+
score -= 15;
|
|
580
|
+
const securityIssues = getSecurityIssues(info.path, info);
|
|
581
|
+
score -= Math.min(securityIssues * 5, 30);
|
|
582
|
+
score = Math.max(0, Math.min(100, score));
|
|
583
|
+
const recommendations = [];
|
|
584
|
+
if (!lockfileExists)
|
|
585
|
+
recommendations.push(`Missing lockfile. Run install to generate one.`);
|
|
586
|
+
if (majorUpdates > 0)
|
|
587
|
+
recommendations.push(`${majorUpdates} major update(s). Review changelogs before updating.`);
|
|
588
|
+
if (securityIssues > 0)
|
|
589
|
+
recommendations.push(`${securityIssues} security issue(s). Run audit fix.`);
|
|
590
|
+
if (outdatedCount > 10)
|
|
591
|
+
recommendations.push("Many outdated packages. Start with minor/patch updates.");
|
|
592
|
+
if (score === 100)
|
|
593
|
+
recommendations.push("All good! Dependencies are up to date.");
|
|
594
|
+
return {
|
|
595
|
+
project: info.name,
|
|
596
|
+
language: info.language,
|
|
597
|
+
framework: info.framework,
|
|
598
|
+
frameworkVersion: getFrameworkVersion(info),
|
|
599
|
+
nodeVersion: info.nodeVersion ?? null,
|
|
600
|
+
packageManager: info.packageManager,
|
|
601
|
+
lockfileExists,
|
|
602
|
+
outdatedCount,
|
|
603
|
+
majorUpdates,
|
|
604
|
+
securityIssues,
|
|
605
|
+
score,
|
|
606
|
+
recommendations,
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
// ─── Update Commands ───────────────────────────────────────────────────
|
|
610
|
+
export function buildUpdateCommand(info, packages, level) {
|
|
611
|
+
const marker = LANGUAGE_MARKERS[info.language];
|
|
612
|
+
if (!marker)
|
|
613
|
+
return `${info.packageManager} update`;
|
|
614
|
+
if (info.language === "node") {
|
|
615
|
+
const pm = info.packageManager;
|
|
616
|
+
const pkgList = packages?.trim() || "";
|
|
617
|
+
if (pm === "pnpm") {
|
|
618
|
+
if (pkgList)
|
|
619
|
+
return level === "latest" ? `pnpm update ${pkgList} --latest` : `pnpm update ${pkgList}`;
|
|
620
|
+
return level === "latest" ? "pnpm update --latest" : "pnpm update";
|
|
621
|
+
}
|
|
622
|
+
if (pm === "yarn") {
|
|
623
|
+
if (pkgList)
|
|
624
|
+
return level === "latest" ? `yarn upgrade ${pkgList} --latest` : `yarn upgrade ${pkgList}`;
|
|
625
|
+
return level === "latest" ? "yarn upgrade --latest" : "yarn upgrade";
|
|
626
|
+
}
|
|
627
|
+
if (pm === "bun")
|
|
628
|
+
return pkgList ? `bun update ${pkgList}` : "bun update";
|
|
629
|
+
// npm: npm update only bumps within semver range, useless for real updates
|
|
630
|
+
// Use npx npm-check-updates to actually bump package.json then npm install
|
|
631
|
+
if (level === "latest") {
|
|
632
|
+
if (pkgList)
|
|
633
|
+
return `npx -y npm-check-updates -u ${pkgList.split(" ").join(" ")} && npm install`;
|
|
634
|
+
return "npx -y npm-check-updates -u && npm install";
|
|
635
|
+
}
|
|
636
|
+
// minor: bump minor+patch only
|
|
637
|
+
if (pkgList)
|
|
638
|
+
return `npx -y npm-check-updates -u --target minor ${pkgList.split(" ").join(" ")} && npm install`;
|
|
639
|
+
return "npx -y npm-check-updates -u --target minor && npm install";
|
|
640
|
+
}
|
|
641
|
+
if (info.language === "python") {
|
|
642
|
+
const pkgList = packages?.trim() || "";
|
|
643
|
+
if (pkgList)
|
|
644
|
+
return `pip install --upgrade ${pkgList}`;
|
|
645
|
+
return `pip install --upgrade -r requirements.txt`;
|
|
646
|
+
}
|
|
647
|
+
return level === "latest" ? marker.updateLatestCmd : marker.updateCmd;
|
|
648
|
+
}
|
|
649
|
+
// ─── Cache ─────────────────────────────────────────────────────────────
|
|
650
|
+
function getCachePath() {
|
|
651
|
+
return join(homedir(), CACHE_FILENAME);
|
|
652
|
+
}
|
|
653
|
+
export function readCache() {
|
|
654
|
+
const path = getCachePath();
|
|
655
|
+
if (!existsSync(path))
|
|
656
|
+
return null;
|
|
657
|
+
try {
|
|
658
|
+
const stat = statSync(path);
|
|
659
|
+
const age = Date.now() - stat.mtimeMs;
|
|
660
|
+
if (age > CACHE_MAX_AGE_MS)
|
|
661
|
+
return null; // expired
|
|
662
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
663
|
+
}
|
|
664
|
+
catch {
|
|
665
|
+
return null;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
export function writeCache(entries) {
|
|
669
|
+
const cache = {
|
|
670
|
+
version: SERVER_VERSION,
|
|
671
|
+
updatedAt: new Date().toISOString(),
|
|
672
|
+
projects: entries,
|
|
673
|
+
};
|
|
674
|
+
writeFileSync(getCachePath(), JSON.stringify(cache, null, 2) + "\n", "utf-8");
|
|
675
|
+
}
|
|
676
|
+
export function getCacheStatus() {
|
|
677
|
+
const cache = readCache();
|
|
678
|
+
if (!cache)
|
|
679
|
+
return { exists: false, age: "none", projectCount: 0, alerts: 0 };
|
|
680
|
+
const ageMs = Date.now() - new Date(cache.updatedAt).getTime();
|
|
681
|
+
const hours = Math.floor(ageMs / 3600000);
|
|
682
|
+
const minutes = Math.floor((ageMs % 3600000) / 60000);
|
|
683
|
+
const age = hours > 0 ? `${hours}h ${minutes}m ago` : `${minutes}m ago`;
|
|
684
|
+
const alerts = cache.projects.filter((p) => p.outdatedCount > 0).length;
|
|
685
|
+
return { exists: true, age, projectCount: cache.projects.length, alerts };
|
|
686
|
+
}
|
|
687
|
+
// ─── Config ────────────────────────────────────────────────────────────
|
|
688
|
+
export function loadConfig() {
|
|
689
|
+
const configPaths = [
|
|
690
|
+
join(homedir(), ".depsonarrc.json"),
|
|
691
|
+
join(homedir(), ".config", "depsonar", "config.json"),
|
|
692
|
+
];
|
|
693
|
+
for (const configPath of configPaths) {
|
|
694
|
+
if (existsSync(configPath)) {
|
|
695
|
+
try {
|
|
696
|
+
const raw = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
697
|
+
return {
|
|
698
|
+
projectsDir: raw.projectsDir ? resolve(raw.projectsDir) : getProjectsDir(),
|
|
699
|
+
ignoredPackages: raw.ignoredPackages || [],
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
catch { /* ignore */ }
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return { projectsDir: getProjectsDir(), ignoredPackages: [] };
|
|
706
|
+
}
|
|
707
|
+
export function saveConfig(config) {
|
|
708
|
+
const configPath = join(homedir(), ".depsonarrc.json");
|
|
709
|
+
const existing = existsSync(configPath)
|
|
710
|
+
? JSON.parse(readFileSync(configPath, "utf-8"))
|
|
711
|
+
: {};
|
|
712
|
+
const merged = { ...existing, ...config };
|
|
713
|
+
writeFileSync(configPath, JSON.stringify(merged, null, 2) + "\n", "utf-8");
|
|
714
|
+
return configPath;
|
|
715
|
+
}
|
|
716
|
+
//# sourceMappingURL=project.js.map
|