pnpm-version-util
v1.0.0
Published
Simple CLI utility to read package version from package.json - a pnpm-friendly alternative to 'npm version'
Maintainers
Readme
pnpm-version-util
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
Global Installation (Recommended)
npm install -g pnpm-version-util
# or
pnpm add -g pnpm-version-utilLocal Installation (For Monorepos)
pnpm add -D pnpm-version-util🚀 Usage
Method 1: Direct Command
After global installation:
pnpm-version
# Output: 1.0.0Method 2: Using pnpm exec (Local installation)
pnpm exec pnpm-version
# Output: 1.0.0Method 3: Add to package.json scripts
{
"scripts": {
"version": "pnpm-version"
}
}Then run:
pnpm run version
# Output: 1.0.0Optional: 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.0Clean 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!
