From 3741d1aa0253291c432e6ce3469f1d16dedbc914 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 26 Jan 2022 17:13:10 +0100 Subject: fix(npx)!: detect new `npx` versions and fail gracefully (#10452) BREAKING CHANGE: the `npx` plugin used a feature of `npx` to check for npm packages and run them if a command was not found. This feature was removed in v7.0.0 and was deemed insecure. The `npx` plugin is now officially deprecated and will be removed soon. Fixes #10452 --- plugins/npx/npx.plugin.zsh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'plugins/npx/npx.plugin.zsh') diff --git a/plugins/npx/npx.plugin.zsh b/plugins/npx/npx.plugin.zsh index 32bb67377..c1e2eca98 100644 --- a/plugins/npx/npx.plugin.zsh +++ b/plugins/npx/npx.plugin.zsh @@ -1,7 +1,12 @@ -# NPX Plugin -# https://www.npmjs.com/package/npx -# Maintainer: Pooya Parsa +if (( ! $+commands[npx] )); then + return +fi -(( $+commands[npx] )) && { - source <(npx --shell-auto-fallback zsh) -} +if ! npx_fallback_script="$(npx --shell-auto-fallback zsh 2>/dev/null)"; then + print -u2 ${(%):-"%F{yellow}This \`npx\` version ($(npx --version)) is not supported.%f"} +else + source <(<<< "$npx_fallback_script") +fi + +print -u2 ${(%):-"%F{yellow}The \`npx\` plugin is deprecated and will be removed soon. %BPlease disable it%b.%f"} +unset npx_fallback_script -- cgit v1.2.3-70-g09d2