-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathinfo.ts
More file actions
78 lines (72 loc) · 3.3 KB
/
Copy pathinfo.ts
File metadata and controls
78 lines (72 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import type { CommandDefinition } from '../types.js';
export const command: CommandDefinition = {
name: 'info',
description: 'Show codegraph engine info and diagnostics',
async execute(_args, _opts, ctx) {
const { getNativePackageVersion, isNativeAvailable, loadNative } = await import(
'../../infrastructure/native.js'
);
const { getActiveEngine } = await import('../../domain/parser.js');
const engine = ctx.program.opts().engine;
const { name: activeName, version: activeVersion } = getActiveEngine({ engine });
const nativeAvailable = isNativeAvailable();
console.log('\nCodegraph Diagnostics');
console.log('====================');
console.log(` Version : ${ctx.program.version()}`);
console.log(` Node.js : ${process.version}`);
console.log(` Platform : ${process.platform}-${process.arch}`);
console.log(` Native engine : ${nativeAvailable ? 'available' : 'unavailable'}`);
if (nativeAvailable) {
const native = loadNative()!;
const binaryVersion =
typeof native.engineVersion === 'function' ? native.engineVersion() : 'unknown';
const pkgVersion = getNativePackageVersion();
const knownBinaryVersion = binaryVersion !== 'unknown' ? binaryVersion : null;
if (pkgVersion && knownBinaryVersion && pkgVersion !== knownBinaryVersion) {
console.log(
` Native version: ${pkgVersion} (binary built as ${knownBinaryVersion}, engine loaded OK)`,
);
} else {
console.log(` Native version: ${pkgVersion ?? binaryVersion}`);
}
}
console.log(` Engine flag : --engine ${engine}`);
console.log(` Active engine : ${activeName}${activeVersion ? ` (v${activeVersion})` : ''}`);
console.log();
try {
const { findDbPath, getBuildMeta } = await import('../../db/index.js');
const Database = (await import('better-sqlite3')).default;
const dbPath = findDbPath();
const fs = await import('node:fs');
if (fs.existsSync(dbPath)) {
const db = new Database(dbPath, { readonly: true });
const buildEngine = getBuildMeta(db, 'engine');
const buildVersion = getBuildMeta(db, 'codegraph_version');
const builtAt = getBuildMeta(db, 'built_at');
db.close();
if (buildEngine || buildVersion || builtAt) {
console.log('Build metadata');
console.log(
'\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500',
);
if (buildEngine) console.log(` Engine : ${buildEngine}`);
if (buildVersion) console.log(` Version : ${buildVersion}`);
if (builtAt) console.log(` Built at : ${builtAt}`);
if (buildVersion && buildVersion !== ctx.program.version()) {
console.log(
` \u26A0 DB was built with v${buildVersion}, current is v${ctx.program.version()}. Consider: codegraph build --no-incremental`,
);
}
if (buildEngine && buildEngine !== activeName) {
console.log(
` \u26A0 DB was built with ${buildEngine} engine, active is ${activeName}. Consider: codegraph build --no-incremental`,
);
}
console.log();
}
}
} catch {
/* diagnostics must never crash */
}
},
};