mirror of
https://github.com/electron/node-gyp.git
synced 2025-08-15 12:58:19 +02:00

* feat!: update `engines.node` to `^14.17.0 || ^16.13.0 || >=18.0.0` * deps: nopt@^7.0.0 * feat: replace npmlog with proc-log * deps: standard@17.0.0 and fix linting errors * deps: which@3.0.0 - this also promiisifies the build command * deps: glob@8.0.3 * feat: drop rimraf dependency * fix: use fs/promises in favor of fs.promises
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
'use strict'
|
|
|
|
const log = require('./log')
|
|
const execFile = require('child_process').execFile
|
|
const path = require('path')
|
|
|
|
function regGetValue (key, value, addOpts, cb) {
|
|
const outReValue = value.replace(/\W/g, '.')
|
|
const outRe = new RegExp(`^\\s+${outReValue}\\s+REG_\\w+\\s+(\\S.*)$`, 'im')
|
|
const reg = path.join(process.env.SystemRoot, 'System32', 'reg.exe')
|
|
const regArgs = ['query', key, '/v', value].concat(addOpts)
|
|
|
|
log.silly('reg', 'running', reg, regArgs)
|
|
const child = execFile(reg, regArgs, { encoding: 'utf8' },
|
|
function (err, stdout, stderr) {
|
|
log.silly('reg', 'reg.exe stdout = %j', stdout)
|
|
if (err || stderr.trim() !== '') {
|
|
log.silly('reg', 'reg.exe err = %j', err && (err.stack || err))
|
|
log.silly('reg', 'reg.exe stderr = %j', stderr)
|
|
return cb(err, stderr)
|
|
}
|
|
|
|
const result = outRe.exec(stdout)
|
|
if (!result) {
|
|
log.silly('reg', 'error parsing stdout')
|
|
return cb(new Error('Could not parse output of reg.exe'))
|
|
}
|
|
log.silly('reg', 'found: %j', result[1])
|
|
cb(null, result[1])
|
|
})
|
|
child.stdin.end()
|
|
}
|
|
|
|
function regSearchKeys (keys, value, addOpts, cb) {
|
|
let i = 0
|
|
const search = () => {
|
|
log.silly('reg-search', 'looking for %j in %j', value, keys[i])
|
|
regGetValue(keys[i], value, addOpts, (err, res) => {
|
|
++i
|
|
if (err && i < keys.length) { return search() }
|
|
cb(err, res)
|
|
})
|
|
}
|
|
search()
|
|
}
|
|
|
|
module.exports = {
|
|
regGetValue,
|
|
regSearchKeys
|
|
}
|