From 1168d094685f5a130ac170cd3bf48c5a42c596be Mon Sep 17 00:00:00 2001 From: ghe Date: Fri, 19 Jun 2020 16:35:08 +0100 Subject: [PATCH] feat: throw if using workspaces with disallowed options --- src/cli/index.ts | 30 ++++++++++++++++++++++++++++ test/acceptance/cli-args.test.ts | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/cli/index.ts b/src/cli/index.ts index 79a800949a4..75d382b802c 100755 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -241,24 +241,54 @@ async function main() { 'all-projects', ]); } + + if (args.options['project-name'] && args.options.yarnWorkspaces) { + throw new UnsupportedOptionCombinationError([ + 'project-name', + 'yarn-workspaces', + ]); + } + + if (args.options.file && args.options.yarnWorkspaces) { + throw new UnsupportedOptionCombinationError(['file', 'all-projects']); + } + if (args.options.file && args.options.allProjects) { throw new UnsupportedOptionCombinationError(['file', 'all-projects']); } + if (args.options.yarnWorkspaces && args.options.allProjects) { throw new UnsupportedOptionCombinationError([ 'yarn-workspaces', 'all-projects', ]); } + + if (args.options.packageManager && args.options.yarnWorkspaces) { + throw new UnsupportedOptionCombinationError([ + 'package-manager', + 'yarn-workspaces', + ]); + } + if (args.options.packageManager && args.options.allProjects) { throw new UnsupportedOptionCombinationError([ 'package-manager', 'all-projects', ]); } + if (args.options.docker && args.options.allProjects) { throw new UnsupportedOptionCombinationError(['docker', 'all-projects']); } + + if (args.options.allSubProjects && args.options.yarnWorkspaces) { + throw new UnsupportedOptionCombinationError([ + 'all-sub-projects', + 'yarn-workspaces', + ]); + } + if (args.options.allSubProjects && args.options.allProjects) { throw new UnsupportedOptionCombinationError([ 'all-sub-projects', diff --git a/test/acceptance/cli-args.test.ts b/test/acceptance/cli-args.test.ts index f637226d83d..23781bdf71a 100644 --- a/test/acceptance/cli-args.test.ts +++ b/test/acceptance/cli-args.test.ts @@ -114,6 +114,40 @@ test('`test --file=blah --scan-all-unmanaged`', (t) => { }); }); +const argsNotAllowedWithYarnWorkspaces = [ + 'file', + 'package-manager', + 'project-name', + 'docker', + 'all-sub-projects', + 'all-projects', +]; + +argsNotAllowedWithYarnWorkspaces.forEach((arg) => { + test(`using --${arg} and --yarn-workspaces displays error message`, (t) => { + t.plan(2); + exec(`node ${main} test --${arg} --yarn-workspaces`, (err, stdout) => { + if (err) { + throw err; + } + t.match( + stdout.trim(), + `The following option combination is not currently supported: ${arg} + all-projects`, + 'when using test', + ); + }); + exec(`node ${main} monitor --${arg} --yarn-workspaces`, (err, stdout) => { + if (err) { + throw err; + } + t.match( + stdout.trim(), + `The following option combination is not currently supported: ${arg} + all-projects`, + 'when using monitor', + ); + }); + }); +}); const argsNotAllowedWithAllProjects = [ 'file', 'package-manager',