mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
fix(link): throw an error if "pnpm link" has no options and params (#3590)
ref #3532
This commit is contained in:
5
.changeset/little-eagles-give.md
Normal file
5
.changeset/little-eagles-give.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-installation": patch
|
||||
---
|
||||
|
||||
An error should be thrown if `pnpm link` is executed with no parameters and no options.
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from '@pnpm/cli-utils'
|
||||
import { UNIVERSAL_OPTIONS } from '@pnpm/common-cli-options-help'
|
||||
import { Config, types as allTypes } from '@pnpm/config'
|
||||
import PnpmError from '@pnpm/error'
|
||||
import findWorkspaceDir from '@pnpm/find-workspace-dir'
|
||||
import findWorkspacePackages, { arrayOfWorkspacePackagesToMap } from '@pnpm/find-workspace-packages'
|
||||
import { StoreController } from '@pnpm/package-store'
|
||||
@@ -106,6 +107,9 @@ export async function handler (
|
||||
|
||||
// pnpm link
|
||||
if ((params == null) || (params.length === 0)) {
|
||||
if (path.relative(linkOpts.dir, cwd) === '') {
|
||||
throw new PnpmError('LINK_BAD_PARAMS', 'You must provide a parameter')
|
||||
}
|
||||
const { manifest, writeProjectManifest } = await tryReadProjectManifest(opts.dir, opts)
|
||||
const newManifest = await linkToGlobal(cwd, {
|
||||
...linkOpts,
|
||||
|
||||
@@ -177,3 +177,14 @@ test('link --production', async () => {
|
||||
await projects['target'].has('is-positive')
|
||||
await projects['target'].has('is-negative')
|
||||
})
|
||||
|
||||
test('link fails if nothing is linked', async () => {
|
||||
prepare()
|
||||
|
||||
await expect(
|
||||
link.handler({
|
||||
...DEFAULT_OPTS,
|
||||
dir: '',
|
||||
}, [])
|
||||
).rejects.toThrow(/You must provide a parameter/)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user