Skip to content

Commit 2a980c3

Browse files
win!: update supported vs versions
Drop VS2017 support for Node.js v22 and above. Refs: nodejs/build#3603 Refs: nodejs/node#45427
1 parent 3298731 commit 2a980c3

File tree

2 files changed

+114
-41
lines changed

2 files changed

+114
-41
lines changed

lib/find-visualstudio.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class VisualStudioFinder {
5454
}
5555

5656
const checks = [
57-
() => this.findVisualStudio2017OrNewer(),
57+
() => this.findVisualStudio2019OrNewer(),
58+
() => this.findVisualStudio2017(),
5859
() => this.findVisualStudio2015(),
5960
() => this.findVisualStudio2013()
6061
]
@@ -113,9 +114,25 @@ class VisualStudioFinder {
113114
throw new Error('Could not find any Visual Studio installation to use')
114115
}
115116

117+
// Invoke the PowerShell script to get information about Visual Studio 2019
118+
// or newer installations
119+
async findVisualStudio2019OrNewer () {
120+
return this.findNewVS([2019, 2022])
121+
}
122+
123+
// Invoke the PowerShell script to get information about Visual Studio 2017
124+
async findVisualStudio2017 () {
125+
if (this.nodeSemver.major >= 22) {
126+
this.addLog(
127+
'not looking for VS2017 as it is only supported up to Node.js 21')
128+
return null
129+
}
130+
return this.findNewVS([2017])
131+
}
132+
116133
// Invoke the PowerShell script to get information about Visual Studio 2017
117134
// or newer installations
118-
async findVisualStudio2017OrNewer () {
135+
async findNewVS (supportedYears) {
119136
const ps = path.join(process.env.SystemRoot, 'System32',
120137
'WindowsPowerShell', 'v1.0', 'powershell.exe')
121138
const csFile = path.join(__dirname, 'Find-VisualStudio.cs')
@@ -129,12 +146,12 @@ class VisualStudioFinder {
129146

130147
this.log.silly('Running', ps, psArgs)
131148
const [err, stdout, stderr] = await execFile(ps, psArgs, { encoding: 'utf8' })
132-
return this.parseData(err, stdout, stderr)
149+
return this.parseData(err, stdout, stderr, supportedYears)
133150
}
134151

135152
// Parse the output of the PowerShell script and look for an installation
136153
// of Visual Studio 2017 or newer to use
137-
parseData (err, stdout, stderr) {
154+
parseData (err, stdout, stderr, supportedYears) {
138155
this.log.silly('PS stderr = %j', stderr)
139156

140157
const failPowershell = () => {
@@ -175,11 +192,12 @@ class VisualStudioFinder {
175192
this.log.silly('vsInfo:', vsInfo)
176193

177194
// Remove future versions or errors parsing version number
195+
// Also remove any unsupported versions
178196
vsInfo = vsInfo.filter((info) => {
179-
if (info.versionYear) {
197+
if (info.versionYear && supportedYears.indexOf(info.versionYear) !== -1) {
180198
return true
181199
}
182-
this.addLog(`unknown version "${info.version}" found at "${info.path}"`)
200+
this.addLog(`${info.versionYear ? 'unsupported' : 'unknown'} version "${info.version}" found at "${info.path}"`)
183201
return false
184202
})
185203

test/test-find-visualstudio.js

Lines changed: 90 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ describe('find-visualstudio', function () {
2525
it('VS2013', async function () {
2626
const finder = new TestVisualStudioFinder(semverV1, null)
2727

28-
finder.findVisualStudio2017OrNewer = async () => {
29-
return finder.parseData(new Error(), '', '')
28+
finder.findVisualStudio2017 = async () => {
29+
return finder.parseData(new Error(), '', '', [2017])
30+
}
31+
finder.findVisualStudio2019OrNewer = async () => {
32+
return finder.parseData(new Error(), '', '', [2019, 2022])
3033
}
3134
finder.regSearchKeys = async (keys, value, addOpts) => {
3235
for (let i = 0; i < keys.length; ++i) {
@@ -69,10 +72,15 @@ describe('find-visualstudio', function () {
6972
patch: 0
7073
}, null)
7174

72-
finder.findVisualStudio2017OrNewer = async () => {
75+
finder.findVisualStudio2017 = async () => {
7376
const file = path.join(__dirname, 'fixtures', 'VS_2017_Unusable.txt')
7477
const data = fs.readFileSync(file)
75-
return finder.parseData(null, data, '')
78+
return finder.parseData(null, data, '', [2017])
79+
}
80+
finder.findVisualStudio2019OrNewer = async () => {
81+
const file = path.join(__dirname, 'fixtures', 'VS_2017_Unusable.txt')
82+
const data = fs.readFileSync(file)
83+
return finder.parseData(null, data, '', [2019, 2022])
7684
}
7785
finder.regSearchKeys = async (keys, value, addOpts) => {
7886
for (let i = 0; i < keys.length; ++i) {
@@ -96,8 +104,11 @@ describe('find-visualstudio', function () {
96104
it('VS2015', async function () {
97105
const finder = new TestVisualStudioFinder(semverV1, null)
98106

99-
finder.findVisualStudio2017OrNewer = async () => {
100-
return finder.parseData(new Error(), '', '')
107+
finder.findVisualStudio2017 = async () => {
108+
return finder.parseData(new Error(), '', '', [2017])
109+
}
110+
finder.findVisualStudio2019OrNewer = async () => {
111+
return finder.parseData(new Error(), '', '', [2019, 2022])
101112
}
102113
finder.regSearchKeys = async (keys, value, addOpts) => {
103114
for (let i = 0; i < keys.length; ++i) {
@@ -132,7 +143,7 @@ describe('find-visualstudio', function () {
132143
it('error from PowerShell', async function () {
133144
const finder = new TestVisualStudioFinder(semverV1, null, null)
134145

135-
finder.parseData(new Error(), '', '', (info) => {
146+
finder.parseData(new Error(), '', '', [], (info) => {
136147
assert.ok(/use PowerShell/i.test(finder.errorLog[0]), 'expect error')
137148
assert.ok(!info, 'no data')
138149
})
@@ -141,7 +152,7 @@ describe('find-visualstudio', function () {
141152
it('empty output from PowerShell', async function () {
142153
const finder = new TestVisualStudioFinder(semverV1, null, null)
143154

144-
finder.parseData(null, '', '', (info) => {
155+
finder.parseData(null, '', '', [], (info) => {
145156
assert.ok(/use PowerShell/i.test(finder.errorLog[0]), 'expect error')
146157
assert.ok(!info, 'no data')
147158
})
@@ -150,7 +161,7 @@ describe('find-visualstudio', function () {
150161
it('output from PowerShell not JSON', async function () {
151162
const finder = new TestVisualStudioFinder(semverV1, null, null)
152163

153-
finder.parseData(null, 'AAAABBBB', '', (info) => {
164+
finder.parseData(null, 'AAAABBBB', '', [], (info) => {
154165
assert.ok(/use PowerShell/i.test(finder.errorLog[0]), 'expect error')
155166
assert.ok(!info, 'no data')
156167
})
@@ -159,7 +170,7 @@ describe('find-visualstudio', function () {
159170
it('wrong JSON from PowerShell', async function () {
160171
const finder = new TestVisualStudioFinder(semverV1, null, null)
161172

162-
finder.parseData(null, '{}', '', (info) => {
173+
finder.parseData(null, '{}', '', [], (info) => {
163174
assert.ok(/use PowerShell/i.test(finder.errorLog[0]), 'expect error')
164175
assert.ok(!info, 'no data')
165176
})
@@ -168,7 +179,7 @@ describe('find-visualstudio', function () {
168179
it('empty JSON from PowerShell', async function () {
169180
const finder = new TestVisualStudioFinder(semverV1, null, null)
170181

171-
finder.parseData(null, '[]', '', (info) => {
182+
finder.parseData(null, '[]', '', [], (info) => {
172183
assert.ok(/find .* Visual Studio/i.test(finder.errorLog[0]), 'expect error')
173184
assert.ok(!info, 'no data')
174185
})
@@ -185,7 +196,7 @@ describe('find-visualstudio', function () {
185196
],
186197
path: 'C:\\VS',
187198
version: '9999.9999.9999.9999'
188-
}]), '', (info) => {
199+
}]), '', [2017, 2019, 2022], (info) => {
189200
assert.ok(/unknown version/i.test(finder.errorLog[0]), 'expect error')
190201
assert.ok(/find .* Visual Studio/i.test(finder.errorLog[1]), 'expect error')
191202
assert.ok(!info, 'no data')
@@ -197,7 +208,7 @@ describe('find-visualstudio', function () {
197208

198209
const file = path.join(__dirname, 'fixtures', 'VS_2017_Unusable.txt')
199210
const data = fs.readFileSync(file)
200-
finder.parseData(null, data, '', (info) => {
211+
finder.parseData(null, data, '', [2017, 2019, 2022], (info) => {
201212
assert.ok(/checking/i.test(finder.errorLog[0]), 'expect error')
202213
assert.ok(/find .* Visual Studio/i.test(finder.errorLog[2]), 'expect error')
203214
assert.ok(!info, 'no data')
@@ -208,11 +219,17 @@ describe('find-visualstudio', function () {
208219
const finder = new TestVisualStudioFinder(semverV1, null)
209220

210221
poison(finder, 'regSearchKeys')
211-
finder.findVisualStudio2017OrNewer = async () => {
222+
finder.findVisualStudio2017 = async () => {
212223
const file = path.join(__dirname, 'fixtures',
213224
'VS_2017_BuildTools_minimal.txt')
214225
const data = fs.readFileSync(file)
215-
return finder.parseData(null, data, '')
226+
return finder.parseData(null, data, '', [2017])
227+
}
228+
finder.findVisualStudio2019OrNewer = async () => {
229+
const file = path.join(__dirname, 'fixtures',
230+
'VS_2017_BuildTools_minimal.txt')
231+
const data = fs.readFileSync(file)
232+
return finder.parseData(null, data, '', [2019, 2022])
216233
}
217234
const { err, info } = await finder.findVisualStudio()
218235
assert.strictEqual(err, null)
@@ -234,11 +251,17 @@ describe('find-visualstudio', function () {
234251
const finder = new TestVisualStudioFinder(semverV1, null)
235252

236253
poison(finder, 'regSearchKeys')
237-
finder.findVisualStudio2017OrNewer = async () => {
254+
finder.findVisualStudio2017 = async () => {
238255
const file = path.join(__dirname, 'fixtures',
239256
'VS_2017_Community_workload.txt')
240257
const data = fs.readFileSync(file)
241-
return finder.parseData(null, data, '')
258+
return finder.parseData(null, data, '', [2017])
259+
}
260+
finder.findVisualStudio2019OrNewer = async () => {
261+
const file = path.join(__dirname, 'fixtures',
262+
'VS_2017_Community_workload.txt')
263+
const data = fs.readFileSync(file)
264+
return finder.parseData(null, data, '', [2019, 2022])
242265
}
243266
const { err, info } = await finder.findVisualStudio()
244267
assert.strictEqual(err, null)
@@ -260,10 +283,15 @@ describe('find-visualstudio', function () {
260283
const finder = new TestVisualStudioFinder(semverV1, null)
261284

262285
poison(finder, 'regSearchKeys')
263-
finder.findVisualStudio2017OrNewer = async () => {
286+
finder.findVisualStudio2017 = async () => {
264287
const file = path.join(__dirname, 'fixtures', 'VS_2017_Express.txt')
265288
const data = fs.readFileSync(file)
266-
return finder.parseData(null, data, '')
289+
return finder.parseData(null, data, '', [2017])
290+
}
291+
finder.findVisualStudio2019OrNewer = async () => {
292+
const file = path.join(__dirname, 'fixtures', 'VS_2017_Express.txt')
293+
const data = fs.readFileSync(file)
294+
return finder.parseData(null, data, '', [2019, 2022])
267295
}
268296
const { err, info } = await finder.findVisualStudio()
269297
assert.strictEqual(err, null)
@@ -285,11 +313,17 @@ describe('find-visualstudio', function () {
285313
const finder = new TestVisualStudioFinder(semverV1, null)
286314

287315
poison(finder, 'regSearchKeys')
288-
finder.findVisualStudio2017OrNewer = async () => {
316+
finder.findVisualStudio2017 = async () => {
289317
const file = path.join(__dirname, 'fixtures',
290318
'VS_2019_Preview.txt')
291319
const data = fs.readFileSync(file)
292-
return finder.parseData(null, data, '')
320+
return finder.parseData(null, data, '', [2017])
321+
}
322+
finder.findVisualStudio2019OrNewer = async () => {
323+
const file = path.join(__dirname, 'fixtures',
324+
'VS_2019_Preview.txt')
325+
const data = fs.readFileSync(file)
326+
return finder.parseData(null, data, '', [2019, 2022])
293327
}
294328
const { err, info } = await finder.findVisualStudio()
295329
assert.strictEqual(err, null)
@@ -311,11 +345,17 @@ describe('find-visualstudio', function () {
311345
const finder = new TestVisualStudioFinder(semverV1, null)
312346

313347
poison(finder, 'regSearchKeys')
314-
finder.findVisualStudio2017OrNewer = async () => {
348+
finder.findVisualStudio2017 = async () => {
349+
const file = path.join(__dirname, 'fixtures',
350+
'VS_2019_BuildTools_minimal.txt')
351+
const data = fs.readFileSync(file)
352+
return finder.parseData(null, data, '', [2017])
353+
}
354+
finder.findVisualStudio2019OrNewer = async () => {
315355
const file = path.join(__dirname, 'fixtures',
316356
'VS_2019_BuildTools_minimal.txt')
317357
const data = fs.readFileSync(file)
318-
return finder.parseData(null, data, '')
358+
return finder.parseData(null, data, '', [2019, 2022])
319359
}
320360
const { err, info } = await finder.findVisualStudio()
321361
assert.strictEqual(err, null)
@@ -337,11 +377,17 @@ describe('find-visualstudio', function () {
337377
const finder = new TestVisualStudioFinder(semverV1, null)
338378

339379
poison(finder, 'regSearchKeys')
340-
finder.findVisualStudio2017OrNewer = async () => {
380+
finder.findVisualStudio2017 = async () => {
381+
const file = path.join(__dirname, 'fixtures',
382+
'VS_2019_Community_workload.txt')
383+
const data = fs.readFileSync(file)
384+
return finder.parseData(null, data, '', [2017])
385+
}
386+
finder.findVisualStudio2019OrNewer = async () => {
341387
const file = path.join(__dirname, 'fixtures',
342388
'VS_2019_Community_workload.txt')
343389
const data = fs.readFileSync(file)
344-
return finder.parseData(null, data, '')
390+
return finder.parseData(null, data, '', [2019, 2022])
345391
}
346392
const { err, info } = await finder.findVisualStudio()
347393
assert.strictEqual(err, null)
@@ -372,11 +418,17 @@ describe('find-visualstudio', function () {
372418
finder.msBuildPathExists = (path) => {
373419
return true
374420
}
375-
finder.findVisualStudio2017OrNewer = async () => {
421+
finder.findVisualStudio2017 = async () => {
376422
const file = path.join(__dirname, 'fixtures',
377423
'VS_2022_Community_workload.txt')
378424
const data = fs.readFileSync(file)
379-
return finder.parseData(null, data, '')
425+
return finder.parseData(null, data, '', [2017])
426+
}
427+
finder.findVisualStudio2019OrNewer = async () => {
428+
const file = path.join(__dirname, 'fixtures',
429+
'VS_2022_Community_workload.txt')
430+
const data = fs.readFileSync(file)
431+
return finder.parseData(null, data, '', [2019, 2022])
380432
}
381433
const { err, info } = await finder.findVisualStudio()
382434
assert.strictEqual(err, null)
@@ -394,7 +446,7 @@ describe('find-visualstudio', function () {
394446
})
395447

396448
function allVsVersions (finder) {
397-
finder.findVisualStudio2017OrNewer = async () => {
449+
finder.findVisualStudio2017 = async () => {
398450
const data0 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
399451
'VS_2017_Unusable.txt')))
400452
const data1 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
@@ -403,17 +455,20 @@ describe('find-visualstudio', function () {
403455
'VS_2017_Community_workload.txt')))
404456
const data3 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
405457
'VS_2017_Express.txt')))
406-
const data4 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
458+
const data = JSON.stringify(data0.concat(data1, data2, data3))
459+
return finder.parseData(null, data, '', [2017])
460+
}
461+
finder.findVisualStudio2019OrNewer = async () => {
462+
const data0 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
407463
'VS_2019_Preview.txt')))
408-
const data5 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
464+
const data1 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
409465
'VS_2019_BuildTools_minimal.txt')))
410-
const data6 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
466+
const data2 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
411467
'VS_2019_Community_workload.txt')))
412-
const data7 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
468+
const data3 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
413469
'VS_2022_Community_workload.txt')))
414-
const data = JSON.stringify(data0.concat(data1, data2, data3, data4,
415-
data5, data6, data7))
416-
return finder.parseData(null, data, '')
470+
const data = JSON.stringify(data0.concat(data1, data2, data3))
471+
return finder.parseData(null, data, '', [2019, 2022])
417472
}
418473
finder.regSearchKeys = async (keys, value, addOpts) => {
419474
for (let i = 0; i < keys.length; ++i) {

0 commit comments

Comments
 (0)