New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

pubun

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pubun

Asynchronous library with built-in caching to identify available package managers

latest
Source
npmnpm
Version
2.1.3
Version published
Weekly downloads
29
383.33%
Maintainers
0
Weekly downloads
 
Created
Source

Pubun

npm Static Badge

Asynchronous library with built-in caching to identify available package managers.

Table of contents

📡 Features

  • Defines the package manager that manages your application.
  • Identifies all available globally installed package managers and their versions.
  • Can detect package managers such as: npm, yarn, pnpm and bun.
  • Uses cache at all stages, which can be forcibly cleared.
...

🕹️ Install

npm install pubun

Pubun offers several import options - default import, or named import.

// 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

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

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.

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

type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';

defineManager: (path?: string) => Promise<PackageManager | null>;
ArgumentTypeDefault valueDescription
pathstringprocess.cwd()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()

interface GlobalManagerData {
  manager: PackageManager;
  version: string;
}

defineGlobalManagers: () => Promise<GlobalManagerData[] | null>;

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.

clearCache: () => void

Keywords

npm

FAQs

Package last updated on 05 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts