forked from olcxjas-softworks/LarpixClient
update electron to v43
This commit is contained in:
parent
68ac0beedf
commit
fb6c8b6ee9
5385 changed files with 513060 additions and 123058 deletions
219
electron/node_modules/node-gyp/lib/build.js
generated
vendored
219
electron/node_modules/node-gyp/lib/build.js
generated
vendored
|
|
@ -1,14 +1,15 @@
|
|||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const gracefulFs = require('graceful-fs')
|
||||
const fs = gracefulFs.promises
|
||||
const path = require('path')
|
||||
const glob = require('glob')
|
||||
const log = require('npmlog')
|
||||
const { glob } = require('tinyglobby')
|
||||
const log = require('./log')
|
||||
const which = require('which')
|
||||
const win = process.platform === 'win32'
|
||||
|
||||
function build (gyp, argv, callback) {
|
||||
var platformMake = 'make'
|
||||
async function build (gyp, argv) {
|
||||
let platformMake = 'make'
|
||||
if (process.platform === 'aix') {
|
||||
platformMake = 'gmake'
|
||||
} else if (process.platform === 'os400') {
|
||||
|
|
@ -21,143 +22,148 @@ function build (gyp, argv, callback) {
|
|||
})
|
||||
}
|
||||
|
||||
var makeCommand = gyp.opts.make || process.env.MAKE || platformMake
|
||||
var command = win ? 'msbuild' : makeCommand
|
||||
var jobs = gyp.opts.jobs || process.env.JOBS
|
||||
var buildType
|
||||
var config
|
||||
var arch
|
||||
var nodeDir
|
||||
var guessedSolution
|
||||
const makeCommand = gyp.opts.make || process.env.MAKE || platformMake
|
||||
let command = win ? 'msbuild' : makeCommand
|
||||
const jobs = gyp.opts.jobs || process.env.JOBS
|
||||
let buildType
|
||||
let config
|
||||
let arch
|
||||
let nodeDir
|
||||
let guessedSolution
|
||||
let python
|
||||
let buildBinsDir
|
||||
|
||||
loadConfigGypi()
|
||||
await loadConfigGypi()
|
||||
|
||||
/**
|
||||
* Load the "config.gypi" file that was generated during "configure".
|
||||
*/
|
||||
|
||||
function loadConfigGypi () {
|
||||
var configPath = path.resolve('build', 'config.gypi')
|
||||
|
||||
fs.readFile(configPath, 'utf8', function (err, data) {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
callback(new Error('You must run `node-gyp configure` first!'))
|
||||
} else {
|
||||
callback(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
config = JSON.parse(data.replace(/#.+\n/, ''))
|
||||
|
||||
// get the 'arch', 'buildType', and 'nodeDir' vars from the config
|
||||
buildType = config.target_defaults.default_configuration
|
||||
arch = config.variables.target_arch
|
||||
nodeDir = config.variables.nodedir
|
||||
|
||||
if ('debug' in gyp.opts) {
|
||||
buildType = gyp.opts.debug ? 'Debug' : 'Release'
|
||||
}
|
||||
if (!buildType) {
|
||||
buildType = 'Release'
|
||||
}
|
||||
|
||||
log.verbose('build type', buildType)
|
||||
log.verbose('architecture', arch)
|
||||
log.verbose('node dev dir', nodeDir)
|
||||
|
||||
if (win) {
|
||||
findSolutionFile()
|
||||
async function loadConfigGypi () {
|
||||
let data
|
||||
try {
|
||||
const configPath = path.resolve('build', 'config.gypi')
|
||||
data = await fs.readFile(configPath, 'utf8')
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
throw new Error('You must run `node-gyp configure` first!')
|
||||
} else {
|
||||
doWhich()
|
||||
throw err
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
config = JSON.parse(data.replace(/#.+\n/, ''))
|
||||
|
||||
// get the 'arch', 'buildType', and 'nodeDir' vars from the config
|
||||
buildType = config.target_defaults.default_configuration
|
||||
arch = config.variables.target_arch
|
||||
nodeDir = config.variables.nodedir
|
||||
python = config.variables.python
|
||||
|
||||
if ('debug' in gyp.opts) {
|
||||
buildType = gyp.opts.debug ? 'Debug' : 'Release'
|
||||
}
|
||||
if (!buildType) {
|
||||
buildType = 'Release'
|
||||
}
|
||||
|
||||
log.verbose('build type', buildType)
|
||||
log.verbose('architecture', arch)
|
||||
log.verbose('node dev dir', nodeDir)
|
||||
log.verbose('python', python)
|
||||
|
||||
if (win) {
|
||||
await findSolutionFile()
|
||||
} else {
|
||||
await doWhich()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On Windows, find the first build/*.sln file.
|
||||
*/
|
||||
|
||||
function findSolutionFile () {
|
||||
glob('build/*.sln', function (err, files) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
async function findSolutionFile () {
|
||||
const files = await glob('build/*.sln', { expandDirectories: false })
|
||||
if (files.length === 0) {
|
||||
if (gracefulFs.existsSync('build/Makefile') ||
|
||||
(await glob('build/*.mk', { expandDirectories: false })).length !== 0) {
|
||||
command = makeCommand
|
||||
await doWhich(false)
|
||||
return
|
||||
} else {
|
||||
throw new Error('Could not find *.sln file or Makefile. Did you run "configure"?')
|
||||
}
|
||||
if (files.length === 0) {
|
||||
return callback(new Error('Could not find *.sln file. Did you run "configure"?'))
|
||||
}
|
||||
guessedSolution = files[0]
|
||||
log.verbose('found first Solution file', guessedSolution)
|
||||
doWhich()
|
||||
})
|
||||
}
|
||||
guessedSolution = files[0]
|
||||
log.verbose('found first Solution file', guessedSolution)
|
||||
await doWhich(true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses node-which to locate the msbuild / make executable.
|
||||
*/
|
||||
|
||||
function doWhich () {
|
||||
async function doWhich (msvs) {
|
||||
// On Windows use msbuild provided by node-gyp configure
|
||||
if (win) {
|
||||
if (msvs) {
|
||||
if (!config.variables.msbuild_path) {
|
||||
return callback(new Error(
|
||||
'MSBuild is not set, please run `node-gyp configure`.'))
|
||||
throw new Error('MSBuild is not set, please run `node-gyp configure`.')
|
||||
}
|
||||
command = config.variables.msbuild_path
|
||||
log.verbose('using MSBuild:', command)
|
||||
doBuild()
|
||||
await doBuild(msvs)
|
||||
return
|
||||
}
|
||||
|
||||
// First make sure we have the build command in the PATH
|
||||
which(command, function (err, execPath) {
|
||||
if (err) {
|
||||
// Some other error or 'make' not found on Unix, report that to the user
|
||||
callback(err)
|
||||
return
|
||||
}
|
||||
log.verbose('`which` succeeded for `' + command + '`', execPath)
|
||||
doBuild()
|
||||
})
|
||||
const execPath = await which(command)
|
||||
log.verbose('`which` succeeded for `' + command + '`', execPath)
|
||||
await doBuild(msvs)
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually spawn the process and compile the module.
|
||||
*/
|
||||
|
||||
function doBuild () {
|
||||
async function doBuild (msvs) {
|
||||
// Enable Verbose build
|
||||
var verbose = log.levels[log.level] <= log.levels.verbose
|
||||
var j
|
||||
const verbose = log.logger.isVisible('verbose')
|
||||
let j
|
||||
|
||||
if (!win && verbose) {
|
||||
if (!msvs && verbose) {
|
||||
argv.push('V=1')
|
||||
}
|
||||
|
||||
if (win && !verbose) {
|
||||
if (msvs && !verbose) {
|
||||
argv.push('/clp:Verbosity=minimal')
|
||||
}
|
||||
|
||||
if (win) {
|
||||
if (msvs) {
|
||||
// Turn off the Microsoft logo on Windows
|
||||
argv.push('/nologo')
|
||||
// No lingering msbuild processes and open file handles
|
||||
argv.push('/nodeReuse:false')
|
||||
}
|
||||
|
||||
// Specify the build type, Release by default
|
||||
if (win) {
|
||||
if (msvs) {
|
||||
// Convert .gypi config target_arch to MSBuild /Platform
|
||||
// Since there are many ways to state '32-bit Intel', default to it.
|
||||
// N.B. msbuild's Condition string equality tests are case-insensitive.
|
||||
var archLower = arch.toLowerCase()
|
||||
var p = archLower === 'x64' ? 'x64'
|
||||
: (archLower === 'arm' ? 'ARM'
|
||||
: (archLower === 'arm64' ? 'ARM64' : 'Win32'))
|
||||
const archLower = arch.toLowerCase()
|
||||
const p = archLower === 'x64'
|
||||
? 'x64'
|
||||
: (archLower === 'arm'
|
||||
? 'ARM'
|
||||
: (archLower === 'arm64' ? 'ARM64' : 'Win32'))
|
||||
argv.push('/p:Configuration=' + buildType + ';Platform=' + p)
|
||||
if (jobs) {
|
||||
j = parseInt(jobs, 10)
|
||||
if (!isNaN(j) && j > 0) {
|
||||
argv.push('/m:' + j)
|
||||
} else if (jobs.toUpperCase() === 'MAX') {
|
||||
argv.push('/m:' + require('os').cpus().length)
|
||||
argv.push('/m:' + require('os').availableParallelism())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -172,14 +178,14 @@ function build (gyp, argv, callback) {
|
|||
argv.push(j)
|
||||
} else if (jobs.toUpperCase() === 'MAX') {
|
||||
argv.push('--jobs')
|
||||
argv.push(require('os').cpus().length)
|
||||
argv.push(require('os').availableParallelism())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (win) {
|
||||
if (msvs) {
|
||||
// did the user specify their own .sln file?
|
||||
var hasSln = argv.some(function (arg) {
|
||||
const hasSln = argv.some(function (arg) {
|
||||
return path.extname(arg) === '.sln'
|
||||
})
|
||||
if (!hasSln) {
|
||||
|
|
@ -189,23 +195,34 @@ function build (gyp, argv, callback) {
|
|||
|
||||
if (!win) {
|
||||
// Add build-time dependency symlinks (such as Python) to PATH
|
||||
const buildBinsDir = path.resolve('build', 'node_gyp_bins')
|
||||
buildBinsDir = path.resolve('build', 'node_gyp_bins')
|
||||
process.env.PATH = `${buildBinsDir}:${process.env.PATH}`
|
||||
log.verbose('bin symlinks', `adding symlinks (such as Python), at "${buildBinsDir}", to PATH`)
|
||||
await fs.mkdir(buildBinsDir, { recursive: true })
|
||||
const symlinkDestination = path.join(buildBinsDir, 'python3')
|
||||
try {
|
||||
await fs.unlink(symlinkDestination)
|
||||
} catch (err) {
|
||||
if (err.code !== 'ENOENT') throw err
|
||||
}
|
||||
await fs.symlink(python, symlinkDestination)
|
||||
log.verbose('bin symlinks', `created symlink to "${python}" in "${buildBinsDir}" and added to PATH`)
|
||||
}
|
||||
|
||||
var proc = gyp.spawn(command, argv)
|
||||
proc.on('exit', onExit)
|
||||
}
|
||||
const proc = gyp.spawn(command, argv)
|
||||
await new Promise((resolve, reject) => proc.on('exit', async (code, signal) => {
|
||||
if (buildBinsDir) {
|
||||
// Clean up the build-time dependency symlinks:
|
||||
await fs.rm(buildBinsDir, { recursive: true, maxRetries: 3 })
|
||||
}
|
||||
|
||||
function onExit (code, signal) {
|
||||
if (code !== 0) {
|
||||
return callback(new Error('`' + command + '` failed with exit code: ' + code))
|
||||
}
|
||||
if (signal) {
|
||||
return callback(new Error('`' + command + '` got signal: ' + signal))
|
||||
}
|
||||
callback()
|
||||
if (code !== 0) {
|
||||
return reject(new Error('`' + command + '` failed with exit code: ' + code))
|
||||
}
|
||||
if (signal) {
|
||||
return reject(new Error('`' + command + '` got signal: ' + signal))
|
||||
}
|
||||
resolve()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
10
electron/node_modules/node-gyp/lib/clean.js
generated
vendored
10
electron/node_modules/node-gyp/lib/clean.js
generated
vendored
|
|
@ -1,14 +1,14 @@
|
|||
'use strict'
|
||||
|
||||
const rm = require('rimraf')
|
||||
const log = require('npmlog')
|
||||
const fs = require('graceful-fs').promises
|
||||
const log = require('./log')
|
||||
|
||||
function clean (gyp, argv, callback) {
|
||||
async function clean (gyp, argv) {
|
||||
// Remove the 'build' dir
|
||||
var buildDir = 'build'
|
||||
const buildDir = 'build'
|
||||
|
||||
log.verbose('clean', 'removing "%s" directory', buildDir)
|
||||
rm(buildDir, callback)
|
||||
await fs.rm(buildDir, { recursive: true, force: true, maxRetries: 3 })
|
||||
}
|
||||
|
||||
module.exports = clean
|
||||
|
|
|
|||
368
electron/node_modules/node-gyp/lib/configure.js
generated
vendored
368
electron/node_modules/node-gyp/lib/configure.js
generated
vendored
|
|
@ -1,47 +1,62 @@
|
|||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const { promises: fs, readFileSync } = require('graceful-fs')
|
||||
const path = require('path')
|
||||
const log = require('npmlog')
|
||||
const log = require('./log')
|
||||
const os = require('os')
|
||||
const processRelease = require('./process-release')
|
||||
const win = process.platform === 'win32'
|
||||
const findNodeDirectory = require('./find-node-directory')
|
||||
const createConfigGypi = require('./create-config-gypi')
|
||||
const msgFormat = require('util').format
|
||||
var findPython = require('./find-python')
|
||||
if (win) {
|
||||
var findVisualStudio = require('./find-visualstudio')
|
||||
}
|
||||
const { createConfigGypi } = require('./create-config-gypi')
|
||||
const { format: msgFormat } = require('util')
|
||||
const { findAccessibleSync } = require('./util')
|
||||
const { findPython } = require('./find-python')
|
||||
const { findVisualStudio } = win ? require('./find-visualstudio') : {}
|
||||
|
||||
function configure (gyp, argv, callback) {
|
||||
var python
|
||||
var buildDir = path.resolve('build')
|
||||
var buildBinsDir = path.join(buildDir, 'node_gyp_bins')
|
||||
var configNames = ['config.gypi', 'common.gypi']
|
||||
var configs = []
|
||||
var nodeDir
|
||||
var release = processRelease(argv, gyp, process.version, process.release)
|
||||
const majorRe = /^#define NODE_MAJOR_VERSION (\d+)/m
|
||||
const minorRe = /^#define NODE_MINOR_VERSION (\d+)/m
|
||||
const patchRe = /^#define NODE_PATCH_VERSION (\d+)/m
|
||||
|
||||
findPython(gyp.opts.python, function (err, found) {
|
||||
if (err) {
|
||||
callback(err)
|
||||
} else {
|
||||
python = found
|
||||
getNodeDir()
|
||||
}
|
||||
})
|
||||
async function configure (gyp, argv) {
|
||||
const buildDir = path.resolve('build')
|
||||
const configNames = ['config.gypi', 'common.gypi']
|
||||
const configs = []
|
||||
let nodeDir
|
||||
const release = processRelease(argv, gyp, process.version, process.release)
|
||||
|
||||
function getNodeDir () {
|
||||
const python = await findPython(gyp.opts.python)
|
||||
return getNodeDir()
|
||||
|
||||
async function getNodeDir () {
|
||||
// 'python' should be set by now
|
||||
process.env.PYTHON = python
|
||||
|
||||
if (!gyp.opts.nodedir &&
|
||||
process.config.variables.use_prefix_to_find_headers) {
|
||||
// check if the headers can be found using the prefix specified
|
||||
// at build time. Use them if they match the version expected
|
||||
const prefix = process.config.variables.node_prefix
|
||||
let availVersion
|
||||
try {
|
||||
const nodeVersionH = readFileSync(path.join(prefix,
|
||||
'include', 'node', 'node_version.h'), { encoding: 'utf8' })
|
||||
const major = nodeVersionH.match(majorRe)[1]
|
||||
const minor = nodeVersionH.match(minorRe)[1]
|
||||
const patch = nodeVersionH.match(patchRe)[1]
|
||||
availVersion = major + '.' + minor + '.' + patch
|
||||
} catch {}
|
||||
if (availVersion === release.version) {
|
||||
// ok version matches, use the headers
|
||||
gyp.opts.nodedir = prefix
|
||||
log.verbose('using local node headers based on prefix',
|
||||
'setting nodedir to ' + gyp.opts.nodedir)
|
||||
}
|
||||
}
|
||||
|
||||
if (gyp.opts.nodedir) {
|
||||
// --nodedir was specified. use that for the dev files
|
||||
nodeDir = gyp.opts.nodedir.replace(/^~/, os.homedir())
|
||||
|
||||
log.verbose('get node dir', 'compiling against specified --nodedir dev files: %s', nodeDir)
|
||||
createBuildDir()
|
||||
} else {
|
||||
// if no --nodedir specified, ensure node dependencies are installed
|
||||
if ('v' + release.version !== process.version) {
|
||||
|
|
@ -54,108 +69,86 @@ function configure (gyp, argv, callback) {
|
|||
|
||||
if (!release.semver) {
|
||||
// could not parse the version string with semver
|
||||
return callback(new Error('Invalid version number: ' + release.version))
|
||||
throw new Error('Invalid version number: ' + release.version)
|
||||
}
|
||||
|
||||
// If the tarball option is set, always remove and reinstall the headers
|
||||
// into devdir. Otherwise only install if they're not already there.
|
||||
gyp.opts.ensure = !gyp.opts.tarball
|
||||
|
||||
gyp.commands.install([release.version], function (err) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
log.verbose('get node dir', 'target node version installed:', release.versionDir)
|
||||
nodeDir = path.resolve(gyp.devDir, release.versionDir)
|
||||
createBuildDir()
|
||||
})
|
||||
await gyp.commands.install([release.version])
|
||||
|
||||
log.verbose('get node dir', 'target node version installed:', release.versionDir)
|
||||
nodeDir = path.resolve(gyp.devDir, release.versionDir)
|
||||
}
|
||||
|
||||
return createBuildDir()
|
||||
}
|
||||
|
||||
function createBuildDir () {
|
||||
async function createBuildDir () {
|
||||
log.verbose('build dir', 'attempting to create "build" dir: %s', buildDir)
|
||||
|
||||
const deepestBuildDirSubdirectory = win ? buildDir : buildBinsDir
|
||||
fs.mkdir(deepestBuildDirSubdirectory, { recursive: true }, function (err, isNew) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
log.verbose(
|
||||
'build dir', '"build" dir needed to be created?', isNew ? 'Yes' : 'No'
|
||||
)
|
||||
if (win) {
|
||||
findVisualStudio(release.semver, gyp.opts.msvs_version,
|
||||
createConfigFile)
|
||||
} else {
|
||||
createPythonSymlink()
|
||||
createConfigFile()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function createPythonSymlink () {
|
||||
const symlinkDestination = path.join(buildBinsDir, 'python3')
|
||||
|
||||
log.verbose('python symlink', `creating symlink to "${python}" at "${symlinkDestination}"`)
|
||||
|
||||
fs.unlink(symlinkDestination, function (err) {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
log.verbose('python symlink', 'error when attempting to remove existing symlink')
|
||||
log.verbose('python symlink', err.stack, 'errno: ' + err.errno)
|
||||
}
|
||||
fs.symlink(python, symlinkDestination, function (err) {
|
||||
if (err) {
|
||||
log.verbose('python symlink', 'error when attempting to create Python symlink')
|
||||
log.verbose('python symlink', err.stack, 'errno: ' + err.errno)
|
||||
const isNew = await fs.mkdir(buildDir, { recursive: true })
|
||||
log.verbose(
|
||||
'build dir', '"build" dir needed to be created?', isNew ? 'Yes' : 'No'
|
||||
)
|
||||
if (win) {
|
||||
let usingMakeGenerator = false
|
||||
for (let i = argv.length - 1; i >= 0; --i) {
|
||||
const arg = argv[i]
|
||||
if (arg === '-f' || arg === '--format') {
|
||||
const format = argv[i + 1]
|
||||
if (typeof format === 'string' && format.startsWith('make')) {
|
||||
usingMakeGenerator = true
|
||||
break
|
||||
}
|
||||
} else if (arg.startsWith('--format=make')) {
|
||||
usingMakeGenerator = true
|
||||
break
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
let vsInfo = {}
|
||||
if (!usingMakeGenerator) {
|
||||
vsInfo = await findVisualStudio(release.semver, gyp.opts['msvs-version'])
|
||||
}
|
||||
return createConfigFile(vsInfo)
|
||||
}
|
||||
return createConfigFile(null)
|
||||
}
|
||||
|
||||
function createConfigFile (err, vsInfo) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
if (process.platform === 'win32') {
|
||||
async function createConfigFile (vsInfo) {
|
||||
if (win) {
|
||||
process.env.GYP_MSVS_VERSION = Math.min(vsInfo.versionYear, 2015)
|
||||
process.env.GYP_MSVS_OVERRIDE_PATH = vsInfo.path
|
||||
}
|
||||
createConfigGypi({ gyp, buildDir, nodeDir, vsInfo }).then(configPath => {
|
||||
configs.push(configPath)
|
||||
findConfigs()
|
||||
}).catch(err => {
|
||||
callback(err)
|
||||
})
|
||||
const configPath = await createConfigGypi({ gyp, buildDir, nodeDir, vsInfo, python })
|
||||
configs.push(configPath)
|
||||
return findConfigs()
|
||||
}
|
||||
|
||||
function findConfigs () {
|
||||
var name = configNames.shift()
|
||||
async function findConfigs () {
|
||||
const name = configNames.shift()
|
||||
if (!name) {
|
||||
return runGyp()
|
||||
}
|
||||
var fullPath = path.resolve(name)
|
||||
|
||||
const fullPath = path.resolve(name)
|
||||
log.verbose(name, 'checking for gypi file: %s', fullPath)
|
||||
fs.stat(fullPath, function (err) {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
findConfigs() // check next gypi filename
|
||||
} else {
|
||||
callback(err)
|
||||
}
|
||||
} else {
|
||||
log.verbose(name, 'found gypi file')
|
||||
configs.push(fullPath)
|
||||
findConfigs()
|
||||
try {
|
||||
await fs.stat(fullPath)
|
||||
log.verbose(name, 'found gypi file')
|
||||
configs.push(fullPath)
|
||||
} catch (err) {
|
||||
// ENOENT will check next gypi filename
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function runGyp (err) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
return findConfigs()
|
||||
}
|
||||
|
||||
async function runGyp () {
|
||||
if (!~argv.indexOf('-f') && !~argv.indexOf('--format')) {
|
||||
if (win) {
|
||||
log.verbose('gyp', 'gyp format was not specified; forcing "msvs"')
|
||||
|
|
@ -175,11 +168,13 @@ function configure (gyp, argv, callback) {
|
|||
|
||||
// For AIX and z/OS we need to set up the path to the exports file
|
||||
// which contains the symbols needed for linking.
|
||||
var nodeExpFile
|
||||
let nodeExpFile
|
||||
let nodeRootDir
|
||||
let candidates
|
||||
let logprefix = 'find exports file'
|
||||
if (process.platform === 'aix' || process.platform === 'os390' || process.platform === 'os400') {
|
||||
var ext = process.platform === 'os390' ? 'x' : 'exp'
|
||||
var nodeRootDir = findNodeDirectory()
|
||||
var candidates
|
||||
const ext = process.platform === 'os390' ? 'x' : 'exp'
|
||||
nodeRootDir = findNodeDirectory()
|
||||
|
||||
if (process.platform === 'aix' || process.platform === 'os400') {
|
||||
candidates = [
|
||||
|
|
@ -202,24 +197,23 @@ function configure (gyp, argv, callback) {
|
|||
})
|
||||
}
|
||||
|
||||
var logprefix = 'find exports file'
|
||||
nodeExpFile = findAccessibleSync(logprefix, nodeRootDir, candidates)
|
||||
if (nodeExpFile !== undefined) {
|
||||
log.verbose(logprefix, 'Found exports file: %s', nodeExpFile)
|
||||
} else {
|
||||
var msg = msgFormat('Could not find node.%s file in %s', ext, nodeRootDir)
|
||||
const msg = msgFormat('Could not find node.%s file in %s', ext, nodeRootDir)
|
||||
log.error(logprefix, 'Could not find exports file')
|
||||
return callback(new Error(msg))
|
||||
throw new Error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
// For z/OS we need to set up the path to zoslib include directory,
|
||||
// which contains headers included in v8config.h.
|
||||
var zoslibIncDir
|
||||
let zoslibIncDir
|
||||
if (process.platform === 'os390') {
|
||||
logprefix = "find zoslib's zos-base.h:"
|
||||
let msg
|
||||
var zoslibIncPath = process.env.ZOSLIB_INCLUDES
|
||||
let zoslibIncPath = process.env.ZOSLIB_INCLUDES
|
||||
if (zoslibIncPath) {
|
||||
zoslibIncPath = findAccessibleSync(logprefix, zoslibIncPath, ['zos-base.h'])
|
||||
if (zoslibIncPath === undefined) {
|
||||
|
|
@ -247,114 +241,88 @@ function configure (gyp, argv, callback) {
|
|||
} else if (release.version.split('.')[0] >= 16) {
|
||||
// zoslib is only shipped in Node v16 and above.
|
||||
log.error(logprefix, msg)
|
||||
return callback(new Error(msg))
|
||||
throw new Error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
// this logic ported from the old `gyp_addon` python file
|
||||
var gypScript = path.resolve(__dirname, '..', 'gyp', 'gyp_main.py')
|
||||
var addonGypi = path.resolve(__dirname, '..', 'addon.gypi')
|
||||
var commonGypi = path.resolve(nodeDir, 'include/node/common.gypi')
|
||||
fs.stat(commonGypi, function (err) {
|
||||
if (err) {
|
||||
commonGypi = path.resolve(nodeDir, 'common.gypi')
|
||||
}
|
||||
const gypScript = path.resolve(__dirname, '..', 'gyp', 'gyp_main.py')
|
||||
const addonGypi = path.resolve(__dirname, '..', 'addon.gypi')
|
||||
let commonGypi = path.resolve(nodeDir, 'include/node/common.gypi')
|
||||
try {
|
||||
await fs.stat(commonGypi)
|
||||
} catch (err) {
|
||||
commonGypi = path.resolve(nodeDir, 'common.gypi')
|
||||
}
|
||||
|
||||
var outputDir = 'build'
|
||||
if (win) {
|
||||
// Windows expects an absolute path
|
||||
outputDir = buildDir
|
||||
}
|
||||
var nodeGypDir = path.resolve(__dirname, '..')
|
||||
let outputDir = 'build'
|
||||
if (win) {
|
||||
// Windows expects an absolute path
|
||||
outputDir = buildDir
|
||||
}
|
||||
const nodeGypDir = path.resolve(__dirname, '..')
|
||||
|
||||
var nodeLibFile = path.join(nodeDir,
|
||||
!gyp.opts.nodedir ? '<(target_arch)' : '$(Configuration)',
|
||||
release.name + '.lib')
|
||||
let nodeLibFile = path.join(nodeDir,
|
||||
!gyp.opts.nodedir ? '<(target_arch)' : '$(Configuration)',
|
||||
release.name + '.lib')
|
||||
|
||||
argv.push('-I', addonGypi)
|
||||
argv.push('-I', commonGypi)
|
||||
argv.push('-Dlibrary=shared_library')
|
||||
argv.push('-Dvisibility=default')
|
||||
argv.push('-Dnode_root_dir=' + nodeDir)
|
||||
if (process.platform === 'aix' || process.platform === 'os390' || process.platform === 'os400') {
|
||||
argv.push('-Dnode_exp_file=' + nodeExpFile)
|
||||
if (process.platform === 'os390' && zoslibIncDir) {
|
||||
argv.push('-Dzoslib_include_dir=' + zoslibIncDir)
|
||||
}
|
||||
argv.push('-I', addonGypi)
|
||||
argv.push('-I', commonGypi)
|
||||
argv.push('-Dlibrary=shared_library')
|
||||
argv.push('-Dvisibility=default')
|
||||
argv.push('-Dnode_root_dir=' + nodeDir)
|
||||
if (process.platform === 'aix' || process.platform === 'os390' || process.platform === 'os400') {
|
||||
argv.push('-Dnode_exp_file=' + nodeExpFile)
|
||||
if (process.platform === 'os390' && zoslibIncDir) {
|
||||
argv.push('-Dzoslib_include_dir=' + zoslibIncDir)
|
||||
}
|
||||
argv.push('-Dnode_gyp_dir=' + nodeGypDir)
|
||||
}
|
||||
argv.push('-Dnode_gyp_dir=' + nodeGypDir)
|
||||
|
||||
// Do this to keep Cygwin environments happy, else the unescaped '\' gets eaten up,
|
||||
// resulting in bad paths, Ex c:parentFolderfolderanotherFolder instead of c:\parentFolder\folder\anotherFolder
|
||||
if (win) {
|
||||
nodeLibFile = nodeLibFile.replace(/\\/g, '\\\\')
|
||||
}
|
||||
argv.push('-Dnode_lib_file=' + nodeLibFile)
|
||||
argv.push('-Dmodule_root_dir=' + process.cwd())
|
||||
argv.push('-Dnode_engine=' +
|
||||
// Do this to keep Cygwin environments happy, else the unescaped '\' gets eaten up,
|
||||
// resulting in bad paths, Ex c:parentFolderfolderanotherFolder instead of c:\parentFolder\folder\anotherFolder
|
||||
if (win) {
|
||||
nodeLibFile = nodeLibFile.replace(/\\/g, '\\\\')
|
||||
}
|
||||
argv.push('-Dnode_lib_file=' + nodeLibFile)
|
||||
argv.push('-Dmodule_root_dir=' + process.cwd())
|
||||
argv.push('-Dnode_engine=' +
|
||||
(gyp.opts.node_engine || process.jsEngine || 'v8'))
|
||||
argv.push('--depth=.')
|
||||
argv.push('--no-parallel')
|
||||
argv.push('--depth=.')
|
||||
argv.push('--no-parallel')
|
||||
|
||||
// tell gyp to write the Makefile/Solution files into output_dir
|
||||
argv.push('--generator-output', outputDir)
|
||||
// tell gyp to write the Makefile/Solution files into output_dir
|
||||
argv.push('--generator-output', outputDir)
|
||||
|
||||
// tell make to write its output into the same dir
|
||||
argv.push('-Goutput_dir=.')
|
||||
// tell make to write its output into the same dir
|
||||
argv.push('-Goutput_dir=.')
|
||||
|
||||
// enforce use of the "binding.gyp" file
|
||||
argv.unshift('binding.gyp')
|
||||
// enforce use of the "binding.gyp" file
|
||||
argv.unshift('binding.gyp')
|
||||
|
||||
// execute `gyp` from the current target nodedir
|
||||
argv.unshift(gypScript)
|
||||
// execute `gyp` from the current target nodedir
|
||||
argv.unshift(gypScript)
|
||||
|
||||
// make sure python uses files that came with this particular node package
|
||||
var pypath = [path.join(__dirname, '..', 'gyp', 'pylib')]
|
||||
if (process.env.PYTHONPATH) {
|
||||
pypath.push(process.env.PYTHONPATH)
|
||||
}
|
||||
process.env.PYTHONPATH = pypath.join(win ? ';' : ':')
|
||||
// make sure python uses files that came with this particular node package
|
||||
const pypath = [path.join(__dirname, '..', 'gyp', 'pylib')]
|
||||
if (process.env.PYTHONPATH) {
|
||||
pypath.push(process.env.PYTHONPATH)
|
||||
}
|
||||
process.env.PYTHONPATH = pypath.join(win ? ';' : ':')
|
||||
|
||||
var cp = gyp.spawn(python, argv)
|
||||
cp.on('exit', onCpExit)
|
||||
await new Promise((resolve, reject) => {
|
||||
const cp = gyp.spawn(python, argv)
|
||||
cp.on('exit', (code) => {
|
||||
if (code !== 0) {
|
||||
reject(new Error('`gyp` failed with exit code: ' + code))
|
||||
} else {
|
||||
// we're done
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function onCpExit (code) {
|
||||
if (code !== 0) {
|
||||
callback(new Error('`gyp` failed with exit code: ' + code))
|
||||
} else {
|
||||
// we're done
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first file or directory from an array of candidates that is
|
||||
* readable by the current user, or undefined if none of the candidates are
|
||||
* readable.
|
||||
*/
|
||||
function findAccessibleSync (logprefix, dir, candidates) {
|
||||
for (var next = 0; next < candidates.length; next++) {
|
||||
var candidate = path.resolve(dir, candidates[next])
|
||||
try {
|
||||
var fd = fs.openSync(candidate, 'r')
|
||||
} catch (e) {
|
||||
// this candidate was not found or not readable, do nothing
|
||||
log.silly(logprefix, 'Could not open %s: %s', candidate, e.message)
|
||||
continue
|
||||
}
|
||||
fs.closeSync(fd)
|
||||
log.silly(logprefix, 'Found readable %s', candidate)
|
||||
return candidate
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
module.exports = configure
|
||||
module.exports.test = {
|
||||
findAccessibleSync: findAccessibleSync
|
||||
}
|
||||
module.exports.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' for the current module'
|
||||
|
|
|
|||
28
electron/node_modules/node-gyp/lib/create-config-gypi.js
generated
vendored
28
electron/node_modules/node-gyp/lib/create-config-gypi.js
generated
vendored
|
|
@ -1,7 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const log = require('npmlog')
|
||||
const fs = require('graceful-fs').promises
|
||||
const log = require('./log')
|
||||
const path = require('path')
|
||||
|
||||
function parseConfigGypi (config) {
|
||||
|
|
@ -24,7 +24,7 @@ async function getBaseConfigGypi ({ gyp, nodeDir }) {
|
|||
if (shouldReadConfigGypi && nodeDir) {
|
||||
try {
|
||||
const baseConfigGypiPath = path.resolve(nodeDir, 'include/node/config.gypi')
|
||||
const baseConfigGypi = await fs.promises.readFile(baseConfigGypiPath)
|
||||
const baseConfigGypi = await fs.readFile(baseConfigGypiPath)
|
||||
return parseConfigGypi(baseConfigGypi.toString())
|
||||
} catch (err) {
|
||||
log.warn('read config.gypi', err.message)
|
||||
|
|
@ -35,7 +35,7 @@ async function getBaseConfigGypi ({ gyp, nodeDir }) {
|
|||
return JSON.parse(JSON.stringify(process.config))
|
||||
}
|
||||
|
||||
async function getCurrentConfigGypi ({ gyp, nodeDir, vsInfo }) {
|
||||
async function getCurrentConfigGypi ({ gyp, nodeDir, vsInfo, python }) {
|
||||
const config = await getBaseConfigGypi({ gyp, nodeDir })
|
||||
if (!config.target_defaults) {
|
||||
config.target_defaults = {}
|
||||
|
|
@ -75,6 +75,9 @@ async function getCurrentConfigGypi ({ gyp, nodeDir, vsInfo }) {
|
|||
// set the node development directory
|
||||
variables.nodedir = nodeDir
|
||||
|
||||
// set the configured Python path
|
||||
variables.python = python
|
||||
|
||||
// disable -T "thin" static archives by default
|
||||
variables.standalone_static_library = gyp.opts.thin ? 0 : 1
|
||||
|
||||
|
|
@ -93,6 +96,9 @@ async function getCurrentConfigGypi ({ gyp, nodeDir, vsInfo }) {
|
|||
}
|
||||
}
|
||||
variables.msbuild_path = vsInfo.msBuild
|
||||
if (config.variables.clang === 1) {
|
||||
config.variables.clang = 0
|
||||
}
|
||||
}
|
||||
|
||||
// loop through the rest of the opts and add the unknown ones as variables.
|
||||
|
|
@ -112,13 +118,13 @@ async function getCurrentConfigGypi ({ gyp, nodeDir, vsInfo }) {
|
|||
return config
|
||||
}
|
||||
|
||||
async function createConfigGypi ({ gyp, buildDir, nodeDir, vsInfo }) {
|
||||
async function createConfigGypi ({ gyp, buildDir, nodeDir, vsInfo, python }) {
|
||||
const configFilename = 'config.gypi'
|
||||
const configPath = path.resolve(buildDir, configFilename)
|
||||
|
||||
log.verbose('build/' + configFilename, 'creating config file')
|
||||
|
||||
const config = await getCurrentConfigGypi({ gyp, nodeDir, vsInfo })
|
||||
const config = await getCurrentConfigGypi({ gyp, nodeDir, vsInfo, python })
|
||||
|
||||
// ensures that any boolean values in config.gypi get stringified
|
||||
function boolsToString (k, v) {
|
||||
|
|
@ -135,13 +141,13 @@ async function createConfigGypi ({ gyp, buildDir, nodeDir, vsInfo }) {
|
|||
|
||||
const json = JSON.stringify(config, boolsToString, 2)
|
||||
log.verbose('build/' + configFilename, 'writing out config file: %s', configPath)
|
||||
await fs.promises.writeFile(configPath, [prefix, json, ''].join('\n'))
|
||||
await fs.writeFile(configPath, [prefix, json, ''].join('\n'))
|
||||
|
||||
return configPath
|
||||
}
|
||||
|
||||
module.exports = createConfigGypi
|
||||
module.exports.test = {
|
||||
parseConfigGypi: parseConfigGypi,
|
||||
getCurrentConfigGypi: getCurrentConfigGypi
|
||||
module.exports = {
|
||||
createConfigGypi,
|
||||
parseConfigGypi,
|
||||
getCurrentConfigGypi
|
||||
}
|
||||
|
|
|
|||
86
electron/node_modules/node-gyp/lib/download.js
generated
vendored
Normal file
86
electron/node_modules/node-gyp/lib/download.js
generated
vendored
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
const { Readable } = require('stream')
|
||||
const { Agent, EnvHttpProxyAgent, RetryAgent, fetch } = require('undici')
|
||||
const { promises: fs } = require('graceful-fs')
|
||||
const log = require('./log')
|
||||
|
||||
async function download (gyp, url) {
|
||||
log.http('GET', url)
|
||||
|
||||
const requestOpts = {
|
||||
headers: {
|
||||
'User-Agent': `node-gyp v${gyp.version} (node ${process.version})`,
|
||||
Connection: 'keep-alive'
|
||||
},
|
||||
dispatcher: await createDispatcher(gyp)
|
||||
}
|
||||
|
||||
let res
|
||||
try {
|
||||
res = await fetch(url, requestOpts)
|
||||
} catch (err) {
|
||||
// Built-in fetch wraps low-level errors in "TypeError: fetch failed" with
|
||||
// the underlying error on .cause. Callers inspect .code (e.g. ENOTFOUND).
|
||||
if (err.cause) {
|
||||
throw err.cause
|
||||
}
|
||||
throw err
|
||||
}
|
||||
|
||||
log.http(res.status, res.url)
|
||||
|
||||
const body = res.body ? Readable.fromWeb(res.body) : Readable.from([])
|
||||
return {
|
||||
status: res.status,
|
||||
url: res.url,
|
||||
body,
|
||||
text: async () => {
|
||||
let data = ''
|
||||
body.setEncoding('utf8')
|
||||
for await (const chunk of body) {
|
||||
data += chunk
|
||||
}
|
||||
return data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function createDispatcher (gyp) {
|
||||
const env = process.env
|
||||
const hasProxyEnv = env.http_proxy || env.HTTP_PROXY || env.https_proxy || env.HTTPS_PROXY
|
||||
if (!gyp.opts.proxy && !gyp.opts.cafile && !hasProxyEnv) {
|
||||
return new RetryAgent(new Agent(), { maxRetries: 3 })
|
||||
}
|
||||
|
||||
const opts = {}
|
||||
if (gyp.opts.cafile) {
|
||||
const ca = await readCAFile(gyp.opts.cafile)
|
||||
// EnvHttpProxyAgent forwards opts to both its internal Agent (direct) and
|
||||
// ProxyAgent (proxied). Agent reads TLS config from `connect`; ProxyAgent
|
||||
// reads it from `requestTls` (origin) / `proxyTls` (proxy). Set all three
|
||||
// so the custom CA is applied regardless of which path a request takes.
|
||||
opts.connect = { ca }
|
||||
opts.requestTls = { ca }
|
||||
opts.proxyTls = { ca }
|
||||
}
|
||||
if (gyp.opts.proxy) {
|
||||
opts.httpProxy = gyp.opts.proxy
|
||||
opts.httpsProxy = gyp.opts.proxy
|
||||
}
|
||||
if (gyp.opts.noproxy) {
|
||||
opts.noProxy = gyp.opts.noproxy
|
||||
}
|
||||
return new RetryAgent(new EnvHttpProxyAgent(opts), { maxRetries: 3 })
|
||||
}
|
||||
|
||||
async function readCAFile (filename) {
|
||||
// The CA file can contain multiple certificates so split on certificate
|
||||
// boundaries. [\S\s]*? is used to match everything including newlines.
|
||||
const ca = await fs.readFile(filename, 'utf8')
|
||||
const re = /(-----BEGIN CERTIFICATE-----[\S\s]*?-----END CERTIFICATE-----)/g
|
||||
return ca.match(re)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
download,
|
||||
readCAFile
|
||||
}
|
||||
10
electron/node_modules/node-gyp/lib/find-node-directory.js
generated
vendored
10
electron/node_modules/node-gyp/lib/find-node-directory.js
generated
vendored
|
|
@ -1,7 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const path = require('path')
|
||||
const log = require('npmlog')
|
||||
const log = require('./log')
|
||||
|
||||
function findNodeDirectory (scriptLocation, processObj) {
|
||||
// set dirname and process if not passed in
|
||||
|
|
@ -14,10 +14,10 @@ function findNodeDirectory (scriptLocation, processObj) {
|
|||
}
|
||||
|
||||
// Have a look to see what is above us, to try and work out where we are
|
||||
var npmParentDirectory = path.join(scriptLocation, '../../../..')
|
||||
const npmParentDirectory = path.join(scriptLocation, '../../../..')
|
||||
log.verbose('node-gyp root', 'npm_parent_directory is ' +
|
||||
path.basename(npmParentDirectory))
|
||||
var nodeRootDir = ''
|
||||
let nodeRootDir = ''
|
||||
|
||||
log.verbose('node-gyp root', 'Finding node root directory')
|
||||
if (path.basename(npmParentDirectory) === 'deps') {
|
||||
|
|
@ -41,8 +41,8 @@ function findNodeDirectory (scriptLocation, processObj) {
|
|||
} else {
|
||||
// We don't know where we are, try working it out from the location
|
||||
// of the node binary
|
||||
var nodeDir = path.dirname(processObj.execPath)
|
||||
var directoryUp = path.basename(nodeDir)
|
||||
const nodeDir = path.dirname(processObj.execPath)
|
||||
const directoryUp = path.basename(nodeDir)
|
||||
if (directoryUp === 'bin') {
|
||||
nodeRootDir = path.join(nodeDir, '..')
|
||||
} else if (directoryUp === 'Release' || directoryUp === 'Debug') {
|
||||
|
|
|
|||
302
electron/node_modules/node-gyp/lib/find-python.js
generated
vendored
302
electron/node_modules/node-gyp/lib/find-python.js
generated
vendored
|
|
@ -1,11 +1,15 @@
|
|||
'use strict'
|
||||
|
||||
const log = require('npmlog')
|
||||
const log = require('./log')
|
||||
const semver = require('semver')
|
||||
const cp = require('child_process')
|
||||
const extend = require('util')._extend // eslint-disable-line
|
||||
const { execFile } = require('./util')
|
||||
const win = process.platform === 'win32'
|
||||
const logWithPrefix = require('./util').logWithPrefix
|
||||
|
||||
function getOsUserInfo () {
|
||||
try {
|
||||
return require('os').userInfo().username
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const systemDrive = process.env.SystemDrive || 'C:'
|
||||
const username = process.env.USERNAME || process.env.USER || getOsUserInfo()
|
||||
|
|
@ -15,7 +19,7 @@ const programFiles = process.env.ProgramW6432 || process.env.ProgramFiles || `${
|
|||
const programFilesX86 = process.env['ProgramFiles(x86)'] || `${programFiles} (x86)`
|
||||
|
||||
const winDefaultLocationsArray = []
|
||||
for (const majorMinor of ['39', '38', '37', '36']) {
|
||||
for (const majorMinor of ['311', '310', '39', '38']) {
|
||||
if (foundLocalAppData) {
|
||||
winDefaultLocationsArray.push(
|
||||
`${localAppData}\\Programs\\Python\\Python${majorMinor}\\python.exe`,
|
||||
|
|
@ -33,45 +37,39 @@ for (const majorMinor of ['39', '38', '37', '36']) {
|
|||
}
|
||||
}
|
||||
|
||||
function getOsUserInfo () {
|
||||
try {
|
||||
return require('os').userInfo().username
|
||||
} catch (e) {}
|
||||
}
|
||||
class PythonFinder {
|
||||
static findPython = (...args) => new PythonFinder(...args).findPython()
|
||||
|
||||
function PythonFinder (configPython, callback) {
|
||||
this.callback = callback
|
||||
this.configPython = configPython
|
||||
this.errorLog = []
|
||||
}
|
||||
|
||||
PythonFinder.prototype = {
|
||||
log: logWithPrefix(log, 'find Python'),
|
||||
argsExecutable: ['-c', 'import sys; print(sys.executable);'],
|
||||
argsVersion: ['-c', 'import sys; print("%s.%s.%s" % sys.version_info[:3]);'],
|
||||
semverRange: '>=3.6.0',
|
||||
log = log.withPrefix('find Python')
|
||||
argsExecutable = ['-c', 'import sys; sys.stdout.buffer.write(sys.executable.encode(\'utf-8\'));']
|
||||
argsVersion = ['-c', 'import sys; print("%s.%s.%s" % sys.version_info[:3]);']
|
||||
semverRange = '>=3.6.0'
|
||||
|
||||
// These can be overridden for testing:
|
||||
execFile: cp.execFile,
|
||||
env: process.env,
|
||||
win: win,
|
||||
pyLauncher: 'py.exe',
|
||||
winDefaultLocations: winDefaultLocationsArray,
|
||||
execFile = execFile
|
||||
env = process.env
|
||||
win = win
|
||||
pyLauncher = 'py.exe'
|
||||
winDefaultLocations = winDefaultLocationsArray
|
||||
|
||||
constructor (configPython) {
|
||||
this.configPython = configPython
|
||||
this.errorLog = []
|
||||
}
|
||||
|
||||
// Logs a message at verbose level, but also saves it to be displayed later
|
||||
// at error level if an error occurs. This should help diagnose the problem.
|
||||
addLog: function addLog (message) {
|
||||
addLog (message) {
|
||||
this.log.verbose(message)
|
||||
this.errorLog.push(message)
|
||||
},
|
||||
}
|
||||
|
||||
// Find Python by trying a sequence of possibilities.
|
||||
// Ignore errors, keep trying until Python is found.
|
||||
findPython: function findPython () {
|
||||
const SKIP = 0; const FAIL = 1
|
||||
var toCheck = getChecks.apply(this)
|
||||
|
||||
function getChecks () {
|
||||
async findPython () {
|
||||
const SKIP = 0
|
||||
const FAIL = 1
|
||||
const toCheck = (() => {
|
||||
if (this.env.NODE_GYP_FORCE_PYTHON) {
|
||||
return [{
|
||||
before: () => {
|
||||
|
|
@ -80,26 +78,20 @@ PythonFinder.prototype = {
|
|||
this.addLog('- process.env.NODE_GYP_FORCE_PYTHON is ' +
|
||||
`"${this.env.NODE_GYP_FORCE_PYTHON}"`)
|
||||
},
|
||||
check: this.checkCommand,
|
||||
arg: this.env.NODE_GYP_FORCE_PYTHON
|
||||
check: () => this.checkCommand(this.env.NODE_GYP_FORCE_PYTHON)
|
||||
}]
|
||||
}
|
||||
|
||||
var checks = [
|
||||
const checks = [
|
||||
{
|
||||
before: () => {
|
||||
if (!this.configPython) {
|
||||
this.addLog(
|
||||
'Python is not set from command line or npm configuration')
|
||||
this.addLog('--python was not set on the command line')
|
||||
return SKIP
|
||||
}
|
||||
this.addLog('checking Python explicitly set from command line or ' +
|
||||
'npm configuration')
|
||||
this.addLog('- "--python=" or "npm config get python" is ' +
|
||||
`"${this.configPython}"`)
|
||||
this.addLog(`--python=${this.configPython} was set on the command line`)
|
||||
},
|
||||
check: this.checkCommand,
|
||||
arg: this.configPython
|
||||
check: () => this.checkCommand(this.configPython)
|
||||
},
|
||||
{
|
||||
before: () => {
|
||||
|
|
@ -112,78 +104,69 @@ PythonFinder.prototype = {
|
|||
'variable PYTHON')
|
||||
this.addLog(`- process.env.PYTHON is "${this.env.PYTHON}"`)
|
||||
},
|
||||
check: this.checkCommand,
|
||||
arg: this.env.PYTHON
|
||||
},
|
||||
{
|
||||
before: () => { this.addLog('checking if "python3" can be used') },
|
||||
check: this.checkCommand,
|
||||
arg: 'python3'
|
||||
},
|
||||
{
|
||||
before: () => { this.addLog('checking if "python" can be used') },
|
||||
check: this.checkCommand,
|
||||
arg: 'python'
|
||||
check: () => this.checkCommand(this.env.PYTHON)
|
||||
}
|
||||
]
|
||||
|
||||
if (this.win) {
|
||||
for (var i = 0; i < this.winDefaultLocations.length; ++i) {
|
||||
const location = this.winDefaultLocations[i]
|
||||
checks.push({
|
||||
before: () => {
|
||||
this.addLog('checking if Python is ' +
|
||||
`${location}`)
|
||||
},
|
||||
check: this.checkExecPath,
|
||||
arg: location
|
||||
})
|
||||
}
|
||||
checks.push({
|
||||
before: () => {
|
||||
this.addLog(
|
||||
'checking if the py launcher can be used to find Python 3')
|
||||
},
|
||||
check: this.checkPyLauncher
|
||||
check: () => this.checkPyLauncher()
|
||||
})
|
||||
}
|
||||
|
||||
return checks
|
||||
}
|
||||
checks.push(...[
|
||||
{
|
||||
before: () => { this.addLog('checking if "python3" can be used') },
|
||||
check: () => this.checkCommand('python3')
|
||||
},
|
||||
{
|
||||
before: () => { this.addLog('checking if "python" can be used') },
|
||||
check: () => this.checkCommand('python')
|
||||
}
|
||||
])
|
||||
|
||||
function runChecks (err) {
|
||||
this.log.silly('runChecks: err = %j', (err && err.stack) || err)
|
||||
|
||||
const check = toCheck.shift()
|
||||
if (!check) {
|
||||
return this.fail()
|
||||
if (this.win) {
|
||||
for (let i = 0; i < this.winDefaultLocations.length; ++i) {
|
||||
const location = this.winDefaultLocations[i]
|
||||
checks.push({
|
||||
before: () => this.addLog(`checking if Python is ${location}`),
|
||||
check: () => this.checkExecPath(location)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const before = check.before.apply(this)
|
||||
return checks
|
||||
})()
|
||||
|
||||
for (const check of toCheck) {
|
||||
const before = check.before()
|
||||
if (before === SKIP) {
|
||||
return runChecks.apply(this)
|
||||
continue
|
||||
}
|
||||
if (before === FAIL) {
|
||||
return this.fail()
|
||||
}
|
||||
|
||||
const args = [runChecks.bind(this)]
|
||||
if (check.arg) {
|
||||
args.unshift(check.arg)
|
||||
try {
|
||||
return await check.check()
|
||||
} catch (err) {
|
||||
this.log.silly('runChecks: err = %j', (err && err.stack) || err)
|
||||
}
|
||||
check.check.apply(this, args)
|
||||
}
|
||||
|
||||
runChecks.apply(this)
|
||||
},
|
||||
return this.fail()
|
||||
}
|
||||
|
||||
// Check if command is a valid Python to use.
|
||||
// Will exit the Python finder on success.
|
||||
// If on Windows, run in a CMD shell to support BAT/CMD launchers.
|
||||
checkCommand: function checkCommand (command, errorCallback) {
|
||||
var exec = command
|
||||
var args = this.argsExecutable
|
||||
var shell = false
|
||||
async checkCommand (command) {
|
||||
let exec = command
|
||||
let args = this.argsExecutable
|
||||
let shell = false
|
||||
if (this.win) {
|
||||
// Arguments have to be manually quoted
|
||||
exec = `"${exec}"`
|
||||
|
|
@ -192,19 +175,19 @@ PythonFinder.prototype = {
|
|||
}
|
||||
|
||||
this.log.verbose(`- executing "${command}" to get executable path`)
|
||||
this.run(exec, args, shell, function (err, execPath) {
|
||||
// Possible outcomes:
|
||||
// - Error: not in PATH, not executable or execution fails
|
||||
// - Gibberish: the next command to check version will fail
|
||||
// - Absolute path to executable
|
||||
if (err) {
|
||||
this.addLog(`- "${command}" is not in PATH or produced an error`)
|
||||
return errorCallback(err)
|
||||
}
|
||||
// Possible outcomes:
|
||||
// - Error: not in PATH, not executable or execution fails
|
||||
// - Gibberish: the next command to check version will fail
|
||||
// - Absolute path to executable
|
||||
try {
|
||||
const execPath = await this.run(exec, args, shell)
|
||||
this.addLog(`- executable path is "${execPath}"`)
|
||||
this.checkExecPath(execPath, errorCallback)
|
||||
}.bind(this))
|
||||
},
|
||||
return this.checkExecPath(execPath)
|
||||
} catch (err) {
|
||||
this.addLog(`- "${command}" is not in PATH or produced an error`)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the py launcher can find a valid Python to use.
|
||||
// Will exit the Python finder on success.
|
||||
|
|
@ -216,97 +199,86 @@ PythonFinder.prototype = {
|
|||
// the first command line argument. Since "py.exe -3" would be an invalid
|
||||
// executable for "execFile", we have to use the launcher to figure out
|
||||
// where the actual "python.exe" executable is located.
|
||||
checkPyLauncher: function checkPyLauncher (errorCallback) {
|
||||
this.log.verbose(
|
||||
`- executing "${this.pyLauncher}" to get Python 3 executable path`)
|
||||
this.run(this.pyLauncher, ['-3', ...this.argsExecutable], false,
|
||||
function (err, execPath) {
|
||||
// Possible outcomes: same as checkCommand
|
||||
if (err) {
|
||||
this.addLog(
|
||||
`- "${this.pyLauncher}" is not in PATH or produced an error`)
|
||||
return errorCallback(err)
|
||||
}
|
||||
this.addLog(`- executable path is "${execPath}"`)
|
||||
this.checkExecPath(execPath, errorCallback)
|
||||
}.bind(this))
|
||||
},
|
||||
async checkPyLauncher () {
|
||||
this.log.verbose(`- executing "${this.pyLauncher}" to get Python 3 executable path`)
|
||||
// Possible outcomes: same as checkCommand
|
||||
try {
|
||||
const execPath = await this.run(this.pyLauncher, ['-3', ...this.argsExecutable], false)
|
||||
this.addLog(`- executable path is "${execPath}"`)
|
||||
return this.checkExecPath(execPath)
|
||||
} catch (err) {
|
||||
this.addLog(`- "${this.pyLauncher}" is not in PATH or produced an error`)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Check if a Python executable is the correct version to use.
|
||||
// Will exit the Python finder on success.
|
||||
checkExecPath: function checkExecPath (execPath, errorCallback) {
|
||||
async checkExecPath (execPath) {
|
||||
this.log.verbose(`- executing "${execPath}" to get version`)
|
||||
this.run(execPath, this.argsVersion, false, function (err, version) {
|
||||
// Possible outcomes:
|
||||
// - Error: executable can not be run (likely meaning the command wasn't
|
||||
// a Python executable and the previous command produced gibberish)
|
||||
// - Gibberish: somehow the last command produced an executable path,
|
||||
// this will fail when verifying the version
|
||||
// - Version of the Python executable
|
||||
if (err) {
|
||||
this.addLog(`- "${execPath}" could not be run`)
|
||||
return errorCallback(err)
|
||||
}
|
||||
// Possible outcomes:
|
||||
// - Error: executable can not be run (likely meaning the command wasn't
|
||||
// a Python executable and the previous command produced gibberish)
|
||||
// - Gibberish: somehow the last command produced an executable path,
|
||||
// this will fail when verifying the version
|
||||
// - Version of the Python executable
|
||||
try {
|
||||
const version = await this.run(execPath, this.argsVersion, false)
|
||||
this.addLog(`- version is "${version}"`)
|
||||
|
||||
const range = new semver.Range(this.semverRange)
|
||||
var valid = false
|
||||
let valid = false
|
||||
try {
|
||||
valid = range.test(version)
|
||||
} catch (err) {
|
||||
this.log.silly('range.test() threw:\n%s', err.stack)
|
||||
this.addLog(`- "${execPath}" does not have a valid version`)
|
||||
this.addLog('- is it a Python executable?')
|
||||
return errorCallback(err)
|
||||
throw err
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
this.addLog(`- version is ${version} - should be ${this.semverRange}`)
|
||||
this.addLog('- THIS VERSION OF PYTHON IS NOT SUPPORTED')
|
||||
return errorCallback(new Error(
|
||||
`Found unsupported Python version ${version}`))
|
||||
throw new Error(`Found unsupported Python version ${version}`)
|
||||
}
|
||||
this.succeed(execPath, version)
|
||||
}.bind(this))
|
||||
},
|
||||
return this.succeed(execPath, version)
|
||||
} catch (err) {
|
||||
this.addLog(`- "${execPath}" could not be run`)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Run an executable or shell command, trimming the output.
|
||||
run: function run (exec, args, shell, callback) {
|
||||
var env = extend({}, this.env)
|
||||
async run (exec, args, shell) {
|
||||
const env = Object.assign({}, this.env)
|
||||
env.TERM = 'dumb'
|
||||
const opts = { env: env, shell: shell }
|
||||
const opts = { env, shell }
|
||||
|
||||
this.log.silly('execFile: exec = %j', exec)
|
||||
this.log.silly('execFile: args = %j', args)
|
||||
this.log.silly('execFile: opts = %j', opts)
|
||||
try {
|
||||
this.execFile(exec, args, opts, execFileCallback.bind(this))
|
||||
} catch (err) {
|
||||
this.log.silly('execFile: threw:\n%s', err.stack)
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
function execFileCallback (err, stdout, stderr) {
|
||||
const [err, stdout, stderr] = await this.execFile(exec, args, opts)
|
||||
this.log.silly('execFile result: err = %j', (err && err.stack) || err)
|
||||
this.log.silly('execFile result: stdout = %j', stdout)
|
||||
this.log.silly('execFile result: stderr = %j', stderr)
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
const execPath = stdout.trim()
|
||||
callback(null, execPath)
|
||||
return stdout.trim()
|
||||
} catch (err) {
|
||||
this.log.silly('execFile: threw:\n%s', err.stack)
|
||||
throw err
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
succeed: function succeed (execPath, version) {
|
||||
succeed (execPath, version) {
|
||||
this.log.info(`using Python version ${version} found at "${execPath}"`)
|
||||
process.nextTick(this.callback.bind(null, null, execPath))
|
||||
},
|
||||
return execPath
|
||||
}
|
||||
|
||||
fail: function fail () {
|
||||
fail () {
|
||||
const errorLog = this.errorLog.join('\n')
|
||||
|
||||
const pathExample = this.win ? 'C:\\Path\\To\\python.exe'
|
||||
const pathExample = this.win
|
||||
? 'C:\\Path\\To\\python.exe'
|
||||
: '/path/to/pythonexecutable'
|
||||
// For Windows 80 col console, use up to the column before the one marked
|
||||
// with X (total 79 chars including logger prefix, 58 chars usable here):
|
||||
|
|
@ -319,26 +291,14 @@ PythonFinder.prototype = {
|
|||
`- Use the switch --python="${pathExample}"`,
|
||||
' (accepted by both node-gyp and npm)',
|
||||
'- Set the environment variable PYTHON',
|
||||
'- Set the npm configuration variable python:',
|
||||
` npm config set python "${pathExample}"`,
|
||||
'For more information consult the documentation at:',
|
||||
'https://github.com/nodejs/node-gyp#installation',
|
||||
'**********************************************************'
|
||||
].join('\n')
|
||||
|
||||
this.log.error(`\n${errorLog}\n\n${info}\n`)
|
||||
process.nextTick(this.callback.bind(null, new Error(
|
||||
'Could not find any Python installation to use')))
|
||||
throw new Error('Could not find any Python installation to use')
|
||||
}
|
||||
}
|
||||
|
||||
function findPython (configPython, callback) {
|
||||
var finder = new PythonFinder(configPython, callback)
|
||||
finder.findPython()
|
||||
}
|
||||
|
||||
module.exports = findPython
|
||||
module.exports.test = {
|
||||
PythonFinder: PythonFinder,
|
||||
findPython: findPython
|
||||
}
|
||||
module.exports = PythonFinder
|
||||
|
|
|
|||
413
electron/node_modules/node-gyp/lib/find-visualstudio.js
generated
vendored
413
electron/node_modules/node-gyp/lib/find-visualstudio.js
generated
vendored
|
|
@ -1,43 +1,36 @@
|
|||
'use strict'
|
||||
|
||||
const log = require('npmlog')
|
||||
const execFile = require('child_process').execFile
|
||||
const fs = require('fs')
|
||||
const path = require('path').win32
|
||||
const logWithPrefix = require('./util').logWithPrefix
|
||||
const regSearchKeys = require('./util').regSearchKeys
|
||||
const log = require('./log')
|
||||
const { existsSync } = require('fs')
|
||||
const { win32: path } = require('path')
|
||||
const { regSearchKeys, execFile } = require('./util')
|
||||
|
||||
function findVisualStudio (nodeSemver, configMsvsVersion, callback) {
|
||||
const finder = new VisualStudioFinder(nodeSemver, configMsvsVersion,
|
||||
callback)
|
||||
finder.findVisualStudio()
|
||||
}
|
||||
class VisualStudioFinder {
|
||||
static findVisualStudio = (...args) => new VisualStudioFinder(...args).findVisualStudio()
|
||||
|
||||
function VisualStudioFinder (nodeSemver, configMsvsVersion, callback) {
|
||||
this.nodeSemver = nodeSemver
|
||||
this.configMsvsVersion = configMsvsVersion
|
||||
this.callback = callback
|
||||
this.errorLog = []
|
||||
this.validVersions = []
|
||||
}
|
||||
log = log.withPrefix('find VS')
|
||||
|
||||
VisualStudioFinder.prototype = {
|
||||
log: logWithPrefix(log, 'find VS'),
|
||||
regSearchKeys = regSearchKeys
|
||||
|
||||
regSearchKeys: regSearchKeys,
|
||||
constructor (nodeSemver, configMsvsVersion) {
|
||||
this.nodeSemver = nodeSemver
|
||||
this.configMsvsVersion = configMsvsVersion
|
||||
this.errorLog = []
|
||||
this.validVersions = []
|
||||
}
|
||||
|
||||
// Logs a message at verbose level, but also saves it to be displayed later
|
||||
// at error level if an error occurs. This should help diagnose the problem.
|
||||
addLog: function addLog (message) {
|
||||
addLog (message) {
|
||||
this.log.verbose(message)
|
||||
this.errorLog.push(message)
|
||||
},
|
||||
}
|
||||
|
||||
findVisualStudio: function findVisualStudio () {
|
||||
async findVisualStudio () {
|
||||
this.configVersionYear = null
|
||||
this.configPath = null
|
||||
if (this.configMsvsVersion) {
|
||||
this.addLog('msvs_version was set from command line or npm config')
|
||||
this.addLog(`--msvs_version=${this.configMsvsVersion} was set on the command line`)
|
||||
if (this.configMsvsVersion.match(/^\d{4}$/)) {
|
||||
this.configVersionYear = parseInt(this.configMsvsVersion, 10)
|
||||
this.addLog(
|
||||
|
|
@ -48,7 +41,7 @@ VisualStudioFinder.prototype = {
|
|||
`- looking for Visual Studio installed in "${this.configPath}"`)
|
||||
}
|
||||
} else {
|
||||
this.addLog('msvs_version not set from command line or npm config')
|
||||
this.addLog('--msvs_version was not set on the command line')
|
||||
}
|
||||
|
||||
if (process.env.VCINSTALLDIR) {
|
||||
|
|
@ -60,32 +53,35 @@ VisualStudioFinder.prototype = {
|
|||
this.addLog('VCINSTALLDIR not set, not running in VS Command Prompt')
|
||||
}
|
||||
|
||||
this.findVisualStudio2017OrNewer((info) => {
|
||||
const checks = [
|
||||
() => this.findVisualStudio2019OrNewerFromSpecifiedLocation(),
|
||||
() => this.findVisualStudio2019OrNewerUsingSetupModule(),
|
||||
() => this.findVisualStudio2019OrNewer(),
|
||||
() => this.findVisualStudio2017FromSpecifiedLocation(),
|
||||
() => this.findVisualStudio2017UsingSetupModule(),
|
||||
() => this.findVisualStudio2017(),
|
||||
() => this.findVisualStudio2015(),
|
||||
() => this.findVisualStudio2013()
|
||||
]
|
||||
|
||||
for (const check of checks) {
|
||||
const info = await check()
|
||||
if (info) {
|
||||
return this.succeed(info)
|
||||
}
|
||||
this.findVisualStudio2015((info) => {
|
||||
if (info) {
|
||||
return this.succeed(info)
|
||||
}
|
||||
this.findVisualStudio2013((info) => {
|
||||
if (info) {
|
||||
return this.succeed(info)
|
||||
}
|
||||
this.fail()
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
succeed: function succeed (info) {
|
||||
return this.fail()
|
||||
}
|
||||
|
||||
succeed (info) {
|
||||
this.log.info(`using VS${info.versionYear} (${info.version}) found at:` +
|
||||
`\n"${info.path}"` +
|
||||
'\nrun with --verbose for detailed information')
|
||||
process.nextTick(this.callback.bind(null, null, info))
|
||||
},
|
||||
return info
|
||||
}
|
||||
|
||||
fail: function fail () {
|
||||
fail () {
|
||||
if (this.configMsvsVersion && this.envVcInstallDir) {
|
||||
this.errorLog.push(
|
||||
'msvs_version does not match this VS Command Prompt or the',
|
||||
|
|
@ -119,49 +115,174 @@ VisualStudioFinder.prototype = {
|
|||
].join('\n')
|
||||
|
||||
this.log.error(`\n${errorLog}\n\n${infoLog}\n`)
|
||||
process.nextTick(this.callback.bind(null, new Error(
|
||||
'Could not find any Visual Studio installation to use')))
|
||||
},
|
||||
throw new Error('Could not find any Visual Studio installation to use')
|
||||
}
|
||||
|
||||
async findVisualStudio2019OrNewerFromSpecifiedLocation () {
|
||||
return this.findVSFromSpecifiedLocation([2019, 2022, 2026])
|
||||
}
|
||||
|
||||
async findVisualStudio2017FromSpecifiedLocation () {
|
||||
if (this.nodeSemver.major >= 22) {
|
||||
this.addLog(
|
||||
'not looking for VS2017 as it is only supported up to Node.js 21')
|
||||
return null
|
||||
}
|
||||
return this.findVSFromSpecifiedLocation([2017])
|
||||
}
|
||||
|
||||
async findVSFromSpecifiedLocation (supportedYears) {
|
||||
if (!this.envVcInstallDir) {
|
||||
return null
|
||||
}
|
||||
const info = {
|
||||
path: path.resolve(this.envVcInstallDir),
|
||||
// Assume the version specified by the user is correct.
|
||||
// Since Visual Studio 2015, the Developer Command Prompt sets the
|
||||
// VSCMD_VER environment variable which contains the version information
|
||||
// for Visual Studio.
|
||||
// https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022
|
||||
version: process.env.VSCMD_VER,
|
||||
packages: [
|
||||
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
|
||||
'Microsoft.VisualStudio.Component.VC.Tools.ARM64',
|
||||
// Assume MSBuild exists. It will be checked in processing.
|
||||
'Microsoft.VisualStudio.VC.MSBuild.Base'
|
||||
]
|
||||
}
|
||||
|
||||
// Is there a better way to get SDK information?
|
||||
const envWindowsSDKVersion = process.env.WindowsSDKVersion
|
||||
const sdkVersionMatched = envWindowsSDKVersion?.match(/^(\d+)\.(\d+)\.(\d+)\..*/)
|
||||
if (sdkVersionMatched) {
|
||||
info.packages.push(`Microsoft.VisualStudio.Component.Windows10SDK.${sdkVersionMatched[3]}.Desktop`)
|
||||
}
|
||||
// pass for further processing
|
||||
return this.processData([info], supportedYears)
|
||||
}
|
||||
|
||||
async findVisualStudio2019OrNewerUsingSetupModule () {
|
||||
return this.findNewVSUsingSetupModule([2019, 2022, 2026])
|
||||
}
|
||||
|
||||
async findVisualStudio2017UsingSetupModule () {
|
||||
if (this.nodeSemver.major >= 22) {
|
||||
this.addLog(
|
||||
'not looking for VS2017 as it is only supported up to Node.js 21')
|
||||
return null
|
||||
}
|
||||
return this.findNewVSUsingSetupModule([2017])
|
||||
}
|
||||
|
||||
async findNewVSUsingSetupModule (supportedYears) {
|
||||
const ps = path.join(process.env.SystemRoot, 'System32',
|
||||
'WindowsPowerShell', 'v1.0', 'powershell.exe')
|
||||
const vcInstallDir = this.envVcInstallDir
|
||||
|
||||
const checkModuleArgs = [
|
||||
'-NoProfile',
|
||||
'-Command',
|
||||
'&{@(Get-Module -ListAvailable -Name VSSetup).Version.ToString()}'
|
||||
]
|
||||
this.log.silly('Running', ps, checkModuleArgs)
|
||||
const [cErr] = await this.execFile(ps, checkModuleArgs)
|
||||
if (cErr) {
|
||||
this.addLog('VSSetup module doesn\'t seem to exist. You can install it via: "Install-Module VSSetup -Scope CurrentUser"')
|
||||
this.log.silly('VSSetup error = %j', cErr && (cErr.stack || cErr))
|
||||
return null
|
||||
}
|
||||
const filterArg = vcInstallDir !== undefined ? `| where {$_.InstallationPath -eq '${vcInstallDir}' }` : ''
|
||||
const psArgs = [
|
||||
'-NoProfile',
|
||||
'-Command',
|
||||
`&{Get-VSSetupInstance ${filterArg} | ConvertTo-Json -Depth 3}`
|
||||
]
|
||||
|
||||
this.log.silly('Running', ps, psArgs)
|
||||
const [err, stdout, stderr] = await this.execFile(ps, psArgs)
|
||||
let parsedData = this.parseData(err, stdout, stderr)
|
||||
if (parsedData === null) {
|
||||
return null
|
||||
}
|
||||
this.log.silly('Parsed data', parsedData)
|
||||
if (!Array.isArray(parsedData)) {
|
||||
// if there are only 1 result, then Powershell will output non-array
|
||||
parsedData = [parsedData]
|
||||
}
|
||||
// normalize output
|
||||
parsedData = parsedData.map((info) => {
|
||||
info.path = info.InstallationPath
|
||||
info.version = `${info.InstallationVersion.Major}.${info.InstallationVersion.Minor}.${info.InstallationVersion.Build}.${info.InstallationVersion.Revision}`
|
||||
info.packages = info.Packages.map((p) => p.Id)
|
||||
return info
|
||||
})
|
||||
// pass for further processing
|
||||
return this.processData(parsedData, supportedYears)
|
||||
}
|
||||
|
||||
// Invoke the PowerShell script to get information about Visual Studio 2019
|
||||
// or newer installations
|
||||
async findVisualStudio2019OrNewer () {
|
||||
return this.findNewVS([2019, 2022, 2026])
|
||||
}
|
||||
|
||||
// Invoke the PowerShell script to get information about Visual Studio 2017
|
||||
async findVisualStudio2017 () {
|
||||
if (this.nodeSemver.major >= 22) {
|
||||
this.addLog(
|
||||
'not looking for VS2017 as it is only supported up to Node.js 21')
|
||||
return null
|
||||
}
|
||||
return this.findNewVS([2017])
|
||||
}
|
||||
|
||||
// Invoke the PowerShell script to get information about Visual Studio 2017
|
||||
// or newer installations
|
||||
findVisualStudio2017OrNewer: function findVisualStudio2017OrNewer (cb) {
|
||||
var ps = path.join(process.env.SystemRoot, 'System32',
|
||||
async findNewVS (supportedYears) {
|
||||
const ps = path.join(process.env.SystemRoot, 'System32',
|
||||
'WindowsPowerShell', 'v1.0', 'powershell.exe')
|
||||
var csFile = path.join(__dirname, 'Find-VisualStudio.cs')
|
||||
var psArgs = [
|
||||
const csFile = path.join(__dirname, 'Find-VisualStudio.cs')
|
||||
const psArgs = [
|
||||
'-ExecutionPolicy',
|
||||
'Unrestricted',
|
||||
'-NoProfile',
|
||||
'-Command',
|
||||
'&{Add-Type -Path \'' + csFile + '\';' + '[VisualStudioConfiguration.Main]::PrintJson()}'
|
||||
'&{Add-Type -IgnoreWarnings -Path \'' + csFile + '\';' + '[VisualStudioConfiguration.Main]::PrintJson()}'
|
||||
]
|
||||
|
||||
this.log.silly('Running', ps, psArgs)
|
||||
var child = execFile(ps, psArgs, { encoding: 'utf8' },
|
||||
(err, stdout, stderr) => {
|
||||
this.parseData(err, stdout, stderr, cb)
|
||||
})
|
||||
child.stdin.end()
|
||||
},
|
||||
const [err, stdout, stderr] = await this.execFile(ps, psArgs)
|
||||
const parsedData = this.parseData(err, stdout, stderr, { checkIsArray: true })
|
||||
if (parsedData === null) {
|
||||
return null
|
||||
}
|
||||
return this.processData(parsedData, supportedYears)
|
||||
}
|
||||
|
||||
// Parse the output of the PowerShell script, make sanity checks
|
||||
parseData (err, stdout, stderr, sanityCheckOptions) {
|
||||
const defaultOptions = {
|
||||
checkIsArray: false
|
||||
}
|
||||
|
||||
// Merging provided options with the default options
|
||||
const sanityOptions = { ...defaultOptions, ...sanityCheckOptions }
|
||||
|
||||
// Parse the output of the PowerShell script and look for an installation
|
||||
// of Visual Studio 2017 or newer to use
|
||||
parseData: function parseData (err, stdout, stderr, cb) {
|
||||
this.log.silly('PS stderr = %j', stderr)
|
||||
|
||||
const failPowershell = () => {
|
||||
const failPowershell = (failureDetails) => {
|
||||
this.addLog(
|
||||
'could not use PowerShell to find Visual Studio 2017 or newer, try re-running with \'--loglevel silly\' for more details')
|
||||
cb(null)
|
||||
`could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details. \n
|
||||
Failure details: ${failureDetails}`)
|
||||
return null
|
||||
}
|
||||
|
||||
if (err) {
|
||||
this.log.silly('PS err = %j', err && (err.stack || err))
|
||||
return failPowershell()
|
||||
return failPowershell(`${err}`.substring(0, 40))
|
||||
}
|
||||
|
||||
var vsInfo
|
||||
let vsInfo
|
||||
try {
|
||||
vsInfo = JSON.parse(stdout)
|
||||
} catch (e) {
|
||||
|
|
@ -170,15 +291,20 @@ VisualStudioFinder.prototype = {
|
|||
return failPowershell()
|
||||
}
|
||||
|
||||
if (!Array.isArray(vsInfo)) {
|
||||
if (sanityOptions.checkIsArray && !Array.isArray(vsInfo)) {
|
||||
this.log.silly('PS stdout = %j', stdout)
|
||||
return failPowershell()
|
||||
return failPowershell('Expected array as output of the PS script')
|
||||
}
|
||||
return vsInfo
|
||||
}
|
||||
|
||||
// Process parsed data containing information about VS installations
|
||||
// Look for the required parts, extract and output them back
|
||||
processData (vsInfo, supportedYears) {
|
||||
vsInfo = vsInfo.map((info) => {
|
||||
this.log.silly(`processing installation: "${info.path}"`)
|
||||
info.path = path.resolve(info.path)
|
||||
var ret = this.getVersionInfo(info)
|
||||
const ret = this.getVersionInfo(info)
|
||||
ret.path = info.path
|
||||
ret.msBuild = this.getMSBuild(info, ret.versionYear)
|
||||
ret.toolset = this.getToolset(info, ret.versionYear)
|
||||
|
|
@ -188,18 +314,19 @@ VisualStudioFinder.prototype = {
|
|||
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
|
||||
})
|
||||
|
||||
// Sort to place newer versions first
|
||||
vsInfo.sort((a, b) => b.versionYear - a.versionYear)
|
||||
|
||||
for (var i = 0; i < vsInfo.length; ++i) {
|
||||
for (let i = 0; i < vsInfo.length; ++i) {
|
||||
const info = vsInfo[i]
|
||||
this.addLog(`checking VS${info.versionYear} (${info.version}) found ` +
|
||||
`at:\n"${info.path}"`)
|
||||
|
|
@ -229,23 +356,23 @@ VisualStudioFinder.prototype = {
|
|||
continue
|
||||
}
|
||||
|
||||
return cb(info)
|
||||
return info
|
||||
}
|
||||
|
||||
this.addLog(
|
||||
'could not find a version of Visual Studio 2017 or newer to use')
|
||||
cb(null)
|
||||
},
|
||||
return null
|
||||
}
|
||||
|
||||
// Helper - process version information
|
||||
getVersionInfo: function getVersionInfo (info) {
|
||||
const match = /^(\d+)\.(\d+)\..*/.exec(info.version)
|
||||
getVersionInfo (info) {
|
||||
const match = /^(\d+)\.(\d+)(?:\..*)?/.exec(info.version)
|
||||
if (!match) {
|
||||
this.log.silly('- failed to parse version:', info.version)
|
||||
return {}
|
||||
}
|
||||
this.log.silly('- version match = %j', match)
|
||||
var ret = {
|
||||
const ret = {
|
||||
version: info.version,
|
||||
versionMajor: parseInt(match[1], 10),
|
||||
versionMinor: parseInt(match[2], 10)
|
||||
|
|
@ -262,16 +389,20 @@ VisualStudioFinder.prototype = {
|
|||
ret.versionYear = 2022
|
||||
return ret
|
||||
}
|
||||
if (ret.versionMajor === 18) {
|
||||
ret.versionYear = 2026
|
||||
return ret
|
||||
}
|
||||
this.log.silly('- unsupported version:', ret.versionMajor)
|
||||
return {}
|
||||
},
|
||||
}
|
||||
|
||||
msBuildPathExists: function msBuildPathExists (path) {
|
||||
return fs.existsSync(path)
|
||||
},
|
||||
msBuildPathExists (path) {
|
||||
return existsSync(path)
|
||||
}
|
||||
|
||||
// Helper - process MSBuild information
|
||||
getMSBuild: function getMSBuild (info, versionYear) {
|
||||
getMSBuild (info, versionYear) {
|
||||
const pkg = 'Microsoft.VisualStudio.VC.MSBuild.Base'
|
||||
const msbuildPath = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'MSBuild.exe')
|
||||
const msbuildPathArm64 = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'arm64', 'MSBuild.exe')
|
||||
|
|
@ -281,7 +412,11 @@ VisualStudioFinder.prototype = {
|
|||
return path.join(info.path, 'MSBuild', '15.0', 'Bin', 'MSBuild.exe')
|
||||
}
|
||||
if (versionYear === 2019) {
|
||||
return msbuildPath
|
||||
if (process.arch === 'arm64' && this.msBuildPathExists(msbuildPathArm64)) {
|
||||
return msbuildPathArm64
|
||||
} else {
|
||||
return msbuildPath
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
@ -295,16 +430,25 @@ VisualStudioFinder.prototype = {
|
|||
return msbuildPath
|
||||
}
|
||||
return null
|
||||
},
|
||||
}
|
||||
|
||||
// Helper - process toolset information
|
||||
getToolset: function getToolset (info, versionYear) {
|
||||
const pkg = 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
|
||||
getToolset (info, versionYear) {
|
||||
const vcToolsArm64 = 'VC.Tools.ARM64'
|
||||
const pkgArm64 = `Microsoft.VisualStudio.Component.${vcToolsArm64}`
|
||||
const vcToolsX64 = 'VC.Tools.x86.x64'
|
||||
const pkgX64 = `Microsoft.VisualStudio.Component.${vcToolsX64}`
|
||||
const express = 'Microsoft.VisualStudio.WDExpress'
|
||||
|
||||
if (info.packages.indexOf(pkg) !== -1) {
|
||||
this.log.silly('- found VC.Tools.x86.x64')
|
||||
} else if (info.packages.indexOf(express) !== -1) {
|
||||
if (process.arch === 'arm64' && info.packages.includes(pkgArm64)) {
|
||||
this.log.silly(`- found ${vcToolsArm64}`)
|
||||
} else if (info.packages.includes(pkgX64)) {
|
||||
if (process.arch === 'arm64') {
|
||||
this.addLog(`- found ${vcToolsX64} on ARM64 platform. Expect less performance and/or link failure with ARM64 binary.`)
|
||||
} else {
|
||||
this.log.silly(`- found ${vcToolsX64}`)
|
||||
}
|
||||
} else if (info.packages.includes(express)) {
|
||||
this.log.silly('- found Visual Studio Express (looking for toolset)')
|
||||
} else {
|
||||
return null
|
||||
|
|
@ -316,18 +460,20 @@ VisualStudioFinder.prototype = {
|
|||
return 'v142'
|
||||
} else if (versionYear === 2022) {
|
||||
return 'v143'
|
||||
} else if (versionYear === 2026) {
|
||||
return 'v145'
|
||||
}
|
||||
this.log.silly('- invalid versionYear:', versionYear)
|
||||
return null
|
||||
},
|
||||
}
|
||||
|
||||
// Helper - process Windows SDK information
|
||||
getSDK: function getSDK (info) {
|
||||
getSDK (info) {
|
||||
const win8SDK = 'Microsoft.VisualStudio.Component.Windows81SDK'
|
||||
const win10SDKPrefix = 'Microsoft.VisualStudio.Component.Windows10SDK.'
|
||||
const win11SDKPrefix = 'Microsoft.VisualStudio.Component.Windows11SDK.'
|
||||
|
||||
var Win10or11SDKVer = 0
|
||||
let Win10or11SDKVer = 0
|
||||
info.packages.forEach((pkg) => {
|
||||
if (!pkg.startsWith(win10SDKPrefix) && !pkg.startsWith(win11SDKPrefix)) {
|
||||
return
|
||||
|
|
@ -354,14 +500,14 @@ VisualStudioFinder.prototype = {
|
|||
return '8.1'
|
||||
}
|
||||
return null
|
||||
},
|
||||
}
|
||||
|
||||
// Find an installation of Visual Studio 2015 to use
|
||||
findVisualStudio2015: function findVisualStudio2015 (cb) {
|
||||
async findVisualStudio2015 () {
|
||||
if (this.nodeSemver.major >= 19) {
|
||||
this.addLog(
|
||||
'not looking for VS2015 as it is only supported up to Node.js 18')
|
||||
return cb(null)
|
||||
return null
|
||||
}
|
||||
return this.findOldVS({
|
||||
version: '14.0',
|
||||
|
|
@ -369,15 +515,15 @@ VisualStudioFinder.prototype = {
|
|||
versionMinor: 0,
|
||||
versionYear: 2015,
|
||||
toolset: 'v140'
|
||||
}, cb)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Find an installation of Visual Studio 2013 to use
|
||||
findVisualStudio2013: function findVisualStudio2013 (cb) {
|
||||
async findVisualStudio2013 () {
|
||||
if (this.nodeSemver.major >= 9) {
|
||||
this.addLog(
|
||||
'not looking for VS2013 as it is only supported up to Node.js 8')
|
||||
return cb(null)
|
||||
return null
|
||||
}
|
||||
return this.findOldVS({
|
||||
version: '12.0',
|
||||
|
|
@ -385,55 +531,52 @@ VisualStudioFinder.prototype = {
|
|||
versionMinor: 0,
|
||||
versionYear: 2013,
|
||||
toolset: 'v120'
|
||||
}, cb)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Helper - common code for VS2013 and VS2015
|
||||
findOldVS: function findOldVS (info, cb) {
|
||||
async findOldVS (info) {
|
||||
const regVC7 = ['HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7',
|
||||
'HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7']
|
||||
const regMSBuild = 'HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions'
|
||||
|
||||
this.addLog(`looking for Visual Studio ${info.versionYear}`)
|
||||
this.regSearchKeys(regVC7, info.version, [], (err, res) => {
|
||||
if (err) {
|
||||
this.addLog('- not found')
|
||||
return cb(null)
|
||||
}
|
||||
|
||||
try {
|
||||
let res = await this.regSearchKeys(regVC7, info.version, [])
|
||||
const vsPath = path.resolve(res, '..')
|
||||
this.addLog(`- found in "${vsPath}"`)
|
||||
|
||||
const msBuildRegOpts = process.arch === 'ia32' ? [] : ['/reg:32']
|
||||
this.regSearchKeys([`${regMSBuild}\\${info.version}`],
|
||||
'MSBuildToolsPath', msBuildRegOpts, (err, res) => {
|
||||
if (err) {
|
||||
this.addLog(
|
||||
'- could not find MSBuild in registry for this version')
|
||||
return cb(null)
|
||||
}
|
||||
|
||||
const msBuild = path.join(res, 'MSBuild.exe')
|
||||
this.addLog(`- MSBuild in "${msBuild}"`)
|
||||
try {
|
||||
res = await this.regSearchKeys([`${regMSBuild}\\${info.version}`], 'MSBuildToolsPath', msBuildRegOpts)
|
||||
} catch (err) {
|
||||
this.addLog('- could not find MSBuild in registry for this version')
|
||||
return null
|
||||
}
|
||||
|
||||
if (!this.checkConfigVersion(info.versionYear, vsPath)) {
|
||||
return cb(null)
|
||||
}
|
||||
const msBuild = path.join(res, 'MSBuild.exe')
|
||||
this.addLog(`- MSBuild in "${msBuild}"`)
|
||||
|
||||
info.path = vsPath
|
||||
info.msBuild = msBuild
|
||||
info.sdk = null
|
||||
cb(info)
|
||||
})
|
||||
})
|
||||
},
|
||||
if (!this.checkConfigVersion(info.versionYear, vsPath)) {
|
||||
return null
|
||||
}
|
||||
|
||||
info.path = vsPath
|
||||
info.msBuild = msBuild
|
||||
info.sdk = null
|
||||
return info
|
||||
} catch (err) {
|
||||
this.addLog('- not found')
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// After finding a usable version of Visual Studio:
|
||||
// - add it to validVersions to be displayed at the end if a specific
|
||||
// version was requested and not found;
|
||||
// - check if this is the version that was requested.
|
||||
// - check if this matches the Visual Studio Command Prompt
|
||||
checkConfigVersion: function checkConfigVersion (versionYear, vsPath) {
|
||||
checkConfigVersion (versionYear, vsPath) {
|
||||
this.validVersions.push(versionYear)
|
||||
this.validVersions.push(vsPath)
|
||||
|
||||
|
|
@ -454,10 +597,10 @@ VisualStudioFinder.prototype = {
|
|||
|
||||
return true
|
||||
}
|
||||
|
||||
async execFile (exec, args) {
|
||||
return await execFile(exec, args, { encoding: 'utf8' })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = findVisualStudio
|
||||
module.exports.test = {
|
||||
VisualStudioFinder: VisualStudioFinder,
|
||||
findVisualStudio: findVisualStudio
|
||||
}
|
||||
module.exports = VisualStudioFinder
|
||||
|
|
|
|||
115
electron/node_modules/node-gyp/lib/install.js
generated
vendored
115
electron/node_modules/node-gyp/lib/install.js
generated
vendored
|
|
@ -1,26 +1,21 @@
|
|||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const { createWriteStream, promises: fs } = require('graceful-fs')
|
||||
const os = require('os')
|
||||
const { backOff } = require('exponential-backoff')
|
||||
const rm = require('rimraf')
|
||||
const tar = require('tar')
|
||||
const path = require('path')
|
||||
const util = require('util')
|
||||
const stream = require('stream')
|
||||
const { Transform, promises: { pipeline } } = require('stream')
|
||||
const crypto = require('crypto')
|
||||
const log = require('npmlog')
|
||||
const log = require('./log')
|
||||
const semver = require('semver')
|
||||
const fetch = require('make-fetch-happen')
|
||||
const { download } = require('./download')
|
||||
const processRelease = require('./process-release')
|
||||
|
||||
const win = process.platform === 'win32'
|
||||
const streamPipeline = util.promisify(stream.pipeline)
|
||||
|
||||
/**
|
||||
* @param {typeof import('graceful-fs')} fs
|
||||
*/
|
||||
|
||||
async function install (fs, gyp, argv) {
|
||||
async function install (gyp, argv) {
|
||||
log.stdout()
|
||||
const release = processRelease(argv, gyp, process.version, process.release)
|
||||
// Detecting target_arch based on logic from create-cnfig-gyp.js. Used on Windows only.
|
||||
const arch = win ? (gyp.opts.target_arch || gyp.opts.arch || process.arch || 'ia32') : ''
|
||||
|
|
@ -60,7 +55,7 @@ async function install (fs, gyp, argv) {
|
|||
if (gyp.opts.ensure) {
|
||||
log.verbose('install', '--ensure was passed, so won\'t reinstall if already installed')
|
||||
try {
|
||||
await fs.promises.stat(devDir)
|
||||
await fs.stat(devDir)
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
log.verbose('install', 'version not already installed, continuing with install', release.version)
|
||||
|
|
@ -78,7 +73,7 @@ async function install (fs, gyp, argv) {
|
|||
const installVersionFile = path.resolve(devDir, 'installVersion')
|
||||
let installVersion = 0
|
||||
try {
|
||||
const ver = await fs.promises.readFile(installVersionFile, 'ascii')
|
||||
const ver = await fs.readFile(installVersionFile, 'ascii')
|
||||
installVersion = parseInt(ver, 10) || 0
|
||||
} catch (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
|
|
@ -100,7 +95,7 @@ async function install (fs, gyp, argv) {
|
|||
log.verbose('on Windows; need to check node.lib')
|
||||
const nodeLibPath = path.resolve(devDir, arch, 'node.lib')
|
||||
try {
|
||||
await fs.promises.stat(nodeLibPath)
|
||||
await fs.stat(nodeLibPath)
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
log.verbose('install', `version not already installed for ${arch}, continuing with install`, release.version)
|
||||
|
|
@ -126,12 +121,12 @@ async function install (fs, gyp, argv) {
|
|||
|
||||
async function copyDirectory (src, dest) {
|
||||
try {
|
||||
await fs.promises.stat(src)
|
||||
await fs.stat(src)
|
||||
} catch {
|
||||
throw new Error(`Missing source directory for copy: ${src}`)
|
||||
}
|
||||
await fs.promises.mkdir(dest, { recursive: true })
|
||||
const entries = await fs.promises.readdir(src, { withFileTypes: true })
|
||||
await fs.mkdir(dest, { recursive: true })
|
||||
const entries = await fs.readdir(src, { withFileTypes: true })
|
||||
for (const entry of entries) {
|
||||
if (entry.isDirectory()) {
|
||||
await copyDirectory(path.join(src, entry.name), path.join(dest, entry.name))
|
||||
|
|
@ -140,12 +135,12 @@ async function install (fs, gyp, argv) {
|
|||
// Windows so use an exponential backoff to resolve collisions
|
||||
await backOff(async () => {
|
||||
try {
|
||||
await fs.promises.copyFile(path.join(src, entry.name), path.join(dest, entry.name))
|
||||
await fs.copyFile(path.join(src, entry.name), path.join(dest, entry.name))
|
||||
} catch (err) {
|
||||
// if ensure, check if file already exists and that's good enough
|
||||
if (gyp.opts.ensure && err.code === 'EBUSY') {
|
||||
try {
|
||||
await fs.promises.stat(path.join(dest, entry.name))
|
||||
await fs.stat(path.join(dest, entry.name))
|
||||
return
|
||||
} catch {}
|
||||
}
|
||||
|
|
@ -163,7 +158,7 @@ async function install (fs, gyp, argv) {
|
|||
|
||||
// first create the dir for the node dev files
|
||||
try {
|
||||
const created = await fs.promises.mkdir(devDir, { recursive: true })
|
||||
const created = await fs.mkdir(devDir, { recursive: true })
|
||||
|
||||
if (created) {
|
||||
log.verbose('created devDir', created)
|
||||
|
|
@ -203,12 +198,12 @@ async function install (fs, gyp, argv) {
|
|||
}
|
||||
|
||||
// download the tarball and extract!
|
||||
// Ommited on Windows if only new node.lib is required
|
||||
// Omitted on Windows if only new node.lib is required
|
||||
|
||||
// on Windows there can be file errors from tar if parallel installs
|
||||
// there can be file errors from tar if parallel installs
|
||||
// are happening (not uncommon with multiple native modules) so
|
||||
// extract the tarball to a temp directory first and then copy over
|
||||
const tarExtractDir = win ? await fs.promises.mkdtemp(path.join(os.tmpdir(), 'node-gyp-tmp-')) : devDir
|
||||
const tarExtractDir = await fs.mkdtemp(path.join(os.tmpdir(), 'node-gyp-tmp-'))
|
||||
|
||||
try {
|
||||
if (shouldDownloadTarball) {
|
||||
|
|
@ -228,7 +223,7 @@ async function install (fs, gyp, argv) {
|
|||
throw new Error(`${res.status} response downloading ${release.tarballUrl}`)
|
||||
}
|
||||
|
||||
await streamPipeline(
|
||||
await pipeline(
|
||||
res.body,
|
||||
// content checksum
|
||||
new ShaSum((_, checksum) => {
|
||||
|
|
@ -267,7 +262,7 @@ async function install (fs, gyp, argv) {
|
|||
// need to download node.lib
|
||||
...(win ? [downloadNodeLib()] : []),
|
||||
// write the "installVersion" file
|
||||
fs.promises.writeFile(installVersionPath, gyp.package.installVersion + '\n'),
|
||||
fs.writeFile(installVersionPath, gyp.package.installVersion + '\n'),
|
||||
// Only download SHASUMS.txt if we downloaded something in need of SHA verification
|
||||
...(!tarPath || win ? [downloadShasums()] : [])
|
||||
])
|
||||
|
|
@ -282,17 +277,13 @@ async function install (fs, gyp, argv) {
|
|||
}
|
||||
|
||||
// copy over the files from the temp tarball extract directory to devDir
|
||||
if (tarExtractDir !== devDir) {
|
||||
await copyDirectory(tarExtractDir, devDir)
|
||||
}
|
||||
await copyDirectory(tarExtractDir, devDir)
|
||||
} finally {
|
||||
if (tarExtractDir !== devDir) {
|
||||
try {
|
||||
// try to cleanup temp dir
|
||||
await util.promisify(rm)(tarExtractDir)
|
||||
} catch {
|
||||
log.warn('failed to clean up temp tarball extract directory')
|
||||
}
|
||||
try {
|
||||
// try to cleanup temp dir
|
||||
await fs.rm(tarExtractDir, { recursive: true, maxRetries: 3 })
|
||||
} catch {
|
||||
log.warn('failed to clean up temp tarball extract directory')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -329,7 +320,7 @@ async function install (fs, gyp, argv) {
|
|||
log.verbose(name, 'dir', dir)
|
||||
log.verbose(name, 'url', libUrl)
|
||||
|
||||
await fs.promises.mkdir(dir, { recursive: true })
|
||||
await fs.mkdir(dir, { recursive: true })
|
||||
log.verbose('streaming', name, 'to:', targetLibPath)
|
||||
|
||||
const res = await download(gyp, libUrl)
|
||||
|
|
@ -339,13 +330,13 @@ async function install (fs, gyp, argv) {
|
|||
throw new Error(`${res.status} status code downloading ${name}`)
|
||||
}
|
||||
|
||||
return streamPipeline(
|
||||
return pipeline(
|
||||
res.body,
|
||||
new ShaSum((_, checksum) => {
|
||||
contentShasums[libPath] = checksum
|
||||
log.verbose('content checksum', libPath, checksum)
|
||||
}),
|
||||
fs.createWriteStream(targetLibPath)
|
||||
createWriteStream(targetLibPath)
|
||||
)
|
||||
} // downloadNodeLib()
|
||||
} // go()
|
||||
|
|
@ -363,7 +354,7 @@ async function install (fs, gyp, argv) {
|
|||
async function rollback (err) {
|
||||
log.warn('install', 'got an error, rolling back install')
|
||||
// roll-back the install if anything went wrong
|
||||
await util.promisify(gyp.commands.remove)([release.versionDir])
|
||||
await gyp.commands.remove([release.versionDir])
|
||||
throw err
|
||||
}
|
||||
|
||||
|
|
@ -394,11 +385,11 @@ async function install (fs, gyp, argv) {
|
|||
log.verbose('tmpdir == cwd', 'automatically will remove dev files after to save disk space')
|
||||
gyp.todo.push({ name: 'remove', args: argv })
|
||||
}
|
||||
return util.promisify(gyp.commands.install)([noretry].concat(argv))
|
||||
return gyp.commands.install([noretry].concat(argv))
|
||||
}
|
||||
}
|
||||
|
||||
class ShaSum extends stream.Transform {
|
||||
class ShaSum extends Transform {
|
||||
constructor (callback) {
|
||||
super()
|
||||
this._callback = callback
|
||||
|
|
@ -416,43 +407,5 @@ class ShaSum extends stream.Transform {
|
|||
}
|
||||
}
|
||||
|
||||
async function download (gyp, url) {
|
||||
log.http('GET', url)
|
||||
|
||||
const requestOpts = {
|
||||
headers: {
|
||||
'User-Agent': `node-gyp v${gyp.version} (node ${process.version})`,
|
||||
Connection: 'keep-alive'
|
||||
},
|
||||
proxy: gyp.opts.proxy,
|
||||
noProxy: gyp.opts.noproxy
|
||||
}
|
||||
|
||||
const cafile = gyp.opts.cafile
|
||||
if (cafile) {
|
||||
requestOpts.ca = await readCAFile(cafile)
|
||||
}
|
||||
|
||||
const res = await fetch(url, requestOpts)
|
||||
log.http(res.status, res.url)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
async function readCAFile (filename) {
|
||||
// The CA file can contain multiple certificates so split on certificate
|
||||
// boundaries. [\S\s]*? is used to match everything including newlines.
|
||||
const ca = await fs.promises.readFile(filename, 'utf8')
|
||||
const re = /(-----BEGIN CERTIFICATE-----[\S\s]*?-----END CERTIFICATE-----)/g
|
||||
return ca.match(re)
|
||||
}
|
||||
|
||||
module.exports = function (gyp, argv, callback) {
|
||||
install(fs, gyp, argv).then(callback.bind(undefined, null), callback)
|
||||
}
|
||||
module.exports.test = {
|
||||
download,
|
||||
install,
|
||||
readCAFile
|
||||
}
|
||||
module.exports = install
|
||||
module.exports.usage = 'Install node development files for the specified node version.'
|
||||
|
|
|
|||
29
electron/node_modules/node-gyp/lib/list.js
generated
vendored
29
electron/node_modules/node-gyp/lib/list.js
generated
vendored
|
|
@ -1,26 +1,25 @@
|
|||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const log = require('npmlog')
|
||||
const fs = require('graceful-fs').promises
|
||||
const log = require('./log')
|
||||
|
||||
function list (gyp, args, callback) {
|
||||
var devDir = gyp.devDir
|
||||
async function list (gyp, args) {
|
||||
const devDir = gyp.devDir
|
||||
log.verbose('list', 'using node-gyp dir:', devDir)
|
||||
|
||||
fs.readdir(devDir, onreaddir)
|
||||
|
||||
function onreaddir (err, versions) {
|
||||
let versions = []
|
||||
try {
|
||||
const dir = await fs.readdir(devDir)
|
||||
if (Array.isArray(dir)) {
|
||||
versions = dir.filter((v) => v !== 'current')
|
||||
}
|
||||
} catch (err) {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
return callback(err)
|
||||
throw err
|
||||
}
|
||||
|
||||
if (Array.isArray(versions)) {
|
||||
versions = versions.filter(function (v) { return v !== 'current' })
|
||||
} else {
|
||||
versions = []
|
||||
}
|
||||
callback(null, versions)
|
||||
}
|
||||
|
||||
return versions
|
||||
}
|
||||
|
||||
module.exports = list
|
||||
|
|
|
|||
168
electron/node_modules/node-gyp/lib/log.js
generated
vendored
Normal file
168
electron/node_modules/node-gyp/lib/log.js
generated
vendored
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
'use strict'
|
||||
|
||||
const { log } = require('proc-log')
|
||||
const { format } = require('util')
|
||||
|
||||
// helper to emit log messages with a predefined prefix
|
||||
const withPrefix = (prefix) => log.LEVELS.reduce((acc, level) => {
|
||||
acc[level] = (...args) => log[level](prefix, ...args)
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
// very basic ansi color generator
|
||||
const COLORS = {
|
||||
wrap: (str, colors) => {
|
||||
const codes = colors.filter(c => typeof c === 'number')
|
||||
return `\x1b[${codes.join(';')}m${str}\x1b[0m`
|
||||
},
|
||||
inverse: 7,
|
||||
fg: {
|
||||
black: 30,
|
||||
red: 31,
|
||||
green: 32,
|
||||
yellow: 33,
|
||||
blue: 34,
|
||||
magenta: 35,
|
||||
cyan: 36,
|
||||
white: 37
|
||||
},
|
||||
bg: {
|
||||
black: 40,
|
||||
red: 41,
|
||||
green: 42,
|
||||
yellow: 43,
|
||||
blue: 44,
|
||||
magenta: 45,
|
||||
cyan: 46,
|
||||
white: 47
|
||||
}
|
||||
}
|
||||
|
||||
class Logger {
|
||||
#buffer = []
|
||||
#paused = null
|
||||
#level = null
|
||||
#stream = null
|
||||
|
||||
// ordered from loudest to quietest
|
||||
#levels = [{
|
||||
id: 'silly',
|
||||
display: 'sill',
|
||||
style: { inverse: true }
|
||||
}, {
|
||||
id: 'verbose',
|
||||
display: 'verb',
|
||||
style: { fg: 'cyan', bg: 'black' }
|
||||
}, {
|
||||
id: 'info',
|
||||
style: { fg: 'green' }
|
||||
}, {
|
||||
id: 'http',
|
||||
style: { fg: 'green', bg: 'black' }
|
||||
}, {
|
||||
id: 'notice',
|
||||
style: { fg: 'cyan', bg: 'black' }
|
||||
}, {
|
||||
id: 'warn',
|
||||
display: 'WARN',
|
||||
style: { fg: 'black', bg: 'yellow' }
|
||||
}, {
|
||||
id: 'error',
|
||||
display: 'ERR!',
|
||||
style: { fg: 'red', bg: 'black' }
|
||||
}]
|
||||
|
||||
constructor (stream) {
|
||||
process.on('log', (...args) => this.#onLog(...args))
|
||||
this.#levels = new Map(this.#levels.map((level, index) => [level.id, { ...level, index }]))
|
||||
this.level = 'info'
|
||||
this.stream = stream
|
||||
log.pause()
|
||||
}
|
||||
|
||||
get stream () {
|
||||
return this.#stream
|
||||
}
|
||||
|
||||
set stream (stream) {
|
||||
this.#stream = stream
|
||||
}
|
||||
|
||||
get level () {
|
||||
return this.#levels.get(this.#level) ?? null
|
||||
}
|
||||
|
||||
set level (level) {
|
||||
this.#level = this.#levels.get(level)?.id ?? null
|
||||
}
|
||||
|
||||
isVisible (level) {
|
||||
return this.level?.index <= this.#levels.get(level)?.index ?? -1
|
||||
}
|
||||
|
||||
#onLog (...args) {
|
||||
const [level] = args
|
||||
|
||||
if (level === 'pause') {
|
||||
this.#paused = true
|
||||
return
|
||||
}
|
||||
|
||||
if (level === 'resume') {
|
||||
this.#paused = false
|
||||
this.#buffer.forEach((b) => this.#log(...b))
|
||||
this.#buffer.length = 0
|
||||
return
|
||||
}
|
||||
|
||||
if (this.#paused) {
|
||||
this.#buffer.push(args)
|
||||
return
|
||||
}
|
||||
|
||||
this.#log(...args)
|
||||
}
|
||||
|
||||
#color (str, { fg, bg, inverse }) {
|
||||
if (!this.#stream?.isTTY) {
|
||||
return str
|
||||
}
|
||||
|
||||
return COLORS.wrap(str, [
|
||||
COLORS.fg[fg],
|
||||
COLORS.bg[bg],
|
||||
inverse && COLORS.inverse
|
||||
])
|
||||
}
|
||||
|
||||
#log (levelId, msgPrefix, ...args) {
|
||||
if (!this.isVisible(levelId) || typeof this.#stream?.write !== 'function') {
|
||||
return
|
||||
}
|
||||
|
||||
const level = this.#levels.get(levelId)
|
||||
|
||||
const prefixParts = [
|
||||
this.#color('gyp', { fg: 'white', bg: 'black' }),
|
||||
this.#color(level.display ?? level.id, level.style)
|
||||
]
|
||||
if (msgPrefix) {
|
||||
prefixParts.push(this.#color(msgPrefix, { fg: 'magenta' }))
|
||||
}
|
||||
|
||||
const prefix = prefixParts.join(' ').trim() + ' '
|
||||
const lines = format(...args).split(/\r?\n/).map(l => prefix + l.trim())
|
||||
|
||||
this.#stream.write(lines.join('\n') + '\n')
|
||||
}
|
||||
}
|
||||
|
||||
// used to suppress logs in tests
|
||||
const NULL_LOGGER = !!process.env.NODE_GYP_NULL_LOGGER
|
||||
|
||||
module.exports = {
|
||||
logger: new Logger(NULL_LOGGER ? null : process.stderr),
|
||||
stdout: NULL_LOGGER ? () => {} : (...args) => console.log(...args),
|
||||
withPrefix,
|
||||
...log
|
||||
}
|
||||
350
electron/node_modules/node-gyp/lib/node-gyp.js
generated
vendored
350
electron/node_modules/node-gyp/lib/node-gyp.js
generated
vendored
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
const path = require('path')
|
||||
const nopt = require('nopt')
|
||||
const log = require('npmlog')
|
||||
const log = require('./log')
|
||||
const childProcess = require('child_process')
|
||||
const EE = require('events').EventEmitter
|
||||
const inherits = require('util').inherits
|
||||
const { EventEmitter } = require('events')
|
||||
|
||||
const commands = [
|
||||
// Module build commands
|
||||
'build',
|
||||
|
|
@ -17,199 +17,183 @@ const commands = [
|
|||
'list',
|
||||
'remove'
|
||||
]
|
||||
const aliases = {
|
||||
ls: 'list',
|
||||
rm: 'remove'
|
||||
}
|
||||
|
||||
// differentiate node-gyp's logs from npm's
|
||||
log.heading = 'gyp'
|
||||
class Gyp extends EventEmitter {
|
||||
/**
|
||||
* Export the contents of the package.json.
|
||||
*/
|
||||
package = require('../package.json')
|
||||
|
||||
function gyp () {
|
||||
return new Gyp()
|
||||
}
|
||||
|
||||
function Gyp () {
|
||||
var self = this
|
||||
|
||||
this.devDir = ''
|
||||
this.commands = {}
|
||||
|
||||
commands.forEach(function (command) {
|
||||
self.commands[command] = function (argv, callback) {
|
||||
log.verbose('command', command, argv)
|
||||
return require('./' + command)(self, argv, callback)
|
||||
}
|
||||
})
|
||||
}
|
||||
inherits(Gyp, EE)
|
||||
exports.Gyp = Gyp
|
||||
var proto = Gyp.prototype
|
||||
|
||||
/**
|
||||
* Export the contents of the package.json.
|
||||
*/
|
||||
|
||||
proto.package = require('../package.json')
|
||||
|
||||
/**
|
||||
* nopt configuration definitions
|
||||
*/
|
||||
|
||||
proto.configDefs = {
|
||||
help: Boolean, // everywhere
|
||||
arch: String, // 'configure'
|
||||
cafile: String, // 'install'
|
||||
debug: Boolean, // 'build'
|
||||
directory: String, // bin
|
||||
make: String, // 'build'
|
||||
msvs_version: String, // 'configure'
|
||||
ensure: Boolean, // 'install'
|
||||
solution: String, // 'build' (windows only)
|
||||
proxy: String, // 'install'
|
||||
noproxy: String, // 'install'
|
||||
devdir: String, // everywhere
|
||||
nodedir: String, // 'configure'
|
||||
loglevel: String, // everywhere
|
||||
python: String, // 'configure'
|
||||
'dist-url': String, // 'install'
|
||||
tarball: String, // 'install'
|
||||
jobs: String, // 'build'
|
||||
thin: String, // 'configure'
|
||||
'force-process-config': Boolean // 'configure'
|
||||
}
|
||||
|
||||
/**
|
||||
* nopt shorthands
|
||||
*/
|
||||
|
||||
proto.shorthands = {
|
||||
release: '--no-debug',
|
||||
C: '--directory',
|
||||
debug: '--debug',
|
||||
j: '--jobs',
|
||||
silly: '--loglevel=silly',
|
||||
verbose: '--loglevel=verbose',
|
||||
silent: '--loglevel=silent'
|
||||
}
|
||||
|
||||
/**
|
||||
* expose the command aliases for the bin file to use.
|
||||
*/
|
||||
|
||||
proto.aliases = aliases
|
||||
|
||||
/**
|
||||
* Parses the given argv array and sets the 'opts',
|
||||
* 'argv' and 'command' properties.
|
||||
*/
|
||||
|
||||
proto.parseArgv = function parseOpts (argv) {
|
||||
this.opts = nopt(this.configDefs, this.shorthands, argv)
|
||||
this.argv = this.opts.argv.remain.slice()
|
||||
|
||||
var commands = this.todo = []
|
||||
|
||||
// create a copy of the argv array with aliases mapped
|
||||
argv = this.argv.map(function (arg) {
|
||||
// is this an alias?
|
||||
if (arg in this.aliases) {
|
||||
arg = this.aliases[arg]
|
||||
}
|
||||
return arg
|
||||
}, this)
|
||||
|
||||
// process the mapped args into "command" objects ("name" and "args" props)
|
||||
argv.slice().forEach(function (arg) {
|
||||
if (arg in this.commands) {
|
||||
var args = argv.splice(0, argv.indexOf(arg))
|
||||
argv.shift()
|
||||
if (commands.length > 0) {
|
||||
commands[commands.length - 1].args = args
|
||||
}
|
||||
commands.push({ name: arg, args: [] })
|
||||
}
|
||||
}, this)
|
||||
if (commands.length > 0) {
|
||||
commands[commands.length - 1].args = argv.splice(0)
|
||||
/**
|
||||
* nopt configuration definitions
|
||||
*/
|
||||
configDefs = {
|
||||
help: Boolean, // everywhere
|
||||
arch: String, // 'configure'
|
||||
cafile: String, // 'install'
|
||||
debug: Boolean, // 'build'
|
||||
directory: String, // bin
|
||||
make: String, // 'build'
|
||||
'msvs-version': String, // 'configure'
|
||||
ensure: Boolean, // 'install'
|
||||
solution: String, // 'build' (windows only)
|
||||
proxy: String, // 'install'
|
||||
noproxy: String, // 'install'
|
||||
devdir: String, // everywhere
|
||||
nodedir: String, // 'configure'
|
||||
loglevel: String, // everywhere
|
||||
python: String, // 'configure'
|
||||
'dist-url': String, // 'install'
|
||||
tarball: String, // 'install'
|
||||
jobs: String, // 'build'
|
||||
thin: String, // 'configure'
|
||||
'force-process-config': Boolean // 'configure'
|
||||
}
|
||||
|
||||
// support for inheriting config env variables from npm
|
||||
var npmConfigPrefix = 'npm_config_'
|
||||
Object.keys(process.env).forEach(function (name) {
|
||||
if (name.indexOf(npmConfigPrefix) !== 0) {
|
||||
return
|
||||
/**
|
||||
* nopt shorthands
|
||||
*/
|
||||
shorthands = {
|
||||
release: '--no-debug',
|
||||
C: '--directory',
|
||||
debug: '--debug',
|
||||
j: '--jobs',
|
||||
silly: '--loglevel=silly',
|
||||
verbose: '--loglevel=verbose',
|
||||
silent: '--loglevel=silent'
|
||||
}
|
||||
|
||||
/**
|
||||
* expose the command aliases for the bin file to use.
|
||||
*/
|
||||
aliases = {
|
||||
ls: 'list',
|
||||
rm: 'remove'
|
||||
}
|
||||
|
||||
constructor (...args) {
|
||||
super(...args)
|
||||
|
||||
this.devDir = ''
|
||||
|
||||
this.commands = commands.reduce((acc, command) => {
|
||||
acc[command] = (argv) => require('./' + command)(this, argv)
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
Object.defineProperty(this, 'version', {
|
||||
enumerable: true,
|
||||
get: function () { return this.package.version }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given argv array and sets the 'opts',
|
||||
* 'argv' and 'command' properties.
|
||||
*/
|
||||
parseArgv (argv) {
|
||||
this.opts = nopt(this.configDefs, this.shorthands, argv)
|
||||
this.argv = this.opts.argv.remain.slice()
|
||||
|
||||
const commands = this.todo = []
|
||||
|
||||
// create a copy of the argv array with aliases mapped
|
||||
argv = this.argv.map((arg) => {
|
||||
// is this an alias?
|
||||
if (arg in this.aliases) {
|
||||
arg = this.aliases[arg]
|
||||
}
|
||||
return arg
|
||||
})
|
||||
|
||||
// process the mapped args into "command" objects ("name" and "args" props)
|
||||
argv.slice().forEach((arg) => {
|
||||
if (arg in this.commands) {
|
||||
const args = argv.splice(0, argv.indexOf(arg))
|
||||
argv.shift()
|
||||
if (commands.length > 0) {
|
||||
commands[commands.length - 1].args = args
|
||||
}
|
||||
commands.push({ name: arg, args: [] })
|
||||
}
|
||||
})
|
||||
if (commands.length > 0) {
|
||||
commands[commands.length - 1].args = argv.splice(0)
|
||||
}
|
||||
var val = process.env[name]
|
||||
if (name === npmConfigPrefix + 'loglevel') {
|
||||
log.level = val
|
||||
} else {
|
||||
|
||||
// support for inheriting config env variables from npm
|
||||
// npm will set environment variables in the following forms:
|
||||
// - `npm_config_<key>` for values from npm's own config. Setting arbitrary
|
||||
// options on npm's config was deprecated in npm v11 but node-gyp still
|
||||
// supports it for backwards compatibility.
|
||||
// See https://github.com/nodejs/node-gyp/issues/3156
|
||||
// - `npm_package_config_node_gyp_<key>` for values from the `config` object
|
||||
// in package.json. This is the preferred way to set options for node-gyp
|
||||
// since npm v11. The `node_gyp_` prefix is used to avoid conflicts with
|
||||
// other tools.
|
||||
// The `npm_package_config_node_gyp_` prefix will take precedence over
|
||||
// `npm_config_` keys.
|
||||
const npmConfigPrefix = /^npm_config_/i
|
||||
const npmPackageConfigPrefix = /^npm_package_config_node_gyp_/i
|
||||
|
||||
const configEnvKeys = Object.keys(process.env)
|
||||
.filter((k) => npmConfigPrefix.test(k) || npmPackageConfigPrefix.test(k))
|
||||
// sort so that npm_package_config_node_gyp_ keys come last and will override
|
||||
.sort((a) => npmConfigPrefix.test(a) ? -1 : 1)
|
||||
|
||||
for (const key of configEnvKeys) {
|
||||
// add the user-defined options to the config
|
||||
name = name.substring(npmConfigPrefix.length)
|
||||
const name = npmConfigPrefix.test(key)
|
||||
? key.replace(npmConfigPrefix, '')
|
||||
: key.replace(npmPackageConfigPrefix, '')
|
||||
// gyp@741b7f1 enters an infinite loop when it encounters
|
||||
// zero-length options so ensure those don't get through.
|
||||
if (name) {
|
||||
// convert names like force_process_config to force-process-config
|
||||
if (name.includes('_')) {
|
||||
name = name.replace(/_/g, '-')
|
||||
}
|
||||
this.opts[name] = val
|
||||
// and convert to lowercase
|
||||
this.opts[name.replaceAll('_', '-').toLowerCase()] = process.env[key]
|
||||
}
|
||||
}
|
||||
}, this)
|
||||
|
||||
if (this.opts.loglevel) {
|
||||
log.level = this.opts.loglevel
|
||||
if (this.opts.loglevel) {
|
||||
log.logger.level = this.opts.loglevel
|
||||
delete this.opts.loglevel
|
||||
}
|
||||
log.resume()
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns a child process and emits a 'spawn' event.
|
||||
*/
|
||||
spawn (command, args, opts) {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
if (!opts.silent && !opts.stdio) {
|
||||
opts.stdio = [0, 1, 2]
|
||||
}
|
||||
const cp = childProcess.spawn(command, args, opts)
|
||||
log.info('spawn', command)
|
||||
log.info('spawn args', args)
|
||||
return cp
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the usage instructions for node-gyp.
|
||||
*/
|
||||
usage () {
|
||||
return [
|
||||
'',
|
||||
' Usage: node-gyp <command> [options]',
|
||||
'',
|
||||
' where <command> is one of:',
|
||||
commands.map((c) => ' - ' + c + ' - ' + require('./' + c).usage).join('\n'),
|
||||
'',
|
||||
'node-gyp@' + this.version + ' ' + path.resolve(__dirname, '..'),
|
||||
'node@' + process.versions.node
|
||||
].join('\n')
|
||||
}
|
||||
log.resume()
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns a child process and emits a 'spawn' event.
|
||||
*/
|
||||
|
||||
proto.spawn = function spawn (command, args, opts) {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
if (!opts.silent && !opts.stdio) {
|
||||
opts.stdio = [0, 1, 2]
|
||||
}
|
||||
var cp = childProcess.spawn(command, args, opts)
|
||||
log.info('spawn', command)
|
||||
log.info('spawn args', args)
|
||||
return cp
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the usage instructions for node-gyp.
|
||||
*/
|
||||
|
||||
proto.usage = function usage () {
|
||||
var str = [
|
||||
'',
|
||||
' Usage: node-gyp <command> [options]',
|
||||
'',
|
||||
' where <command> is one of:',
|
||||
commands.map(function (c) {
|
||||
return ' - ' + c + ' - ' + require('./' + c).usage
|
||||
}).join('\n'),
|
||||
'',
|
||||
'node-gyp@' + this.version + ' ' + path.resolve(__dirname, '..'),
|
||||
'node@' + process.versions.node
|
||||
].join('\n')
|
||||
return str
|
||||
}
|
||||
|
||||
/**
|
||||
* Version number getter.
|
||||
*/
|
||||
|
||||
Object.defineProperty(proto, 'version', {
|
||||
get: function () {
|
||||
return this.package.version
|
||||
},
|
||||
enumerable: true
|
||||
})
|
||||
|
||||
module.exports = exports = gyp
|
||||
module.exports = () => new Gyp()
|
||||
module.exports.Gyp = Gyp
|
||||
|
|
|
|||
73
electron/node_modules/node-gyp/lib/process-release.js
generated
vendored
73
electron/node_modules/node-gyp/lib/process-release.js
generated
vendored
|
|
@ -1,11 +1,8 @@
|
|||
/* eslint-disable node/no-deprecated-api */
|
||||
|
||||
'use strict'
|
||||
|
||||
const semver = require('semver')
|
||||
const url = require('url')
|
||||
const path = require('path')
|
||||
const log = require('npmlog')
|
||||
const log = require('./log')
|
||||
|
||||
// versions where -headers.tar.gz started shipping
|
||||
const headersTarballRange = '>= 3.0.0 || ~0.12.10 || ~0.10.42'
|
||||
|
|
@ -17,29 +14,28 @@ const bitsreV3 = /\/win-(x86|ia32|x64)\// // io.js v3.x.x shipped with "ia32" bu
|
|||
// file names. Inputs come from command-line switches (--target, --dist-url),
|
||||
// `process.version` and `process.release` where it exists.
|
||||
function processRelease (argv, gyp, defaultVersion, defaultRelease) {
|
||||
var version = (semver.valid(argv[0]) && argv[0]) || gyp.opts.target || defaultVersion
|
||||
var versionSemver = semver.parse(version)
|
||||
var overrideDistUrl = gyp.opts['dist-url'] || gyp.opts.disturl
|
||||
var isDefaultVersion
|
||||
var isNamedForLegacyIojs
|
||||
var name
|
||||
var distBaseUrl
|
||||
var baseUrl
|
||||
var libUrl32
|
||||
var libUrl64
|
||||
var libUrlArm64
|
||||
var tarballUrl
|
||||
var canGetHeaders
|
||||
let version = (semver.valid(argv[0]) && argv[0]) || gyp.opts.target || defaultVersion
|
||||
const versionSemver = semver.parse(version)
|
||||
let overrideDistUrl = gyp.opts['dist-url'] || gyp.opts.disturl
|
||||
let isNamedForLegacyIojs
|
||||
let name
|
||||
let distBaseUrl
|
||||
let baseUrl
|
||||
let libUrl32
|
||||
let libUrl64
|
||||
let libUrlArm64
|
||||
let tarballUrl
|
||||
let canGetHeaders
|
||||
|
||||
if (!versionSemver) {
|
||||
// not a valid semver string, nothing we can do
|
||||
return { version: version }
|
||||
return { version }
|
||||
}
|
||||
// flatten version into String
|
||||
version = versionSemver.version
|
||||
|
||||
// defaultVersion should come from process.version so ought to be valid semver
|
||||
isDefaultVersion = version === semver.parse(defaultVersion).version
|
||||
const isDefaultVersion = version === semver.parse(defaultVersion).version
|
||||
|
||||
// can't use process.release if we're using --target=x.y.z
|
||||
if (!isDefaultVersion) {
|
||||
|
|
@ -75,11 +71,11 @@ function processRelease (argv, gyp, defaultVersion, defaultRelease) {
|
|||
} else {
|
||||
distBaseUrl = 'https://nodejs.org/dist'
|
||||
}
|
||||
distBaseUrl += '/v' + version + '/'
|
||||
distBaseUrl = new URL(distBaseUrl + '/v' + version + '/')
|
||||
|
||||
// new style, based on process.release so we have a lot of the data we need
|
||||
if (defaultRelease && defaultRelease.headersUrl && !overrideDistUrl) {
|
||||
baseUrl = url.resolve(defaultRelease.headersUrl, './')
|
||||
baseUrl = new URL('./', defaultRelease.headersUrl)
|
||||
libUrl32 = resolveLibUrl(name, defaultRelease.libUrl || baseUrl || distBaseUrl, 'x86', versionSemver.major)
|
||||
libUrl64 = resolveLibUrl(name, defaultRelease.libUrl || baseUrl || distBaseUrl, 'x64', versionSemver.major)
|
||||
libUrlArm64 = resolveLibUrl(name, defaultRelease.libUrl || baseUrl || distBaseUrl, 'arm64', versionSemver.major)
|
||||
|
|
@ -97,28 +93,28 @@ function processRelease (argv, gyp, defaultVersion, defaultRelease) {
|
|||
// have a *-headers.tar.gz file in its dist location, even some frankenstein
|
||||
// custom version
|
||||
canGetHeaders = semver.satisfies(versionSemver, headersTarballRange)
|
||||
tarballUrl = url.resolve(baseUrl, name + '-v' + version + (canGetHeaders ? '-headers' : '') + '.tar.gz')
|
||||
tarballUrl = new URL(name + '-v' + version + (canGetHeaders ? '-headers' : '') + '.tar.gz', baseUrl).href
|
||||
}
|
||||
|
||||
return {
|
||||
version: version,
|
||||
version,
|
||||
semver: versionSemver,
|
||||
name: name,
|
||||
baseUrl: baseUrl,
|
||||
tarballUrl: tarballUrl,
|
||||
shasumsUrl: url.resolve(baseUrl, 'SHASUMS256.txt'),
|
||||
name,
|
||||
baseUrl: baseUrl.href,
|
||||
tarballUrl,
|
||||
shasumsUrl: new URL('SHASUMS256.txt', baseUrl).href,
|
||||
versionDir: (name !== 'node' ? name + '-' : '') + version,
|
||||
ia32: {
|
||||
libUrl: libUrl32,
|
||||
libPath: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl32).path))
|
||||
libUrl: libUrl32.href,
|
||||
libPath: normalizePath(path.relative(baseUrl.pathname, libUrl32.pathname))
|
||||
},
|
||||
x64: {
|
||||
libUrl: libUrl64,
|
||||
libPath: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl64).path))
|
||||
libUrl: libUrl64.href,
|
||||
libPath: normalizePath(path.relative(baseUrl.pathname, libUrl64.pathname))
|
||||
},
|
||||
arm64: {
|
||||
libUrl: libUrlArm64,
|
||||
libPath: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrlArm64).path))
|
||||
libUrl: libUrlArm64.href,
|
||||
libPath: normalizePath(path.relative(baseUrl.pathname, libUrlArm64.pathname))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -128,20 +124,21 @@ function normalizePath (p) {
|
|||
}
|
||||
|
||||
function resolveLibUrl (name, defaultUrl, arch, versionMajor) {
|
||||
var base = url.resolve(defaultUrl, './')
|
||||
var hasLibUrl = bitsre.test(defaultUrl) || (versionMajor === 3 && bitsreV3.test(defaultUrl))
|
||||
if (!defaultUrl.pathname) defaultUrl = new URL(defaultUrl)
|
||||
const base = new URL('./', defaultUrl)
|
||||
const hasLibUrl = bitsre.test(defaultUrl.pathname) || (versionMajor === 3 && bitsreV3.test(defaultUrl.pathname))
|
||||
|
||||
if (!hasLibUrl) {
|
||||
// let's assume it's a baseUrl then
|
||||
if (versionMajor >= 1) {
|
||||
return url.resolve(base, 'win-' + arch + '/' + name + '.lib')
|
||||
return new URL('win-' + arch + '/' + name + '.lib', base)
|
||||
}
|
||||
// prior to io.js@1.0.0 32-bit node.lib lives in /, 64-bit lives in /x64/
|
||||
return url.resolve(base, (arch === 'x86' ? '' : arch + '/') + name + '.lib')
|
||||
return new URL((arch === 'x86' ? '' : arch + '/') + name + '.lib', base)
|
||||
}
|
||||
|
||||
// else we have a proper url to a .lib, just make sure it's the right arch
|
||||
return defaultUrl.replace(versionMajor === 3 ? bitsreV3 : bitsre, '/win-' + arch + '/')
|
||||
return new URL(defaultUrl.pathname.replace(versionMajor === 3 ? bitsreV3 : bitsre, '/win-' + arch + '/'), defaultUrl)
|
||||
}
|
||||
|
||||
module.exports = processRelease
|
||||
|
|
|
|||
3
electron/node_modules/node-gyp/lib/rebuild.js
generated
vendored
3
electron/node_modules/node-gyp/lib/rebuild.js
generated
vendored
|
|
@ -1,12 +1,11 @@
|
|||
'use strict'
|
||||
|
||||
function rebuild (gyp, argv, callback) {
|
||||
async function rebuild (gyp, argv) {
|
||||
gyp.todo.push(
|
||||
{ name: 'clean', args: [] }
|
||||
, { name: 'configure', args: argv }
|
||||
, { name: 'build', args: [] }
|
||||
)
|
||||
process.nextTick(callback)
|
||||
}
|
||||
|
||||
module.exports = rebuild
|
||||
|
|
|
|||
39
electron/node_modules/node-gyp/lib/remove.js
generated
vendored
39
electron/node_modules/node-gyp/lib/remove.js
generated
vendored
|
|
@ -1,46 +1,43 @@
|
|||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const rm = require('rimraf')
|
||||
const fs = require('graceful-fs').promises
|
||||
const path = require('path')
|
||||
const log = require('npmlog')
|
||||
const log = require('./log')
|
||||
const semver = require('semver')
|
||||
|
||||
function remove (gyp, argv, callback) {
|
||||
var devDir = gyp.devDir
|
||||
async function remove (gyp, argv) {
|
||||
const devDir = gyp.devDir
|
||||
log.verbose('remove', 'using node-gyp dir:', devDir)
|
||||
|
||||
// get the user-specified version to remove
|
||||
var version = argv[0] || gyp.opts.target
|
||||
let version = argv[0] || gyp.opts.target
|
||||
log.verbose('remove', 'removing target version:', version)
|
||||
|
||||
if (!version) {
|
||||
return callback(new Error('You must specify a version number to remove. Ex: "' + process.version + '"'))
|
||||
throw new Error('You must specify a version number to remove. Ex: "' + process.version + '"')
|
||||
}
|
||||
|
||||
var versionSemver = semver.parse(version)
|
||||
const versionSemver = semver.parse(version)
|
||||
if (versionSemver) {
|
||||
// flatten the version Array into a String
|
||||
version = versionSemver.version
|
||||
}
|
||||
|
||||
var versionPath = path.resolve(gyp.devDir, version)
|
||||
const versionPath = path.resolve(gyp.devDir, version)
|
||||
log.verbose('remove', 'removing development files for version:', version)
|
||||
|
||||
// first check if its even installed
|
||||
fs.stat(versionPath, function (err) {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
callback(null, 'version was already uninstalled: ' + version)
|
||||
} else {
|
||||
callback(err)
|
||||
}
|
||||
return
|
||||
try {
|
||||
await fs.stat(versionPath)
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
return 'version was already uninstalled: ' + version
|
||||
}
|
||||
// Go ahead and delete the dir
|
||||
rm(versionPath, callback)
|
||||
})
|
||||
throw err
|
||||
}
|
||||
|
||||
await fs.rm(versionPath, { recursive: true, force: true, maxRetries: 3 })
|
||||
}
|
||||
|
||||
module.exports = exports = remove
|
||||
module.exports = remove
|
||||
module.exports.usage = 'Removes the node development files for the specified version'
|
||||
|
|
|
|||
107
electron/node_modules/node-gyp/lib/util.js
generated
vendored
107
electron/node_modules/node-gyp/lib/util.js
generated
vendored
|
|
@ -1,64 +1,81 @@
|
|||
'use strict'
|
||||
|
||||
const log = require('npmlog')
|
||||
const execFile = require('child_process').execFile
|
||||
const cp = require('child_process')
|
||||
const path = require('path')
|
||||
const { openSync, closeSync } = require('graceful-fs')
|
||||
const log = require('./log')
|
||||
|
||||
function logWithPrefix (log, prefix) {
|
||||
function setPrefix (logFunction) {
|
||||
return (...args) => logFunction.apply(null, [ prefix, ...args ]) // eslint-disable-line
|
||||
}
|
||||
return {
|
||||
silly: setPrefix(log.silly),
|
||||
verbose: setPrefix(log.verbose),
|
||||
info: setPrefix(log.info),
|
||||
warn: setPrefix(log.warn),
|
||||
error: setPrefix(log.error)
|
||||
}
|
||||
}
|
||||
const execFile = async (...args) => new Promise((resolve) => {
|
||||
const child = cp.execFile(...args, (...a) => resolve(a))
|
||||
child.stdin.end()
|
||||
})
|
||||
|
||||
function regGetValue (key, value, addOpts, cb) {
|
||||
async function regGetValue (key, value, addOpts) {
|
||||
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 [err, stdout, stderr] = await execFile(reg, regArgs, { encoding: 'utf8' })
|
||||
|
||||
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()
|
||||
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)
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
throw new Error(stderr)
|
||||
}
|
||||
|
||||
const result = outRe.exec(stdout)
|
||||
if (!result) {
|
||||
log.silly('reg', 'error parsing stdout')
|
||||
throw new Error('Could not parse output of reg.exe')
|
||||
}
|
||||
|
||||
log.silly('reg', 'found: %j', result[1])
|
||||
return result[1]
|
||||
}
|
||||
|
||||
function regSearchKeys (keys, value, addOpts, cb) {
|
||||
var 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)
|
||||
})
|
||||
async function regSearchKeys (keys, value, addOpts) {
|
||||
for (const key of keys) {
|
||||
try {
|
||||
return await regGetValue(key, value, addOpts)
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
search()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first file or directory from an array of candidates that is
|
||||
* readable by the current user, or undefined if none of the candidates are
|
||||
* readable.
|
||||
*/
|
||||
function findAccessibleSync (logprefix, dir, candidates) {
|
||||
for (let next = 0; next < candidates.length; next++) {
|
||||
const candidate = path.resolve(dir, candidates[next])
|
||||
let fd
|
||||
try {
|
||||
fd = openSync(candidate, 'r')
|
||||
} catch (e) {
|
||||
// this candidate was not found or not readable, do nothing
|
||||
log.silly(logprefix, 'Could not open %s: %s', candidate, e.message)
|
||||
continue
|
||||
}
|
||||
closeSync(fd)
|
||||
log.silly(logprefix, 'Found readable %s', candidate)
|
||||
return candidate
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
logWithPrefix: logWithPrefix,
|
||||
regGetValue: regGetValue,
|
||||
regSearchKeys: regSearchKeys
|
||||
execFile,
|
||||
regGetValue,
|
||||
regSearchKeys,
|
||||
findAccessibleSync
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue