Skip to content

feat: allow checkPlatform to override execution libc #71

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

Merged
merged 1 commit into from
Oct 6, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Check if a package's `os`, `cpu` and `libc` match the running system.

`force` argument skips all checks.

`environment` overrides the execution environment which comes from `process.platform` and `process.arch` by default. `environment.os` and `environment.cpu` are available.
`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.

Error code: 'EBADPLATFORM'
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ const checkPlatform = (target, force = false, environment = {}) => {
let libcFamily = null
if (target.libc) {
// libc checks only work in linux, any value is a failure if we aren't
if (platform !== 'linux') {
if (environment.libc) {
libcOk = checkList(environment.libc, target.libc)
} else if (platform !== 'linux') {
libcOk = false
} else {
const report = process.report.getReport()
Expand Down
18 changes: 18 additions & 0 deletions test/check-platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ t.test('nothing wrong with overridden cpu', async t =>
cpu: 'enten-cpu',
}))

t.test('nothing wrong with overridden libc', async t =>
checkPlatform({
cpu: 'enten-cpu',
libc: 'enten-libc',
}, false, {
cpu: 'enten-cpu',
libc: 'enten-libc',
}))

t.test('wrong os with overridden os', async t =>
t.throws(() => checkPlatform({
cpu: 'any',
Expand All @@ -75,6 +84,15 @@ t.test('wrong cpu with overridden cpu', async t =>
cpu: 'another-cpu',
}), { code: 'EBADPLATFORM' }))

t.test('wrong libc with overridden libc', async t =>
t.throws(() => checkPlatform({
cpu: 'enten-cpu',
os: 'any',
libc: 'enten-libc',
}, false, {
libc: 'another-libc',
}), { code: 'EBADPLATFORM' }))

t.test('libc', (t) => {
let PLATFORM = ''

Expand Down