From 2703c9f5f1274ad6380117d81d36feb37b6edf1d Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Tue, 27 Dec 2022 04:45:34 +0200 Subject: [PATCH] fix: only the add command should fail if there is no bin directory in PATH ref #5841 --- .changeset/spicy-panthers-agree.md | 7 +++++++ config/config/src/index.ts | 4 ---- pkg-manager/plugin-commands-installation/src/add.ts | 5 +++++ 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 .changeset/spicy-panthers-agree.md diff --git a/.changeset/spicy-panthers-agree.md b/.changeset/spicy-panthers-agree.md new file mode 100644 index 00000000000..437430dbdba --- /dev/null +++ b/.changeset/spicy-panthers-agree.md @@ -0,0 +1,7 @@ +--- +"@pnpm/config": patch +"@pnpm/plugin-commands-installation": patch +"pnpm": patch +--- + +Only the `pnpm add --global ` command should fail if there is no global pnpm bin directory in the system PATH [#5841](https://github.com/pnpm/pnpm/issues/5841). diff --git a/config/config/src/index.ts b/config/config/src/index.ts index 5ebc1dfe2cd..0d240f9a7f5 100644 --- a/config/config/src/index.ts +++ b/config/config/src/index.ts @@ -316,10 +316,6 @@ export async function getConfig ( if (pnpmConfig.bin) { fs.mkdirSync(pnpmConfig.bin, { recursive: true }) await checkGlobalBinDir(pnpmConfig.bin, { env, shouldAllowWrite: opts.globalDirShouldAllowWrite }) - } else { - throw new PnpmError('NO_GLOBAL_BIN_DIR', 'Unable to find the global bin directory', { - hint: 'Run "pnpm setup" to create it automatically, or set the global-bin-dir setting, or the PNPM_HOME env variable. The global bin directory should be in the PATH.', - }) } pnpmConfig.save = true pnpmConfig.allowNew = true diff --git a/pkg-manager/plugin-commands-installation/src/add.ts b/pkg-manager/plugin-commands-installation/src/add.ts index cd26435bfa5..be9a6cafdf5 100644 --- a/pkg-manager/plugin-commands-installation/src/add.ts +++ b/pkg-manager/plugin-commands-installation/src/add.ts @@ -193,6 +193,11 @@ export async function handler ( 'If you don\'t want to see this warning anymore, you may set the ignore-workspace-root-check setting to true.' ) } + if (opts.global && !opts.bin) { + throw new PnpmError('NO_GLOBAL_BIN_DIR', 'Unable to find the global bin directory', { + hint: 'Run "pnpm setup" to create it automatically, or set the global-bin-dir setting, or the PNPM_HOME env variable. The global bin directory should be in the PATH.', + }) + } const include = { dependencies: opts.production !== false,