Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

> NX Running global Nx CLI with PNPM may have issues. #16

Open
kopach opened this issue Jan 20, 2023 · 5 comments
Open

> NX Running global Nx CLI with PNPM may have issues. #16

kopach opened this issue Jan 20, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@kopach
Copy link

kopach commented Jan 20, 2023

When running nx in pnpm managed repo, I get the following warning (which sometimes even results in not working command)

 >  NX   Running global Nx CLI with PNPM may have issues.

   Prefer to use "pnpm" (https://pnpm.io/cli/exec) to execute commands in this workspace.
    TIP  create a shortcut such as: alias pnx="pnpm nx --"

Using the alias from the TIP would break this autocompletion, so would be really great if the plugin could work with PNPM natively and run pnpm nx whenever nx is used.

Here is what I came up with as a solution for me:

In .zrhrc

function pnpm-nx() {
	local cmd=$BUFFER
	if [[ "$cmd" =~ ^nx ]]; then
		local new_cmd=$(echo $cmd | sed -E 's/^nx /pnpm nx /g')
		BUFFER="$new_cmd"
	fi
	zle accept-line
}

zle -N pnpm-nx
bindkey "^M" pnpm-nx

So, now whenever I type nx {command} it gets replaced by pnpm nx {command} automatically on Enter. This also doesn't break this autocompletion plugin

@edbzn
Copy link
Member

edbzn commented Jan 20, 2023

I recently started to use pnpm and also noticed the warning but I just ignored it, I wonder what issues it can cause and why. I agree it would be great to handle this directly in the plugin, if you want to contribute you are welcome.

@kopach
Copy link
Author

kopach commented Jan 24, 2023

Sometimes, some command will fail if used without pnpm prefix. Usually more complex commands like nx generate or nx migrate, so this is not only warning.

I might take a look on this, but not sure I'll have time. But feel free to reuse that piece of code I've shared.

btw, not sure if this is possible, but I would improve the behavior of that script a bit.
The downside of script from above is that pnpm nx.. command gets written to history instead of nx .... So, I can't navigate back in history with arrows and re-use nx ... command with substitution. nx-completion plugin won't work.
Probably the solution would be to alter terminal history somehow after execution and write there nx ... instead of pnpm nx ...

@Peeeep
Copy link

Peeeep commented Jan 24, 2023

I'm not sure if this helps in your case, but I have added this tiny script to my .zshrc to get autocomplete working whithout nx being globally installed (yarn in my case):

function nx() {
    yarn nx "$@"
}

@edbzn edbzn added the enhancement New feature or request label Jan 24, 2023
@kopach
Copy link
Author

kopach commented Jan 25, 2023

Just as an idea for potential solution. There is a package I use https://github.com/antfu/ni which can automatically detect package manager used in the project and install dependencies with proper manager.
So, this plugin, potentially could do the same – detect package manager used and append yarn , pnpm or nothing in case of npm

@kopach
Copy link
Author

kopach commented Jan 26, 2023

and @Peeeep , your solution works like a charm, thanks.
In my case, I did the following for pnpm

# ~/.zshrc file
function nx() {
    pnpm nx "$@"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants