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

fix!: do not allow to install pnpm globally via pnpm add #8728

Merged
merged 2 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix!: do not allow to install pnpm globally via pnpm add
  • Loading branch information
zkochan committed Nov 2, 2024
commit ac0e74c773b25b627f6e711d6bc1a5b720590406
6 changes: 6 additions & 0 deletions .changeset/tricky-crabs-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-installation": major
"pnpm": major
---

`pnpm add --global pnpm` or (`pnpm add --global @pnpm/exe`) fails with an error suggesting to use `pnpm self-update`.
13 changes: 9 additions & 4 deletions pkg-manager/plugin-commands-installation/src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,15 @@ 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.',
})
if (opts.global) {
if (!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.',
})
}
if (params.includes('pnpm') || params.includes('@pnpm/exe')) {
throw new PnpmError('GLOBAL_PNPM_INSTALL', 'Use the "pnpm self-update" command to install or update pnpm')
}
}

const include = {
Expand Down
40 changes: 40 additions & 0 deletions pkg-manager/plugin-commands-installation/test/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,43 @@ test('add: fail when global bin directory is not found', async () => {
}
expect(err.code).toBe('ERR_PNPM_NO_GLOBAL_BIN_DIR')
})

test('add: fail trying to install pnpm', async () => {
prepareEmpty()

let err!: PnpmError
try {
await add.handler({
...DEFAULT_OPTIONS,
bin: path.resolve('project/bin'),
dir: path.resolve('project'),
global: true,
linkWorkspacePackages: false,
saveWorkspaceProtocol: false,
workspace: false,
}, ['pnpm'])
} catch (_err: any) { // eslint-disable-line
err = _err
}
expect(err.code).toBe('ERR_PNPM_GLOBAL_PNPM_INSTALL')
})

test('add: fail trying to install @pnpm/exe', async () => {
prepareEmpty()

let err!: PnpmError
try {
await add.handler({
...DEFAULT_OPTIONS,
bin: path.resolve('project/bin'),
dir: path.resolve('project'),
global: true,
linkWorkspacePackages: false,
saveWorkspaceProtocol: false,
workspace: false,
}, ['@pnpm/exe'])
} catch (_err: any) { // eslint-disable-line
err = _err
}
expect(err.code).toBe('ERR_PNPM_GLOBAL_PNPM_INSTALL')
})
Loading