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

pnpm-version-util

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pnpm-version-util

Simple CLI utility to read package version from package.json - a pnpm-friendly alternative to 'npm version'

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

pnpm-version-util

npm version License: MIT

A simple CLI utility to read package version from package.json - a pnpm-friendly alternative to npm version.

🎯 Problem

Running pnpm version doesn't work because pnpm doesn't have a native version command. When it falls back to npm, it often fails due to package manager constraints or workspace configurations.

✨ Solution

This package provides a simple CLI that reads the version from package.json in the current directory. No configuration needed, just works!

📦 Installation

npm install -g pnpm-version-util
# or
pnpm add -g pnpm-version-util

Local Installation (For Monorepos)

pnpm add -D pnpm-version-util

🚀 Usage

Method 1: Direct Command

After global installation:

pnpm-version
# Output: 1.0.0

Method 2: Using pnpm exec (Local installation)

pnpm exec pnpm-version
# Output: 1.0.0

Method 3: Add to package.json scripts

{
  "scripts": {
    "version": "pnpm-version"
  }
}

Then run:

pnpm run version
# Output: 1.0.0

Optional: Create an alias

For even shorter commands, add to your ~/.zshrc or ~/.bashrc:

alias pv='pnpm-version'

Then simply run:

pv
# Output: 1.0.0

📖 Output

Always outputs just the version number with no extra noise:

1.0.0

Clean output makes it perfect for:

  • Quick version checks during development
  • Scripting and automation
  • CI/CD pipelines
  • Git tags and release workflows

Example: Use in scripts

# Create git tag from package version
git tag "v$(pnpm-version)"

# Use in release script
VERSION=$(pnpm-version)
echo "Releasing version $VERSION"

🔌 Programmatic API

You can also use this package programmatically in your Node.js code:

import { getVersion } from 'pnpm-version-util';

// Get version from current directory
const version = getVersion();
console.log(version); // "1.0.0"

// Get version from specific directory
const version = getVersion({ cwd: '/path/to/package' });
console.log(version); // "2.3.4"

API Types

interface GetVersionOptions {
  /** Path to the directory containing package.json. Defaults to current working directory. */
  cwd?: string;
}

function getVersion(options?: GetVersionOptions): string

💡 Use Cases

  • Monorepo Management: Quickly check versions of different packages
  • Release Automation: Get version for tagging and changelog generation
  • CI/CD Pipelines: Integrate into build and deployment scripts
  • Development: Quick version checks without opening files

✅ Benefits

Zero Configuration - Works out of the box
Clean Output - Just the version number, nothing else
Fast - Synchronous file read, instant results
Reliable - Comprehensive test coverage
Flexible - CLI + programmatic API
TypeScript - Full type definitions included

🛠️ Requirements

  • Node.js >= 18
  • pnpm (optional, works with npm/yarn too)

🧪 Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Build
pnpm run build

# Run locally
./build/cli.js

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add some amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

📝 License

MIT © Amitai Salmon

🐛 Issues

Found a bug or have a suggestion? Please open an issue.

⭐ Show your support

Give a ⭐️ if this project helped you!

Keywords

pnpm

FAQs

Package last updated on 04 Nov 2025

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