Skip to content

Commit

Permalink
feat: allow checkPlatform to override execution libc (#71)
Browse files Browse the repository at this point in the history
- Part of #65
  • Loading branch information
Brooooooklyn committed Oct 6, 2023
1 parent 4fc835c commit 0419751
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
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

0 comments on commit 0419751

Please sign in to comment.