mirror of
https://github.com/S2-/gitlit
synced 2025-08-04 13:10:09 +02:00
update dependencies
This commit is contained in:
66
node_modules/electron-download/lib/index.js
generated
vendored
66
node_modules/electron-download/lib/index.js
generated
vendored
@@ -1,5 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const arch = require('./arch')
|
||||
const debug = require('debug')('electron-download')
|
||||
const envPaths = require('env-paths')
|
||||
const fs = require('fs-extra')
|
||||
@@ -13,7 +14,10 @@ const sumchecker = require('sumchecker')
|
||||
|
||||
class ElectronDownloader {
|
||||
constructor (opts) {
|
||||
this.opts = opts
|
||||
this.opts = Object.assign({ autoDownload: true }, opts)
|
||||
if (this.opts.force && !this.opts.autoDownload) {
|
||||
throw new Error('force and autoDownload options are incompatible for Electron Download')
|
||||
}
|
||||
|
||||
this.npmrc = {}
|
||||
try {
|
||||
@@ -24,27 +28,47 @@ class ElectronDownloader {
|
||||
}
|
||||
|
||||
get baseUrl () {
|
||||
if (this.version.indexOf('nightly') !== -1) {
|
||||
return process.env.NPM_CONFIG_ELECTRON_NIGHTLY_MIRROR ||
|
||||
process.env.npm_config_electron_nightly_mirror ||
|
||||
process.env.npm_package_config_electron_nightly_mirror ||
|
||||
process.env.ELECTRON_NIGHTLY_MIRROR ||
|
||||
this.opts.nightly_mirror ||
|
||||
'https://github.com/electron/nightlies/releases/download/v'
|
||||
}
|
||||
return process.env.NPM_CONFIG_ELECTRON_MIRROR ||
|
||||
process.env.npm_config_electron_mirror ||
|
||||
process.env.npm_package_config_electron_mirror ||
|
||||
process.env.ELECTRON_MIRROR ||
|
||||
this.opts.mirror ||
|
||||
'https://github.com/electron/electron/releases/download/v'
|
||||
}
|
||||
|
||||
get middleUrl () {
|
||||
return process.env.ELECTRON_CUSTOM_DIR || this.opts.customDir || this.version
|
||||
return process.env.NPM_CONFIG_ELECTRON_CUSTOM_DIR ||
|
||||
process.env.npm_config_electron_custom_dir ||
|
||||
process.env.npm_package_config_electron_custom_dir ||
|
||||
process.env.ELECTRON_CUSTOM_DIR ||
|
||||
this.opts.customDir ||
|
||||
this.version
|
||||
}
|
||||
|
||||
get urlSuffix () {
|
||||
return process.env.ELECTRON_CUSTOM_FILENAME || this.opts.customFilename || this.filename
|
||||
return process.env.NPM_CONFIG_ELECTRON_CUSTOM_FILENAME ||
|
||||
process.env.npm_config_electron_custom_filename ||
|
||||
process.env.npm_package_config_electron_custom_filename ||
|
||||
process.env.ELECTRON_CUSTOM_FILENAME ||
|
||||
this.opts.customFilename ||
|
||||
this.filename
|
||||
}
|
||||
|
||||
get arch () {
|
||||
return this.opts.arch || os.arch()
|
||||
return this.opts.arch || arch.host(this.quiet)
|
||||
}
|
||||
|
||||
get cache () {
|
||||
if (this.opts.cache) return this.opts.cache
|
||||
const cacheLocation = this.opts.cache || process.env.ELECTRON_CACHE
|
||||
if (cacheLocation) return cacheLocation
|
||||
|
||||
const oldCacheDirectory = path.join(os.homedir(), './.electron')
|
||||
if (pathExists.sync(path.join(oldCacheDirectory, this.filename))) {
|
||||
@@ -144,17 +168,22 @@ class ElectronDownloader {
|
||||
}
|
||||
|
||||
get url () {
|
||||
return `${this.baseUrl}${this.middleUrl}/${this.urlSuffix}`
|
||||
return process.env.ELECTRON_DOWNLOAD_OVERRIDE_URL ||
|
||||
`${this.baseUrl}${this.middleUrl}/${this.urlSuffix}`
|
||||
}
|
||||
|
||||
get verifyChecksumNeeded () {
|
||||
return semver.gte(this.version, '1.3.2')
|
||||
return !this.opts.disableChecksumSafetyCheck && semver.gte(this.version, '1.3.2')
|
||||
}
|
||||
|
||||
get version () {
|
||||
return this.opts.version
|
||||
}
|
||||
|
||||
get headers () {
|
||||
return this.opts.headers
|
||||
}
|
||||
|
||||
checkForCachedChecksum (cb) {
|
||||
pathExists(this.cachedChecksum)
|
||||
.then(exists => {
|
||||
@@ -171,8 +200,10 @@ class ElectronDownloader {
|
||||
if (exists && !this.force) {
|
||||
debug('zip exists', this.cachedZip)
|
||||
this.checkIfZipNeedsVerifying(cb)
|
||||
} else {
|
||||
} else if (this.opts.autoDownload) {
|
||||
this.ensureCacheDir(cb)
|
||||
} else {
|
||||
cb(new Error(`File: "${this.cachedZip}" does not exist locally and autoDownload is false`))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -190,7 +221,7 @@ class ElectronDownloader {
|
||||
if (err) {
|
||||
if (err.code !== 'EACCES') return cb(err)
|
||||
// try local folder if homedir is off limits (e.g. some linuxes return '/' as homedir)
|
||||
let localCache = path.resolve('./.electron')
|
||||
const localCache = path.resolve('./.electron')
|
||||
return fs.mkdirs(localCache, function (err) {
|
||||
if (err) return cb(err)
|
||||
cb(null, localCache)
|
||||
@@ -207,13 +238,14 @@ class ElectronDownloader {
|
||||
downloadFile (url, cacheFilename, cb, onSuccess) {
|
||||
const tempFileName = `tmp-${process.pid}-${(ElectronDownloader.tmpFileCounter++).toString(16)}-${path.basename(cacheFilename)}`
|
||||
debug('downloading', url, 'to', this.cache)
|
||||
let nuggetOpts = {
|
||||
const nuggetOpts = {
|
||||
target: tempFileName,
|
||||
dir: this.cache,
|
||||
resume: true,
|
||||
quiet: this.quiet,
|
||||
strictSSL: this.strictSSL,
|
||||
proxy: this.proxy
|
||||
proxy: this.proxy,
|
||||
headers: this.headers
|
||||
}
|
||||
nugget(url, nuggetOpts, (errors) => {
|
||||
if (errors) {
|
||||
@@ -276,11 +308,11 @@ class ElectronDownloader {
|
||||
}
|
||||
|
||||
verifyChecksum (cb) {
|
||||
let options = {}
|
||||
const options = {}
|
||||
if (semver.lt(this.version, '1.3.5')) {
|
||||
options.defaultTextEncoding = 'binary'
|
||||
}
|
||||
let checker = new sumchecker.ChecksumValidator('sha256', this.cachedChecksum, options)
|
||||
const checker = new sumchecker.ChecksumValidator('sha256', this.cachedChecksum, options)
|
||||
checker.validate(this.cache, this.filename).then(() => {
|
||||
cb(null, this.cachedZip)
|
||||
}, (err) => {
|
||||
@@ -295,6 +327,10 @@ class ElectronDownloader {
|
||||
ElectronDownloader.tmpFileCounter = 0
|
||||
|
||||
module.exports = function download (opts, cb) {
|
||||
let downloader = new ElectronDownloader(opts)
|
||||
downloader.downloadIfNotCached(cb)
|
||||
try {
|
||||
const downloader = new ElectronDownloader(opts)
|
||||
downloader.downloadIfNotCached(cb)
|
||||
} catch (err) {
|
||||
cb(err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user