Skip to content

Commit

Permalink
fixup! win!: update supported vs versions
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanStojanovic committed Jan 16, 2024
1 parent 5f6d390 commit 69ed7ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
15 changes: 8 additions & 7 deletions lib/find-visualstudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class VisualStudioFinder {
// Invoke the PowerShell script to get information about Visual Studio 2019
// or newer installations
async findVisualStudio2019OrNewer () {
return this.findNewVS()
return this.findNewVS([2019, 2022])
}

// Invoke the PowerShell script to get information about Visual Studio 2017
Expand All @@ -127,12 +127,12 @@ class VisualStudioFinder {
'not looking for VS2017 as it is only supported up to Node.js 21')
return null
}
return this.findNewVS()
return this.findNewVS([2017])
}

// Invoke the PowerShell script to get information about Visual Studio 2017
// or newer installations
async findNewVS () {
async findNewVS (supportedYears) {
const ps = path.join(process.env.SystemRoot, 'System32',
'WindowsPowerShell', 'v1.0', 'powershell.exe')
const csFile = path.join(__dirname, 'Find-VisualStudio.cs')
Expand All @@ -146,12 +146,12 @@ class VisualStudioFinder {

this.log.silly('Running', ps, psArgs)
const [err, stdout, stderr] = await execFile(ps, psArgs, { encoding: 'utf8' })
return this.parseData(err, stdout, stderr)
return this.parseData(err, stdout, stderr, supportedYears)
}

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

const failPowershell = () => {
Expand Down Expand Up @@ -192,11 +192,12 @@ class VisualStudioFinder {
this.log.silly('vsInfo:', vsInfo)

// Remove future versions or errors parsing version number
// Also remove any unsupported versions
vsInfo = vsInfo.filter((info) => {
if (info.versionYear) {
if (info.versionYear && supportedYears.indexOf(info.versionYear) !== -1) {
return true
}
this.addLog(`unknown version "${info.version}" found at "${info.path}"`)
this.addLog(`${info.versionYear ? 'unsupported' : 'unknown'} version "${info.version}" found at "${info.path}"`)
return false
})

Expand Down
58 changes: 29 additions & 29 deletions test/test-find-visualstudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ describe('find-visualstudio', function () {
const finder = new TestVisualStudioFinder(semverV1, null)

finder.findVisualStudio2017 = async () => {
return finder.parseData(new Error(), '', '')
return finder.parseData(new Error(), '', '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
return finder.parseData(new Error(), '', '')
return finder.parseData(new Error(), '', '', [2019, 2022])
}
finder.regSearchKeys = async (keys, value, addOpts) => {
for (let i = 0; i < keys.length; ++i) {
Expand Down Expand Up @@ -75,12 +75,12 @@ describe('find-visualstudio', function () {
finder.findVisualStudio2017 = async () => {
const file = path.join(__dirname, 'fixtures', 'VS_2017_Unusable.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
const file = path.join(__dirname, 'fixtures', 'VS_2017_Unusable.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2019, 2022])
}
finder.regSearchKeys = async (keys, value, addOpts) => {
for (let i = 0; i < keys.length; ++i) {
Expand All @@ -105,10 +105,10 @@ describe('find-visualstudio', function () {
const finder = new TestVisualStudioFinder(semverV1, null)

finder.findVisualStudio2017 = async () => {
return finder.parseData(new Error(), '', '')
return finder.parseData(new Error(), '', '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
return finder.parseData(new Error(), '', '')
return finder.parseData(new Error(), '', '', [2019, 2022])
}
finder.regSearchKeys = async (keys, value, addOpts) => {
for (let i = 0; i < keys.length; ++i) {
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('find-visualstudio', function () {
it('error from PowerShell', async function () {
const finder = new TestVisualStudioFinder(semverV1, null, null)

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

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

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

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

finder.parseData(null, '[]', '', (info) => {
finder.parseData(null, '[]', '', [], (info) => {
assert.ok(/find .* Visual Studio/i.test(finder.errorLog[0]), 'expect error')
assert.ok(!info, 'no data')
})
Expand All @@ -196,7 +196,7 @@ describe('find-visualstudio', function () {
],
path: 'C:\\VS',
version: '9999.9999.9999.9999'
}]), '', (info) => {
}]), '', [2017, 2019, 2022], (info) => {
assert.ok(/unknown version/i.test(finder.errorLog[0]), 'expect error')
assert.ok(/find .* Visual Studio/i.test(finder.errorLog[1]), 'expect error')
assert.ok(!info, 'no data')
Expand All @@ -208,7 +208,7 @@ describe('find-visualstudio', function () {

const file = path.join(__dirname, 'fixtures', 'VS_2017_Unusable.txt')
const data = fs.readFileSync(file)
finder.parseData(null, data, '', (info) => {
finder.parseData(null, data, '', [2017, 2019, 2022], (info) => {
assert.ok(/checking/i.test(finder.errorLog[0]), 'expect error')
assert.ok(/find .* Visual Studio/i.test(finder.errorLog[2]), 'expect error')
assert.ok(!info, 'no data')
Expand All @@ -223,13 +223,13 @@ describe('find-visualstudio', function () {
const file = path.join(__dirname, 'fixtures',
'VS_2017_BuildTools_minimal.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
const file = path.join(__dirname, 'fixtures',
'VS_2017_BuildTools_minimal.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2019, 2022])
}
const { err, info } = await finder.findVisualStudio()
assert.strictEqual(err, null)
Expand All @@ -255,13 +255,13 @@ describe('find-visualstudio', function () {
const file = path.join(__dirname, 'fixtures',
'VS_2017_Community_workload.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
const file = path.join(__dirname, 'fixtures',
'VS_2017_Community_workload.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2019, 2022])
}
const { err, info } = await finder.findVisualStudio()
assert.strictEqual(err, null)
Expand All @@ -286,12 +286,12 @@ describe('find-visualstudio', function () {
finder.findVisualStudio2017 = async () => {
const file = path.join(__dirname, 'fixtures', 'VS_2017_Express.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
const file = path.join(__dirname, 'fixtures', 'VS_2017_Express.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2019, 2022])
}
const { err, info } = await finder.findVisualStudio()
assert.strictEqual(err, null)
Expand All @@ -317,13 +317,13 @@ describe('find-visualstudio', function () {
const file = path.join(__dirname, 'fixtures',
'VS_2019_Preview.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
const file = path.join(__dirname, 'fixtures',
'VS_2019_Preview.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2019, 2022])
}
const { err, info } = await finder.findVisualStudio()
assert.strictEqual(err, null)
Expand All @@ -349,13 +349,13 @@ describe('find-visualstudio', function () {
const file = path.join(__dirname, 'fixtures',
'VS_2019_BuildTools_minimal.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
const file = path.join(__dirname, 'fixtures',
'VS_2019_BuildTools_minimal.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2019, 2022])
}
const { err, info } = await finder.findVisualStudio()
assert.strictEqual(err, null)
Expand All @@ -381,13 +381,13 @@ describe('find-visualstudio', function () {
const file = path.join(__dirname, 'fixtures',
'VS_2019_Community_workload.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
const file = path.join(__dirname, 'fixtures',
'VS_2019_Community_workload.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2019, 2022])
}
const { err, info } = await finder.findVisualStudio()
assert.strictEqual(err, null)
Expand Down Expand Up @@ -422,13 +422,13 @@ describe('find-visualstudio', function () {
const file = path.join(__dirname, 'fixtures',
'VS_2022_Community_workload.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
const file = path.join(__dirname, 'fixtures',
'VS_2022_Community_workload.txt')
const data = fs.readFileSync(file)
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2019, 2022])
}
const { err, info } = await finder.findVisualStudio()
assert.strictEqual(err, null)
Expand Down Expand Up @@ -456,7 +456,7 @@ describe('find-visualstudio', function () {
const data3 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
'VS_2017_Express.txt')))
const data = JSON.stringify(data0.concat(data1, data2, data3))
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2017])
}
finder.findVisualStudio2019OrNewer = async () => {
const data0 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
Expand All @@ -468,7 +468,7 @@ describe('find-visualstudio', function () {
const data3 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
'VS_2022_Community_workload.txt')))
const data = JSON.stringify(data0.concat(data1, data2, data3))
return finder.parseData(null, data, '')
return finder.parseData(null, data, '', [2019, 2022])
}
finder.regSearchKeys = async (keys, value, addOpts) => {
for (let i = 0; i < keys.length; ++i) {
Expand Down

0 comments on commit 69ed7ef

Please sign in to comment.