sxpm is a library that translates package manager commands between different Node.js package managers. It provides a unified API to convert commands and arguments between npm, yarn (classic and berry), pnpm, bun, and deno.
Note:
This is a core translation engine. For CLI commands, check swpm.
Install with any package manager:
| Package Manager | Install Command |
|---|---|
| npm | npm install sxpm |
| yarn | yarn add sxpm |
| pnpm | pnpm add sxpm |
| bun | bun add sxpm |
Translates a command with its arguments to one or more package managers.
import { crossTranslate } from 'sxpm'
const result = crossTranslate({
command: 'add',
args: ['react', '--save-dev'],
packageManagers: ['npm', 'yarn', 'pnpm']
})
console.log(result)
// {
// npm: { command: 'install', args: ['react', '--save-dev'], cli: 'npm install react --save-dev' },
// yarn: { command: 'add', args: ['react', '--dev'], cli: 'yarn add react --dev' },
// pnpm: { command: 'add', args: ['react', '--save-dev'], cli: 'pnpm add react --save-dev' }
// }When you need to replace <package> placeholder with actual package name:
const result = translate({
command: 'upgrade',
args: ['react', '--latest'],
packageManagers: ['npm'],
packageName: 'react'
})
// npm: { command: 'add', args: ['react', 'react@latest'], cli: 'npm add react react@latest' }Commands that are not available on certain package managers return an error:
const result = translate({
command: 'interactive',
args: [],
packageManagers: ['npm', 'pnpm']
})
console.log(result)
// {
// npm: { command: 'interactive', args: [], cli: '', error: "Command 'interactive' not available on npm" },
// pnpm: { command: 'interactive', args: [], cli: 'pnpm interactive' }
// }Translates a command and its arguments to one or more package managers.
Params:
| Param | Type | Description |
|---|---|---|
command |
string |
The sxpm command to translate |
args |
string[] |
Arguments for the command |
packageManagers |
PackageManagerList[] |
Target package managers (empty = all) |
packageName |
string (optional) |
Package name to replace <package> placeholder |
Returns: TranslateResult
interface TranslateResult {
[packageManager: string]: {
command: string
args: string[]
cli: string
error?: string
}
}| Property | Type | Description |
|---|---|---|
command |
string |
Translated command |
args |
string[] |
Translated arguments |
cli |
string |
Full CLI command string |
error |
string (optional) |
Error message if not available |
| Manager | Version | Lock File |
|---|---|---|
| npm | 7+ | package-lock.json |
| yarn | Classic | yarn.lock |
| yarn@berry | 2+ (Berry) | yarn.lock |
| pnpm | 7+ | pnpm-lock.yaml |
| bun | 1+ | bun.lock |
| deno | 2.0+ | deno.lock |
- TypeScript - JavaScript With Syntax For Types.
- Node.js - A JavaScript runtime built on Chrome's V8 JavaScript engine.
- vitest - A blazing fast unit-test framework powered by Vite.
- ESLint - Find and fix problems in your JavaScript code.
- semver - The semantic versioner for npm.
Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the sxpm on GitHub.
- Camilo Martinez [Equiman]
This project is licensed under the MIT License - see the LICENSE file for details.
