From 77919e65f75ca18ad3b4c668e466bc56da52864b Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 18 Mar 2020 02:40:57 +0200 Subject: [PATCH] fix: rm should fail when called without params --- .../src/remove.ts | 2 ++ .../test/index.ts | 1 + .../test/remove/remove.ts | 22 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 packages/plugin-commands-installation/test/remove/remove.ts diff --git a/packages/plugin-commands-installation/src/remove.ts b/packages/plugin-commands-installation/src/remove.ts index 3724daf7f6..3f6221e079 100644 --- a/packages/plugin-commands-installation/src/remove.ts +++ b/packages/plugin-commands-installation/src/remove.ts @@ -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 diff --git a/packages/plugin-commands-installation/test/index.ts b/packages/plugin-commands-installation/test/index.ts index 84e0b30635..08e58a3b89 100644 --- a/packages/plugin-commands-installation/test/index.ts +++ b/packages/plugin-commands-installation/test/index.ts @@ -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' diff --git a/packages/plugin-commands-installation/test/remove/remove.ts b/packages/plugin-commands-installation/test/remove/remove.ts new file mode 100644 index 0000000000..c719d24d59 --- /dev/null +++ b/packages/plugin-commands-installation/test/remove/remove.ts @@ -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() +})