The Node.js® Website

fix: Wrong bitness information (#6485)

* fix: x86 option in Linux

* fix: set default bitness as 64

* fix: more user agent checks for x64

* refactor: long condition group moved into the regex

* refactor: default bitness values and docs

authored by Caner Akdas and committed by GitHub f7c66135 9f0b6a5b

Changed files
+23 -6
hooks
react-client
util
+6 -4
hooks/react-client/useDetectOS.ts
··· 25 25 ([bitness, architecture]) => { 26 26 const userAgent: string | undefined = 27 27 (typeof navigator === 'object' && navigator.userAgent) || ''; 28 - const defaultBitness: number = 86; // Default bitness if unable to determine 28 + // Default bitness if unable to determine 29 + const defaultBitness: number = 86; 30 + // Regex to detect 64-bit architecture in user agent 31 + const bitnessRegex = /WOW64|Win64|x86_64|x86-64|x64_64|x64;|AMD64/; 32 + 29 33 setUserOSState({ 30 34 os: detectOS(), 31 35 bitness: 32 - bitness === '64' || 33 - userAgent?.includes('WOW64') || 34 - userAgent?.includes('Win64') 36 + bitness === '64' || bitnessRegex.test(userAgent) 35 37 ? 64 36 38 : defaultBitness, 37 39 architecture: architecture ? architecture : '',
+17 -2
util/getNodeDownloadUrl.ts
··· 15 15 16 16 switch (os) { 17 17 case 'MAC': 18 + // Prepares a downloadable Node.js installer link for the x64, ARM64 platforms 18 19 if (kind === 'installer') { 19 20 return `${baseURL}/node-${versionWithPrefix}.pkg`; 20 21 } 21 22 23 + // Prepares a downloadable Node.js link for the ARM64 platform 22 24 if (typeof bitness === 'string') { 23 25 return `${baseURL}/node-${versionWithPrefix}-darwin-${bitness}.tar.gz`; 24 26 } 25 27 26 - return `${baseURL}/node-${versionWithPrefix}-darwin-x${bitness}.tar.gz`; 28 + // Prepares a downloadable Node.js link for the x64 platform. 29 + // Since the x86 platform is not officially supported, returns the x64 30 + // link as the default value. 31 + return `${baseURL}/node-${versionWithPrefix}-darwin-x64.tar.gz`; 27 32 case 'WIN': { 28 33 if (kind === 'installer') { 34 + // Prepares a downloadable Node.js installer link for the ARM platforms 29 35 if (typeof bitness === 'string') { 30 36 return `${baseURL}/node-${versionWithPrefix}-${bitness}.msi`; 31 37 } 32 38 39 + // Prepares a downloadable Node.js installer link for the x64 and x86 platforms 33 40 return `${baseURL}/node-${versionWithPrefix}-x${bitness}.msi`; 34 41 } 35 42 43 + // Prepares a downloadable Node.js link for the ARM64 platform 36 44 if (typeof bitness === 'string') { 37 45 return `${baseURL}/node-${versionWithPrefix}-win-${bitness}.zip`; 38 46 } 39 47 48 + // Prepares a downloadable Node.js link for the x64 and x86 platforms 40 49 return `${baseURL}/node-${versionWithPrefix}-win-x${bitness}.zip`; 41 50 } 42 51 case 'LINUX': 52 + // Prepares a downloadable Node.js link for the ARM platforms such as 53 + // ARMv7 and ARMv8 43 54 if (typeof bitness === 'string') { 44 55 return `${baseURL}/node-${versionWithPrefix}-linux-${bitness}.tar.xz`; 45 56 } 46 57 47 - return `${baseURL}/node-${versionWithPrefix}-linux-x${bitness}.tar.xz`; 58 + // Prepares a downloadable Node.js link for the x64 platform. 59 + // Since the x86 platform is not officially supported, returns the x64 60 + // link as the default value. 61 + return `${baseURL}/node-${versionWithPrefix}-linux-x64.tar.xz`; 48 62 default: 63 + // Prepares a downloadable Node.js source code link 49 64 return `${baseURL}/node-${versionWithPrefix}.tar.gz`; 50 65 } 51 66 };