fix(env): throw an error on a system that uses MUSL libc (#4958)

This commit is contained in:
Zoltan Kochan
2022-06-30 16:11:01 +03:00
committed by GitHub
parent 0cd8a962b4
commit 2105735a0c
6 changed files with 40 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/node.fetcher": patch
"pnpm": patch
---
`pnpm env use` should throw an error on a system that use the MUSL libc.

View File

@@ -36,10 +36,12 @@
"homepage": "https://github.com/pnpm/pnpm/blob/main/packages/node.fetcher#readme",
"dependencies": {
"@pnpm/create-cafs-store": "workspace:2.0.2",
"@pnpm/fetching-types": "workspace:3.0.0",
"@pnpm/error": "workspace:3.0.1",
"@pnpm/fetcher-base": "workspace:13.0.1",
"@pnpm/fetching-types": "workspace:3.0.0",
"@pnpm/tarball-fetcher": "workspace:10.0.8",
"adm-zip": "^0.5.5",
"detect-libc": "^2.0.1",
"rename-overwrite": "^4.0.2",
"tempy": "^1.0.0"
},

View File

@@ -1,5 +1,6 @@
import fs from 'fs'
import path from 'path'
import PnpmError from '@pnpm/error'
import {
FetchFromRegistry,
RetryTimeoutOptions,
@@ -10,6 +11,7 @@ import createFetcher, { waitForFilesIndex } from '@pnpm/tarball-fetcher'
import AdmZip from 'adm-zip'
import renameOverwrite from 'rename-overwrite'
import tempy from 'tempy'
import { isNonGlibcLinux } from 'detect-libc'
import { getNodeTarball } from './getNodeTarball'
export interface FetchNodeOptions {
@@ -20,6 +22,9 @@ export interface FetchNodeOptions {
}
export async function fetchNode (fetch: FetchFromRegistry, version: string, targetDir: string, opts: FetchNodeOptions) {
if (await isNonGlibcLinux()) {
throw new PnpmError('MUSL', 'The current system uses the "MUSL" C standard library. Node.js currently has prebuilt artifacts only for the "glibc" libc, so we can install Node.js only for glibc')
}
const nodeMirrorBaseUrl = opts.nodeMirrorBaseUrl ?? 'https://nodejs.org/download/release/'
const { tarball, pkgName } = getNodeTarball(version, nodeMirrorBaseUrl, process.platform, process.arch)
if (tarball.endsWith('.zip')) {

View File

@@ -4,6 +4,11 @@ import path from 'path'
import { Readable } from 'stream'
import { fetchNode, FetchNodeOptions } from '@pnpm/node.fetcher'
import { tempDir } from '@pnpm/prepare'
import { isNonGlibcLinux } from 'detect-libc'
jest.mock('detect-libc', () => ({
isNonGlibcLinux: jest.fn(),
}))
const fetchMock = jest.fn(async (url: string) => {
if (url.endsWith('.zip')) {
@@ -20,6 +25,7 @@ const fetchMock = jest.fn(async (url: string) => {
})
beforeEach(() => {
isNonGlibcLinux['mockReturnValue'](Promise.resolve(false))
fetchMock.mockClear()
})
@@ -52,3 +58,16 @@ test('install Node using the default node mirror', async () => {
expect(call[0]).toMatch('https://nodejs.org/download/release/')
}
})
test('install Node using a custom node mirror', async () => {
isNonGlibcLinux['mockReturnValue'](Promise.resolve(true))
tempDir()
const opts: FetchNodeOptions = {
cafsDir: path.resolve('files'),
}
await expect(
fetchNode(fetchMock, '16.4.0', path.resolve('node'), opts)
).rejects.toThrow('The current system uses the "MUSL" C standard library. Node.js currently has prebuilt artifacts only for the "glibc" libc, so we can install Node.js only for glibc')
})

View File

@@ -15,6 +15,9 @@
{
"path": "../create-cafs-store"
},
{
"path": "../error"
},
{
"path": "../fetcher-base"
},

4
pnpm-lock.yaml generated
View File

@@ -1736,6 +1736,7 @@ importers:
packages/node.fetcher:
specifiers:
'@pnpm/create-cafs-store': workspace:2.0.2
'@pnpm/error': workspace:3.0.1
'@pnpm/fetcher-base': workspace:13.0.1
'@pnpm/fetching-types': workspace:3.0.0
'@pnpm/node.fetcher': workspace:1.0.3
@@ -1743,15 +1744,18 @@ importers:
'@pnpm/tarball-fetcher': workspace:10.0.8
'@types/adm-zip': ^0.4.34
adm-zip: ^0.5.5
detect-libc: ^2.0.1
node-fetch: 3.0.0-beta.9
rename-overwrite: ^4.0.2
tempy: ^1.0.0
dependencies:
'@pnpm/create-cafs-store': link:../create-cafs-store
'@pnpm/error': link:../error
'@pnpm/fetcher-base': link:../fetcher-base
'@pnpm/fetching-types': link:../fetching-types
'@pnpm/tarball-fetcher': link:../tarball-fetcher
adm-zip: 0.5.9
detect-libc: 2.0.1
rename-overwrite: 4.0.2
tempy: 1.0.1
devDependencies: