Skip to content

Commit

Permalink
fix(node.fetcher): node < 16 download fail on apple silicon
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ambar-arkin committed Aug 19, 2022
1 parent cccaa02 commit 3a84bae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
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.
9 changes: 8 additions & 1 deletion packages/node.fetcher/src/getNodeTarball.ts
@@ -1,3 +1,8 @@
/*
* Copyright 2022 VMware, Inc.
* SPDX-License-Identifier: MIT
*/

import normalizeArch from './normalizeArch'

export function getNodeTarball (
Expand All @@ -8,8 +13,10 @@ export function getNodeTarball (
) {
const platform = processPlatform === 'win32' ? 'win' : processPlatform
const arch = normalizeArch(processPlatform, processArch)
const nodeMajorVersion = +nodeVersion.split('.')[0]
const nodeBinaryArch = (platform === 'darwin' && arch === 'arm64' && (nodeMajorVersion < 16)) ? 'x64' : arch
const extension = platform === 'win' ? 'zip' : 'tar.gz'
const pkgName = `node-v${nodeVersion}-${platform}-${arch}`
const pkgName = `node-v${nodeVersion}-${platform}-${nodeBinaryArch}`
return {
pkgName,
tarball: `${nodeMirror}v${nodeVersion}/${pkgName}.${extension}`,
Expand Down
25 changes: 25 additions & 0 deletions packages/node.fetcher/test/getNodeTarball.test.ts
@@ -1,3 +1,8 @@
/*
* Copyright 2022 VMware, Inc.
* SPDX-License-Identifier: MIT
*/

import { getNodeTarball } from '../lib/getNodeTarball'

test.each([
Expand Down Expand Up @@ -31,6 +36,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)
})

0 comments on commit 3a84bae

Please sign in to comment.