Skip to content

Commit 009802b

Browse files
committed
feat: allow checkPlatform to override execution libc
1 parent 4fc835c commit 009802b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ Check if a package's `os`, `cpu` and `libc` match the running system.
2525

2626
`force` argument skips all checks.
2727

28-
`environment` overrides the execution environment which comes from `process.platform` and `process.arch` by default. `environment.os` and `environment.cpu` are available.
28+
`environment` overrides the execution environment which comes from `process.platform` `process.arch` and current `libc` environment by default. `environment.os` `environment.cpu` and `environment.libc` are available.
2929

3030
Error code: 'EBADPLATFORM'

lib/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ const checkPlatform = (target, force = false, environment = {}) => {
3636
let libcFamily = null
3737
if (target.libc) {
3838
// libc checks only work in linux, any value is a failure if we aren't
39-
if (platform !== 'linux') {
39+
if (environment.libc) {
40+
libcOk = checkList(environment.libc, target.libc)
41+
} else if (platform !== 'linux') {
4042
libcOk = false
4143
} else {
4244
const report = process.report.getReport()

test/check-platform.js

+18
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ t.test('nothing wrong with overridden cpu', async t =>
5959
cpu: 'enten-cpu',
6060
}))
6161

62+
t.test('nothing wrong with overridden libc', async t =>
63+
checkPlatform({
64+
cpu: 'enten-cpu',
65+
libc: 'enten-libc',
66+
}, false, {
67+
cpu: 'enten-cpu',
68+
libc: 'enten-libc',
69+
}))
70+
6271
t.test('wrong os with overridden os', async t =>
6372
t.throws(() => checkPlatform({
6473
cpu: 'any',
@@ -75,6 +84,15 @@ t.test('wrong cpu with overridden cpu', async t =>
7584
cpu: 'another-cpu',
7685
}), { code: 'EBADPLATFORM' }))
7786

87+
t.test('wrong libc with overridden libc', async t =>
88+
t.throws(() => checkPlatform({
89+
cpu: 'enten-cpu',
90+
os: 'any',
91+
libc: 'enten-libc',
92+
}, false, {
93+
libc: 'another-libc',
94+
}), { code: 'EBADPLATFORM' }))
95+
7896
t.test('libc', (t) => {
7997
let PLATFORM = ''
8098

0 commit comments

Comments
 (0)