Skip to content
This repository was archived by the owner on Dec 30, 2023. It is now read-only.

Commit 05015d5

Browse files
authored
fix(runtime): 🐛 Remove another occurence of using RuntimeError (#91)
1 parent ca39497 commit 05015d5

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

.changeset/tricky-kangaroos-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@terminal-nerds/snippets-runtime": patch
3+
---
4+
5+
🐛 Removed `RuntimeError` usage due to CJS issues with `modern-erro`

packages/runtime/source/environment/environment.ts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RuntimeError } from "@terminal-nerds/snippets-error/custom";
1+
/* import { RuntimeError } from "@terminal-nerds/snippets-error/custom"; */
22
import { z } from "zod";
33
/* prettier-ignore */
44
export const RUNTIME_ENVIRONMENTS = [
@@ -15,43 +15,65 @@ export const RUNTIME_ENVIRONMENTS = [
1515
export type RuntimeEnvironment = (typeof RUNTIME_ENVIRONMENTS)[number];
1616
export const RUNTIME_ENVIRONMENT_SCHEMA = z.enum(RUNTIME_ENVIRONMENTS);
1717

18-
/** @see {@link https://bun.sh/docs/api/globals} */
18+
/**
19+
* @see {@link https://bun.sh/docs/api/globals}
20+
*/
1921
export const IN_BUN = globalThis.Bun !== undefined && Bun.version !== undefined;
2022

21-
/** @see {@link https://deno.land/[email protected]/runtime#deno-global} */
23+
/**
24+
* @see {@link https://deno.land/[email protected]/runtime#deno-global}
25+
*/
2226
export const IN_DENO = globalThis.Deno !== undefined && Deno.version !== undefined && Deno.version.deno !== undefined;
2327

24-
/** Detects if the DOM is available. */
28+
/**
29+
* Detects if the DOM is available.
30+
*/
2531
export const IN_DOM =
2632
globalThis.window !== undefined &&
2733
!globalThis.navigator !== undefined &&
2834
// @ts-ignore FIXME: Find a way to make it typed?
2935
window.document !== undefined;
3036

31-
/** @see {@link https://edge-runtime.vercel.app/features/available-apis#addressing-the-runtime} */
37+
/**
38+
* @see {@link https://edge-runtime.vercel.app/features/available-apis#addressing-the-runtime}
39+
*/
3240
// @ts-ignore FIXME: Find a way to make it typed?
3341
export const IN_EDGE = globalThis.EdgeRuntime !== undefined;
3442

35-
/** @see {@link https://github.com/jsdom/jsdom} */
43+
/**
44+
* @see {@link https://github.com/jsdom/jsdom}
45+
*/
3646
export const IN_JSDOM = IN_DOM && navigator.userAgent.includes("jsdom");
3747

38-
/** @see {@link https://github.com/capricorn86/happy-dom/discussions/481} */
48+
/**
49+
* @see {@link https://github.com/capricorn86/happy-dom/discussions/481}
50+
*/
3951
// @ts-ignore FIXME: Find a way to make it typed?
4052
export const IN_HAPPY_DOM = IN_DOM && window.happyDOM !== undefined;
4153

42-
/** @see {@link https://nodejs.org/dist/latest-v18.x/docs/api/process.html#process} */
54+
/**
55+
* @see {@link https://nodejs.org/dist/latest-v18.x/docs/api/process.html#process}
56+
*/
4357
export const IN_NODE = globalThis.process !== undefined && process.version !== undefined;
4458

45-
/** Detect if is running in browser, and is not in a browser emulator (e.g. jsdom or Happy DOM) */
59+
/**
60+
* Detect if is running in browser, and is not in a browser emulator (e.g. jsdom or Happy DOM)
61+
*/
4662
export const IN_BROWSER = IN_DOM && !IN_HAPPY_DOM && !IN_JSDOM;
4763

48-
/** @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers} */
64+
/**
65+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers}
66+
*/
4967
export const IN_WEB_WORKER =
5068
typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
5169

52-
/** Receive the name _(in lowercase)_ of the currently running JavaScript environment. */
70+
/**
71+
* Receive the name _(in lowercase)_ of the currently running JavaScript environment.
72+
*/
5373
export function getRuntimeEnvironmentName(): RuntimeEnvironment {
54-
/** NOTE: Order matters! */
74+
/**
75+
* NOTE: Order matters!
76+
*/
5577
const conditions = {
5678
"edge": IN_EDGE,
5779
"bun": IN_BUN,
@@ -68,7 +90,7 @@ export function getRuntimeEnvironmentName(): RuntimeEnvironment {
6890
if (isTrue) return name as RuntimeEnvironment;
6991
}
7092

71-
throw new RuntimeError(`Unrecognized JavaScript runtime environment!`);
93+
throw new Error(`Unrecognized JavaScript runtime environment!`);
7294
}
7395

7496
export function validateRuntimeEnvironmentName(name: string): asserts name is RuntimeEnvironment {

0 commit comments

Comments
 (0)