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(env): throw an error on a system that uses MUSL libc #4958

Merged
merged 1 commit into from
Jun 30, 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
6 changes: 6 additions & 0 deletions .changeset/strong-ways-tap.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion packages/node.fetcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/node.fetcher/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs'
import path from 'path'
import PnpmError from '@pnpm/error'
import {
FetchFromRegistry,
RetryTimeoutOptions,
Expand All @@ -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 {
Expand All @@ -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')) {
Expand Down
19 changes: 19 additions & 0 deletions packages/node.fetcher/test/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -20,6 +25,7 @@ const fetchMock = jest.fn(async (url: string) => {
})

beforeEach(() => {
isNonGlibcLinux['mockReturnValue'](Promise.resolve(false))
fetchMock.mockClear()
})

Expand Down Expand Up @@ -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')
})
3 changes: 3 additions & 0 deletions packages/node.fetcher/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
{
"path": "../create-cafs-store"
},
{
"path": "../error"
},
{
"path": "../fetcher-base"
},
Expand Down
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.