Skip to content

Commit 391cc5b

Browse files
win: update supported vs versions (#2959)
Drop VS2017 support for Node.js v22 and above. Refs: nodejs/build#3603 Refs: nodejs/node#45427
1 parent 109e3d4 commit 391cc5b

File tree

2 files changed

+142
-81
lines changed

2 files changed

+142
-81
lines changed

lib/find-visualstudio.js

+41-9
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ class VisualStudioFinder {
5454
}
5555

5656
const checks = [
57-
() => this.findVisualStudio2017OrNewerUsingSetupModule(),
58-
() => this.findVisualStudio2017OrNewer(),
57+
() => this.findVisualStudio2019OrNewerUsingSetupModule(),
58+
() => this.findVisualStudio2019OrNewer(),
59+
() => this.findVisualStudio2017UsingSetupModule(),
60+
() => this.findVisualStudio2017(),
5961
() => this.findVisualStudio2015(),
6062
() => this.findVisualStudio2013()
6163
]
@@ -114,7 +116,20 @@ class VisualStudioFinder {
114116
throw new Error('Could not find any Visual Studio installation to use')
115117
}
116118

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) {
118133
const ps = path.join(process.env.SystemRoot, 'System32',
119134
'WindowsPowerShell', 'v1.0', 'powershell.exe')
120135
const vcInstallDir = this.envVcInstallDir
@@ -157,12 +172,28 @@ class VisualStudioFinder {
157172
return info
158173
})
159174
// 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])
161192
}
162193

163194
// Invoke the PowerShell script to get information about Visual Studio 2017
164195
// or newer installations
165-
async findVisualStudio2017OrNewer () {
196+
async findNewVS (supportedYears) {
166197
const ps = path.join(process.env.SystemRoot, 'System32',
167198
'WindowsPowerShell', 'v1.0', 'powershell.exe')
168199
const csFile = path.join(__dirname, 'Find-VisualStudio.cs')
@@ -180,7 +211,7 @@ class VisualStudioFinder {
180211
if (parsedData === null) {
181212
return null
182213
}
183-
return this.processData(parsedData)
214+
return this.processData(parsedData, supportedYears)
184215
}
185216

186217
// Parse the output of the PowerShell script, make sanity checks
@@ -224,7 +255,7 @@ class VisualStudioFinder {
224255

225256
// Process parsed data containing information about VS installations
226257
// Look for the required parts, extract and output them back
227-
processData (vsInfo) {
258+
processData (vsInfo, supportedYears) {
228259
vsInfo = vsInfo.map((info) => {
229260
this.log.silly(`processing installation: "${info.path}"`)
230261
info.path = path.resolve(info.path)
@@ -238,11 +269,12 @@ class VisualStudioFinder {
238269
this.log.silly('vsInfo:', vsInfo)
239270

240271
// Remove future versions or errors parsing version number
272+
// Also remove any unsupported versions
241273
vsInfo = vsInfo.filter((info) => {
242-
if (info.versionYear) {
274+
if (info.versionYear && supportedYears.indexOf(info.versionYear) !== -1) {
243275
return true
244276
}
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}"`)
246278
return false
247279
})
248280

0 commit comments

Comments
 (0)