@dephub/package-manager
v1.0.2
Published
Detect and work with package managers (npm, yarn, pnpm, bun)
Downloads
25
Maintainers
Readme
@dephub/package-manager
Detect and work with package managers (npm, yarn, pnpm, bun) and custom ones
Features ✨
- 🔍 Detect Available Managers - Find installed package managers on your system
- 🎯 Priority Detection - Specify preferred package manager order
- 🚀 Zero Dependencies - Only uses @dephub/spawn for child processes
- 🔒 Type Safe - Full TypeScript support with strict types
- 🔧 Extensible - Support for custom package managers
- 💻 CLI & API - Use via command line or programmatically
Installation 💿
# Using npm
npm install @dephub/package-manager
# Using pnpm
pnpm add @dephub/package-manager
# Using yarn
yarn add @dephub/package-manager
# Using bun
bun add @dephub/package-managerCLI Usage 🖥️
Basic Commands
# Detect available package managers
package-manager detect
# Get first available package manager
package-manager first
# Detect local package manager from lock files
package-manager local
# Detect workspace package manager (monorepo support)
package-manager workspace
# Detect globally installed package managers
package-manager globalOptions
Global Options (apply to all commands)
--cwd <path>- Working directory for detection--additional <managers>- Additional package managers to check (comma-separated)
Command-specific Flags
detectcommand:--required- Throw error if no package manager is found
Examples
# Detect in specific directory
package-manager detect --cwd /path/to/project
# Detect with required flag
package-manager detect --required
# Detect with additional package managers
package-manager global --additional deno,flutter
# Combine global options with commands
package-manager detect --cwd /path/to/project --additional denoProgrammatic Usage 🛠️
import { packageManager } from '@dephub/package-manager';
// Detect all available package managers
const managers = await packageManager.detect();
console.log(managers); // ['pnpm', 'npm']
// Get first available package manager
const manager = await packageManager.detectFirst();
console.log(manager); // 'pnpm'
// Detect local package manager
const localManager = await packageManager.detectLocal();
console.log(localManager); // 'pnpm' or null
// Detect workspace package manager
const workspaceManager = await packageManager.detectWorkspace();
console.log(workspaceManager); // 'pnpm' or null
// Detect global package managers
const globalManagers = await packageManager.detectGlobal();
console.log(globalManagers); // ['npm', 'pnpm', 'yarn']
// Detect with custom package managers
const customManagers = await packageManager.detectGlobal({
additionalManagers: ['flutter', 'deno'],
});
console.log(customManagers); // ['npm', 'pnpm', 'flutter'] if flutter is installedAPI Reference 📚
packageManager.detect(options?)
Detect all available package managers.
Parameters:
options(DetectionOptions) - Optional configurationpriority- Array of package managers to check firstadditionalManagers- Additional custom package managers to checkrequired- Throw if no package manager is found (default: true)scope- Detection scope: 'local', 'workspace', 'global', or 'auto' (default: 'auto')cwd- Working directory for detection (default: process.cwd())
Returns: Promise<PackageManager[]> - Array of detected package managers
packageManager.detectFirst(options?)
Detect first available package manager.
Parameters:
options(DetectionOptions) - Optional configuration
Returns: Promise<PackageManager | null>
packageManager.detectLocal(cwd?)
Detect package manager in the current directory using lock files.
Parameters:
cwd(string) - Current working directory (default: process.cwd())
Returns: Promise<PackageManager | null>
packageManager.detectWorkspace(cwd?)
Detect package manager by traversing up the directory tree.
Parameters:
cwd(string) - Starting directory (default: process.cwd())
Returns: Promise<PackageManager | null>
packageManager.detectGlobal(options?)
Detect globally installed package managers.
Parameters:
options(DetectionOptions) - Optional configuration
Returns: Promise<PackageManager[]>
Detection Scopes 🔎
- local: Only check the current directory for lock files
- workspace: Check current and parent directories for lock files (monorepo support)
- global: Check globally installed package managers
- auto: Try local, then workspace, then global (default)
Types
PackageManager
type KnownPackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';
type PackageManager = KnownPackageManager | string;DetectionOptions
interface DetectionOptions {
priority?: PackageManager[];
additionalManagers?: PackageManager[];
required?: boolean;
scope?: 'local' | 'workspace' | 'global' | 'auto';
cwd?: string;
}License 📄
MIT License
Author: Estarlin R (estarlincito.com)
Note: This package is part of the DepHub ecosystem - a collection of focused, modular tools for modern JavaScript development.
