Introducing the ni Project
The world of package management in software development can sometimes be a tangled web of different tools and commands. The ni project is here to streamline the process, offering a unified command-line interface that smartly selects the appropriate package manager for your needs. Instead of switching between npm, yarn, pnpm, and bun, ni automates the task, ensuring you use the right tool for the job. Here’s how each component of ni works:
Installation with ni
At its core, ni is designed to simplify package installation. By running the simple command ni
, it automatically detects the lockfile of your project and executes the equivalent install command for npm, yarn, pnpm, or bun. Whether you need to add a specific package like Vite or install development dependencies, ni gets it done correctly across all of these package managers.
Running Scripts with nr
Running scripts across different package managers with varying commands can become cumbersome. With nr
, this problem is eliminated. It harmonizes script execution, allowing you to initiate scripts with consistent syntax, while nr
internally calls the appropriate run command) for each manager. Additionally, nr
offers an interactive mode to help select and run scripts effortlessly.
Executing Downloads with nlx
For those tasks that involve running packages without installing them, nlx
mirrors the npx
functionality but works across npm, yarn, pnpm, and bun. This ensures seamless execution, whether testing a package or leveraging a one-time utility.
Upgrading Dependencies with nu
Regular updates are crucial for maintaining software security and performance. The nu
command standardizes upgrading dependencies across the board, whether it's simply upgrading to the latest package versions or using interactive upgrading options available with certain managers.
Uninstallation with nun
Similarly, removing packages is made consistent with the nun
command. Simply indicate the package you wish to remove, and nun
handles the rest, even offering an interactive mode for selecting multiple packages to be uninstalled at once.
Clean Installation with nci
When it's time for a thorough installation from scratch, nci
uses the correct clean install command for each manager, allowing for frozen lockfile usage to ensure consistency and repeatability in builds.
Agent Alias with na
For those moments when precision is crucial, na
facilitates manually specifying the package manager for any given command, ensuring that the right tool is always used, regardless of configurations.
Global Flags and Custom Configuration
ni offers several global flags to suit advanced needs, like changing directories before execution or querying the current version. Users can customize default behavior via a configuration file or set environment variables to override them.
Integration and Troubleshooting
ni is designed to integrate seamlessly with various environments, with the option to install it via the asdf plugin for unified version management. However, the project acknowledges potential conflicts, such as PowerShell’s default ni
alias, and provides clear guidance for resolving these issues.
How it Works
To determine the right package manager, ni inspects the lockfiles present in a project (yarn.lock
, pnpm-lock.yaml
, package-lock.json
, or bun.lockb
) or the packageManager
field in package.json
. It then executes the matching commands.
In summary, the ni project is a powerful tool bridging the gap between multiple package management tools, providing developers with a consistent, reliable interface that optimizes their workflow across various environments and projects.