hostPlatform.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isOfficiallySupportedPlatform = exports.hostPlatform = void 0;
  6. var _os = _interopRequireDefault(require("os"));
  7. var _linuxUtils = require("./linuxUtils");
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /**
  10. * Copyright (c) Microsoft Corporation.
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. function calculatePlatform() {
  25. const platform = _os.default.platform();
  26. if (platform === 'darwin') {
  27. const ver = _os.default.release().split('.').map(a => parseInt(a, 10));
  28. let macVersion = '';
  29. if (ver[0] < 18) {
  30. // Everything before 10.14 is considered 10.13.
  31. macVersion = 'mac10.13';
  32. } else if (ver[0] === 18) {
  33. macVersion = 'mac10.14';
  34. } else if (ver[0] === 19) {
  35. macVersion = 'mac10.15';
  36. } else {
  37. // ver[0] >= 20
  38. const LAST_STABLE_MAC_MAJOR_VERSION = 13;
  39. // Best-effort support for MacOS beta versions.
  40. macVersion = 'mac' + Math.min(ver[0] - 9, LAST_STABLE_MAC_MAJOR_VERSION);
  41. // BigSur is the first version that might run on Apple Silicon.
  42. if (_os.default.cpus().some(cpu => cpu.model.includes('Apple'))) macVersion += '-arm64';
  43. }
  44. return {
  45. hostPlatform: macVersion,
  46. isOfficiallySupportedPlatform: true
  47. };
  48. }
  49. if (platform === 'linux') {
  50. if (!['x64', 'arm64'].includes(_os.default.arch())) return {
  51. hostPlatform: '<unknown>',
  52. isOfficiallySupportedPlatform: false
  53. };
  54. const archSuffix = '-' + _os.default.arch();
  55. const distroInfo = (0, _linuxUtils.getLinuxDistributionInfoSync)();
  56. // Pop!_OS is ubuntu-based and has the same versions.
  57. // KDE Neon is ubuntu-based and has the same versions.
  58. // TUXEDO OS is ubuntu-based and has the same versions.
  59. if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'ubuntu' || (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'pop' || (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'neon' || (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'tuxedo') {
  60. const isOfficiallySupportedPlatform = (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'ubuntu';
  61. if (parseInt(distroInfo.version, 10) <= 19) return {
  62. hostPlatform: 'ubuntu18.04' + archSuffix,
  63. isOfficiallySupportedPlatform
  64. };
  65. if (parseInt(distroInfo.version, 10) <= 21) return {
  66. hostPlatform: 'ubuntu20.04' + archSuffix,
  67. isOfficiallySupportedPlatform
  68. };
  69. return {
  70. hostPlatform: 'ubuntu22.04' + archSuffix,
  71. isOfficiallySupportedPlatform
  72. };
  73. }
  74. // Linux Mint is ubuntu-based but does not have the same versions
  75. if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'linuxmint') {
  76. if (parseInt(distroInfo.version, 10) <= 20) return {
  77. hostPlatform: 'ubuntu20.04' + archSuffix,
  78. isOfficiallySupportedPlatform: false
  79. };
  80. return {
  81. hostPlatform: 'ubuntu22.04' + archSuffix,
  82. isOfficiallySupportedPlatform: false
  83. };
  84. }
  85. if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'debian' || (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'raspbian') {
  86. const isOfficiallySupportedPlatform = (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'debian';
  87. if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.version) === '11') return {
  88. hostPlatform: 'debian11' + archSuffix,
  89. isOfficiallySupportedPlatform
  90. };
  91. if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.version) === '12') return {
  92. hostPlatform: 'debian12' + archSuffix,
  93. isOfficiallySupportedPlatform
  94. };
  95. // use most recent supported release for 'debian testing' and 'unstable'.
  96. // they never include a numeric version entry in /etc/os-release.
  97. if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.version) === '') return {
  98. hostPlatform: 'debian12' + archSuffix,
  99. isOfficiallySupportedPlatform
  100. };
  101. }
  102. return {
  103. hostPlatform: 'ubuntu20.04' + archSuffix,
  104. isOfficiallySupportedPlatform: false
  105. };
  106. }
  107. if (platform === 'win32') return {
  108. hostPlatform: 'win64',
  109. isOfficiallySupportedPlatform: true
  110. };
  111. return {
  112. hostPlatform: '<unknown>',
  113. isOfficiallySupportedPlatform: false
  114. };
  115. }
  116. const {
  117. hostPlatform,
  118. isOfficiallySupportedPlatform
  119. } = calculatePlatform();
  120. exports.isOfficiallySupportedPlatform = isOfficiallySupportedPlatform;
  121. exports.hostPlatform = hostPlatform;