Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/five-ties-add.md
@@ -0,0 +1,5 @@
---
"@pnpm/node.fetcher": patch
---

For node version < 16, install x64 build on darwin arm as arm build is not available.
2 changes: 1 addition & 1 deletion packages/node.fetcher/src/getNodeTarball.ts
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion packages/node.fetcher/src/normalizeArch.ts
@@ -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'
}
Expand Down
20 changes: 20 additions & 0 deletions packages/node.fetcher/test/getNodeTarball.test.ts
Expand Up @@ -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)
})
8 changes: 8 additions & 0 deletions packages/node.fetcher/test/normalizeArch.test.ts
Expand Up @@ -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)
})