Try sxpm online at deinsoftware.github.io/sxpm
Select package managers, type a command, and see real-time translations across npm, yarn, yarn@berry, pnpm, bun, and deno. The CLI output panel shows tabs per package manager — you can embed a similar interactive translation widget in your own documentation or website.
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' }
// }Translates only the command (not args) to one or more package managers.
import { translateCommand } from 'sxpm'
const result = translateCommand({
command: 'add',
args: ['react', '--save-dev'],
packageManagers: ['npm', 'pnpm']
})
// npm: { command: 'install', args: ['react', '--save-dev'], cli: 'npm install react --save-dev' }
// pnpm: { command: 'add', args: ['react', '--save-dev'], cli: 'pnpm add react --save-dev' }Translates only the arguments (not command) to one or more package managers.
import { translateArgs } from 'sxpm'
const result = translateArgs({
args: ['--save-dev'],
packageManagers: ['npm', 'yarn', 'pnpm']
})
// npm: { args: ['--save-dev'] }
// yarn: { args: ['--dev'] }
// pnpm: { args: ['--save-dev'] }All translation functions accept an optional from parameter indicating the source package manager format (defaults to swpm):
const result = crossTranslate({
command: 'add',
args: ['react'],
packageManagers: ['yarn', 'pnpm'],
from: 'swpm' // explicit, this is the default
})Currently only
swpmdictionaries are available as a source. Future versions will support translating directly between any package managers (e.g.,npm→yarn,pnpm→bun, etc.).
When you need to replace <package> placeholder with actual package name:
const result = crossTranslate({
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 known but explicitly unavailable on certain package managers return an error:
const result = crossTranslate({
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' }
// }Unrecognized commands and arguments (not found in any dictionary) are replicated as-is without error. For example,
swpm info sxpm --jsonproducesnpm info sxpm --json,yarn info sxpm --json, etc.
Translates a command and its arguments to one or more package managers.
Params:
| Param | Type | Description |
|---|---|---|
command |
string |
The swpm 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 |
from |
PackageManagerList (optional) |
Source package manager format (default: swpm) |
Returns: CrossTranslateResult
interface CrossTranslateResult {
[packageManager: string]: {
command: string
args: string[]
cli: string
error?: string
}
}Translates a command to one or more package managers. Same params as crossTranslate without the cross-translation logic.
Translates arguments to one or more package managers.
Params:
| Param | Type | Description |
|---|---|---|
args |
string[] |
Arguments to translate |
packageManagers |
PackageManagerList[] |
Target package managers (empty = all) |
command |
string (optional) |
Command context for flag-specific translations |
packageName |
string (optional) |
Package name to replace <package> placeholder |
from |
PackageManagerList (optional) |
Source package manager format (default: swpm) |
| Function | Description |
|---|---|
packageExists |
Check if a package manager is supported |
getPackageConfig |
Get configuration for a specific PM |
availablePackages |
List all supported package managers |
cleanFlag |
Remove a flag from an args array |
| 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.
