is-bun-module
Advanced tools
Comparing version
@@ -1,2 +0,4 @@ | ||
type SemVerStringified = `${number}.${number}.${number}`; | ||
type SemVerBaseStringified = `${bigint}.${bigint}.${bigint}`; | ||
type SemVerStringifiedWithReleaseName = `${SemVerBaseStringified}-${string}`; | ||
type SemVerStringified = SemVerBaseStringified | SemVerStringifiedWithReleaseName; | ||
type Version = SemVerStringified | "latest"; | ||
@@ -3,0 +5,0 @@ declare const MINIMUM_BUN_VERSION = "1.0.0"; |
@@ -98,11 +98,19 @@ "use strict"; | ||
function checkModule(moduleName, modules, bunVersion) { | ||
var _a; | ||
if (typeof moduleName !== "string") throw new TypeError("Module name must be a string"); | ||
if (!(moduleName in modules)) return false; | ||
if (bunVersion != null && !isVersion(bunVersion)) { | ||
throw new TypeError("Bun version must be a string like 1.0.0 or 'latest' or undefined"); | ||
let targetBunVersion; | ||
if (bunVersion) { | ||
targetBunVersion = toSemVerStringified(bunVersion); | ||
if (!targetBunVersion) { | ||
throw new TypeError("Bun version must be a string like 1.0.0 or 'latest'"); | ||
} | ||
} else { | ||
if (typeof process === "undefined" || !((_a = process.versions) == null ? void 0 : _a.bun)) { | ||
throw new Error("Bun version is not provided and cannot be detected"); | ||
} | ||
targetBunVersion = process.versions.bun; | ||
} | ||
const targetBunVersion = bunVersion ? bunVersion === "latest" ? "999.999.999" : bunVersion : typeof process !== "undefined" && process.versions.bun; | ||
if (!targetBunVersion) throw "Bun version is not provided and cannot be detected"; | ||
if (import_semver.default.lt(targetBunVersion, MINIMUM_BUN_VERSION)) { | ||
throw `Bun version must be at least ${MINIMUM_BUN_VERSION}`; | ||
throw new RangeError(`Bun version must be at least ${MINIMUM_BUN_VERSION}`); | ||
} | ||
@@ -113,4 +121,6 @@ const versionRange = modules[moduleName]; | ||
} | ||
function isVersion(input) { | ||
return typeof input === "string" && (input === "latest" || Boolean(input.match(/^(?:\d+\.){2}\d+$/))); | ||
function toSemVerStringified(input) { | ||
if (typeof input !== "string") return; | ||
if (input === "latest") return "999.999.999"; | ||
if (import_semver.default.valid(input)) return input; | ||
} | ||
@@ -117,0 +127,0 @@ // Annotate the CommonJS export names for ESM import in node: |
@@ -5,3 +5,3 @@ { | ||
"description": "Is this specifier a Bun core module or supported Node one?", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"license": "MIT", | ||
@@ -39,5 +39,34 @@ "files": [ | ||
], | ||
"scripts": { | ||
"build": "bun --bun tsup", | ||
"check-all": "concurrently --kill-others=failure 'bun run test' 'bun lint' 'bun type-check' 'bun format:check'", | ||
"test": "bun run build && bun test", | ||
"format": "bun format:base --write", | ||
"format:check": "bun format:base --check", | ||
"format:base": "bun --bun prettier . --cache", | ||
"lint": "bun --bun eslint . --cache", | ||
"type-check": "bun --bun tsc", | ||
"postinstall": "bun --bun husky" | ||
}, | ||
"dependencies": { | ||
"semver": "^7.6.3" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^19.4.1", | ||
"@commitlint/config-conventional": "^19.4.1", | ||
"@eslint/js": "^9.10.0", | ||
"@semantic-release/exec": "^6.0.3", | ||
"@types/bun": "^1.1.8", | ||
"@types/eslint__js": "^8.42.3", | ||
"@types/semver": "^7.5.8", | ||
"concurrently": "^9.0.0", | ||
"eslint": "^9.10.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"husky": "^9.1.5", | ||
"prettier": "^3.3.3", | ||
"semantic-release": "^24.1.0", | ||
"tsup": "^8.2.4", | ||
"typescript": "^5.5.4", | ||
"typescript-eslint": "^8.4.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
11690
15.97%224
10.89%16
Infinity%1
Infinity%