|
1 | 1 | import { Commands } from '../../constants/Commands';
|
2 | 2 | import { Notifications } from '../dataType/Notifications';
|
3 | 3 | import { execSync } from 'child_process';
|
4 |
| -import { commands, ProgressLocation, window } from 'vscode'; |
| 4 | +import { commands, ProgressLocation, window, Uri } from 'vscode'; |
| 5 | +import * as os from 'os'; |
5 | 6 | import { Logger } from '../dataType/Logger';
|
6 | 7 | import { NpmLs, Subscription } from '../../models';
|
7 | 8 | import { TerminalCommandExecuter } from '../executeWrappers/TerminalCommandExecuter';
|
@@ -33,28 +34,49 @@ export class Dependencies {
|
33 | 34 | await window.withProgress({
|
34 | 35 | location: ProgressLocation.Notification,
|
35 | 36 | cancellable: false,
|
36 |
| - title: 'Checking dependencies', |
| 37 | + title: 'Validating local setup', |
37 | 38 | }, async (progress) => {
|
38 | 39 | return new Promise((resolve) => {
|
39 | 40 | setTimeout(() => {
|
40 | 41 | try {
|
41 |
| - progress.report({ message: 'Checking node version...' }); |
| 42 | + progress.report({ message: 'Validating node version...' }); |
42 | 43 |
|
43 | 44 | // Validate node
|
44 | 45 | const isNodeValid = Dependencies.isValidNodeJs();
|
45 | 46 | if (!isNodeValid) {
|
46 |
| - Notifications.warning('Your Node.js version is not supported with SPFx development. Make sure you are using version: >=22.14.0 and <23.0.0'); |
| 47 | + const installNodeJSOption = 'Install Node.js'; |
| 48 | + const useNvmOption = os.platform() === 'win32' ? 'Use NVM for Windows' : 'Use NVM'; |
| 49 | + const useNvsOption = 'Use NVS'; |
| 50 | + |
| 51 | + Notifications.warning( |
| 52 | + 'Your Node.js version is not supported with SPFx development. Make sure you are using version: >=22.14.0 and <23.0.0', |
| 53 | + installNodeJSOption, |
| 54 | + useNvmOption, |
| 55 | + useNvsOption |
| 56 | + ).then((selectedOption) => { |
| 57 | + if (selectedOption === installNodeJSOption) { |
| 58 | + commands.executeCommand('vscode.open', Uri.parse('https://nodejs.org/en/download/')); |
| 59 | + } else if (selectedOption === useNvmOption) { |
| 60 | + const nvmInstallUrl = os.platform() === 'win32' |
| 61 | + ? 'https://github.com/coreybutler/nvm-windows?tab=readme-ov-file#overview' |
| 62 | + : 'https://github.com/nvm-sh/nvm?tab=readme-ov-file#intro'; |
| 63 | + commands.executeCommand('vscode.open', Uri.parse(nvmInstallUrl)); |
| 64 | + } else if (selectedOption === useNvsOption) { |
| 65 | + const nvsInstallUrl = 'https://github.com/jasongin/nvs?tab=readme-ov-file#nvs-node-version-switcher'; |
| 66 | + commands.executeCommand('vscode.open', Uri.parse(nvsInstallUrl)); |
| 67 | + } |
| 68 | + }); |
47 | 69 | resolve(null);
|
48 | 70 | return;
|
49 | 71 | }
|
50 | 72 |
|
51 |
| - progress.report({ message: 'Checking npm dependencies...' }); |
| 73 | + progress.report({ message: 'Validating npm dependencies...' }); |
52 | 74 |
|
53 | 75 | const command = 'npm list -g --json --silent';
|
54 | 76 | const result = execSync(command, { shell: TerminalCommandExecuter.shell, timeout: 15000 });
|
55 | 77 |
|
56 | 78 | if (!result) {
|
57 |
| - Notifications.error('Failed checking dependencies'); |
| 79 | + Notifications.error('Failed validating local setup'); |
58 | 80 | }
|
59 | 81 |
|
60 | 82 | // Check for missing dependencies
|
@@ -82,7 +104,7 @@ export class Dependencies {
|
82 | 104 | }
|
83 | 105 | resolve(null);
|
84 | 106 | } catch (e) {
|
85 |
| - Notifications.error('Failed checking dependencies'); |
| 107 | + Notifications.error('Failed validating local setup'); |
86 | 108 | Logger.error(`${(e as Error).message}`);
|
87 | 109 | resolve(null);
|
88 | 110 | }
|
|
0 commit comments