feat: add proxy support (set environment variable HTTPS_PROXY)
This commit is contained in:
@@ -10,9 +10,7 @@ if (require.main === module) {
|
||||
process.stderr.write(showHelp ? options.help : options.version + eol)
|
||||
} else {
|
||||
const nexe = require('./lib/nexe')
|
||||
nexe.compile(argv).catch((e) => {
|
||||
process.stderr.write(eol + e.stack)
|
||||
})
|
||||
nexe.compile(argv)
|
||||
}
|
||||
} else {
|
||||
module.exports = require('./lib/nexe')
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"app-builder": "^5.1.0",
|
||||
"caw": "^2.0.1",
|
||||
"chalk": "^1.1.3",
|
||||
"download": "^6.2.0",
|
||||
"fuse-box": "^2.3.4-beta.11",
|
||||
|
||||
+20
-19
@@ -180,14 +180,15 @@ export class NexeCompiler<T extends NexeOptions = NexeOptions> {
|
||||
}
|
||||
|
||||
private async _fetchPrebuiltBinaryAsync(target: NexeTarget) {
|
||||
const downloadOptions: any = {
|
||||
headers: {
|
||||
'User-Agent': 'nexe (https://www.npmjs.com/package/nexe)'
|
||||
}
|
||||
}
|
||||
let downloadOptions = this.options.downloadOptions
|
||||
|
||||
if (this.options.ghToken) {
|
||||
downloadOptions.headers.Authorization = 'token ' + this.options.ghToken
|
||||
downloadOptions = Object.assign({}, downloadOptions)
|
||||
downloadOptions.headers = Object.assign({}, downloadOptions.headers, {
|
||||
Authorization: 'token ' + this.options.ghToken
|
||||
})
|
||||
}
|
||||
|
||||
const githubRelease = await getLatestGitRelease(downloadOptions)
|
||||
const assetName = target.toString()
|
||||
const asset = githubRelease.assets.find(x => x.name === assetName)
|
||||
@@ -196,19 +197,19 @@ export class NexeCompiler<T extends NexeOptions = NexeOptions> {
|
||||
throw new Error(`${assetName} not available, create it using the --build flag`)
|
||||
}
|
||||
const filename = this.getNodeExecutableLocation(target)
|
||||
// Remove the authorization, as the download is done via amazon S3 and does not need the token
|
||||
delete downloadOptions.headers.Authorization
|
||||
await download(asset.browser_download_url, dirname(filename), downloadOptions).on(
|
||||
'response',
|
||||
(res: IncomingMessage) => {
|
||||
const total = +res.headers['content-length']!
|
||||
let current = 0
|
||||
res.on('data', data => {
|
||||
current += data.length
|
||||
this.compileStep.modify(`Downloading...${(current / total * 100).toFixed()}%`)
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
await download(
|
||||
asset.browser_download_url,
|
||||
dirname(filename),
|
||||
this.options.downloadOptions
|
||||
).on('response', (res: IncomingMessage) => {
|
||||
const total = +res.headers['content-length']!
|
||||
let current = 0
|
||||
res.on('data', data => {
|
||||
current += data.length
|
||||
this.compileStep.modify(`Downloading...${(current / total * 100).toFixed()}%`)
|
||||
})
|
||||
})
|
||||
return createReadStream(filename)
|
||||
}
|
||||
|
||||
|
||||
+12
-1
@@ -10,6 +10,7 @@ import artifacts from './steps/artifacts'
|
||||
import patches from './patches'
|
||||
import { rimrafAsync } from './util'
|
||||
import { NexeTarget } from './target'
|
||||
import { EOL } from 'os'
|
||||
|
||||
async function compile(
|
||||
compilerOptions?: Partial<NexeOptions>,
|
||||
@@ -39,11 +40,21 @@ async function compile(
|
||||
? void nexe(compiler).then(
|
||||
() => callback && callback(null),
|
||||
(e: Error) => {
|
||||
if (compiler.options.loglevel !== 'silent') {
|
||||
process.stderr.write(EOL + e.stack + EOL)
|
||||
}
|
||||
compiler.quit()
|
||||
if (callback) callback(e)
|
||||
else throw e
|
||||
}
|
||||
)
|
||||
: nexe(compiler)
|
||||
: nexe(compiler).catch((e: Error) => {
|
||||
if (compiler.options.loglevel !== 'silent') {
|
||||
process.stderr.write(EOL + e.stack + EOL)
|
||||
}
|
||||
compiler.quit()
|
||||
throw e
|
||||
})
|
||||
}
|
||||
|
||||
export { argv, compile, version, NexeCompiler, NexeOptions, help }
|
||||
|
||||
@@ -6,6 +6,8 @@ import { getTarget, NexeTarget } from './target'
|
||||
import { EOL, homedir } from 'os'
|
||||
import * as c from 'chalk'
|
||||
|
||||
const caw = require('caw')
|
||||
|
||||
export const version = '{{replace:0}}'
|
||||
|
||||
export interface NexePatch {
|
||||
@@ -227,6 +229,15 @@ function normalizeOptions(input?: Partial<NexeOptions>): NexeOptions {
|
||||
options.make = flatten(options.vcBuild, options.make)
|
||||
options.configure = flatten(options.configure)
|
||||
options.resources = flatten(opts.resource, options.resources)
|
||||
|
||||
options.downloadOptions = options.downloadOptions || {}
|
||||
options.downloadOptions.headers = options.downloadOptions.headers || {}
|
||||
options.downloadOptions.headers['User-Agent'] = 'nexe (https://www.npmjs.com/package/nexe)'
|
||||
options.downloadOptions.agent = process.env.HTTPS_PROXY
|
||||
? caw(process.env.HTTPS_PROXY, { protocol: 'https' })
|
||||
: options.downloadOptions.agent || require('https').globalAgent
|
||||
options.downloadOptions.rejectUnauthorized = process.env.HTTPS_PROXY ? false : true
|
||||
|
||||
options.rc = options.rc || extractCliMap(/^rc-.*/, options)
|
||||
options.output =
|
||||
(options.targets[0] as NexeTarget).platform === 'windows'
|
||||
|
||||
@@ -363,7 +363,7 @@ caseless@~0.12.0:
|
||||
version "0.12.0"
|
||||
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
|
||||
|
||||
caw@^2.0.0:
|
||||
caw@^2.0.0, caw@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/caw/-/caw-2.0.1.tgz#6c3ca071fc194720883c2dc5da9b074bfc7e9e95"
|
||||
dependencies:
|
||||
|
||||
Reference in New Issue
Block a user