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
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.'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue