diff --git a/install.js b/install.js index 26ef3c7d..80b32979 100644 --- a/install.js +++ b/install.js @@ -15,18 +15,28 @@ */ const Downloader = require('./utils/ChromiumDownloader'); +const platform = Downloader.currentPlatform(); const revision = require('./package').puppeteer.chromium_revision; const ProgressBar = require('progress'); +const revisionInfo = Downloader.revisionInfo(platform, revision); // Do nothing if the revision is already downloaded. -if (Downloader.revisionInfo(Downloader.currentPlatform(), revision)) +if (revisionInfo.downloaded) return; let allRevisions = Downloader.downloadedRevisions(); -Downloader.downloadRevision(Downloader.currentPlatform(), revision, onProgress) +Downloader.downloadRevision(platform, revision, onProgress) // Remove previous chromium revisions. .then(() => Promise.all(allRevisions.map(({platform, revision}) => Downloader.removeRevision(platform, revision)))) - .catch(error => console.error('Download failed: ' + error.message)); + .catch(onError); + +function onError(error) { + console.error(`ERROR: Failed to download chromium r${revision}! +- Download chromium manually: + ${revisionInfo.url} +- Extract chromium into ${revisionInfo.folderPath} + * Chromium executable should be at ${revisionInfo.executablePath}`); +} let progressBar = null; function onProgress(bytesTotal, delta) { diff --git a/lib/Launcher.js b/lib/Launcher.js index bd269213..32c91016 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -72,7 +72,7 @@ class Launcher { if (typeof chromeExecutable !== 'string') { let chromiumRevision = require('../package.json').puppeteer.chromium_revision; let revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), chromiumRevision); - console.assert(revisionInfo, 'Chromium revision is not downloaded. Run npm install'); + console.assert(revisionInfo.downloaded, `Chromium revision is not downloaded. Run "npm install"`); chromeExecutable = revisionInfo.executablePath; } if (Array.isArray(options.args)) diff --git a/test/test.js b/test/test.js index 9f473a04..f44af2a3 100644 --- a/test/test.js +++ b/test/test.js @@ -59,7 +59,7 @@ else const Downloader = require('../utils/ChromiumDownloader'); const chromiumRevision = require('../package.json').puppeteer.chromium_revision; const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), chromiumRevision); - console.assert(revisionInfo, `Chromium r${chromiumRevision} is not downloaded. Run 'npm install' and try to re-run tests.`); + console.assert(revisionInfo.downloaded, `Chromium r${chromiumRevision} is not downloaded. Run 'npm install' and try to re-run tests.`); } let server; diff --git a/utils/ChromiumDownloader.js b/utils/ChromiumDownloader.js index 6653f63f..6ab8a3a1 100644 --- a/utils/ChromiumDownloader.js +++ b/utils/ChromiumDownloader.js @@ -129,13 +129,11 @@ module.exports = { /** * @param {string} platform * @param {string} revision - * @return {?{executablePath: string}} + * @return {!{folderPath: string, executablePath: string, downloaded: boolean, url: string}} */ revisionInfo: function(platform, revision) { console.assert(downloadURLs[platform], `Unsupported platform: ${platform}`); let folderPath = getFolderPath(platform, revision); - if (!fs.existsSync(folderPath)) - return null; let executablePath = ''; if (platform === 'mac') executablePath = path.join(folderPath, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium'); @@ -146,7 +144,10 @@ module.exports = { else throw 'Unsupported platfrom: ' + platfrom; return { - executablePath: executablePath + executablePath, + folderPath, + downloaded: fs.existsSync(folderPath), + url: util.format(downloadURLs[platform], revision) }; }, };