package-manager-detector
Detect the package manager used in a project from lock files and metadata
Repository Health
Technical Analysis
package-manager-detector is a tiny, dependency-free TypeScript library that determines which JavaScript package manager a project uses. It inspects lock files, the packageManager and devEngines fields in package.json, and installation metadata to identify npm, Yarn, pnpm, Deno, Bun, and other supported managers.
Beyond detection, it exposes a normalized set of agents and command mappings, so tools can resolve the correct install, run, add, or execute command for whichever package manager is in use. It is widely relied upon by build tools and CLIs that need to stay package-manager agnostic.
What You Get
- A detect API that finds the active package manager by walking up the directory tree
- A getUserAgent helper to identify the currently running package manager
- Configurable detection strategies (lockfile, packageManager-field, devEngines-field, install-metadata)
- Normalized agent and command mappings for install, run, add, and execute across managers
- Zero runtime dependencies and full TypeScript types
Common Use Cases
- Making a CLI or build tool package-manager agnostic
- Generating the correct install/run commands in docs or scaffolding output
- Detecting the package manager to invoke the right underlying command
- Resolving the active manager inside monorepo tooling
Under The Hood
Architecture - The source is a small, focused set of TypeScript modules: detect.ts implements the strategy-driven detection loop (lock files, packageManager/devEngines fields, install metadata) with upward directory crawling; commands.ts and constants.ts define the agent and command mapping tables; and types.ts plus index.ts expose the typed public surface. Subpath exports (./detect, ./commands, ./constants) let consumers import only what they need.
Tech Stack - Written entirely in TypeScript with no runtime dependencies, built with unbuild into ESM output, and developed with a modern toolchain: pnpm workspaces, ESLint via @antfu/eslint-config, and Vitest for testing.
Code Quality - The test directory covers detection, commands, user-agent parsing, and public exports, with snapshot tests and fixtures for realistic project layouts. The tiny, dependency-free surface and strong typing keep the code easy to audit and reason about.
API Design - The public API is minimal and ergonomic: an async detect() with an options object for strategy ordering, plus getUserAgent() and command-resolution helpers. Subpath entry points keep imports lean, and the whole thing is designed to be embedded in other tools with near-zero configuration.
Used by 4 apps in this directory
Epicenter
Knowledge Management · Note Taking · Developer Tools
A local-first monorepo led by Whispering, an open-source speech-to-text app, built on an MIT toolkit that turns your data into plain Markdown and SQLite files you own instead of a database you rent.
likec4
Developer Tools · Devops
Define your software architecture as code and get always up-to-date, interactive C4 diagrams generated automatically from a DSL.
open-pencil
AI Design Tools · Design Tools
An open-source design editor that reads native Figma files, ships a built-in AI assistant with 100+ design tools, and offers real-time serverless collaboration — all without giving up your files.
OpenPanel
Hosting Control Panel · Devops
Docker-powered web hosting control panel that gives every user a fully isolated environment with dedicated web server, database, and networking — VPS-grade security on shared hardware.