UNPKG

@xec-sh/core

Version:

Universal shell execution engine

70 lines 2.08 kB
export class RuntimeDetector { static { this._runtime = null; } static { this._bunVersion = null; } static detect() { if (this._runtime) { return this._runtime; } if (typeof globalThis.Bun !== 'undefined' && globalThis.Bun) { this._runtime = 'bun'; this._bunVersion = globalThis.Bun.version; return 'bun'; } if (typeof globalThis.Deno !== 'undefined' && globalThis.Deno) { this._runtime = 'deno'; return 'deno'; } this._runtime = 'node'; return 'node'; } static getBunVersion() { if (this._bunVersion !== null) { return this._bunVersion; } const runtime = this.detect(); if (runtime === 'bun' && globalThis.Bun) { this._bunVersion = globalThis.Bun.version; return this._bunVersion; } return null; } static hasFeature(feature) { const runtime = this.detect(); if (runtime === 'bun') { const bunGlobal = globalThis.Bun; if (!bunGlobal) return false; switch (feature) { case 'spawn': return typeof bunGlobal.spawn === 'function'; case 'serve': return typeof bunGlobal.serve === 'function'; case 'sqlite': return typeof bunGlobal.SQLite === 'function'; } } if (runtime === 'node') { switch (feature) { case 'spawn': return true; default: return false; } } return false; } static isNode() { return this.detect() === 'node'; } static isBun() { return this.detect() === 'bun'; } static isDeno() { return this.detect() === 'deno'; } static reset() { this._runtime = null; this._bunVersion = null; } } //# sourceMappingURL=runtime-detect.js.map