From aa08c35c062d0db004b9aaedcd8d427eda8aa7c7 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Wed, 23 Aug 2023 18:15:21 -0700 Subject: Add Debugger docs and a couple guides (#4281) * Add debugger docs. Add guides. * Add files --- docs/guides/util/detect-bun.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 docs/guides/util/detect-bun.md (limited to 'docs/guides/util/detect-bun.md') diff --git a/docs/guides/util/detect-bun.md b/docs/guides/util/detect-bun.md new file mode 100644 index 000000000..0a2506b5c --- /dev/null +++ b/docs/guides/util/detect-bun.md @@ -0,0 +1,23 @@ +--- +name: Detect when code is executed with Bun +--- + +The recommended way to conditionally detect when code is being executed with `bun` is to check for the existence of the `Bun` global. + +This is similar to how you'd check for the existence of the `window` variable to detect when code is being executed in a browser. + +```ts +if (typeof Bun !== "undefined") { + // this code will only run when the file is run with Bun +} +``` + +--- + +In TypeScript environments, the previous approach will result in a type error unless `bun-types` is globally installed. To avoid this, you can check `process.versions` instead. + +```ts +if (process.versions.bun) { + // this code will only run when the file is run with Bun +} +``` -- cgit v1.2.3