From e29c040d387fe6632e7cd57d35ddefb1b76e7cc0 Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Mon, 26 Aug 2019 14:31:21 +0200 Subject: [PATCH] =?UTF-8?q?feat(pnpm):=20make=C2=A0`pnpm=C2=A0add`=20requi?= =?UTF-8?q?re=20the=C2=A0=C2=A0parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #1976 close #1970 --- packages/pnpm/src/cmd/help.ts | 50 ++++++++++++++++-------- packages/pnpm/src/cmd/index.ts | 1 + packages/pnpm/src/cmd/install.ts | 5 +++ packages/pnpm/src/cmd/recursive/index.ts | 6 +++ packages/pnpm/src/getCommandFullName.ts | 3 +- packages/pnpm/src/main.ts | 2 + packages/pnpm/test/install/misc.ts | 22 +++++++++++ 7 files changed, 70 insertions(+), 19 deletions(-) diff --git a/packages/pnpm/src/cmd/help.ts b/packages/pnpm/src/cmd/help.ts index 63af36f39f..14f421dbe7 100644 --- a/packages/pnpm/src/cmd/help.ts +++ b/packages/pnpm/src/cmd/help.ts @@ -11,18 +11,9 @@ function getHelpText (command: string) { switch (getCommandFullName(command)) { case 'install': return stripIndent` - pnpm install (with no args, in package dir) - pnpm install [<@scope>/] - pnpm install [<@scope>/]@ - pnpm install [<@scope>/]@ - pnpm install [<@scope>/]@ - pnpm install :/ - pnpm install - pnpm install - pnpm install - pnpm install + pnpm install - Aliases: i, install, add + Aliases: i Installs all dependencies of the project in the current working directory. To install dependencies in every project of a monorepo, run \`pnpm recursive install\` @@ -30,12 +21,6 @@ function getHelpText (command: string) { Options: - -P, --save-prod save package to your \`dependencies\`. The default behavior - -D, --save-dev save package to your \`devDependencies\` - -O, --save-optional save package to your \`optionalDependencies\` - --save-peer save package to your \`peerDependencies\` and \`devDependencies\` - -E, --save-exact install exact version - -g, --global install as a global package -r run installation recursively in every package found in subdirectories or in every workspace package, when executed inside a workspace. For options that may be used with \`-r\`, see "pnpm help recursive" @@ -112,6 +97,33 @@ function getHelpText (command: string) { Includes all packages that are under the current working directory. ` + case 'add': + return stripIndent` + pnpm add [<@scope>/] + pnpm add [<@scope>/]@ + pnpm add [<@scope>/]@ + pnpm add [<@scope>/]@ + pnpm add :/ + pnpm add + pnpm add + pnpm add + pnpm add + + Installs a package and any packages that it depends on. + + Options: + + -P, --save-prod save package to your \`dependencies\`. The default behavior + -D, --save-dev save package to your \`devDependencies\` + -O, --save-optional save package to your \`optionalDependencies\` + --save-peer save package to your \`peerDependencies\` and \`devDependencies\` + -E, --save-exact install exact version + -g, --global install as a global package + -r run installation recursively in every package found in subdirectories + or in every workspace package, when executed inside a workspace. + For options that may be used with \`-r\`, see "pnpm help recursive" + ` + case 'import': return stripIndent` pnpm import @@ -412,6 +424,8 @@ function getHelpText (command: string) { install + add + update uninstall [<@scope>/]... @@ -489,6 +503,7 @@ function getHelpText (command: string) { manage your dependencies: - install + - add - update - uninstall - link @@ -517,6 +532,7 @@ function getHelpText (command: string) { manage you monorepo: - recursive exec - recursive install + - recursive add - recursive list - recursive outdated - recursive rebuild diff --git a/packages/pnpm/src/cmd/index.ts b/packages/pnpm/src/cmd/index.ts index f815cd2430..f776676729 100644 --- a/packages/pnpm/src/cmd/index.ts +++ b/packages/pnpm/src/cmd/index.ts @@ -18,6 +18,7 @@ import unlink from './unlink' import update from './update' export default { + add: install, help, import: importCmd, install, diff --git a/packages/pnpm/src/cmd/install.ts b/packages/pnpm/src/cmd/install.ts index 89b7e0bec1..d2e8a1911f 100644 --- a/packages/pnpm/src/cmd/install.ts +++ b/packages/pnpm/src/cmd/install.ts @@ -28,7 +28,9 @@ export default async function installCmd ( input: string[], opts: PnpmOptions & { allowNew?: boolean, + useBetaCli?: boolean, }, + invocation?: string, ) { // `pnpm install ""` is going to be just `pnpm install` input = input.filter(Boolean) @@ -73,6 +75,9 @@ export default async function installCmd ( delete installOpts.include } if (!input || !input.length) { + if (invocation === 'add' && opts.useBetaCli) { + throw new PnpmError('MISSING_PACKAGE_NAME', '`pnpm add` requires the package name') + } await install(manifest, installOpts) } else { const [updatedImporter] = await mutateModules([ diff --git a/packages/pnpm/src/cmd/recursive/index.ts b/packages/pnpm/src/cmd/recursive/index.ts index a07ad76c80..fba7934c5b 100644 --- a/packages/pnpm/src/cmd/recursive/index.ts +++ b/packages/pnpm/src/cmd/recursive/index.ts @@ -102,6 +102,7 @@ export async function recursive ( allowNew?: boolean, packageSelectors?: PackageSelector[], ignoredPackages?: Set, + useBetaCli?: boolean, }, cmdFullName: string, cmd: string, @@ -143,6 +144,11 @@ export async function recursive ( case 'outdated': await outdated(pkgs, input, cmd, opts as any) // tslint:disable-line:no-any return true + case 'install': + if (cmd === 'add' && opts.useBetaCli && (!input || !input.length)) { + throw new PnpmError('MISSING_PACKAGE_NAME', '`pnpm recursive add` requires the package name') + } + break } const chunks = opts.sort diff --git a/packages/pnpm/src/getCommandFullName.ts b/packages/pnpm/src/getCommandFullName.ts index 43ab30128d..76e42e2c50 100644 --- a/packages/pnpm/src/getCommandFullName.ts +++ b/packages/pnpm/src/getCommandFullName.ts @@ -1,6 +1,5 @@ export default function getCommandFullName (cmd: string) { switch (cmd) { - case 'add': case 'install': case 'i': return 'install' @@ -41,7 +40,7 @@ export default function getCommandFullName (cmd: string) { case 'multi': case 'm': return 'recursive' - // some commands have no aliases: publish, prune + // some commands have no aliases: publish, prune, add default: return cmd } diff --git a/packages/pnpm/src/main.ts b/packages/pnpm/src/main.ts index a405f34d17..0afbccb9c8 100644 --- a/packages/pnpm/src/main.ts +++ b/packages/pnpm/src/main.ts @@ -32,6 +32,7 @@ import initReporter, { ReporterType } from './reporter' pnpmCmds['install-test'] = pnpmCmds.installTest type CANONICAL_COMMAND_NAMES = 'help' + | 'add' | 'import' | 'install-test' | 'install' @@ -58,6 +59,7 @@ type CANONICAL_COMMAND_NAMES = 'help' const COMMANDS_WITH_NO_DASHDASH_FILTER = new Set(['run', 'exec', 'restart', 'start', 'stop', 'test']) const supportedCmds = new Set([ + 'add', 'install', 'uninstall', 'update', diff --git a/packages/pnpm/test/install/misc.ts b/packages/pnpm/test/install/misc.ts index ee62fd77e1..d67322ee85 100644 --- a/packages/pnpm/test/install/misc.ts +++ b/packages/pnpm/test/install/misc.ts @@ -302,6 +302,28 @@ test('pnpm install --save-peer', async (t) => { } }) +test('`pnpm add` should fail if no package name was provided (beta)', (t: tape.Test) => { + prepare(t) + + const { status, stdout } = execPnpmSync('add', '--use-beta-cli') + + t.equal(status, 1) + t.ok(stdout.toString().includes('`pnpm add` requires the package name')) + + t.end() +}) + +test('`pnpm recursive add` should fail if no package name was provided (beta)', (t: tape.Test) => { + prepare(t) + + const { status, stdout } = execPnpmSync('recursive', 'add', '--use-beta-cli') + + t.equal(status, 1) + t.ok(stdout.toString().includes('`pnpm recursive add` requires the package name')) + + t.end() +}) + test('install should fail if the used pnpm version does not satisfy the pnpm version specified in engines', async (t: tape.Test) => { prepare(t, { name: 'project',