chromium.ts (2419B)
1 /** 2 * @license 3 * Copyright 2023 Google Inc. 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 import path from 'node:path'; 8 9 import {getText} from '../httpUtil.js'; 10 11 import {BrowserPlatform} from './types.js'; 12 13 function archive(platform: BrowserPlatform, buildId: string): string { 14 switch (platform) { 15 case BrowserPlatform.LINUX_ARM: 16 case BrowserPlatform.LINUX: 17 return 'chrome-linux'; 18 case BrowserPlatform.MAC_ARM: 19 case BrowserPlatform.MAC: 20 return 'chrome-mac'; 21 case BrowserPlatform.WIN32: 22 case BrowserPlatform.WIN64: 23 // Windows archive name changed at r591479. 24 return parseInt(buildId, 10) > 591479 ? 'chrome-win' : 'chrome-win32'; 25 } 26 } 27 28 function folder(platform: BrowserPlatform): string { 29 switch (platform) { 30 case BrowserPlatform.LINUX: 31 return 'Linux_x64'; 32 case BrowserPlatform.MAC_ARM: 33 return 'Mac_Arm'; 34 case BrowserPlatform.LINUX_ARM: 35 case BrowserPlatform.MAC: 36 return 'Mac'; 37 case BrowserPlatform.WIN32: 38 return 'Win'; 39 case BrowserPlatform.WIN64: 40 return 'Win_x64'; 41 } 42 } 43 44 export function resolveDownloadUrl( 45 platform: BrowserPlatform, 46 buildId: string, 47 baseUrl = 'https://storage.googleapis.com/chromium-browser-snapshots', 48 ): string { 49 return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`; 50 } 51 52 export function resolveDownloadPath( 53 platform: BrowserPlatform, 54 buildId: string, 55 ): string[] { 56 return [folder(platform), buildId, `${archive(platform, buildId)}.zip`]; 57 } 58 59 export function relativeExecutablePath( 60 platform: BrowserPlatform, 61 _buildId: string, 62 ): string { 63 switch (platform) { 64 case BrowserPlatform.MAC: 65 case BrowserPlatform.MAC_ARM: 66 return path.join( 67 'chrome-mac', 68 'Chromium.app', 69 'Contents', 70 'MacOS', 71 'Chromium', 72 ); 73 case BrowserPlatform.LINUX_ARM: 74 case BrowserPlatform.LINUX: 75 return path.join('chrome-linux', 'chrome'); 76 case BrowserPlatform.WIN32: 77 case BrowserPlatform.WIN64: 78 return path.join('chrome-win', 'chrome.exe'); 79 } 80 } 81 export async function resolveBuildId( 82 platform: BrowserPlatform, 83 ): Promise<string> { 84 return await getText( 85 new URL( 86 `https://storage.googleapis.com/chromium-browser-snapshots/${folder( 87 platform, 88 )}/LAST_CHANGE`, 89 ), 90 ); 91 } 92 93 export function compareVersions(a: string, b: string): number { 94 return Number(a) - Number(b); 95 }