@@ -54,8 +54,10 @@ class VisualStudioFinder {
54
54
}
55
55
56
56
const checks = [
57
- ( ) => this . findVisualStudio2017OrNewerUsingSetupModule ( ) ,
58
- ( ) => this . findVisualStudio2017OrNewer ( ) ,
57
+ ( ) => this . findVisualStudio2019OrNewerUsingSetupModule ( ) ,
58
+ ( ) => this . findVisualStudio2019OrNewer ( ) ,
59
+ ( ) => this . findVisualStudio2017UsingSetupModule ( ) ,
60
+ ( ) => this . findVisualStudio2017 ( ) ,
59
61
( ) => this . findVisualStudio2015 ( ) ,
60
62
( ) => this . findVisualStudio2013 ( )
61
63
]
@@ -114,7 +116,20 @@ class VisualStudioFinder {
114
116
throw new Error ( 'Could not find any Visual Studio installation to use' )
115
117
}
116
118
117
- async findVisualStudio2017OrNewerUsingSetupModule ( ) {
119
+ async findVisualStudio2019OrNewerUsingSetupModule ( ) {
120
+ return this . findNewVSUsingSetupModule ( [ 2019 , 2022 ] )
121
+ }
122
+
123
+ async findVisualStudio2017UsingSetupModule ( ) {
124
+ if ( this . nodeSemver . major >= 22 ) {
125
+ this . addLog (
126
+ 'not looking for VS2017 as it is only supported up to Node.js 21' )
127
+ return null
128
+ }
129
+ return this . findNewVSUsingSetupModule ( [ 2017 ] )
130
+ }
131
+
132
+ async findNewVSUsingSetupModule ( supportedYears ) {
118
133
const ps = path . join ( process . env . SystemRoot , 'System32' ,
119
134
'WindowsPowerShell' , 'v1.0' , 'powershell.exe' )
120
135
const vcInstallDir = this . envVcInstallDir
@@ -157,12 +172,28 @@ class VisualStudioFinder {
157
172
return info
158
173
} )
159
174
// pass for further processing
160
- return this . processData ( parsedData )
175
+ return this . processData ( parsedData , supportedYears )
176
+ }
177
+
178
+ // Invoke the PowerShell script to get information about Visual Studio 2019
179
+ // or newer installations
180
+ async findVisualStudio2019OrNewer ( ) {
181
+ return this . findNewVS ( [ 2019 , 2022 ] )
182
+ }
183
+
184
+ // Invoke the PowerShell script to get information about Visual Studio 2017
185
+ async findVisualStudio2017 ( ) {
186
+ if ( this . nodeSemver . major >= 22 ) {
187
+ this . addLog (
188
+ 'not looking for VS2017 as it is only supported up to Node.js 21' )
189
+ return null
190
+ }
191
+ return this . findNewVS ( [ 2017 ] )
161
192
}
162
193
163
194
// Invoke the PowerShell script to get information about Visual Studio 2017
164
195
// or newer installations
165
- async findVisualStudio2017OrNewer ( ) {
196
+ async findNewVS ( supportedYears ) {
166
197
const ps = path . join ( process . env . SystemRoot , 'System32' ,
167
198
'WindowsPowerShell' , 'v1.0' , 'powershell.exe' )
168
199
const csFile = path . join ( __dirname , 'Find-VisualStudio.cs' )
@@ -180,7 +211,7 @@ class VisualStudioFinder {
180
211
if ( parsedData === null ) {
181
212
return null
182
213
}
183
- return this . processData ( parsedData )
214
+ return this . processData ( parsedData , supportedYears )
184
215
}
185
216
186
217
// Parse the output of the PowerShell script, make sanity checks
@@ -224,7 +255,7 @@ class VisualStudioFinder {
224
255
225
256
// Process parsed data containing information about VS installations
226
257
// Look for the required parts, extract and output them back
227
- processData ( vsInfo ) {
258
+ processData ( vsInfo , supportedYears ) {
228
259
vsInfo = vsInfo . map ( ( info ) => {
229
260
this . log . silly ( `processing installation: "${ info . path } "` )
230
261
info . path = path . resolve ( info . path )
@@ -238,11 +269,12 @@ class VisualStudioFinder {
238
269
this . log . silly ( 'vsInfo:' , vsInfo )
239
270
240
271
// Remove future versions or errors parsing version number
272
+ // Also remove any unsupported versions
241
273
vsInfo = vsInfo . filter ( ( info ) => {
242
- if ( info . versionYear ) {
274
+ if ( info . versionYear && supportedYears . indexOf ( info . versionYear ) !== - 1 ) {
243
275
return true
244
276
}
245
- this . addLog ( `unknown version "${ info . version } " found at "${ info . path } "` )
277
+ this . addLog ( `${ info . versionYear ? 'unsupported' : ' unknown' } version "${ info . version } " found at "${ info . path } "` )
246
278
return false
247
279
} )
248
280
0 commit comments