Skip to content
Open
Show file tree
Hide file tree
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
32 changes: 31 additions & 1 deletion browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,45 @@ module.exports = function arch () {
return 'x64'
}

if ([
'ARM64',
'AArch64'
].some(function (str) {
return userAgent.indexOf(str) > -1
})) {
return 'arm64'
}

/**
* Platform strings that indicate a 64-bit OS.
* See: http://stackoverflow.com/a/19883965/292185
*/
var platform = navigator.platform
if (platform === 'MacIntel' || platform === 'Linux x86_64') {
if (platform === 'Linux x86_64' || platform === 'Linux x86_64 X11') {
return 'x64'
}

if (platform === 'Linux aarch64' || platform === 'Linux armv8l') {
return 'arm64'
}

/**
*
* Detect if the browser is running on an Mac ARM64 architecture.
* See: https://stackoverflow.com/a/65412357
*/
if (platform === 'MacIntel') {
var canvas = OffscreenCanvas(1, 1);
var w = canvas.getContext("webgl");
var d = w.getExtension('WEBGL_debug_renderer_info');
var g = d && w.getParameter(d.UNMASKED_RENDERER_WEBGL) || "";
if (g.match(/Apple/) && !g.match(/Apple GPU/)) {
return 'arm64'
} else {
return 'x64'
}
}

/**
* CPU class strings that indicate a 64-bit OS.
* See: http://stackoverflow.com/a/6267019/292185
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ module.exports = function arch () {
* See: https://twitter.com/feross/status/776949077208510464
*/
if (process.platform === 'win32') {
if (process.arch === 'arm64') {
return 'arm64'
}

var useEnv = false
try {
useEnv = !!(process.env.SYSTEMROOT && fs.statSync(process.env.SYSTEMROOT))
Expand All @@ -54,6 +58,10 @@ module.exports = function arch () {
* On Linux, use the `getconf` command to get the architecture.
*/
if (process.platform === 'linux') {
if (process.arch === 'arm64') {
return 'arm64'
}

var output = cp.execSync('getconf LONG_BIT', { encoding: 'utf8' })
return output === '64\n' ? 'x64' : 'x86'
}
Expand Down