DEV Community

Karibash
Karibash

Posted on • Originally published at karibash.Medium

Alternative ni written in fish

What is "ni"?

ni is a tool that selects and executes the appropriate package manager, such as npm or yarn, for each project.
It also provides commands such as nun (npm uninstall) and nr (npm run), and common commands other than install have been standardized.

Internally, it uses logic that selects the appropriate package manager from lock files and the packageManager field in package.json.
https://github.com/antfu/ni/blob/main/src/detect.ts

In addition, the options are also converted appropriately according to each package manager, so it absorbs the differences between package managers.
https://github.com/antfu/ni/blob/main/src/agents.ts

zsh version

Someone is working on an implementation of a zsh version of ni.
Unlike the original, this zsh implementation consolidates all the commands into the ni command, so commands such as run and uninstall are executed through ni.

fish version

https://github.com/Karibash/ni.fish

There was a psychological hurdle to the fact that the original ni would define multiple commands with very short names.
I thought the zsh version's approach of handling subcommands was very good, so I created a similar plugin for fish.

Since it is a fish plugin, installation is easy.

fisher install Karibash/ni.fish
Enter fullscreen mode Exit fullscreen mode

The package manager detection logic in the zsh version is slightly different from the original ni, but the fish version tries to use the same logic as much as possible.
It searches recursively for lock files in the parent directories, so it can correctly determine the package manager even when in a subdirectory of a monorepo such as npm workspace.

The simple usage is summarized in README.md, so if you are interested in the details, please check it.
Also, issues, PR, etc. are welcome!
If you like it, I would appreciate a star to the repository.

Top comments (0)