mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(browserfetcher): Fix windows fetching (#3256)
Since r591479 windows archives are uploaded with a different name.
This commit is contained in:
parent
f5d388af7d
commit
7f00860abd
@ -28,13 +28,42 @@ const ProxyAgent = require('https-proxy-agent');
|
|||||||
const getProxyForUrl = require('proxy-from-env').getProxyForUrl;
|
const getProxyForUrl = require('proxy-from-env').getProxyForUrl;
|
||||||
|
|
||||||
const DEFAULT_DOWNLOAD_HOST = 'https://storage.googleapis.com';
|
const DEFAULT_DOWNLOAD_HOST = 'https://storage.googleapis.com';
|
||||||
|
|
||||||
|
const supportedPlatforms = ['mac', 'linux', 'win32', 'win64'];
|
||||||
const downloadURLs = {
|
const downloadURLs = {
|
||||||
linux: '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip',
|
linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip',
|
||||||
mac: '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip',
|
mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip',
|
||||||
win32: '%s/chromium-browser-snapshots/Win/%d/chrome-win32.zip',
|
win32: '%s/chromium-browser-snapshots/Win/%d/%s.zip',
|
||||||
win64: '%s/chromium-browser-snapshots/Win_x64/%d/chrome-win32.zip',
|
win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} platform
|
||||||
|
* @param {string} revision
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
function archiveName(platform, revision) {
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} platform
|
||||||
|
* @param {string} host
|
||||||
|
* @param {string} revision
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
function downloadURL(platform, host, revision) {
|
||||||
|
return util.format(downloadURLs[platform], host, revision, archiveName(platform, revision));
|
||||||
|
}
|
||||||
|
|
||||||
const readdirAsync = helper.promisify(fs.readdir.bind(fs));
|
const readdirAsync = helper.promisify(fs.readdir.bind(fs));
|
||||||
const mkdirAsync = helper.promisify(fs.mkdir.bind(fs));
|
const mkdirAsync = helper.promisify(fs.mkdir.bind(fs));
|
||||||
const unlinkAsync = helper.promisify(fs.unlink.bind(fs));
|
const unlinkAsync = helper.promisify(fs.unlink.bind(fs));
|
||||||
@ -66,7 +95,6 @@ class BrowserFetcher {
|
|||||||
this._platform = os.arch() === 'x64' ? 'win64' : 'win32';
|
this._platform = os.arch() === 'x64' ? 'win64' : 'win32';
|
||||||
assert(this._platform, 'Unsupported platform: ' + os.platform());
|
assert(this._platform, 'Unsupported platform: ' + os.platform());
|
||||||
}
|
}
|
||||||
const supportedPlatforms = ['mac', 'linux', 'win32', 'win64'];
|
|
||||||
assert(supportedPlatforms.includes(this._platform), 'Unsupported platform: ' + this._platform);
|
assert(supportedPlatforms.includes(this._platform), 'Unsupported platform: ' + this._platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,8 +110,7 @@ class BrowserFetcher {
|
|||||||
* @return {!Promise<boolean>}
|
* @return {!Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
canDownload(revision) {
|
canDownload(revision) {
|
||||||
const url = util.format(downloadURLs[this._platform], this._downloadHost, revision);
|
const url = downloadURL(this._platform, this._downloadHost, revision);
|
||||||
|
|
||||||
let resolve;
|
let resolve;
|
||||||
const promise = new Promise(x => resolve = x);
|
const promise = new Promise(x => resolve = x);
|
||||||
const request = httpRequest(url, 'HEAD', response => {
|
const request = httpRequest(url, 'HEAD', response => {
|
||||||
@ -102,8 +129,7 @@ class BrowserFetcher {
|
|||||||
* @return {!Promise<!BrowserFetcher.RevisionInfo>}
|
* @return {!Promise<!BrowserFetcher.RevisionInfo>}
|
||||||
*/
|
*/
|
||||||
async download(revision, progressCallback) {
|
async download(revision, progressCallback) {
|
||||||
let url = downloadURLs[this._platform];
|
const url = downloadURL(this._platform, this._downloadHost, revision);
|
||||||
url = util.format(url, this._downloadHost, revision);
|
|
||||||
const zipPath = path.join(this._downloadsFolder, `download-${this._platform}-${revision}.zip`);
|
const zipPath = path.join(this._downloadsFolder, `download-${this._platform}-${revision}.zip`);
|
||||||
const folderPath = this._getFolderPath(revision);
|
const folderPath = this._getFolderPath(revision);
|
||||||
if (await existsAsync(folderPath))
|
if (await existsAsync(folderPath))
|
||||||
@ -151,15 +177,14 @@ class BrowserFetcher {
|
|||||||
const folderPath = this._getFolderPath(revision);
|
const folderPath = this._getFolderPath(revision);
|
||||||
let executablePath = '';
|
let executablePath = '';
|
||||||
if (this._platform === 'mac')
|
if (this._platform === 'mac')
|
||||||
executablePath = path.join(folderPath, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
|
executablePath = path.join(folderPath, archiveName(this._platform, revision), 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
|
||||||
else if (this._platform === 'linux')
|
else if (this._platform === 'linux')
|
||||||
executablePath = path.join(folderPath, 'chrome-linux', 'chrome');
|
executablePath = path.join(folderPath, archiveName(this._platform, revision), 'chrome');
|
||||||
else if (this._platform === 'win32' || this._platform === 'win64')
|
else if (this._platform === 'win32' || this._platform === 'win64')
|
||||||
executablePath = path.join(folderPath, 'chrome-win32', 'chrome.exe');
|
executablePath = path.join(folderPath, archiveName(this._platform, revision), 'chrome.exe');
|
||||||
else
|
else
|
||||||
throw new Error('Unsupported platform: ' + this._platform);
|
throw new Error('Unsupported platform: ' + this._platform);
|
||||||
let url = downloadURLs[this._platform];
|
const url = downloadURL(this._platform, this._downloadHost, revision);
|
||||||
url = util.format(url, this._downloadHost, revision);
|
|
||||||
const local = fs.existsSync(folderPath);
|
const local = fs.existsSync(folderPath);
|
||||||
return {revision, executablePath, folderPath, local, url};
|
return {revision, executablePath, folderPath, local, url};
|
||||||
}
|
}
|
||||||
@ -185,7 +210,7 @@ function parseFolderPath(folderPath) {
|
|||||||
if (splits.length !== 2)
|
if (splits.length !== 2)
|
||||||
return null;
|
return null;
|
||||||
const [platform, revision] = splits;
|
const [platform, revision] = splits;
|
||||||
if (!downloadURLs[platform])
|
if (!supportedPlatforms.includes(platform))
|
||||||
return null;
|
return null;
|
||||||
return {platform, revision};
|
return {platform, revision};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user