|
1 | | -import { |
2 | | - getNxWorkspacePath, |
3 | | - GlobalConfigurationStore, |
4 | | -} from '@nx-console/vscode/configuration'; |
5 | | -import { getNxWorkspace } from '@nx-console/vscode/nx-workspace'; |
| 1 | +import { GlobalConfigurationStore } from '@nx-console/vscode/configuration'; |
| 2 | +import { onWorkspaceRefreshed } from '@nx-console/vscode/lsp-client'; |
| 3 | +import { CliTaskProvider } from '@nx-console/vscode/tasks'; |
6 | 4 | import { |
7 | 5 | AbstractTreeProvider, |
8 | | - getShellExecutionForConfig, |
9 | 6 | logAndShowTaskCreationError, |
10 | 7 | } from '@nx-console/vscode/utils'; |
11 | | -import { commands, ExtensionContext, Task, tasks, TaskScope } from 'vscode'; |
| 8 | +import { commands, ExtensionContext } from 'vscode'; |
12 | 9 | import { NxCommandConfig, NxCommandsTreeItem } from './nx-commands-tree-item'; |
13 | | -import { onWorkspaceRefreshed } from '@nx-console/vscode/lsp-client'; |
14 | | -import { importNxPackagePath } from '@nx-console/shared/npm'; |
15 | 10 |
|
16 | 11 | export const EXECUTE_ARBITRARY_COMMAND = 'nxConsole.executeArbitraryCommand'; |
17 | 12 |
|
@@ -77,31 +72,29 @@ export class NxCommandsTreeProvider extends AbstractTreeProvider<NxCommandsTreeI |
77 | 72 | } |
78 | 73 |
|
79 | 74 | async executeArbitraryCommand(command: string) { |
80 | | - const prefixedCommand = command.startsWith('nx ') |
81 | | - ? command |
82 | | - : `nx ${command}`; |
83 | | - const workspacePath = getNxWorkspacePath(); |
84 | | - const isEncapsulatedNx = |
85 | | - (await getNxWorkspace())?.isEncapsulatedNx ?? false; |
86 | | - const { detectPackageManager } = await importNxPackagePath< |
87 | | - typeof import('nx/src/devkit-exports') |
88 | | - >(workspacePath, 'src/devkit-exports'); |
89 | | - const pkgManager = detectPackageManager(workspacePath); |
| 75 | + let _command: string; |
| 76 | + let positional: string | undefined; |
| 77 | + |
| 78 | + const commandBeforeFlags = command.split(' -')[0]; |
| 79 | + if (commandBeforeFlags.includes(' ')) { |
| 80 | + _command = commandBeforeFlags.split(' ')[0]; |
| 81 | + positional = commandBeforeFlags.replace(_command, '').trim(); |
| 82 | + } else { |
| 83 | + _command = commandBeforeFlags; |
| 84 | + positional = undefined; |
| 85 | + } |
| 86 | + |
| 87 | + const flags = command |
| 88 | + .replace(commandBeforeFlags, '') |
| 89 | + .split(' ') |
| 90 | + .filter(Boolean); |
90 | 91 |
|
91 | 92 | try { |
92 | | - const task = new Task( |
93 | | - { type: 'nx' }, |
94 | | - TaskScope.Workspace, |
95 | | - prefixedCommand, |
96 | | - pkgManager, |
97 | | - await getShellExecutionForConfig({ |
98 | | - cwd: workspacePath, |
99 | | - displayCommand: prefixedCommand, |
100 | | - encapsulatedNx: isEncapsulatedNx, |
101 | | - workspacePath, |
102 | | - }) |
103 | | - ); |
104 | | - tasks.executeTask(task); |
| 93 | + CliTaskProvider.instance.executeTask({ |
| 94 | + command: _command, |
| 95 | + positional, |
| 96 | + flags, |
| 97 | + }); |
105 | 98 | } catch (e) { |
106 | 99 | logAndShowTaskCreationError(e); |
107 | 100 | return; |
|
0 commit comments