From 4c5f803447f7db290d0c8a0cc3c08165519d42ba Mon Sep 17 00:00:00 2001 From: omrilotan Date: Mon, 29 Apr 2024 15:40:18 +0100 Subject: [PATCH] Fix browser entry --- package.json | 2 +- scripts/build/procedure.sh | 2 +- src/browser.ts | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e7b2c5c..ec0deda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "isbot", - "version": "5.1.5", + "version": "5.1.6-rc.1", "description": "🤖/👨‍🦰 Recognise bots/crawlers/spiders using the user agent string.", "keywords": [ "bot", diff --git a/scripts/build/procedure.sh b/scripts/build/procedure.sh index 379b0b3..1cde15a 100755 --- a/scripts/build/procedure.sh +++ b/scripts/build/procedure.sh @@ -15,7 +15,7 @@ esbuild src/index.ts --outfile=index.mjs --bundle --platform=neutral --format=es failures=$((failures + $?)) echo "→ Build browser file (iife)" -esbuild src/browser.ts --outfile=index.iife.js --bundle --platform=neutral --format=iife --global-name=isbot --log-level=warning --target=es2016 +esbuild src/browser.ts --outfile=index.iife.js --bundle --platform=neutral --format=iife --log-level=warning --target=es2016 failures=$((failures + $?)) echo "→ Build TypeScript declaration file" diff --git a/src/browser.ts b/src/browser.ts index 94cdfa6..61c3ace 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -1,3 +1,19 @@ import { isbot } from "."; -export default isbot; +(function () { + if (typeof globalThis === "object") { + globalThis.isbot = isbot; + return; + } + if (typeof window === "object") { + window.isbot = isbot; + return; + } + if (typeof global === "object") { + global.isbot = isbot; + return; + } + if (typeof self === "object") { + self.isbot = isbot; + } +})();