You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*! arch. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  2. var cp = require('child_process')
  3. var fs = require('fs')
  4. var path = require('path')
  5. /**
  6. * Returns the operating system's CPU architecture. This is different than
  7. * `process.arch` or `os.arch()` which returns the architecture the Node.js (or
  8. * Electron) binary was compiled for.
  9. */
  10. module.exports = function arch () {
  11. /**
  12. * The running binary is 64-bit, so the OS is clearly 64-bit.
  13. */
  14. if (process.arch === 'x64') {
  15. return 'x64'
  16. }
  17. /**
  18. * All recent versions of Mac OS are 64-bit.
  19. */
  20. if (process.platform === 'darwin') {
  21. return 'x64'
  22. }
  23. /**
  24. * On Windows, the most reliable way to detect a 64-bit OS from within a 32-bit
  25. * app is based on the presence of a WOW64 file: %SystemRoot%\SysNative.
  26. * See: https://twitter.com/feross/status/776949077208510464
  27. */
  28. if (process.platform === 'win32') {
  29. var useEnv = false
  30. try {
  31. useEnv = !!(process.env.SYSTEMROOT && fs.statSync(process.env.SYSTEMROOT))
  32. } catch (err) {}
  33. var sysRoot = useEnv ? process.env.SYSTEMROOT : 'C:\\Windows'
  34. // If %SystemRoot%\SysNative exists, we are in a WOW64 FS Redirected application.
  35. var isWOW64 = false
  36. try {
  37. isWOW64 = !!fs.statSync(path.join(sysRoot, 'sysnative'))
  38. } catch (err) {}
  39. return isWOW64 ? 'x64' : 'x86'
  40. }
  41. /**
  42. * On Linux, use the `getconf` command to get the architecture.
  43. */
  44. if (process.platform === 'linux') {
  45. var output = cp.execSync('getconf LONG_BIT', { encoding: 'utf8' })
  46. return output === '64\n' ? 'x64' : 'x86'
  47. }
  48. /**
  49. * If none of the above, assume the architecture is 32-bit.
  50. */
  51. return 'x86'
  52. }