Skip to content

Commit

Permalink
fix: rm should fail when called without params
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Mar 18, 2020
1 parent 7c3b731 commit 77919e6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/plugin-commands-installation/src/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-commands-installation/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
22 changes: 22 additions & 0 deletions packages/plugin-commands-installation/test/remove/remove.ts
Original file line number Diff line number Diff line change
@@ -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()
})

0 comments on commit 77919e6

Please sign in to comment.