Skip to content

Commit

Permalink
feat: use simpler env vars for win32
Browse files Browse the repository at this point in the history
Just use environment variables `PROCESSOR_ARCHITEW6432`/`PROCESSOR_ARCHITECTURE` on win32 instead of checking paths. Closes feross#26.
  • Loading branch information
CanadaHonk committed Feb 13, 2024
1 parent af5b7e1 commit 03c91e4
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,14 @@ 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 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'
var arch = process.env.PROCESSOR_ARCHITEW6432 || process.env.PROCESSOR_ARCHITECTURE
return ['AMD64', 'IA64', 'ARM64'].includes(arch) ? 'x64' : 'x86'
}

/**
Expand Down

0 comments on commit 03c91e4

Please sign in to comment.