chrome.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright 2023 Google Inc.
  5. * SPDX-License-Identifier: Apache-2.0
  6. */
  7. var __importDefault = (this && this.__importDefault) || function (mod) {
  8. return (mod && mod.__esModule) ? mod : { "default": mod };
  9. };
  10. Object.defineProperty(exports, "__esModule", { value: true });
  11. exports.compareVersions = exports.resolveSystemExecutablePath = exports.resolveBuildId = exports.getLastKnownGoodReleaseForBuild = exports.getLastKnownGoodReleaseForMilestone = exports.getLastKnownGoodReleaseForChannel = exports.relativeExecutablePath = exports.resolveDownloadPath = exports.resolveDownloadUrl = void 0;
  12. const path_1 = __importDefault(require("path"));
  13. const semver_1 = __importDefault(require("semver"));
  14. const httpUtil_js_1 = require("../httpUtil.js");
  15. const types_js_1 = require("./types.js");
  16. function folder(platform) {
  17. switch (platform) {
  18. case types_js_1.BrowserPlatform.LINUX:
  19. return 'linux64';
  20. case types_js_1.BrowserPlatform.MAC_ARM:
  21. return 'mac-arm64';
  22. case types_js_1.BrowserPlatform.MAC:
  23. return 'mac-x64';
  24. case types_js_1.BrowserPlatform.WIN32:
  25. return 'win32';
  26. case types_js_1.BrowserPlatform.WIN64:
  27. return 'win64';
  28. }
  29. }
  30. function resolveDownloadUrl(platform, buildId, baseUrl = 'https://storage.googleapis.com/chrome-for-testing-public') {
  31. return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
  32. }
  33. exports.resolveDownloadUrl = resolveDownloadUrl;
  34. function resolveDownloadPath(platform, buildId) {
  35. return [buildId, folder(platform), `chrome-${folder(platform)}.zip`];
  36. }
  37. exports.resolveDownloadPath = resolveDownloadPath;
  38. function relativeExecutablePath(platform, _buildId) {
  39. switch (platform) {
  40. case types_js_1.BrowserPlatform.MAC:
  41. case types_js_1.BrowserPlatform.MAC_ARM:
  42. return path_1.default.join('chrome-' + folder(platform), 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing');
  43. case types_js_1.BrowserPlatform.LINUX:
  44. return path_1.default.join('chrome-linux64', 'chrome');
  45. case types_js_1.BrowserPlatform.WIN32:
  46. case types_js_1.BrowserPlatform.WIN64:
  47. return path_1.default.join('chrome-' + folder(platform), 'chrome.exe');
  48. }
  49. }
  50. exports.relativeExecutablePath = relativeExecutablePath;
  51. async function getLastKnownGoodReleaseForChannel(channel) {
  52. const data = (await (0, httpUtil_js_1.getJSON)(new URL('https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json')));
  53. for (const channel of Object.keys(data.channels)) {
  54. data.channels[channel.toLowerCase()] = data.channels[channel];
  55. delete data.channels[channel];
  56. }
  57. return data.channels[channel];
  58. }
  59. exports.getLastKnownGoodReleaseForChannel = getLastKnownGoodReleaseForChannel;
  60. async function getLastKnownGoodReleaseForMilestone(milestone) {
  61. const data = (await (0, httpUtil_js_1.getJSON)(new URL('https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone.json')));
  62. return data.milestones[milestone];
  63. }
  64. exports.getLastKnownGoodReleaseForMilestone = getLastKnownGoodReleaseForMilestone;
  65. async function getLastKnownGoodReleaseForBuild(
  66. /**
  67. * @example `112.0.23`,
  68. */
  69. buildPrefix) {
  70. const data = (await (0, httpUtil_js_1.getJSON)(new URL('https://googlechromelabs.github.io/chrome-for-testing/latest-patch-versions-per-build.json')));
  71. return data.builds[buildPrefix];
  72. }
  73. exports.getLastKnownGoodReleaseForBuild = getLastKnownGoodReleaseForBuild;
  74. async function resolveBuildId(channel) {
  75. if (Object.values(types_js_1.ChromeReleaseChannel).includes(channel)) {
  76. return (await getLastKnownGoodReleaseForChannel(channel)).version;
  77. }
  78. if (channel.match(/^\d+$/)) {
  79. // Potentially a milestone.
  80. return (await getLastKnownGoodReleaseForMilestone(channel))?.version;
  81. }
  82. if (channel.match(/^\d+\.\d+\.\d+$/)) {
  83. // Potentially a build prefix without the patch version.
  84. return (await getLastKnownGoodReleaseForBuild(channel))?.version;
  85. }
  86. return;
  87. }
  88. exports.resolveBuildId = resolveBuildId;
  89. function resolveSystemExecutablePath(platform, channel) {
  90. switch (platform) {
  91. case types_js_1.BrowserPlatform.WIN64:
  92. case types_js_1.BrowserPlatform.WIN32:
  93. switch (channel) {
  94. case types_js_1.ChromeReleaseChannel.STABLE:
  95. return `${process.env['PROGRAMFILES']}\\Google\\Chrome\\Application\\chrome.exe`;
  96. case types_js_1.ChromeReleaseChannel.BETA:
  97. return `${process.env['PROGRAMFILES']}\\Google\\Chrome Beta\\Application\\chrome.exe`;
  98. case types_js_1.ChromeReleaseChannel.CANARY:
  99. return `${process.env['PROGRAMFILES']}\\Google\\Chrome SxS\\Application\\chrome.exe`;
  100. case types_js_1.ChromeReleaseChannel.DEV:
  101. return `${process.env['PROGRAMFILES']}\\Google\\Chrome Dev\\Application\\chrome.exe`;
  102. }
  103. case types_js_1.BrowserPlatform.MAC_ARM:
  104. case types_js_1.BrowserPlatform.MAC:
  105. switch (channel) {
  106. case types_js_1.ChromeReleaseChannel.STABLE:
  107. return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
  108. case types_js_1.ChromeReleaseChannel.BETA:
  109. return '/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta';
  110. case types_js_1.ChromeReleaseChannel.CANARY:
  111. return '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary';
  112. case types_js_1.ChromeReleaseChannel.DEV:
  113. return '/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev';
  114. }
  115. case types_js_1.BrowserPlatform.LINUX:
  116. switch (channel) {
  117. case types_js_1.ChromeReleaseChannel.STABLE:
  118. return '/opt/google/chrome/chrome';
  119. case types_js_1.ChromeReleaseChannel.BETA:
  120. return '/opt/google/chrome-beta/chrome';
  121. case types_js_1.ChromeReleaseChannel.DEV:
  122. return '/opt/google/chrome-unstable/chrome';
  123. }
  124. }
  125. throw new Error(`Unable to detect browser executable path for '${channel}' on ${platform}.`);
  126. }
  127. exports.resolveSystemExecutablePath = resolveSystemExecutablePath;
  128. function compareVersions(a, b) {
  129. if (!semver_1.default.valid(a)) {
  130. throw new Error(`Version ${a} is not a valid semver version`);
  131. }
  132. if (!semver_1.default.valid(b)) {
  133. throw new Error(`Version ${b} is not a valid semver version`);
  134. }
  135. if (semver_1.default.gt(a, b)) {
  136. return 1;
  137. }
  138. else if (semver_1.default.lt(a, b)) {
  139. return -1;
  140. }
  141. else {
  142. return 0;
  143. }
  144. }
  145. exports.compareVersions = compareVersions;
  146. //# sourceMappingURL=chrome.js.map