[test] Update Puppeteer to v22.3.0

Drive-by: remove @puppeteer/replay that is not used in tests
Bug: none
Change-Id: I512794442c43cddd8a40b7816d3fc31f398251d2
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5318365
Auto-Submit: Alex Rudenko <[email protected]>
Reviewed-by: Simon Zünd <[email protected]>
Commit-Queue: Simon Zünd <[email protected]>
diff --git a/node_modules/@puppeteer/browsers/lib/esm/Cache.js b/node_modules/@puppeteer/browsers/lib/esm/Cache.js
index 0af8720..bacf330 100644
--- a/node_modules/@puppeteer/browsers/lib/esm/Cache.js
+++ b/node_modules/@puppeteer/browsers/lib/esm/Cache.js
@@ -6,8 +6,10 @@
 import fs from 'fs';
 import os from 'os';
 import path from 'path';
-import { Browser, executablePathByBrowser, } from './browser-data/browser-data.js';
+import debug from 'debug';
+import { Browser, executablePathByBrowser, getVersionComparator, } from './browser-data/browser-data.js';
 import { detectBrowserPlatform } from './detectPlatform.js';
+const debugCache = debug('puppeteer:browsers:cache');
 /**
  * @public
  */
@@ -38,6 +40,12 @@
     get path() {
         return this.#cache.installationDir(this.browser, this.platform, this.buildId);
     }
+    readMetadata() {
+        return this.#cache.readMetadata(this.browser);
+    }
+    writeMetadata(metadata) {
+        this.#cache.writeMetadata(this.browser, metadata);
+    }
 }
 /**
  * The cache used by Puppeteer relies on the following structure:
@@ -67,6 +75,35 @@
     browserRoot(browser) {
         return path.join(this.#rootDir, browser);
     }
+    metadataFile(browser) {
+        return path.join(this.browserRoot(browser), '.metadata');
+    }
+    readMetadata(browser) {
+        const metatadaPath = this.metadataFile(browser);
+        if (!fs.existsSync(metatadaPath)) {
+            return { aliases: {} };
+        }
+        // TODO: add type-safe parsing.
+        const data = JSON.parse(fs.readFileSync(metatadaPath, 'utf8'));
+        if (typeof data !== 'object') {
+            throw new Error('.metadata is not an object');
+        }
+        return data;
+    }
+    writeMetadata(browser, metadata) {
+        const metatadaPath = this.metadataFile(browser);
+        fs.mkdirSync(path.dirname(metatadaPath), { recursive: true });
+        fs.writeFileSync(metatadaPath, JSON.stringify(metadata, null, 2));
+    }
+    resolveAlias(browser, alias) {
+        const metadata = this.readMetadata(browser);
+        if (alias === 'latest') {
+            return Object.values(metadata.aliases || {})
+                .sort(getVersionComparator(browser))
+                .at(-1);
+        }
+        return metadata.aliases[alias];
+    }
     installationDir(browser, platform, buildId) {
         return path.join(this.browserRoot(browser), `${platform}-${buildId}`);
     }
@@ -79,6 +116,12 @@
         });
     }
     uninstall(browser, platform, buildId) {
+        const metadata = this.readMetadata(browser);
+        for (const alias of Object.keys(metadata.aliases)) {
+            if (metadata.aliases[alias] === buildId) {
+                delete metadata.aliases[alias];
+            }
+        }
         fs.rmSync(this.installationDir(browser, platform, buildId), {
             force: true,
             recursive: true,
@@ -114,6 +157,13 @@
         if (!options.platform) {
             throw new Error(`Cannot download a binary for the provided platform: ${os.platform()} (${os.arch()})`);
         }
+        try {
+            options.buildId =
+                this.resolveAlias(options.browser, options.buildId) ?? options.buildId;
+        }
+        catch {
+            debugCache('could not read .metadata file for the browser');
+        }
         const installationDir = this.installationDir(options.browser, options.platform, options.buildId);
         return path.join(installationDir, executablePathByBrowser[options.browser](options.platform, options.buildId));
     }