mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-27 11:31:45 -04:00
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:
5
.changeset/five-ties-add.md
Normal file
5
.changeset/five-ties-add.md
Normal 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.
|
||||
@@ -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 {
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user