mirror of
https://github.com/electron/node-gyp.git
synced 2025-08-15 12:58:19 +02:00
feat: convert internal classes from util.inherits to classes
BREAKING CHANGE: the `Gyp` class exported is now created using ECMAScript classes and therefore might have small differences to classes that were previously created with `util.inherits`.
This commit is contained in:
parent
355622f4aa
commit
d52997e975
7 changed files with 307 additions and 344 deletions
|
@ -1,3 +1,17 @@
|
|||
const envPaths = require('env-paths')
|
||||
|
||||
module.exports.devDir = () => envPaths('node-gyp', { suffix: '' }).cache
|
||||
|
||||
module.exports.poison = (object, property) => {
|
||||
function fail () {
|
||||
console.error(Error(`Property ${property} should not have been accessed.`))
|
||||
process.abort()
|
||||
}
|
||||
const descriptor = {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
get: fail,
|
||||
set: fail
|
||||
}
|
||||
Object.defineProperty(object, property, descriptor)
|
||||
}
|
||||
|
|
|
@ -4,43 +4,34 @@ delete process.env.PYTHON
|
|||
|
||||
const { describe, it } = require('mocha')
|
||||
const assert = require('assert')
|
||||
const { test: { PythonFinder, findPython: testFindPython } } = require('../lib/find-python')
|
||||
const PythonFinder = require('../lib/find-python')
|
||||
const { execFile } = require('../lib/util')
|
||||
const { poison } = require('./common')
|
||||
|
||||
class TestPythonFinder extends PythonFinder {
|
||||
constructor (...args) {
|
||||
super(...args)
|
||||
delete this.env.NODE_GYP_FORCE_PYTHON
|
||||
}
|
||||
|
||||
async findPython () {
|
||||
try {
|
||||
return { err: null, python: await super.findPython() }
|
||||
} catch (err) {
|
||||
return { err, python: null }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('find-python', function () {
|
||||
it('find python', async function () {
|
||||
const found = await testFindPython(null)
|
||||
const found = await PythonFinder.findPython(null)
|
||||
const [err, stdout, stderr] = await execFile(found, ['-V'], { encoding: 'utf-8' })
|
||||
assert.strictEqual(err, null)
|
||||
assert.ok(/Python 3/.test(stdout))
|
||||
assert.strictEqual(stderr, '')
|
||||
})
|
||||
|
||||
function poison (object, property) {
|
||||
function fail () {
|
||||
console.error(Error(`Property ${property} should not have been accessed.`))
|
||||
process.abort()
|
||||
}
|
||||
const descriptor = {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
get: fail,
|
||||
set: fail
|
||||
}
|
||||
Object.defineProperty(object, property, descriptor)
|
||||
}
|
||||
|
||||
function TestPythonFinder () { PythonFinder.apply(this, arguments) }
|
||||
TestPythonFinder.prototype = Object.create(PythonFinder.prototype)
|
||||
delete TestPythonFinder.prototype.env.NODE_GYP_FORCE_PYTHON
|
||||
const findPython = async (f) => {
|
||||
try {
|
||||
return { err: null, python: await f.findPython() }
|
||||
} catch (err) {
|
||||
return { err, python: null }
|
||||
}
|
||||
}
|
||||
|
||||
it('find python - python', async function () {
|
||||
const f = new TestPythonFinder('python')
|
||||
f.execFile = async function (program, args, opts) {
|
||||
|
@ -55,7 +46,7 @@ describe('find-python', function () {
|
|||
return [null, '/path/python']
|
||||
}
|
||||
|
||||
const { err, python } = await findPython(f)
|
||||
const { err, python } = await f.findPython()
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(python, '/path/python')
|
||||
})
|
||||
|
@ -72,7 +63,7 @@ describe('find-python', function () {
|
|||
}
|
||||
}
|
||||
|
||||
const { err } = await findPython(f)
|
||||
const { err } = await f.findPython()
|
||||
assert.ok(/Could not find any Python/.test(err))
|
||||
assert.ok(/not supported/i.test(f.errorLog))
|
||||
})
|
||||
|
@ -89,7 +80,7 @@ describe('find-python', function () {
|
|||
}
|
||||
}
|
||||
|
||||
const { err } = await findPython(f)
|
||||
const { err } = await f.findPython()
|
||||
assert.ok(/Could not find any Python/.test(err))
|
||||
assert.ok(/not in PATH/.test(f.errorLog))
|
||||
})
|
||||
|
@ -107,7 +98,7 @@ describe('find-python', function () {
|
|||
}
|
||||
}
|
||||
|
||||
const { err } = await findPython(f)
|
||||
const { err } = await f.findPython()
|
||||
assert.ok(/Could not find any Python/.test(err))
|
||||
assert.ok(/not in PATH/.test(f.errorLog))
|
||||
})
|
||||
|
@ -136,7 +127,7 @@ describe('find-python', function () {
|
|||
assert.fail()
|
||||
}
|
||||
}
|
||||
const { err, python } = await findPython(f)
|
||||
const { err, python } = await f.findPython()
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(python, 'Z:\\snake.exe')
|
||||
})
|
||||
|
@ -159,7 +150,7 @@ describe('find-python', function () {
|
|||
assert.fail()
|
||||
}
|
||||
}
|
||||
const { err, python } = await findPython(f)
|
||||
const { err, python } = await f.findPython()
|
||||
assert.strictEqual(err, null)
|
||||
assert.ok(python === expectedProgram)
|
||||
})
|
||||
|
@ -177,7 +168,7 @@ describe('find-python', function () {
|
|||
assert.fail()
|
||||
}
|
||||
}
|
||||
const { err } = await findPython(f)
|
||||
const { err } = await f.findPython()
|
||||
assert.ok(/Could not find any Python/.test(err))
|
||||
assert.ok(/not in PATH/.test(f.errorLog))
|
||||
})
|
||||
|
|
|
@ -4,34 +4,20 @@ const { describe, it } = require('mocha')
|
|||
const assert = require('assert')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { test: { VisualStudioFinder } } = require('../lib/find-visualstudio')
|
||||
const VisualStudioFinder = require('../lib/find-visualstudio')
|
||||
const { poison } = require('./common')
|
||||
|
||||
const semverV1 = { major: 1, minor: 0, patch: 0 }
|
||||
|
||||
delete process.env.VCINSTALLDIR
|
||||
|
||||
function poison (object, property) {
|
||||
function fail () {
|
||||
console.error(Error(`Property ${property} should not have been accessed.`))
|
||||
process.abort()
|
||||
}
|
||||
const descriptor = {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
get: fail,
|
||||
set: fail
|
||||
}
|
||||
Object.defineProperty(object, property, descriptor)
|
||||
}
|
||||
|
||||
function TestVisualStudioFinder () { VisualStudioFinder.apply(this, arguments) }
|
||||
TestVisualStudioFinder.prototype = Object.create(VisualStudioFinder.prototype)
|
||||
|
||||
const findVisualStudio = async (finder) => {
|
||||
try {
|
||||
return { err: null, info: await finder.findVisualStudio() }
|
||||
} catch (err) {
|
||||
return { err, info: null }
|
||||
class TestVisualStudioFinder extends VisualStudioFinder {
|
||||
async findVisualStudio () {
|
||||
try {
|
||||
return { err: null, info: await super.findVisualStudio() }
|
||||
} catch (err) {
|
||||
return { err, info: null }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +48,7 @@ describe('find-visualstudio', function () {
|
|||
throw new Error()
|
||||
}
|
||||
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info, {
|
||||
msBuild: 'C:\\MSBuild12\\MSBuild.exe',
|
||||
|
@ -102,7 +88,7 @@ describe('find-visualstudio', function () {
|
|||
throw new Error()
|
||||
}
|
||||
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.ok(/find .* Visual Studio/i.test(err), 'expect error')
|
||||
assert.ok(!info, 'no data')
|
||||
})
|
||||
|
@ -129,7 +115,7 @@ describe('find-visualstudio', function () {
|
|||
}
|
||||
throw new Error()
|
||||
}
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info, {
|
||||
msBuild: 'C:\\MSBuild14\\MSBuild.exe',
|
||||
|
@ -228,7 +214,7 @@ describe('find-visualstudio', function () {
|
|||
const data = fs.readFileSync(file)
|
||||
return finder.parseData(null, data, '')
|
||||
}
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info, {
|
||||
msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\' +
|
||||
|
@ -254,7 +240,7 @@ describe('find-visualstudio', function () {
|
|||
const data = fs.readFileSync(file)
|
||||
return finder.parseData(null, data, '')
|
||||
}
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info, {
|
||||
msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\' +
|
||||
|
@ -279,7 +265,7 @@ describe('find-visualstudio', function () {
|
|||
const data = fs.readFileSync(file)
|
||||
return finder.parseData(null, data, '')
|
||||
}
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info, {
|
||||
msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\' +
|
||||
|
@ -305,7 +291,7 @@ describe('find-visualstudio', function () {
|
|||
const data = fs.readFileSync(file)
|
||||
return finder.parseData(null, data, '')
|
||||
}
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info, {
|
||||
msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\' +
|
||||
|
@ -331,7 +317,7 @@ describe('find-visualstudio', function () {
|
|||
const data = fs.readFileSync(file)
|
||||
return finder.parseData(null, data, '')
|
||||
}
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info, {
|
||||
msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\' +
|
||||
|
@ -357,7 +343,7 @@ describe('find-visualstudio', function () {
|
|||
const data = fs.readFileSync(file)
|
||||
return finder.parseData(null, data, '')
|
||||
}
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info, {
|
||||
msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\' +
|
||||
|
@ -392,7 +378,7 @@ describe('find-visualstudio', function () {
|
|||
const data = fs.readFileSync(file)
|
||||
return finder.parseData(null, data, '')
|
||||
}
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info, {
|
||||
msBuild: msBuildPath,
|
||||
|
@ -456,7 +442,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, 'AABB')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.ok(/find .* Visual Studio/i.test(err), 'expect error')
|
||||
assert.ok(!info, 'no data')
|
||||
})
|
||||
|
@ -465,7 +451,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, '2013')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.versionYear, 2013)
|
||||
})
|
||||
|
@ -474,7 +460,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, 'C:\\VS2013')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.path, 'C:\\VS2013')
|
||||
})
|
||||
|
@ -483,7 +469,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, '2015')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.versionYear, 2015)
|
||||
})
|
||||
|
@ -492,7 +478,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, 'C:\\VS2015')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.path, 'C:\\VS2015')
|
||||
})
|
||||
|
@ -501,7 +487,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, '2017')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.versionYear, 2017)
|
||||
})
|
||||
|
@ -511,7 +497,7 @@ describe('find-visualstudio', function () {
|
|||
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.path,
|
||||
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community')
|
||||
|
@ -521,7 +507,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, '2019')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.versionYear, 2019)
|
||||
})
|
||||
|
@ -531,7 +517,7 @@ describe('find-visualstudio', function () {
|
|||
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.path,
|
||||
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools')
|
||||
|
@ -545,7 +531,7 @@ describe('find-visualstudio', function () {
|
|||
}
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.versionYear, 2022)
|
||||
})
|
||||
|
@ -555,7 +541,7 @@ describe('find-visualstudio', function () {
|
|||
'c:\\program files (x86)\\microsoft visual studio\\2019\\BUILDTOOLS')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.path,
|
||||
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools')
|
||||
|
@ -569,7 +555,7 @@ describe('find-visualstudio', function () {
|
|||
}
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.versionYear, 2022)
|
||||
})
|
||||
|
@ -582,7 +568,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, null)
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.path, 'C:\\VS2015')
|
||||
})
|
||||
|
@ -594,7 +580,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, null)
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.path,
|
||||
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools')
|
||||
|
@ -607,7 +593,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, null)
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.ok(/find .* Visual Studio/i.test(err), 'expect error')
|
||||
assert.ok(!info, 'no data')
|
||||
})
|
||||
|
@ -618,7 +604,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, 'C:\\VS2015')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.strictEqual(err, null)
|
||||
assert.deepStrictEqual(info.path, 'C:\\VS2015')
|
||||
})
|
||||
|
@ -630,7 +616,7 @@ describe('find-visualstudio', function () {
|
|||
const finder = new TestVisualStudioFinder(semverV1, 'C:\\VS2015')
|
||||
|
||||
allVsVersions(finder)
|
||||
const { err, info } = await findVisualStudio(finder)
|
||||
const { err, info } = await finder.findVisualStudio()
|
||||
assert.ok(/find .* Visual Studio/i.test(err), 'expect error')
|
||||
assert.ok(!info, 'no data')
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue