@axhxrx/detect-runtime@0.2.1Built and signed on GitHub ActionsBuilt 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.
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
🧨 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
Add Package
deno add jsr:@axhxrx/detect-runtime
Import symbol
import * as detect_runtime from "@axhxrx/detect-runtime";
Import directly with a jsr specifier
import * as detect_runtime from "jsr:@axhxrx/detect-runtime";
Add Package
pnpm i jsr:@axhxrx/detect-runtime
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
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";