Package Exports
- swpm
- swpm/src/swpm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (swpm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Switch Package Manager

Menu
Getting Started
When switching between JavaScript projects, it's often easy to forget which package manager should be used. JavaScript package managers aren't quite compatible either and each one resolves dependencies differently, so accidentally installing with npm could cause a yarn, pnpm or bun project to break.
swpm is a CLI that intends to solve this problem by unifying the most used commands for the most common Node Package Managers into one. It will recognize the Package Manager used on the project and automatically will translate those commands.
This is an example of how #swpm works. The same command, no matter the package manager used on the project.

Note:
We will start with most used command, then other commands will be added gradually.
Track the command progress implementation on CHEATSHEET
Prerequisites
What things you need to install?
Installing
Install as global with any of this package managers
| Package Manager | Install Command |
|---|---|
| npm | npm install swpm --location=global |
| yarn | yarn global add swpm |
| pnpm | pnpm install swpm --global |
| bun | bun install -g swpm |
Help
With swpm --help it will show a command help resume.
swpm [<command>] [--] [args] [FLAGS]
Commands:
swpm install [FLAGS] install packages from package.json
[aliases: i]
swpm add <package> [args] [FLAGS] add package [aliases: a]
swpm remove <package> [args] [FLAGS] remove package
[aliases: r, rm, uninstall, un]
swpm update <package> [args] [FLAGS] update package [aliases: up, ud]
swpm upgrade <package> [args] [FLAGS] upgrade package to latest [aliases: ug]
swpm interactive [args] [FLAGS] update packages interactive
[aliases: ui]
swpm clean [FLAGS] clean packages [aliases: c]
Options:
-u, --use use a package manager [choices: "npm", "yarn", "pnpm", "bun"]
-p, --pin pin a package manager [choices: "npm", "yarn", "pnpm", "bun"]
-t, --test test command (without running)
[choices: "npm", "yarn", "pnpm", "bun"]
--info show information and versions [boolean]
--help Show help [boolean]Usage
The swpm will run the command switching automatically to the pinned Package Manager.
swpm <command> [--] [args] [FLAGS]Commands
Install
By default, will install all modules listed as dependencies in package.json.
swpm install [args] [FLAGS]Alias:
i
This command installs a package and any packages that it depends on. If the package has a lock file, the installation of dependencies will be driven by that.
| Args | Alias | Description |
|---|---|---|
--frozen-lockfile |
-F |
install dependencies from lock file (without updating it). Also known as ci |
--package-lock |
-P |
install dependencies but don't read or generate a lockfile |
Note:
Sadly, the--package-lockargument is not available on bun Package Manager.
Add
This command, no arguments, will add a package to local package.json file. Package will appear as dependencies by default.
swpm add <package> [args] [FLAGS]Alias:
a
swpm add <package> saves any specified packages into dependencies by default. Additionally, you can control where and how they get saved with some additional flags:
| Args | Alias | Description |
|---|---|---|
--save-dev |
-D |
Package will appear in devDependencies |
--save-optional |
-O |
Package will appear in optionalDependencies |
--save-peer |
Package will appear in peerDependencies | |
--save-exact |
-E |
Dependencies will be configured with an exact version rather than using default semver range operator |
--global |
-g |
Remove the current package context as a global package |
Remove
This command, no arguments, will remove a package to local package.json file. Package will be removed as dependencies by default.
swpm remove <package> [args] [FLAGS]Aliases:
r,rm,uninstall,un
| Args | Alias | Description |
|---|---|---|
--save-dev |
-D |
Package will be removed from devDependencies |
--save-optional |
-O |
Package will be removed from optionalDependencies |
--save-peer |
Package will be removed from peerDependencies | |
--global |
-g |
Remove the current package context as a global package |
Update
This command will update all the packages listed to the latest version (specified by the tag config), respecting the semver constraints of both your package and its dependencies (if they also require the same package). It will also install missing packages.
swpm update [<package>] [args] [FLAGS]Aliases:
up,ud
| Args | Alias | Description |
|---|---|---|
--global |
-g |
Remove the current package context as a global package |
It will not made modifications on
package.jsonfile
Upgrade
This command will upgrade the packages to the latest version, ignoring ranges specified in package.json.
It will save new version on
package.jsonfile
swpm upgrade <package> [args] [FLAGS]Alias:
ug
| Args | Alias | Description |
|---|---|---|
--save-exact |
-E |
Dependencies will be configured with an exact version rather than using default semver range operator |
--global |
-g |
Remove the current package context as a global package |
Note:
Sadly, this command is not available on bun Package Manager.
Interactive
Show outdated dependencies and select which ones to upgrade.
swpm interactive [FLAGS]Alias:
ui
| Args | Alias | Description |
|---|---|---|
--latest |
-L |
Updates all dependencies, ignoring ranges specified in package.json |
--global |
-g |
Remove the current package context as a global package |
Note:
Sadly, this command is not available on npm and bun Package Manager.
Clean
This command does not exist in the package managers, but is one of the most repetitive tasks, deleting files.
swpm clean [args]Alias:
c
| Args | Alias | Description |
|---|---|---|
--node-modules |
Delete node_modules folder | |
--lock |
Delete lock files | |
--log |
Delete log files | |
--build |
Delete build folder | |
--coverage |
Delete coverage folder | |
--all |
Run all args |
Shared Commands
There are commands that don't need the swpm translation tool, because share the same structure as all package managers.
Init
init or create can be used to set up a new or existing package.
swpm init [<name> --yes]
swpm create [<name> --yes]To run these commands in a path where a
package.jsondidn't exist add the flag--use <npm|yarn|pnpm|bun>at the end or setup anSWPMenvironment variable.
Login/Logout
Login and logout to https://www.npmjs.com/.
Commonly used when you need to publish or admin packages.
swpm login
swpm logoutTo run these commands in a path where a
package.jsondidn't exist add the flag--use <npm|yarn|pnpm|bun>at the end or setup anSWPMenvironment variable.
Scripts
This runs an arbitrary command from a package's "scripts" object.
If no "command" is provided, it will list the available scripts.
swpm run <command> [-- <args>]
swpm test
swpm buildYou can run
testandbuild"scripts" without therunprefix.
Publish
Commands to publish, unpublish or deprecate a package on https://www.npmjs.com/.
swpm publish
swpm unpublish <package>
swpm deprecate <package> <message>Config
See the local configuration, or setup default values.
swpm config list
swpm config set <key> <value>Example:
swpm config set save-exact true
swpm config set save-prefix '~'To run these commands in a path where a
package.jsondidn't exist add the flag--use <npm|yarn|pnpm|bun>at the end.
Versions
outdated will check the registry to see if any (or, specific) installed packages are currently outdated.
swpm outdated [<package>] [--global]To run this commands in a path where a
package.jsondidn't exist with flag--globaladd the flag--use <npm|yarn|pnpm|bun>at the end or setup anSWPMenvironment variable.
Flags
Flags are important to swpm because can modify or set his behavior.
Use
The swpm --use flag allows you to choose your Package Manager for a project.
swpm <command> [--] [args] --use <npm|yarn|pnpm|bun>
swpm <command> [--] [args] --u <npm|yarn|pnpm|bun>It will run the command using the selected Package Manager, no matter the swpm property in your package.json.
Pin
The swpm --pin flag allows you to choose your Package Manager for a project.
swpm --pin <npm|yarn|pnpm|bun>
swpm -p <npm|yarn|pnpm|bun>It will store the pinned Package Manager in the package.json file, so you can commit your choice of tools to version control:
{
+ "swpm": "<package-manager-name>"
}You also can set it manually. Just take care writing a valid Package Manager:
npm,yarn,pnpmorbun.
Test
The swpm --test flag show the equivalent command using the selected Package Manager, but it will not run the command
swpm <command> [--] [args] --test <npm|yarn|pnpm|bun>
swpm <command> [--] [args] -t <npm|yarn|pnpm|bun>It will show the command using the selected Package Manager, no matter the swpm property in your package.json.
Info
The swpm --info flag show the current Package Manager used and some versions information.
swpm --infoIt will search firs the swpm property on the package.json file, and if doesn't not found it, will try to infer the Package Manager in use with help of the lock's file.
Default
In order to avoid the --use flag on paths where no exist a package.json or --pin flag on each project. You can set a global package manager creating an SWPM environment variable with one of this values <npm|yarn|pnpm>.
| OS | Command |
|---|---|
| win | `setx SWPM "<npm|yarn|pnpm |
| macOS | `echo 'export SWPM="<npm|yarn|pnpm |
| linux | `echo 'export SWPM="<npm|yarn|pnpm |
FAQ
How infer the Package Manager?
swpm search some characteristics following this order.
| Icon | Stage |
|---|---|
| 📌 | Search the swpm property pinned on package.json file |
| 📦 | Search the packageManager property on package.json file |
| 🌐 | Search a SWPM environment variable |
| 🔒 | Search for a lock file |
What can I use as Package parameter?
The <package> parameter should follow one of these structures:
[<@scope>/]<name>
[<@scope>/]<name>@<tag>
[<@scope>/]<name>@<version>
[<@scope>/]<name>@<version range>
<alias>@npm:<name>
<git-host>:<git-user>/<repo-name>
<git repo url>
<tarball file>
<tarball url>
<folder>Non documented commands
swpm is not restrictive, if a command translations was not included yet, you can write the command as the package manager expect, then swpm will try to infer the package manager and preserve the rest of the command and arguments without changes and run them.
But, if you found one of this cases, please open a command compatibility issue.
About
Built With
- VS Code - Code editing redefined.
- WSL - Windows Subsystem for Linux.
- Windows Terminal - A modern terminal application for users of command-line tools and shells.
- Node.js - A JavaScript runtime built on Chrome's V8 JavaScript engine.
- Chalk - Terminal string styling done right.
- Yargs - Yargs be a node.js library fer hearties tryin' ter parse optstrings.
- common-tags - A set of well-tested, commonly used template literal tag functions for use in ES2015+.
- update-notifier - Update notifications for your CLI app.
- ESLint - Find and fix problems in your JavaScript code.
- vitest - A blazing fast unit-test framework powered by Vite ⚡️.
Contributing
Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the swpm on GitHub.
Brand
If you want to help, spread the word of swpm in a project or web, please use this BRAND's images.
Authors
- Camilo Martinez [Equiman]
See also the list of contributors who participated in this project.
Sponsors
If this project helps you, consider buying me a cup of coffee.
License
This project is licensed under the MIT License - see the LICENSE file for details.