fix: rm should fail when called without params

This commit is contained in:
Zoltan Kochan committed 2020-03-18 02:44:24 +02:00
1 parent 7c3b73166e
commit 77919e65f7
3 files changed
+25

No files matched your search

@@ -7,6 +7,7 @@ import {
import { CompletionFunc } from '@pnpm/command'
import { FILTERING, OPTIONS, UNIVERSAL_OPTIONS } from '@pnpm/common-cli-options-help'
import { Config, types as allTypes } from '@pnpm/config'
import PnpmError from '@pnpm/error'
import findWorkspacePackages, { arrayOfWorkspacePackagesToMap } from '@pnpm/find-workspace-packages'
import { requireHooks } from '@pnpm/pnpmfile'
import { createOrConnectStoreController, CreateStoreControllerOptions } from '@pnpm/store-connection-manager'
@@ -120,6 +121,7 @@ export async function handler (
},
params: string[],
) {
if (params.length === 0) throw new PnpmError('MUST_REMOVE_SOMETHING', 'At least one dependency name should be specified for removal')
if (opts.recursive && opts.allProjects && opts.selectedProjectsGraph && opts.workspaceDir) {
await recursive(opts.allProjects, params, { ...opts, selectedProjectsGraph: opts.selectedProjectsGraph!, workspaceDir: opts.workspaceDir! }, 'remove')
return
@@ -5,6 +5,7 @@ import './linkRecursive'
import './miscRecursive'
import './prune'
import './remove/completion'
import './remove/remove'
import './update/getUpdateChoices.test'
import './update/interactive'
import './update/recursive'
@@ -0,0 +1,22 @@
import PnpmError from '@pnpm/error'
import { remove } from '@pnpm/plugin-commands-installation'
import prepare, { preparePackages } from '@pnpm/prepare'
import test = require('tape')
import { DEFAULT_OPTS } from '../utils'
test('remove should fail if no dependency is specified for removal', async (t) => {
prepare(t)
let err!: PnpmError
try {
await remove.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
}, [])
} catch (_err) {
err = _err
}
t.equal(err.code, 'ERR_PNPM_MUST_REMOVE_SOMETHING')
t.equal(err.message, 'At least one dependency name should be specified for removal')
t.end()
})