function detectRuntime
detectRuntime(globals?: GlobalScope): RuntimePlatform

Detects the current runtime platform.

Detection order (first match wins):

  1. Deno — Deno global exists
  2. Bun — Bun global exists (checked before Cloudflare to avoid false positives since Bun might also have caches)
  3. Cloudflare Workers — caches exists and navigator.userAgent contains 'cloudflare', case-insensitively (a real Worker reports 'Cloudflare-Workers')
  4. Default — Node.js

process is deliberately NOT consulted: nodejs_compat defines it on Cloudflare Workers, so a process-based check would misreport every Worker scaffolded with that flag — which is every Worker this CLI emits.

Parameters

optional
globals: GlobalScope = globalThis

Injectable global scope (defaults to globalThis)

Return Type

RuntimePlatform

Detected runtime platform

Usage

import { detectRuntime } from "runtime/src/index.ts";