https://github.com/pilaton/pubun
Library for identifying available package managers (npm, yarn, pnpm, bun)
https://github.com/pilaton/pubun
bun npm package-json package-lock package-manager pnpm pubun yarn
Last synced: 8 months ago
JSON representation
Library for identifying available package managers (npm, yarn, pnpm, bun)
- Host: GitHub
- URL: https://github.com/pilaton/pubun
- Owner: Pilaton
- License: mit
- Created: 2023-12-01T18:50:50.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-05T18:32:50.000Z (10 months ago)
- Last Synced: 2025-01-06T14:29:15.276Z (9 months ago)
- Topics: bun, npm, package-json, package-lock, package-manager, pnpm, pubun, yarn
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/pubun
- Size: 597 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Pubun

![Static Badge]()Asynchronous library with built-in caching to identify available package managers.
## Table of contents
- [đĄ Features](#-features)
- [đšī¸ Install](#ī¸-install)
- [đââī¸ Usage](#ī¸-usage)
- [Example of defining a package manager for the current project](#example-of-defining-a-package-manager-for-the-current-project)
- [Example of detecting all globally installed package managers](#example-of-detecting-all-globally-installed-package-managers)
- [Clearing Pubun cache](#clearing-pubun-cache)
- [đ API](#-api)
- [defineManager()](#definemanager)
- [defineGlobalManagers()](#defineglobalmanagers)
- [clearCache()](#clearcache)## đĄ Features
- [x] Defines the package manager that manages your application.
- [x] Identifies all available globally installed package managers and their versions.
- [x] Can detect package managers such as: **`npm`**, **`yarn`**, **`pnpm`** and **`bun`**.
- [x] **Uses cache** at all stages, which can be forcibly cleared....## đšī¸ Install
```bash
npm install pubun
```Pubun offers several import options - default import, or named import.
```js
// default import
import pubun from 'pubun';// or named import. Recommended!
import { defineManager, defineGlobalManagers } from 'pubun';
```...## đââī¸ Usage
### Example of defining a package manager for the current project
```js
import { defineManager } from 'pubun';async function demoFunction() {
const packageManager = await defineManager('/path/to/project');console.log(packageManager); // npm | yarn | pnpm | bun
}demoFunction();
```### Example of detecting all globally installed package managers
```js
import { defineGlobalManagers } from 'pubun';async function demoFunction() {
const globalManagers = await defineGlobalManagers();console.log(globalManagers);
// [
// {
// manager: 'pnpm';
// version: '8.11.0';
// },
// {
// manager: 'bun';
// version: '1.0.14';
// },
// ...
// ]
}demoFunction();
```### Clearing Pubun cache
Since all Pubun operations are cached in order to optimize speed, sometimes you may need to clear the cache manually.
```js
import { clearCache } from 'pubun';clearCache();
```...## đ API
### defineManager()
Defines the package manager used in a given directory.
Checks for the presence of characteristic files (e.g., package-lock.json for npm) for each known package manager.Supported package managers: **`npm`**, **`yarn`**, **`pnpm`**, **`bun`**
```ts
type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';defineManager: (path?: string) => Promise;
```| Argument | Type | Default value | Description |
| -------- | -------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `path` | `string` | [`process.cwd()`](https://nodejs.org/api/process.html#processcwd) | The path to the directory to check. If not provided, defaults to the current working directory. |**Return**: A promise that resolves to the type of package manager used or `null` if no package manager can be defined.
### defineGlobalManagers()
```ts
interface GlobalManagerData {
manager: PackageManager;
version: string;
}defineGlobalManagers: () => Promise;
```**Return:** A promise that resolves to an array of global manager data, including the name and version of each installed package manager, or `null` if none is installed.
### clearCache()
Clears the entire cache.
This function removes all cached data related to package manager checks.
Useful for resetting the state to ensure fresh data is fetched.```ts
clearCache: () => void
```