DEV Community

Cover image for Switch Package Manager
Camilo Martinez
Camilo Martinez

Posted on • Edited on

Switch Package Manager

Well, I'm working on projects that use different Package Managers and I'm a little tired of writing wrong commands or mixing the incorrect flags.

I've started creating a command cheatsheet to guide me through, but if speak with truth, it was not enough, because don't solve the problem at all.

So, inspired by projects like NVM and Volta I've decided to create a CLI translator, to write commands in only one way and this CLI tool will translate them to the current package manager form used in the project.

That's how swpm (Switch Package Manager) was born.

This is an example of how swpm works. The same command, no matter the package manager used on the project.

example


Install

So, if you are in the same boat as me, or don't want to relearn commands for each package manager, install swpm...



npm install swpm --location=global
yarn global add swpm
pnpm install swpm --global
bun install -g swpm
volta install swpm


Enter fullscreen mode Exit fullscreen mode

... and enjoy life.

Commands

This is a WIP project, and for now, there are available for translation the most used commands install, add, and remove, but we will add other gradually (or by request).

But commands are not restricted only to this list. Using swpm will try to infer the package manager and reuse the rest of the parameters.

For example, shared commands between all the package managers, like:



swpm init [<name> --yes]
swpm run <command> [-- <args>]
swpm test
swpm publish
swpm unpublish <package>
swpm deprecate <package> <message>


Enter fullscreen mode Exit fullscreen mode

Flags

Flags are important to swpm because can modify or set his behavior.

For example, you can pin a package manager to be used by default on a project.



swpm --pin <npm|yarn|pnpm|bun>
swpm -p <npm|yarn|pnpm|bun>


Enter fullscreen mode Exit fullscreen mode

So, with this pin, you can change over the projects, and in the future, you not going to need to worry or remember about the package manager to use. Just use the swpm command and it will do all the work for you.


This is a little introduction about what swpm can do, if calls your attention, you can learn more about it on:

GitHub logo deinsoftware / swpm

Switch Package Manager - Say goodbye to Package Manager confusion

Switch Package Manager

build publish Sonar-reliability sonar-security sonar-maintainability sonar-coverage
npm-version npm-downloads node-engine volta js-standard-style license

swpm


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 (classic or berry), 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.

swpm-example

Note:
We will start with most used command, then other commands will be added gradually.
Track the command progress implementation on CHEATSHEET.

Progress…

Comments and contributions are welcome. It's my first project using node.js and I'm sure not following the best practices, but if you have recommendations, I'm open to listening and learning.


That’s All Folks!
Happy Coding 🖖

beer

Top comments (0)