arch.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getArtifactArchName = exports.defaultArchFromString = exports.archFromString = exports.getArchSuffix = exports.getArchCliNames = exports.toLinuxArchString = exports.Arch = void 0;
  4. var Arch;
  5. (function (Arch) {
  6. Arch[Arch["ia32"] = 0] = "ia32";
  7. Arch[Arch["x64"] = 1] = "x64";
  8. Arch[Arch["armv7l"] = 2] = "armv7l";
  9. Arch[Arch["arm64"] = 3] = "arm64";
  10. Arch[Arch["universal"] = 4] = "universal";
  11. })(Arch = exports.Arch || (exports.Arch = {}));
  12. function toLinuxArchString(arch, targetName) {
  13. switch (arch) {
  14. case Arch.x64:
  15. return targetName === "flatpak" ? "x86_64" : "amd64";
  16. case Arch.ia32:
  17. return targetName === "pacman" ? "i686" : "i386";
  18. case Arch.armv7l:
  19. return targetName === "snap" || targetName === "deb" ? "armhf" : targetName === "flatpak" ? "arm" : "armv7l";
  20. case Arch.arm64:
  21. return targetName === "pacman" || targetName === "rpm" || targetName === "flatpak" ? "aarch64" : "arm64";
  22. default:
  23. throw new Error(`Unsupported arch ${arch}`);
  24. }
  25. }
  26. exports.toLinuxArchString = toLinuxArchString;
  27. function getArchCliNames() {
  28. return [Arch[Arch.ia32], Arch[Arch.x64], Arch[Arch.armv7l], Arch[Arch.arm64]];
  29. }
  30. exports.getArchCliNames = getArchCliNames;
  31. function getArchSuffix(arch, defaultArch) {
  32. return arch === defaultArchFromString(defaultArch) ? "" : `-${Arch[arch]}`;
  33. }
  34. exports.getArchSuffix = getArchSuffix;
  35. function archFromString(name) {
  36. switch (name) {
  37. case "x64":
  38. return Arch.x64;
  39. case "ia32":
  40. return Arch.ia32;
  41. case "arm64":
  42. return Arch.arm64;
  43. case "arm":
  44. case "armv7l":
  45. return Arch.armv7l;
  46. case "universal":
  47. return Arch.universal;
  48. default:
  49. throw new Error(`Unsupported arch ${name}`);
  50. }
  51. }
  52. exports.archFromString = archFromString;
  53. function defaultArchFromString(name) {
  54. return name ? archFromString(name) : Arch.x64;
  55. }
  56. exports.defaultArchFromString = defaultArchFromString;
  57. function getArtifactArchName(arch, ext) {
  58. let archName = Arch[arch];
  59. const isAppImage = ext === "AppImage" || ext === "appimage";
  60. if (arch === Arch.x64) {
  61. if (isAppImage || ext === "rpm" || ext === "flatpak") {
  62. archName = "x86_64";
  63. }
  64. else if (ext === "deb" || ext === "snap") {
  65. archName = "amd64";
  66. }
  67. }
  68. else if (arch === Arch.ia32) {
  69. if (ext === "deb" || isAppImage || ext === "snap" || ext === "flatpak") {
  70. archName = "i386";
  71. }
  72. else if (ext === "pacman" || ext === "rpm") {
  73. archName = "i686";
  74. }
  75. }
  76. else if (arch === Arch.armv7l) {
  77. if (ext === "snap") {
  78. archName = "armhf";
  79. }
  80. else if (ext === "flatpak") {
  81. archName = "arm";
  82. }
  83. }
  84. else if (arch === Arch.arm64) {
  85. if (ext === "pacman" || ext === "rpm" || ext === "flatpak") {
  86. archName = "aarch64";
  87. }
  88. }
  89. return archName;
  90. }
  91. exports.getArtifactArchName = getArtifactArchName;
  92. //# sourceMappingURL=arch.js.map