fix(env): installing Node.js on Raspberry Pi 4 (#4008)

close #4007
This commit is contained in:
Zoltan Kochan
2021-11-19 18:36:43 +02:00
committed by GitHub
parent 12ee3c144e
commit d4d7c4aee2
4 changed files with 26 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-env": patch
"pnpm": patch
---
`pnpm env use` should download the right Node.js tarball on Raspberry Pi [#4007](https://github.com/pnpm/pnpm/issues/4007).

View File

@@ -11,6 +11,7 @@ import renameOverwrite from 'rename-overwrite'
import tempy from 'tempy'
import loadJsonFile from 'load-json-file'
import writeJsonFile from 'write-json-file'
import normalizeArch from './normalizeArch'
export type NvmNodeCommandOptions = Pick<Config,
| 'bin'
@@ -116,7 +117,7 @@ async function downloadAndUnpackZip (
function getNodeJSTarball (nodeVersion: string, releaseDir: string) {
const platform = process.platform === 'win32' ? 'win' : process.platform
const arch = platform === 'win' && process.arch === 'ia32' ? 'x86' : process.arch
const arch = normalizeArch(process.platform, process.arch)
const extension = platform === 'win' ? 'zip' : 'tar.gz'
const pkgName = `node-v${nodeVersion}-${platform}-${arch}`
return {

View File

@@ -0,0 +1,9 @@
export default function getNormalizedArch (platform: string, arch: string) {
if (platform === 'win32' && arch === 'ia32') {
return 'x86'
}
if (arch === 'arm') {
return 'armv7l'
}
return arch
}

View File

@@ -0,0 +1,9 @@
import normalizeArch from '@pnpm/plugin-commands-env/lib/normalizeArch'
test.each([
['win32', 'ia32', 'x86'],
['linux', 'arm', 'armv7l'], // Raspberry Pi 4
['linux', 'x64', 'x64'],
])('normalizedArch(%s, %s)', (platform, arch, normalizedArch) => {
expect(normalizeArch(platform, arch)).toBe(normalizedArch)
})