fix(install): only install browsers needed by this revision (#2112)

This commit is contained in:
Pavel Feldman 2020-05-04 22:24:40 -07:00 committed by GitHub
parent 33ebe66ad4
commit d95891ebad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -63,7 +63,6 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
let downloadedBrowsers = (await fsReaddirAsync(browsersPath)).map(file => path.join(browsersPath, file)); let downloadedBrowsers = (await fsReaddirAsync(browsersPath)).map(file => path.join(browsersPath, file));
downloadedBrowsers = downloadedBrowsers.filter(file => browserPaths.isBrowserDirectory(file)); downloadedBrowsers = downloadedBrowsers.filter(file => browserPaths.isBrowserDirectory(file));
const directories = new Set<string>(downloadedBrowsers); const directories = new Set<string>(downloadedBrowsers);
directories.delete(path.join(browsersPath, '.links'));
for (const browser of allBrowsers) for (const browser of allBrowsers)
directories.delete(browserPaths.browserDirectory(browsersPath, browser)); directories.delete(browserPaths.browserDirectory(browsersPath, browser));
for (const directory of directories) { for (const directory of directories) {
@ -71,8 +70,9 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
await removeFolderAsync(directory).catch(e => {}); await removeFolderAsync(directory).catch(e => {});
} }
// 3. Install missing browsers. // 3. Install missing browsers for this package.
for (const browser of allBrowsers) { const myBrowsers = JSON.parse((await fsReadFileAsync(path.join(packagePath, 'browsers.json'))).toString())['browsers'];
for (const browser of myBrowsers) {
const browserPath = browserPaths.browserDirectory(browsersPath, browser); const browserPath = browserPaths.browserDirectory(browsersPath, browser);
if (await browserFetcher.downloadBrowserWithProgressBar(browserPath, browser)) if (await browserFetcher.downloadBrowserWithProgressBar(browserPath, browser))
await installBrowser(packagePath, browserPath, browser); await installBrowser(packagePath, browserPath, browser);