mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
refactor: make it easier to extend trimCache (#10202)
This commit is contained in:
parent
1ad32ec994
commit
9cba24a961
@ -301,44 +301,66 @@ export class PuppeteerNode extends Puppeteer {
|
|||||||
|
|
||||||
const product = this.configuration.defaultProduct!;
|
const product = this.configuration.defaultProduct!;
|
||||||
|
|
||||||
const chromeBuildId = await resolveBuildId(
|
const puppeteerBrowsers: Array<{
|
||||||
SupportedBrowser.CHROME,
|
product: Product;
|
||||||
platform,
|
browser: SupportedBrowser;
|
||||||
(product === 'chrome' ? this.configuration.browserRevision : null) ||
|
currentBuildId: string;
|
||||||
PUPPETEER_REVISIONS['chrome']
|
}> = [
|
||||||
|
{
|
||||||
|
product: 'chrome',
|
||||||
|
browser: SupportedBrowser.CHROME,
|
||||||
|
currentBuildId: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
product: 'firefox',
|
||||||
|
browser: SupportedBrowser.FIREFOX,
|
||||||
|
currentBuildId: '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// Resolve current buildIds.
|
||||||
|
for (const item of puppeteerBrowsers) {
|
||||||
|
item.currentBuildId = await resolveBuildId(
|
||||||
|
item.browser,
|
||||||
|
platform,
|
||||||
|
(product === item.product
|
||||||
|
? this.configuration.browserRevision
|
||||||
|
: null) || PUPPETEER_REVISIONS[item.product]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentBrowserBuilds = new Set(
|
||||||
|
puppeteerBrowsers.map(browser => {
|
||||||
|
return `${browser.browser}_${browser.currentBuildId}`;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const firefoxBuildId = await resolveBuildId(
|
const currentBrowsers = new Set(
|
||||||
SupportedBrowser.FIREFOX,
|
puppeteerBrowsers.map(browser => {
|
||||||
platform,
|
return browser.browser;
|
||||||
(product === 'firefox' ? this.configuration.browserRevision : null) ||
|
})
|
||||||
PUPPETEER_REVISIONS['firefox']
|
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const browser of installedBrowsers) {
|
for (const installedBrowser of installedBrowsers) {
|
||||||
|
// Don't uninstall browsers that are not managed by Puppeteer yet.
|
||||||
|
if (!currentBrowsers.has(installedBrowser.browser)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Keep the browser build used by the current Puppeteer installation.
|
||||||
if (
|
if (
|
||||||
browser.browser === SupportedBrowser.CHROME &&
|
currentBrowserBuilds.has(
|
||||||
browser.buildId !== chromeBuildId
|
`${installedBrowser.browser}_${installedBrowser.buildId}`
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
await uninstall({
|
continue;
|
||||||
browser: SupportedBrowser.CHROME,
|
|
||||||
platform,
|
|
||||||
cacheDir,
|
|
||||||
buildId: chromeBuildId,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
await uninstall({
|
||||||
browser.browser === SupportedBrowser.FIREFOX &&
|
browser: SupportedBrowser.CHROME,
|
||||||
browser.buildId !== firefoxBuildId
|
platform,
|
||||||
) {
|
cacheDir,
|
||||||
await uninstall({
|
buildId: installedBrowser.buildId,
|
||||||
browser: SupportedBrowser.FIREFOX,
|
});
|
||||||
platform,
|
|
||||||
cacheDir,
|
|
||||||
buildId: firefoxBuildId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user