Something like
if ('Bun' in globalThis) ...
if ('Deno' in globalThis) ...
if ('window' in globalThis) ...
could be used to determine the runtime.