2017-05-15 03:05:41 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-08-02 19:06:47 +00:00
|
|
|
const os = require('os');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const util = require('util');
|
2020-03-10 20:59:03 +00:00
|
|
|
const childProcess = require('child_process');
|
2019-10-16 15:00:20 +00:00
|
|
|
const extract = require('extract-zip');
|
2020-03-10 20:59:03 +00:00
|
|
|
const debugFetcher = require('debug')(`puppeteer:fetcher`);
|
2017-08-02 19:06:47 +00:00
|
|
|
const URL = require('url');
|
2018-05-31 23:53:51 +00:00
|
|
|
const {helper, assert} = require('./helper');
|
2017-08-02 19:06:47 +00:00
|
|
|
const removeRecursive = require('rimraf');
|
2017-10-10 05:31:40 +00:00
|
|
|
// @ts-ignore
|
2017-08-23 15:33:29 +00:00
|
|
|
const ProxyAgent = require('https-proxy-agent');
|
2017-10-10 05:31:40 +00:00
|
|
|
// @ts-ignore
|
2017-08-23 15:33:29 +00:00
|
|
|
const getProxyForUrl = require('proxy-from-env').getProxyForUrl;
|
2017-05-15 03:05:41 +00:00
|
|
|
|
2017-08-02 19:06:47 +00:00
|
|
|
const downloadURLs = {
|
2020-03-10 20:59:03 +00:00
|
|
|
chrome: {
|
|
|
|
linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip',
|
|
|
|
mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip',
|
|
|
|
win32: '%s/chromium-browser-snapshots/Win/%d/%s.zip',
|
|
|
|
win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip',
|
|
|
|
},
|
|
|
|
firefox: {
|
|
|
|
linux: '%s/firefox-%s.0a1.en-US.%s-x86_64.tar.bz2',
|
|
|
|
mac: '%s/firefox-%s.0a1.en-US.%s.dmg',
|
|
|
|
win32: '%s/firefox-%s.0a1.en-US.%s.zip',
|
|
|
|
win64: '%s/firefox-%s.0a1.en-US.%s.zip',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const browserConfig = {
|
|
|
|
chrome: {
|
|
|
|
host: 'https://storage.googleapis.com',
|
|
|
|
destination: '.local-chromium',
|
|
|
|
},
|
|
|
|
firefox: {
|
|
|
|
host: 'https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central',
|
|
|
|
destination: '.local-firefox',
|
|
|
|
}
|
2017-05-15 03:05:41 +00:00
|
|
|
};
|
|
|
|
|
2018-09-17 17:15:08 +00:00
|
|
|
/**
|
2020-03-10 20:59:03 +00:00
|
|
|
* @param {string} product
|
2018-09-17 17:15:08 +00:00
|
|
|
* @param {string} platform
|
|
|
|
* @param {string} revision
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2020-03-10 20:59:03 +00:00
|
|
|
function archiveName(product, platform, revision) {
|
|
|
|
if (product === 'chrome') {
|
|
|
|
if (platform === 'linux')
|
|
|
|
return 'chrome-linux';
|
|
|
|
if (platform === 'mac')
|
|
|
|
return 'chrome-mac';
|
|
|
|
if (platform === 'win32' || platform === 'win64') {
|
|
|
|
// Windows archive name changed at r591479.
|
|
|
|
return parseInt(revision, 10) > 591479 ? 'chrome-win' : 'chrome-win32';
|
|
|
|
}
|
|
|
|
} else if (product === 'firefox') {
|
|
|
|
return platform;
|
2018-09-17 17:15:08 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-10 20:59:03 +00:00
|
|
|
* @param {string} product
|
2018-09-17 17:15:08 +00:00
|
|
|
* @param {string} platform
|
|
|
|
* @param {string} host
|
|
|
|
* @param {string} revision
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2020-03-10 20:59:03 +00:00
|
|
|
function downloadURL(product, platform, host, revision) {
|
|
|
|
const url = util.format(downloadURLs[product][platform], host, revision, archiveName(product, platform, revision));
|
|
|
|
return url;
|
2018-09-17 17:15:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 17:31:53 +00:00
|
|
|
const readdirAsync = helper.promisify(fs.readdir.bind(fs));
|
|
|
|
const mkdirAsync = helper.promisify(fs.mkdir.bind(fs));
|
|
|
|
const unlinkAsync = helper.promisify(fs.unlink.bind(fs));
|
2018-04-10 21:11:59 +00:00
|
|
|
const chmodAsync = helper.promisify(fs.chmod.bind(fs));
|
2017-12-08 21:39:13 +00:00
|
|
|
|
2018-02-07 17:31:53 +00:00
|
|
|
function existsAsync(filePath) {
|
|
|
|
let fulfill = null;
|
|
|
|
const promise = new Promise(x => fulfill = x);
|
|
|
|
fs.access(filePath, err => fulfill(!err));
|
|
|
|
return promise;
|
|
|
|
}
|
2017-12-08 21:39:13 +00:00
|
|
|
|
2018-02-07 17:31:53 +00:00
|
|
|
class BrowserFetcher {
|
2017-06-21 20:51:06 +00:00
|
|
|
/**
|
2018-09-06 19:33:41 +00:00
|
|
|
* @param {string} projectRoot
|
2018-02-07 17:31:53 +00:00
|
|
|
* @param {!BrowserFetcher.Options=} options
|
2017-07-12 21:46:41 +00:00
|
|
|
*/
|
2018-09-06 19:33:41 +00:00
|
|
|
constructor(projectRoot, options = {}) {
|
2020-03-10 20:59:03 +00:00
|
|
|
this._product = (options.product || 'chrome').toLowerCase();
|
|
|
|
assert(this._product === 'chrome' || this._product === 'firefox', `Unknown product: "${options.product}"`);
|
|
|
|
this._downloadsFolder = options.path || path.join(projectRoot, browserConfig[this._product].destination);
|
|
|
|
this._downloadHost = options.host || browserConfig[this._product].host;
|
2018-02-07 17:31:53 +00:00
|
|
|
this._platform = options.platform || '';
|
|
|
|
if (!this._platform) {
|
|
|
|
const platform = os.platform();
|
|
|
|
if (platform === 'darwin')
|
|
|
|
this._platform = 'mac';
|
|
|
|
else if (platform === 'linux')
|
|
|
|
this._platform = 'linux';
|
|
|
|
else if (platform === 'win32')
|
|
|
|
this._platform = os.arch() === 'x64' ? 'win64' : 'win32';
|
2018-05-31 23:53:51 +00:00
|
|
|
assert(this._platform, 'Unsupported platform: ' + os.platform());
|
2018-02-07 17:31:53 +00:00
|
|
|
}
|
2020-03-10 20:59:03 +00:00
|
|
|
assert(downloadURLs[this._product][this._platform], 'Unsupported platform: ' + this._platform);
|
2017-12-08 21:39:13 +00:00
|
|
|
}
|
2017-05-15 03:05:41 +00:00
|
|
|
|
2017-06-21 20:51:06 +00:00
|
|
|
/**
|
2017-07-12 21:46:41 +00:00
|
|
|
* @return {string}
|
|
|
|
*/
|
2018-02-07 17:31:53 +00:00
|
|
|
platform() {
|
|
|
|
return this._platform;
|
2017-12-08 21:39:13 +00:00
|
|
|
}
|
2017-05-15 03:05:41 +00:00
|
|
|
|
2020-03-10 20:59:03 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
product() {
|
|
|
|
return this._product;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
host() {
|
|
|
|
return this._downloadHost;
|
|
|
|
}
|
|
|
|
|
2017-06-21 20:51:06 +00:00
|
|
|
/**
|
2017-07-12 21:46:41 +00:00
|
|
|
* @param {string} revision
|
|
|
|
* @return {!Promise<boolean>}
|
|
|
|
*/
|
2018-02-07 17:31:53 +00:00
|
|
|
canDownload(revision) {
|
2020-03-10 20:59:03 +00:00
|
|
|
const url = downloadURL(this._product, this._platform, this._downloadHost, revision);
|
2017-06-22 20:38:10 +00:00
|
|
|
let resolve;
|
2017-08-21 23:39:04 +00:00
|
|
|
const promise = new Promise(x => resolve = x);
|
2017-12-04 21:45:21 +00:00
|
|
|
const request = httpRequest(url, 'HEAD', response => {
|
2017-06-21 20:51:06 +00:00
|
|
|
resolve(response.statusCode === 200);
|
|
|
|
});
|
|
|
|
request.on('error', error => {
|
|
|
|
console.error(error);
|
|
|
|
resolve(false);
|
|
|
|
});
|
|
|
|
return promise;
|
2017-12-08 21:39:13 +00:00
|
|
|
}
|
2017-05-15 03:05:41 +00:00
|
|
|
|
2017-06-21 20:51:06 +00:00
|
|
|
/**
|
2017-07-12 21:46:41 +00:00
|
|
|
* @param {string} revision
|
2019-01-11 06:56:39 +00:00
|
|
|
* @param {?function(number, number):void} progressCallback
|
2018-02-07 17:31:53 +00:00
|
|
|
* @return {!Promise<!BrowserFetcher.RevisionInfo>}
|
2017-07-12 21:46:41 +00:00
|
|
|
*/
|
2018-02-07 17:31:53 +00:00
|
|
|
async download(revision, progressCallback) {
|
2020-03-10 20:59:03 +00:00
|
|
|
const url = downloadURL(this._product, this._platform, this._downloadHost, revision);
|
|
|
|
const fileName = url.split('/').pop();
|
|
|
|
const archivePath = path.join(this._downloadsFolder, fileName);
|
|
|
|
const outputPath = this._getFolderPath(revision);
|
|
|
|
if (await existsAsync(outputPath))
|
2018-02-07 17:31:53 +00:00
|
|
|
return this.revisionInfo(revision);
|
|
|
|
if (!(await existsAsync(this._downloadsFolder)))
|
|
|
|
await mkdirAsync(this._downloadsFolder);
|
|
|
|
try {
|
2020-03-10 20:59:03 +00:00
|
|
|
await downloadFile(url, archivePath, progressCallback);
|
|
|
|
await install(archivePath, outputPath);
|
2018-02-07 17:31:53 +00:00
|
|
|
} finally {
|
2020-03-10 20:59:03 +00:00
|
|
|
if (await existsAsync(archivePath))
|
|
|
|
await unlinkAsync(archivePath);
|
2018-02-07 17:31:53 +00:00
|
|
|
}
|
2018-04-10 21:11:59 +00:00
|
|
|
const revisionInfo = this.revisionInfo(revision);
|
|
|
|
if (revisionInfo)
|
|
|
|
await chmodAsync(revisionInfo.executablePath, 0o755);
|
|
|
|
return revisionInfo;
|
2017-12-08 21:39:13 +00:00
|
|
|
}
|
2017-05-15 03:05:41 +00:00
|
|
|
|
2017-06-21 20:51:06 +00:00
|
|
|
/**
|
2018-02-07 17:31:53 +00:00
|
|
|
* @return {!Promise<!Array<string>>}
|
2017-07-12 21:46:41 +00:00
|
|
|
*/
|
2018-02-07 17:31:53 +00:00
|
|
|
async localRevisions() {
|
|
|
|
if (!await existsAsync(this._downloadsFolder))
|
2017-07-12 21:54:48 +00:00
|
|
|
return [];
|
2018-02-07 17:31:53 +00:00
|
|
|
const fileNames = await readdirAsync(this._downloadsFolder);
|
2020-03-10 20:59:03 +00:00
|
|
|
return fileNames.map(fileName => parseFolderPath(this._product, fileName)).filter(entry => entry && entry.platform === this._platform).map(entry => entry.revision);
|
2017-12-08 21:39:13 +00:00
|
|
|
}
|
2017-07-12 21:46:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} revision
|
|
|
|
*/
|
2018-02-07 17:31:53 +00:00
|
|
|
async remove(revision) {
|
|
|
|
const folderPath = this._getFolderPath(revision);
|
2018-05-31 23:53:51 +00:00
|
|
|
assert(await existsAsync(folderPath), `Failed to remove: revision ${revision} is not downloaded`);
|
2018-02-07 17:31:53 +00:00
|
|
|
await new Promise(fulfill => removeRecursive(folderPath, fulfill));
|
2017-12-08 21:39:13 +00:00
|
|
|
}
|
2017-07-12 21:46:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} revision
|
2018-02-07 17:31:53 +00:00
|
|
|
* @return {!BrowserFetcher.RevisionInfo}
|
2017-07-12 21:46:41 +00:00
|
|
|
*/
|
2018-02-07 17:31:53 +00:00
|
|
|
revisionInfo(revision) {
|
|
|
|
const folderPath = this._getFolderPath(revision);
|
2017-06-22 20:38:10 +00:00
|
|
|
let executablePath = '';
|
2020-03-10 20:59:03 +00:00
|
|
|
if (this._product === 'chrome') {
|
|
|
|
if (this._platform === 'mac')
|
|
|
|
executablePath = path.join(folderPath, archiveName(this._product, this._platform, revision), 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
|
|
|
|
else if (this._platform === 'linux')
|
|
|
|
executablePath = path.join(folderPath, archiveName(this._product, this._platform, revision), 'chrome');
|
|
|
|
else if (this._platform === 'win32' || this._platform === 'win64')
|
|
|
|
executablePath = path.join(folderPath, archiveName(this._product, this._platform, revision), 'chrome.exe');
|
|
|
|
else
|
|
|
|
throw new Error('Unsupported platform: ' + this._platform);
|
|
|
|
} else if (this._product === 'firefox') {
|
|
|
|
if (this._platform === 'mac')
|
|
|
|
executablePath = path.join(folderPath, 'Firefox Nightly.app', 'Contents', 'MacOS', 'firefox');
|
|
|
|
else if (this._platform === 'linux')
|
|
|
|
executablePath = path.join(folderPath, 'firefox', 'firefox');
|
|
|
|
else if (this._platform === 'win32' || this._platform === 'win64')
|
|
|
|
executablePath = path.join(folderPath, 'firefox', 'firefox.exe');
|
|
|
|
else
|
|
|
|
throw new Error('Unsupported platform: ' + this._platform);
|
|
|
|
} else {
|
|
|
|
throw new Error('Unsupported product: ' + this._product);
|
|
|
|
}
|
|
|
|
const url = downloadURL(this._product, this._platform, this._downloadHost, revision);
|
2018-02-07 17:31:53 +00:00
|
|
|
const local = fs.existsSync(folderPath);
|
2020-03-10 20:59:03 +00:00
|
|
|
debugFetcher({revision, executablePath, folderPath, local, url, product: this._product});
|
|
|
|
return {revision, executablePath, folderPath, local, url, product: this._product};
|
2017-12-08 21:39:13 +00:00
|
|
|
}
|
2017-05-15 03:05:41 +00:00
|
|
|
|
2017-12-08 21:39:13 +00:00
|
|
|
/**
|
|
|
|
* @param {string} revision
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2018-02-07 17:31:53 +00:00
|
|
|
_getFolderPath(revision) {
|
|
|
|
return path.join(this._downloadsFolder, this._platform + '-' + revision);
|
2017-12-08 21:39:13 +00:00
|
|
|
}
|
2017-07-12 21:46:41 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 17:31:53 +00:00
|
|
|
module.exports = BrowserFetcher;
|
2017-12-08 21:39:13 +00:00
|
|
|
|
2017-07-12 21:46:41 +00:00
|
|
|
/**
|
|
|
|
* @param {string} folderPath
|
2020-03-10 20:59:03 +00:00
|
|
|
* @return {?{product: string, platform: string, revision: string}}
|
2017-07-12 21:46:41 +00:00
|
|
|
*/
|
2020-03-10 20:59:03 +00:00
|
|
|
function parseFolderPath(product, folderPath) {
|
2017-08-21 23:39:04 +00:00
|
|
|
const name = path.basename(folderPath);
|
|
|
|
const splits = name.split('-');
|
2017-07-12 21:46:41 +00:00
|
|
|
if (splits.length !== 2)
|
|
|
|
return null;
|
2017-08-21 23:39:04 +00:00
|
|
|
const [platform, revision] = splits;
|
2020-03-10 20:59:03 +00:00
|
|
|
if (!downloadURLs[product][platform])
|
2017-07-12 21:46:41 +00:00
|
|
|
return null;
|
2020-03-10 20:59:03 +00:00
|
|
|
return {product, platform, revision};
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} url
|
|
|
|
* @param {string} destinationPath
|
2019-01-11 06:56:39 +00:00
|
|
|
* @param {?function(number, number):void} progressCallback
|
2017-05-15 03:05:41 +00:00
|
|
|
* @return {!Promise}
|
|
|
|
*/
|
|
|
|
function downloadFile(url, destinationPath, progressCallback) {
|
2020-03-10 20:59:03 +00:00
|
|
|
debugFetcher(`Downloading binary from ${url}`);
|
2017-06-22 20:38:10 +00:00
|
|
|
let fulfill, reject;
|
2018-02-07 17:31:53 +00:00
|
|
|
let downloadedBytes = 0;
|
|
|
|
let totalBytes = 0;
|
2017-08-23 15:33:29 +00:00
|
|
|
|
2017-08-21 23:39:04 +00:00
|
|
|
const promise = new Promise((x, y) => { fulfill = x; reject = y; });
|
2017-08-23 15:33:29 +00:00
|
|
|
|
2017-12-04 21:45:21 +00:00
|
|
|
const request = httpRequest(url, 'GET', response => {
|
2017-06-21 20:51:06 +00:00
|
|
|
if (response.statusCode !== 200) {
|
2017-08-21 23:39:04 +00:00
|
|
|
const error = new Error(`Download failed: server returned code ${response.statusCode}. URL: ${url}`);
|
2017-06-21 20:51:06 +00:00
|
|
|
// consume response data to free up memory
|
|
|
|
response.resume();
|
|
|
|
reject(error);
|
|
|
|
return;
|
2017-06-21 20:36:04 +00:00
|
|
|
}
|
2017-08-21 23:39:04 +00:00
|
|
|
const file = fs.createWriteStream(destinationPath);
|
2017-06-21 20:51:06 +00:00
|
|
|
file.on('finish', () => fulfill());
|
|
|
|
file.on('error', error => reject(error));
|
|
|
|
response.pipe(file);
|
2018-02-07 17:31:53 +00:00
|
|
|
totalBytes = parseInt(/** @type {string} */ (response.headers['content-length']), 10);
|
2017-06-21 20:51:06 +00:00
|
|
|
if (progressCallback)
|
2018-02-07 17:31:53 +00:00
|
|
|
response.on('data', onData);
|
2017-06-21 20:51:06 +00:00
|
|
|
});
|
|
|
|
request.on('error', error => reject(error));
|
|
|
|
return promise;
|
|
|
|
|
2018-02-07 17:31:53 +00:00
|
|
|
function onData(chunk) {
|
|
|
|
downloadedBytes += chunk.length;
|
|
|
|
progressCallback(downloadedBytes, totalBytes);
|
2017-06-21 20:51:06 +00:00
|
|
|
}
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 20:59:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Install from a zip, tar.bz2 or dmg file.
|
|
|
|
*
|
|
|
|
* @param {string} archivePath
|
|
|
|
* @param {string} folderPath
|
|
|
|
* @return {!Promise<?Error>}
|
|
|
|
*/
|
|
|
|
function install(archivePath, folderPath) {
|
|
|
|
debugFetcher(`Installing ${archivePath} to ${folderPath}`);
|
|
|
|
if (archivePath.endsWith('.zip'))
|
|
|
|
return extractZip(archivePath, folderPath);
|
|
|
|
else if (archivePath.endsWith('.tar.bz2'))
|
|
|
|
return extractTar(archivePath, folderPath);
|
|
|
|
else if (archivePath.endsWith('.dmg'))
|
|
|
|
return mkdirAsync(folderPath).then(() => installDMG(archivePath, folderPath));
|
|
|
|
else
|
|
|
|
throw new Error(`Unsupported archive format: ${archivePath}`);
|
|
|
|
}
|
|
|
|
|
2017-05-15 03:05:41 +00:00
|
|
|
/**
|
|
|
|
* @param {string} zipPath
|
|
|
|
* @param {string} folderPath
|
|
|
|
* @return {!Promise<?Error>}
|
|
|
|
*/
|
|
|
|
function extractZip(zipPath, folderPath) {
|
2018-08-09 18:14:58 +00:00
|
|
|
return new Promise((fulfill, reject) => extract(zipPath, {dir: folderPath}, err => {
|
|
|
|
if (err)
|
|
|
|
reject(err);
|
|
|
|
else
|
|
|
|
fulfill();
|
|
|
|
}));
|
2017-05-15 03:05:41 +00:00
|
|
|
}
|
2017-08-23 15:33:29 +00:00
|
|
|
|
2020-03-10 20:59:03 +00:00
|
|
|
/**
|
|
|
|
* @param {string} tarPath
|
|
|
|
* @param {string} folderPath
|
|
|
|
* @return {!Promise<?Error>}
|
|
|
|
*/
|
|
|
|
function extractTar(tarPath, folderPath) {
|
|
|
|
const tar = require('tar-fs');
|
|
|
|
// @ts-ignore
|
|
|
|
const bzip = require('unbzip2-stream');
|
|
|
|
return new Promise((fulfill, reject) => {
|
|
|
|
const tarStream = tar.extract(folderPath);
|
|
|
|
tarStream.on('error', reject);
|
|
|
|
tarStream.on('finish', fulfill);
|
|
|
|
const readStream = fs.createReadStream(tarPath);
|
|
|
|
readStream.on('data', () => { process.stdout.write('\rExtracting...'); });
|
|
|
|
readStream.pipe(bzip()).pipe(tarStream);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Install *.app directory from dmg file
|
|
|
|
*
|
|
|
|
* @param {string} dmgPath
|
|
|
|
* @param {string} folderPath
|
|
|
|
* @return {!Promise<?Error>}
|
|
|
|
*/
|
|
|
|
function installDMG(dmgPath, folderPath) {
|
|
|
|
let mountPath;
|
|
|
|
|
|
|
|
function mountAndCopy(fulfill, reject) {
|
|
|
|
const mountCommand = `hdiutil attach -nobrowse -noautoopen "${dmgPath}"`;
|
|
|
|
childProcess.exec(mountCommand, (err, stdout, stderr) => {
|
|
|
|
if (err)
|
|
|
|
return reject(err);
|
|
|
|
const volumes = stdout.match(/\/Volumes\/(.*)/m);
|
|
|
|
if (!volumes)
|
|
|
|
return reject(new Error(`Could not find volume path in ${stdout}`));
|
|
|
|
mountPath = volumes[0];
|
|
|
|
readdirAsync(mountPath).then(fileNames => {
|
|
|
|
const appName = fileNames.filter(item => typeof item === 'string' && item.endsWith('.app'))[0];
|
|
|
|
if (!appName)
|
|
|
|
return reject(new Error(`Cannot find app in ${mountPath}`));
|
|
|
|
const copyPath = path.join(mountPath, appName);
|
|
|
|
debugFetcher(`Copying ${copyPath} to ${folderPath}`);
|
|
|
|
childProcess.exec(`cp -R "${copyPath}" "${folderPath}"`, (err, stdout) => {
|
|
|
|
if (err)
|
|
|
|
reject(err);
|
|
|
|
else
|
|
|
|
fulfill();
|
|
|
|
});
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function unmount() {
|
|
|
|
if (!mountPath)
|
|
|
|
return;
|
|
|
|
const unmountCommand = `hdiutil detach "${mountPath}" -quiet`;
|
|
|
|
debugFetcher(`Unmounting ${mountPath}`);
|
|
|
|
childProcess.exec(unmountCommand, err => {
|
|
|
|
if (err)
|
|
|
|
console.error(`Error unmounting dmg: ${err}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise(mountAndCopy).catch(err => { console.error(err); }).finally(unmount);
|
|
|
|
}
|
|
|
|
|
2017-12-04 21:45:21 +00:00
|
|
|
function httpRequest(url, method, response) {
|
2017-10-10 05:31:40 +00:00
|
|
|
/** @type {Object} */
|
2019-06-10 08:11:01 +00:00
|
|
|
let options = URL.parse(url);
|
2017-12-04 21:45:21 +00:00
|
|
|
options.method = method;
|
2017-08-23 15:33:29 +00:00
|
|
|
|
|
|
|
const proxyURL = getProxyForUrl(url);
|
|
|
|
if (proxyURL) {
|
2019-06-10 08:11:01 +00:00
|
|
|
if (url.startsWith('http:')) {
|
|
|
|
const proxy = URL.parse(proxyURL);
|
|
|
|
options = {
|
|
|
|
path: options.href,
|
|
|
|
host: proxy.hostname,
|
|
|
|
port: proxy.port,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
/** @type {Object} */
|
|
|
|
const parsedProxyURL = URL.parse(proxyURL);
|
|
|
|
parsedProxyURL.secureProxy = parsedProxyURL.protocol === 'https:';
|
2017-12-04 21:45:21 +00:00
|
|
|
|
2019-06-10 08:11:01 +00:00
|
|
|
options.agent = new ProxyAgent(parsedProxyURL);
|
|
|
|
options.rejectUnauthorized = false;
|
|
|
|
}
|
2017-08-23 15:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 19:33:41 +00:00
|
|
|
const requestCallback = res => {
|
2018-01-09 02:10:13 +00:00
|
|
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location)
|
|
|
|
httpRequest(res.headers.location, method, response);
|
|
|
|
else
|
|
|
|
response(res);
|
2018-09-06 19:33:41 +00:00
|
|
|
};
|
|
|
|
const request = options.protocol === 'https:' ?
|
|
|
|
require('https').request(options, requestCallback) :
|
|
|
|
require('http').request(options, requestCallback);
|
2017-12-04 21:45:21 +00:00
|
|
|
request.end();
|
|
|
|
return request;
|
2017-09-01 16:47:57 +00:00
|
|
|
}
|
2018-02-07 17:31:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {Object} BrowserFetcher.Options
|
|
|
|
* @property {string=} platform
|
2020-03-10 20:59:03 +00:00
|
|
|
* @property {string=} product
|
2018-02-07 17:31:53 +00:00
|
|
|
* @property {string=} path
|
|
|
|
* @property {string=} host
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {Object} BrowserFetcher.RevisionInfo
|
|
|
|
* @property {string} folderPath
|
|
|
|
* @property {string} executablePath
|
|
|
|
* @property {string} url
|
|
|
|
* @property {boolean} local
|
|
|
|
* @property {string} revision
|
2020-03-10 20:59:03 +00:00
|
|
|
* @property {string} product
|
2018-02-07 17:31:53 +00:00
|
|
|
*/
|