From 8886ce5b5b0d3d1e4b2f71cfd0c8a730fcfa8c2a Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sun, 6 Oct 2019 21:41:00 +0300 Subject: [PATCH] fix: validate options passed to "install" and "add" separatly --- packages/pnpm/src/main.ts | 86 +++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 22 deletions(-) diff --git a/packages/pnpm/src/main.ts b/packages/pnpm/src/main.ts index f86b8f6b95..146667bc01 100644 --- a/packages/pnpm/src/main.ts +++ b/packages/pnpm/src/main.ts @@ -136,12 +136,10 @@ const INSTALL_CLI_OPTIONS = new Set([ 'frozen-lockfile', 'force', 'global-pnpmfile', - 'global', 'hoist', 'hoist-pattern', 'ignore-pnpmfile', 'ignore-scripts', - 'ignore-workspace-root-check', 'independent-leaves', 'link-workspace-packages', 'lock', @@ -156,12 +154,6 @@ const INSTALL_CLI_OPTIONS = new Set([ 'recursive', 'registry', 'reporter', - 'save-dev', - 'save-exact', - 'save-optional', - 'save-peer', - 'save-prod', - 'save-workspace-protocol', 'shamefully-hoist', 'shared-workspace-lockfile', 'side-effects-cache-readonly', @@ -178,7 +170,51 @@ const INSTALL_CLI_OPTIONS = new Set([ ]) const SUPPORTED_CLI_OPTIONS: Record> = { - 'add': INSTALL_CLI_OPTIONS, + 'add': new Set([ + 'child-concurrency', + 'dev', + 'engine-strict', + 'force', + 'global-pnpmfile', + 'global', + 'hoist', + 'hoist-pattern', + 'ignore-pnpmfile', + 'ignore-scripts', + 'ignore-workspace-root-check', + 'independent-leaves', + 'link-workspace-packages', + 'lock', + 'lockfile-directory', + 'lockfile-only', + 'lockfile', + 'package-import-method', + 'pnpmfile', + 'prefer-offline', + 'production', + 'recursive', + 'registry', + 'reporter', + 'save-dev', + 'save-exact', + 'save-optional', + 'save-peer', + 'save-prod', + 'save-workspace-protocol', + 'shamefully-hoist', + 'shared-workspace-lockfile', + 'side-effects-cache-readonly', + 'side-effects-cache', + 'store', + 'strict-peer-dependencies', + 'offline', + 'only', + 'optional', + 'use-running-store-server', + 'use-store-server', + 'verify-store-integrity', + 'workspace-prefix', + ]), 'help': new Set([]), 'import': new Set([]), 'install': INSTALL_CLI_OPTIONS, @@ -418,18 +454,6 @@ export default async function run (inputArgv: string[]) { subCmd = null } - const allowedOptions = !subCmd - ? SUPPORTED_CLI_OPTIONS[cmd] - : new Set([...Array.from(SUPPORTED_CLI_OPTIONS[cmd]), ...Array.from(SUPPORTED_CLI_OPTIONS[subCmd])]) - for (const cliOption of Object.keys(cliConf)) { - if (!GLOBAL_OPTIONS.has(cliOption as CLI_OPTIONS) && !allowedOptions.has(cliOption)) { - console.error(`${chalk.bgRed.black('\u2009ERROR\u2009')} ${chalk.red(`Unknown option '${cliOption}'`)}`) - console.log(`For help, run: pnpm help ${cmd}`) - process.exit(1) - return - } - } - let config!: Config & { forceSharedLockfile?: boolean, argv?: { remain: string[], cooked: string[], original: string[] } } try { config = await getConfig(cliConf, { @@ -474,7 +498,25 @@ export default async function run (inputArgv: string[]) { } } - const selfUpdate = config.global && (cmd === 'install' || cmd === 'update') && argv.remain.includes(packageManager.name) + if (cmd === 'install' && cliArgs.length > 0) { + cmd = 'add' + } else if (subCmd === 'install' && cliArgs.length > 1) { + subCmd = 'add' + } + + const allowedOptions = !subCmd + ? SUPPORTED_CLI_OPTIONS[cmd] + : new Set([...Array.from(SUPPORTED_CLI_OPTIONS[cmd]), ...Array.from(SUPPORTED_CLI_OPTIONS[subCmd])]) + for (const cliOption of Object.keys(cliConf)) { + if (!GLOBAL_OPTIONS.has(cliOption as CLI_OPTIONS) && !allowedOptions.has(cliOption)) { + console.error(`${chalk.bgRed.black('\u2009ERROR\u2009')} ${chalk.red(`Unknown option '${cliOption}'`)}`) + console.log(`For help, run: pnpm help ${cmd}`) + process.exit(1) + return + } + } + + const selfUpdate = config.global && (cmd === 'add' || cmd === 'update') && argv.remain.includes(packageManager.name) // Don't check for updates // 1. on CI environments