platform.js 964 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2013 Lovell Fuller and others.
  2. // SPDX-License-Identifier: Apache-2.0
  3. 'use strict';
  4. const detectLibc = require('detect-libc');
  5. const env = process.env;
  6. module.exports = function () {
  7. const arch = env.npm_config_arch || process.arch;
  8. const platform = env.npm_config_platform || process.platform;
  9. const libc = process.env.npm_config_libc ||
  10. /* istanbul ignore next */
  11. (detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '');
  12. const libcId = platform !== 'linux' || libc === detectLibc.GLIBC ? '' : libc;
  13. const platformId = [`${platform}${libcId}`];
  14. if (arch === 'arm') {
  15. const fallback = process.versions.electron ? '7' : '6';
  16. platformId.push(`armv${env.npm_config_arm_version || process.config.variables.arm_version || fallback}`);
  17. } else if (arch === 'arm64') {
  18. platformId.push(`arm64v${env.npm_config_arm_version || '8'}`);
  19. } else {
  20. platformId.push(arch);
  21. }
  22. return platformId.join('-');
  23. };