// rnx cli version, resolved once and cached. standalone builds embed it so // lazy command chunks do not depend on an npm package layout at runtime. import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { rnxPublicBrand } from './public-brand.ts' declare const __RNX_CLI_VERSION__: string let cached: string | null = null export function getCliVersion(): string { if (cached != null) return cached if ( typeof __RNX_CLI_VERSION__ !== 'undefined' && typeof __RNX_CLI_VERSION__ === 'string' && __RNX_CLI_VERSION__ ) { cached = __RNX_CLI_VERSION__ return cached } // prefer package resolution (works for npm/global installs); fall back to // the package.json next to this module's source for repo / bundled runs. const candidates: Array<() => string> = [ () => fileURLToPath(import.meta.resolve(`${rnxPublicBrand.packageName}/package.json`)), () => fileURLToPath(new URL('../package.json', import.meta.url)), ] for (const resolve of candidates) { try { const version = JSON.parse(readFileSync(resolve(), 'utf8')).version if (typeof version === 'string' && version) { cached = version return cached } } catch {} } cached = '0.0.0' return cached }