mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
20957cbc7b
Bug 1: version.ts used a single-level parent lookup for package.json, which broke after #784 changed rootDir from "src" to "." (version.js now lives in dist/src/ instead of dist/). Walk up until package.json is found — works in both dev (src/) and prod (dist/src/). Bug 2: adapters copied to ~/.opencli/clis/ import ../../src/registry.js etc., which resolves to ~/.opencli/src/. Derive src/ compat shims from the existing rootShims list so these imports resolve correctly.
26 lines
698 B
TypeScript
26 lines
698 B
TypeScript
/**
|
|
* Single source of truth for package version.
|
|
*/
|
|
|
|
import * as fs from 'node:fs';
|
|
import * as path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
// Dev: __dirname is src/ (one level to root).
|
|
// Prod: __dirname is dist/src/ (two levels to root).
|
|
let _pkgDir = path.resolve(__dirname, '..');
|
|
if (!fs.existsSync(path.join(_pkgDir, 'package.json'))) {
|
|
_pkgDir = path.resolve(_pkgDir, '..');
|
|
}
|
|
const pkgJsonPath = path.join(_pkgDir, 'package.json');
|
|
|
|
export const PKG_VERSION: string = (() => {
|
|
try {
|
|
return JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')).version;
|
|
} catch {
|
|
return '0.0.0';
|
|
}
|
|
})();
|