antfu-collective / ni

💡 Use the right package manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduce `-w` global flag for running commands in workspaces

Not-Jayden opened this issue · comments

Clear and concise description of the problem

All package managers support some form of setting a workspace/package for running commands. It would be convenient to have this as a unified -w/--workspace flag, rather than having to figure out what package manager a workspace is using in order to run commands for specific workspaces.

If there is interest in this, I'd be willing to attempt a PR at implementing it.

Suggested solution

Introduce a global -w flag that lets you run commands based on a workspace name.

e.g. ni would be translated as:

ni -w packageA vite

# npm -w packageA i vite
# yarn workspace packageA add vite
# pnpm add vite --filter packageA
# (cd path/to/packageA bun add vite) (not sure yet what the best way to handle bun is as it doesn't allow you to just specify the workspace name)

There's probably some more considerations and complexity beyond the basic use case to figure out, such as:

  • Supporting defining multiple workspaces (-w packageA -w packageB)
  • supporting pattern matching for specific packages (-w @package/*)
    • This should provide support for running in all workspaces as well (-w *)
  • If -w diverges from the npm implementation (likely will), we'd probably want a different flag. Maybe just uppercase -W

Alternative

Continue just using the per-package way of doing things. They're not super standard between packages (especially bun), so maybe it does make sense to leave as is.

Additional context

No response

Validations

Wow, I think this idea is great!