fix(link): throw an error if "pnpm link" has no options and params (#3590)

ref #3532
This commit is contained in:
Zoltan Kochan
2021-07-09 12:26:29 +03:00
committed by GitHub
parent 2264bfdf45
commit 8678e25533
3 changed files with 20 additions and 0 deletions

View 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.

View File

@@ -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,

View File

@@ -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/)
})