| 6 | // Both the npm-published layout (dist/<lib>/src/index.js) and the .mcpb bundle |
| 7 | // layout (server/<lib>/src/index.js) place package.json three levels up. |
| 8 | export function readPackageVersion(entryUrl: string): string { |
| 9 | const entryDir = dirname(fileURLToPath(entryUrl)); |
| 10 | const pkgPath = join(entryDir, '..', '..', '..', 'package.json'); |
| 11 | try { |
| 12 | const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')); |
| 13 | if (typeof pkg.version === 'string' && pkg.version.length > 0) { |
| 14 | return pkg.version; |
| 15 | } |
| 16 | } catch { |
| 17 | // fall through |
| 18 | } |
| 19 | return '0.0.0'; |
| 20 | } |
| 21 | |
| 22 | export function errorToString(err: unknown): string { |
| 23 | if (err && typeof err === 'object' && 'stack' in err && typeof (err as any).stack === 'string') { |