Skip to content

Commit c7827c7

Browse files
committed
rephrase messages, fix terminal profile issues
1 parent 07a512c commit c7827c7

File tree

2 files changed

+60
-63
lines changed

2 files changed

+60
-63
lines changed

src/services/actions/CliActions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ export class CliActions {
104104
const spfxVersion = SpfxCompatibilityMatrix.find(spfx => spfx.Version === sPFxCheck.version);
105105
const nodeCheck = Dependencies.isValidNodeJs(spfxVersion?.SupportedNodeVersions || []);
106106
if (!nodeCheck) {
107-
const installForSpecifiedVersion = `Yes, setup for v${sPFxCheck.version} SPFx version`;
107+
const installForSpecifiedVersion = `Yes, setup for SPFx v${sPFxCheck.version}`;
108108
const abortOption = 'No';
109109

110110
Notifications.warning(
111-
`Your Node version is not supported for v${sPFxCheck.version} SPFx version. Do you want to set up your environment for the v${sPFxCheck.version} SPFx version?`,
111+
`Your Node.js version is not compatible with SPFx v${sPFxCheck.version}. Do you want to set up your environment for SPFx v${sPFxCheck.version}?`,
112112
installForSpecifiedVersion,
113113
abortOption
114114
).then(selectedOption => {
@@ -123,11 +123,11 @@ export class CliActions {
123123
return;
124124
}
125125

126-
const installForSpecifiedVersion = `Yes, setup for v${sPFxCheck.version} SPFx version`;
126+
const installForSpecifiedVersion = `Yes, setup for SPFx v${sPFxCheck.version}`;
127127
const abortOption = 'No';
128128

129129
Notifications.warning(
130-
`The following dependencies are not set up correctly: ${notPassedChecks.map(c => c.check).join(', ')}. Do you want to set up your environment for the v${sPFxCheck.version} SPFx version?`,
130+
`The following dependencies are not set up correctly: ${notPassedChecks.map(c => c.check).join(', ')}. Do you want to set up your environment for SPFx v${sPFxCheck.version}?`,
131131
installForSpecifiedVersion,
132132
abortOption
133133
).then(selectedOption => {

src/services/actions/Dependencies.ts

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ export class Dependencies {
6161
return;
6262
}
6363

64+
const isValidNode = shouldValidateNode ? Dependencies.isValidNodeJs(spfxVersion.SupportedNodeVersions) : true;
65+
66+
let canProceedWithDependencyCheck = false;
67+
if (!isValidNode) {
68+
canProceedWithDependencyCheck = await Dependencies.HandleNotValidNodeVersion(spfxVersion.SupportedNodeVersions[spfxVersion.SupportedNodeVersions.length - 1], spfxVersion.SupportedNodeVersions, spfxVersion.Version);
69+
}
70+
71+
if (!isValidNode && !canProceedWithDependencyCheck) {
72+
return;
73+
}
74+
6475
await window.withProgress({
6576
location: ProgressLocation.Notification,
6677
cancellable: false,
@@ -69,28 +80,14 @@ export class Dependencies {
6980
return new Promise((resolve) => {
7081
setTimeout(async () => {
7182
try {
72-
progress.report({ message: 'Validating node version...' });
73-
const isValidNode = shouldValidateNode ? Dependencies.isValidNodeJs(spfxVersion.SupportedNodeVersions) : true;
74-
75-
let canProceedWithDependencyCheck = false;
76-
if (!isValidNode) {
77-
progress.report({ message: 'Node.js version not supported. Checking options...' });
78-
canProceedWithDependencyCheck = await Dependencies.HandleNotValidNodeVersion(spfxVersion.SupportedNodeVersions[spfxVersion.SupportedNodeVersions.length - 1], spfxVersion.SupportedNodeVersions, spfxVersion.Version);
79-
}
80-
81-
if (isValidNode || canProceedWithDependencyCheck) {
82-
progress.report({ message: 'installing npm global dependencies...' });
83-
const dependencies = spfxVersion.Dependencies.map(dep => `${dep.Name}@${dep.InstallVersion}`).join(' ');
84-
Logger.info(`Installing dependencies: ${dependencies}`);
85-
86-
await TerminalCommandExecuter.runCommandAndWait(`npm install -g ${dependencies} @microsoft/generator-sharepoint@${spfxVersion.Version}`, 'Installing dependencies', 'cloud-download');
87-
} else {
88-
resolve(null);
89-
return;
90-
}
91-
92-
const releaseNotes = 'Check out the release notes';
93-
const learningPath = 'Go to Learning path';
83+
progress.report({ message: 'Installing dependencies...' });
84+
const dependencies = spfxVersion.Dependencies.map(dep => `${dep.Name}@${dep.InstallVersion}`).join(' ');
85+
Logger.info(`Installing dependencies: ${dependencies}`);
86+
87+
await TerminalCommandExecuter.runCommandAndWait(`npm install -g ${dependencies} @microsoft/generator-sharepoint@${spfxVersion.Version}`, 'Installing dependencies', 'cloud-download');
88+
89+
const releaseNotes = 'Release Notes';
90+
const learningPath = 'Learn SPFx';
9491
Notifications.info(
9592
`You are all set for SPFx v${spfxVersion.Version}!`,
9693
releaseNotes,
@@ -113,14 +110,32 @@ export class Dependencies {
113110
});
114111
}
115112

113+
/**
114+
* Gets the current installed Node.js version.
115+
* @returns The current Node.js version.
116+
*/
117+
public static getCurrentNodeVersion(): string | null {
118+
try {
119+
const output = execSync('node --version', { encoding: 'utf8' }).trim();
120+
return output;
121+
} catch (e) {
122+
Logger.error(`Failed to get current Node.js version: ${(e as Error).message}`);
123+
return null;
124+
}
125+
}
126+
116127
/**
117128
* Checks if the installed version of Node.js is valid.
118129
* @returns Returns true if the installed version of Node.js is valid, otherwise false.
119130
*/
120131
public static isValidNodeJs(SupportedNodeVersions: string[], NodeVersion: string | null = null): boolean {
121132
try {
122-
const output = NodeVersion ? `v${NodeVersion}` : execSync('node --version');
123-
const match = /v(?<major_version>\d+)\.(?<minor_version>\d+)\.(?<patch_version>\d+)/gm.exec(output.toString());
133+
const output = NodeVersion ? `v${NodeVersion}` : Dependencies.getCurrentNodeVersion();
134+
if (!output) {
135+
return false;
136+
}
137+
138+
const match = /v(?<major_version>\d+)\.(?<minor_version>\d+)\.(?<patch_version>\d+)/gm.exec(output);
124139

125140
Logger.info(`Node.js version: ${output}`);
126141

@@ -146,7 +161,7 @@ export class Dependencies {
146161

147162
return !!supported;
148163
} catch (e) {
149-
Logger.error(`Failed checking node version: ${(e as Error).message}`);
164+
Logger.error(`Failed to check Node.js version: ${(e as Error).message}`);
150165
return false;
151166
}
152167
}
@@ -155,22 +170,22 @@ export class Dependencies {
155170
* Handles the case when the Node.js version is not valid for SPFx development.
156171
* @param requiredNodeVersions - A string representing the required Node.js version(s) for SPFx development
157172
* @param supportedNodeVersions - An array of strings representing the supported Node.js versions for SPFx development
173+
* @param spfxVersion - The SPFx version being installed
158174
* @returns A boolean indicating whether the invalid Node.js version was successfully handled
159175
*/
160176
private static HandleNotValidNodeVersion(requiredNodeVersions: string, supportedNodeVersions: string[], spfxVersion: string): boolean {
161177
const nodeVersionManager = getExtensionSettings<string>('nodeVersionManager', 'none');
162178
const isWindows = os.platform() === 'win32';
179+
const currentNodeVersion = Dependencies.getCurrentNodeVersion();
163180

164181
if (nodeVersionManager === NodeVersionManagers.none) {
165-
const installNodeJSOption = 'Install Node.js';
166-
const useNvmOption = isWindows ? 'Use NVM for Windows' : 'Use NVM';
167-
const useNvsOption = 'Use NVS';
182+
const installNodeJSOption = 'Download Node.js';
183+
const useNvmOption = isWindows ? 'Install NVM for Windows' : 'Install NVM';
184+
const useNvsOption = 'Install NVS';
168185

169186
Notifications.warning(
170-
`Node.js v${requiredNodeVersions} is not supported for SPFx ${spfxVersion}.
171-
It is recommended to use a Node Version Manager to handle multiple Node.js versions
172-
and set SPFx Toolkit setting with your preferred Node Version Manager.
173-
Please select one of the options below to get help on installing or updating your Node.js version.`,
187+
`Node.js ${currentNodeVersion} is incompatible with SPFx v${spfxVersion}. Required: ${requiredNodeVersions}.
188+
It is recommended to use a Node Version Manager and update the SPFx Toolkit setting (File > Preferences > Settings > search "Node Version Manager").`,
174189
installNodeJSOption,
175190
useNvmOption,
176191
useNvsOption
@@ -191,40 +206,22 @@ export class Dependencies {
191206
} else if (nodeVersionManager === NodeVersionManagers.nvm || nodeVersionManager === NodeVersionManagers.nvs) {
192207
let useNodeVersionOption: string = '';
193208
const requiredNodeVersionToInstall = requiredNodeVersions.replace(/x/g, '0');
209+
194210
if (nodeVersionManager === NodeVersionManagers.nvm) {
195-
const nvmListCommand = isWindows ? 'list' : 'ls --no-alias';
196-
const nodeVersions = execSync(`nvm ${nvmListCommand}`);
197-
const versions = isWindows ?
198-
nodeVersions.toString().split('\n').map(v => v.trim().replace(/^\*?\s*/, '').replace(/\s*\(.*\)$/, '').trim()).filter(v => v && /^\d+\.\d+\.\d+$/.test(v))
199-
: nodeVersions.toString().split('\n').map(v => v.trim().replace(/^(\*|->)?\s*/, '').replace(/\s*\(.*\)$/, '').replace(/^v/, '').trim()).filter(v => v && /^\d+\.\d+\.\d+$/.test(v));
200-
const firstNodeValidVersion = versions.find(v => Dependencies.isValidNodeJs(supportedNodeVersions, v))?.replace(/x/g, '0');
201-
202-
const nvmUseCommand = `nvm use ${firstNodeValidVersion}`;
203-
const nvmInstallAndUseCommand = `nvm install ${requiredNodeVersionToInstall} && nvm use ${requiredNodeVersionToInstall}`;
204-
useNodeVersionOption = firstNodeValidVersion ? nvmUseCommand : nvmInstallAndUseCommand;
211+
useNodeVersionOption = `nvm install ${requiredNodeVersionToInstall} && nvm use ${requiredNodeVersionToInstall}`;
205212
} else {
206-
const nodeVersions = execSync('nvs list');
207-
const versions = nodeVersions.toString().split('\n').map(v => {
208-
const match = /node\/(\d+\.\d+\.\d+)/.exec(v.trim());
209-
return match ? match[1] : '';
210-
}).filter(v => v);
211-
const firstNodeValidVersion = versions.find(v => Dependencies.isValidNodeJs(supportedNodeVersions, v))?.replace(/x/g, '0');
212-
213-
const nvsUseCommand = `nvs use ${firstNodeValidVersion}`;
214-
const nvsInstallAndUseCommand = `nvs add ${requiredNodeVersionToInstall} && nvs use ${requiredNodeVersionToInstall}`;
215-
useNodeVersionOption = firstNodeValidVersion ? nvsUseCommand : nvsInstallAndUseCommand;
213+
useNodeVersionOption = `nvs add ${requiredNodeVersionToInstall} && nvs use ${requiredNodeVersionToInstall}`;
216214
}
217215

218-
const abortOption = 'I will handle it myself';
216+
const abortOption = 'I will handle it manually';
217+
const switchVersionButton = 'Switch to compatible Node.js version';
219218
const output = Notifications.warning(
220-
`Your Node.js version is not supported with SPFx development. Make sure you are using version: v${requiredNodeVersions}.
221-
It looks like you are using ${nodeVersionManager === NodeVersionManagers.nvm ? 'NVM' : 'NVS'}. You can use the command '${useNodeVersionOption}' to set the correct Node.js version for SPFx development.
222-
Please select one of the options below to get help on installing or updating your Node.js version.`,
223-
useNodeVersionOption,
219+
`Node.js ${currentNodeVersion} is incompatible with SPFx v${spfxVersion}. Need Node.js ${requiredNodeVersions}.`,
220+
switchVersionButton,
224221
abortOption
225222
).then(async (selectedOption): Promise<boolean> => {
226-
if (selectedOption === useNodeVersionOption) {
227-
await TerminalCommandExecuter.runCommandAndWait(useNodeVersionOption, 'Installing Node.js version', 'cloud-download');
223+
if (selectedOption === switchVersionButton) {
224+
await TerminalCommandExecuter.runCommandAndWait(useNodeVersionOption, 'Switching Node.js version', 'cloud-download');
228225
return true;
229226
} else if (selectedOption === abortOption) {
230227
return false;

0 commit comments

Comments
 (0)