diff --git a/libs/vscode/tasks/src/lib/nx-task-commands.ts b/libs/vscode/tasks/src/lib/nx-task-commands.ts index 3b8cecd90d..104481c23a 100644 --- a/libs/vscode/tasks/src/lib/nx-task-commands.ts +++ b/libs/vscode/tasks/src/lib/nx-task-commands.ts @@ -142,11 +142,6 @@ const AFFECTED_OPTIONS: Option[] = [ ].map((v) => ({ ...v, aliases: [] })); const RUN_MANY_OPTIONS: Option[] = [ - { - name: 'projects', - type: OptionType.Array, - description: 'Projects to run', - }, { name: 'all', type: OptionType.Boolean, description: 'All projects' }, { name: 'parallel', @@ -266,14 +261,28 @@ async function promptForRunMany() { return; } - const flags = await selectFlags('run-many', RUN_MANY_OPTIONS, 'nx'); + let options = RUN_MANY_OPTIONS; + const projects = validProjectsForTarget(target); + if (projects && projects.length) { + options = [ + { + name: 'projects', + type: OptionType.Array, + description: 'Projects to run', + aliases: [], + enum: projects, + }, + ...RUN_MANY_OPTIONS, + ]; + } + + const flags = await selectFlags('run-many', options, 'nx', { target }); if (flags !== undefined) { const task = NxTask.create( { command: 'run-many', flags, - positional: `--target=${target}`, }, cliTaskProvider.getWorkspacePath() ); @@ -324,3 +333,21 @@ async function promptForMigrate() { ); tasks.executeTask(task); } + +function validProjectsForTarget(target: string): string[] | undefined { + const { validWorkspaceJson, json } = verifyWorkspace(); + + if (!validWorkspaceJson || !json) { + return; + } + + return Array.from( + new Set( + Object.entries(json.projects) + .filter( + ([_, project]) => project.architect && project.architect[target] + ) + .map(([project]) => project) + ) + ).sort(); +} diff --git a/libs/vscode/tasks/src/lib/select-flags.ts b/libs/vscode/tasks/src/lib/select-flags.ts index 6362462058..26a0a5680f 100644 --- a/libs/vscode/tasks/src/lib/select-flags.ts +++ b/libs/vscode/tasks/src/lib/select-flags.ts @@ -23,7 +23,7 @@ export async function selectFlags( const flagValue = await promptForFlagValue(selection.flag); - if (flagValue) { + if (flagValue && flagValue.length > 0) { userSetFlags[selection.flag.flagName] = flagValue; } else { delete userSetFlags[selection.flag.flagName]; @@ -83,6 +83,7 @@ function promptForFlagValue(flagToSet: CliTaskFlagQuickPickItem) { } else if (flagToSet.option.enum && flagToSet.option.enum.length) { return window.showQuickPick([...flagToSet.option.enum.map(String)], { placeHolder, + canPickMany: flagToSet.option.type === 'array' }); } else { return window.showInputBox({