Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use simpler env vars for win32 #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*! arch. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
var cp = require('child_process')
var fs = require('fs')
var path = require('path')

/**
* Returns the operating system's CPU architecture. This is different than
Expand Down Expand Up @@ -29,25 +27,16 @@ module.exports = function arch () {
}

/**
* On Windows, the most reliable way to detect a 64-bit OS from within a 32-bit
* app is based on the presence of a WOW64 file: %SystemRoot%\SysNative.
* See: https://twitter.com/feross/status/776949077208510464
* On Windows, use the standard environment variables:
* "64-bit process: PROCESSOR_ARCHITECTURE=AMD64/IA64/ARM64"
* "32-bit process: PROCESSOR_ARCHITECTURE=x86, PROCESSOR_ARCHITEW6432=%PROCESSOR_ARCHITECTURE%"
* https://learn.microsoft.com/en-gb/windows/win32/winprog64/wow64-implementation-details#environment-variables
*/
if (process.platform === 'win32') {
var useEnv = false
try {
useEnv = !!(process.env.SYSTEMROOT && fs.statSync(process.env.SYSTEMROOT))
} catch (err) {}
var arch = process.env.PROCESSOR_ARCHITEW6432 || process.env.PROCESSOR_ARCHITECTURE
if (arch === 'ARM64') return 'arm64'

var sysRoot = useEnv ? process.env.SYSTEMROOT : 'C:\\Windows'

// If %SystemRoot%\SysNative exists, we are in a WOW64 FS Redirected application.
var isWOW64 = false
try {
isWOW64 = !!fs.statSync(path.join(sysRoot, 'sysnative'))
} catch (err) {}

return isWOW64 ? 'x64' : 'x86'
return ['AMD64', 'IA64'].includes(arch) ? 'x64' : 'x86'
}

/**
Expand Down