fix: node<16 download fail on arm chips on macos (#5239)

* fix(node.fetcher): node < 16 download fail on apple silicon

Add a check for macos apple silicon and required node version < 16.
In such case, download x64 binary.
Because arm build does not exist.
Previous behaviour:
Try to download non existing arm build and fail with 404.

NO breaking change
fixes #4489

* refactor(node.fetcher): move code to normalizeArch
This commit is contained in:
Ambar Mutha
2022-08-20 18:58:24 +05:30
committed by GitHub
parent cccaa0208f
commit 1c7b439bbe
5 changed files with 41 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/node.fetcher": patch
---
For node version < 16, install x64 build on darwin arm as arm build is not available.

View File

@@ -7,7 +7,7 @@ export function getNodeTarball (
processArch: string
) {
const platform = processPlatform === 'win32' ? 'win' : processPlatform
const arch = normalizeArch(processPlatform, processArch)
const arch = normalizeArch(processPlatform, processArch, nodeVersion)
const extension = platform === 'win' ? 'zip' : 'tar.gz'
const pkgName = `node-v${nodeVersion}-${platform}-${arch}`
return {

View File

@@ -1,4 +1,10 @@
export default function getNormalizedArch (platform: string, arch: string) {
export default function getNormalizedArch (platform: string, arch: string, nodeVersion?: string) {
if (nodeVersion) {
const nodeMajorVersion = +nodeVersion.split('.')[0]
if ((platform === 'darwin' && arch === 'arm64' && (nodeMajorVersion < 16))) {
return 'x64'
}
}
if (platform === 'win32' && arch === 'ia32') {
return 'x86'
}

View File

@@ -31,6 +31,26 @@ test.each([
tarball: 'https://nodejs.org/download/release/v16.0.0/node-v16.0.0-linux-x64.tar.gz',
},
],
[
'15.14.0',
'https://nodejs.org/download/release/',
'darwin',
'arm64',
{
pkgName: 'node-v15.14.0-darwin-x64',
tarball: 'https://nodejs.org/download/release/v15.14.0/node-v15.14.0-darwin-x64.tar.gz',
},
],
[
'16.0.0',
'https://nodejs.org/download/release/',
'darwin',
'arm64',
{
pkgName: 'node-v16.0.0-darwin-arm64',
tarball: 'https://nodejs.org/download/release/v16.0.0/node-v16.0.0-darwin-arm64.tar.gz',
},
],
])('getNodeTarball', (version, nodeMirrorBaseUrl, platform, arch, tarball) => {
expect(getNodeTarball(version, nodeMirrorBaseUrl, platform, arch)).toStrictEqual(tarball)
})

View File

@@ -7,3 +7,11 @@ test.each([
])('normalizedArch(%s, %s)', (platform, arch, normalizedArch) => {
expect(normalizeArch(platform, arch)).toBe(normalizedArch)
})
// macos apple silicon
test.each([
['darwin', 'arm64', '14.20.0', 'x64'],
['darwin', 'arm64', '16.17.0', 'arm64'],
])('normalizedArch(%s, %s)', (platform, arch, nodeVersion, normalizedArch) => {
expect(normalizeArch(platform, arch, nodeVersion)).toBe(normalizedArch)
})