Skip to main content
Home

Built and signed on GitHub Actions

A junk lib that tries to detect the runtime environment (e.g. Deno, Bun, or Node.js). You probably don't want to use this.

This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
It is unknown whether this package works with Browsers
JSR Score
100%
Published
11 months ago (0.2.1)

detect-runtime

Tries to detect the runtime environment (e.g. Deno, Bun, or Node.js).

Usage

On the command line:

# Deno
deno run index.ts

# Bun
bun run index.ts

# Node
bun build index.ts --outdir=dist && node dist/index.js

From TypeScript code

const 肉まん = detectRuntime();
if (肉まん.isBun)
{
  console.log(`I knew it!! This is Bun ${肉まん.version}.`);
}

test

This lib tests with Bun, not Deno (just to prove we can do either).

bun test
bun test v1.1.13 (bd6a6051)

tests.bun.spec.ts:
I knew it!! This is Bun 1.1.13.
✓ the README example code  > should not have compile errors [1.15ms]

 1 pass
 0 fail
Ran 1 tests across 1 files. [69.00ms]
➜  detect-runtime git:(main) ✗ 

About the source code

This mainly exists to test monorepo/megarepo setups, and to investigate how to write TypeScript code and configuration in such a way that it can be used in various different runtime/packaging contexts. This includes producing a library that can be used as-is in a monorepo context by Deno and Bun, can be bundled for use in a browser context or a Node.js context, and can be packaged as a JSR.io package. (And maybe even NPM package? 🤷‍♀️)

So anyway, like the saying goes, "this may not be useful".

# Build with Bun
bun build index.ts --outdir=dist

License

WTFPL

🧨 boom

NOTE: This lib is part of a proof-of-concept test of using JSR.io packages in a monorepo/megarepo context.

The experimental repo is here: https://github.com/axhxrx/axhxrx-megarepo-jsr-deno-bun-node-hootenanny

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@axhxrx/detect-runtime

Import symbol

import * as detect_runtime from "@axhxrx/detect-runtime";
or

Import directly with a jsr specifier

import * as detect_runtime from "jsr:@axhxrx/detect-runtime";

Add Package

pnpm i jsr:@axhxrx/detect-runtime
or (using pnpm 10.8 or older)
pnpm dlx jsr add @axhxrx/detect-runtime

Import symbol

import * as detect_runtime from "@axhxrx/detect-runtime";

Add Package

yarn add jsr:@axhxrx/detect-runtime
or (using Yarn 4.8 or older)
yarn dlx jsr add @axhxrx/detect-runtime

Import symbol

import * as detect_runtime from "@axhxrx/detect-runtime";

Add Package

npx jsr add @axhxrx/detect-runtime

Import symbol

import * as detect_runtime from "@axhxrx/detect-runtime";

Add Package

bunx jsr add @axhxrx/detect-runtime

Import symbol

import * as detect_runtime from "@axhxrx/detect-runtime";