Skip to content

Commit 634bfd2

Browse files
committed
wip: adding devEngines
Super preliminary loop that will not even work right w/ libc
1 parent 3d0d00b commit 634bfd2

File tree

5 files changed

+81
-20
lines changed

5 files changed

+81
-20
lines changed

lib/current-env.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const process = require('node:process')
2+
3+
function os () {
4+
return process.platform
5+
}
6+
7+
function cpu () {
8+
return process.arch
9+
}
10+
11+
function isMusl (file) {
12+
return file.includes('libc.musl-') || file.includes('ld-musl-')
13+
}
14+
15+
// libc checks only work in linux, environment and os check needs to happen out of band from this function
16+
function libcFamily () {
17+
let family = null
18+
const report = process.report.getReport()
19+
if (report.header?.glibcVersionRuntime) {
20+
family = 'glibc'
21+
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
22+
family = 'musl'
23+
}
24+
return family
25+
}
26+
27+
module.exports = {
28+
cpu,
29+
libcFamily,
30+
os,
31+
}

lib/env.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const process = require('node:process')
2+
3+
function os () {
4+
return process.platform
5+
}
6+
7+
function cpu () {
8+
return process.arch
9+
}
10+
11+
function isMusl (file) {
12+
return file.includes('libc.musl-') || file.includes('ld-musl-')
13+
}
14+
15+
// libc checks only work in linux, environment and os check needs to happen out of band from this function
16+
function libcFamily (environment) {
17+
let family = null
18+
const report = process.report.getReport()
19+
if (report.header?.glibcVersionRuntime) {
20+
family = 'glibc'
21+
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
22+
family = 'musl'
23+
}
24+
return family
25+
}
26+
27+
module.exports = {
28+
cpu,
29+
libcFamily,
30+
os,
31+
}

lib/index.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const process = require('node:process')
21
const satisfies = require('semver/functions/satisfies')
32
const validRange = require('semver/ranges/valid')
3+
const currentEnv = require('./current-env.js')
44

55
/*
66
@@ -48,14 +48,16 @@ function checkDev (wanted = {}, current = {}, opts = {}) {
4848
failures[env] = w
4949
break
5050
}
51-
if (validRange(w.version)) {
52-
if (!satisfies(currentEnv.version, w.version, opts.semver)) {
51+
if (w.version) {
52+
if (validRange(w.version)) {
53+
if (!satisfies(currentEnv.version, w.version, opts.semver)) {
54+
failures[env] = w
55+
break
56+
}
57+
} else if (currentEnv.version !== w.version) {
5358
failures[env] = w
5459
break
5560
}
56-
} else if (currentEnv.version !== w.version) {
57-
failures[env] = w
58-
break
5961
}
6062
}
6163
}
@@ -86,19 +88,15 @@ function checkEngine (target, npmVer, nodeVer, force = false) {
8688
}
8789
}
8890

89-
function isMusl (file) {
90-
return file.includes('libc.musl-') || file.includes('ld-musl-')
91-
}
92-
9391
function checkPlatform (target, force = false, environment = {}) {
9492
if (force) {
9593
return
9694
}
9795

98-
const platform = environment.os || process.platform
99-
const arch = environment.cpu || process.arch
96+
const platform = environment.os || currentEnv.os()
97+
const cpu = environment.cpu || currentEnv.cpu()
10098
const osOk = target.os ? checkList(platform, target.os) : true
101-
const cpuOk = target.cpu ? checkList(arch, target.cpu) : true
99+
const cpuOk = target.cpu ? checkList(cpu, target.cpu) : true
102100

103101
let libcOk = true
104102
let libcFamily = null
@@ -109,12 +107,7 @@ function checkPlatform (target, force = false, environment = {}) {
109107
} else if (platform !== 'linux') {
110108
libcOk = false
111109
} else {
112-
const report = process.report.getReport()
113-
if (report.header?.glibcVersionRuntime) {
114-
libcFamily = 'glibc'
115-
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
116-
libcFamily = 'musl'
117-
}
110+
libcFamily = currentEnv.libcFamily()
118111
libcOk = libcFamily ? checkList(libcFamily, target.libc) : false
119112
}
120113
}
@@ -124,7 +117,7 @@ function checkPlatform (target, force = false, environment = {}) {
124117
pkgid: target._id,
125118
current: {
126119
os: platform,
127-
cpu: arch,
120+
cpu,
128121
libc: libcFamily,
129122
},
130123
required: {

test/check-dev.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ t.test('tests all the right fields', async t => {
1717
const wanted = { name: `test-${env}-wanted` }
1818
t.same(checkDev({ [env]: wanted }), { [env]: wanted })
1919
})
20+
t.test('name only', async t => {
21+
const wanted = { name: 'test-name' }
22+
const current = { name: 'test-name' }
23+
t.same(checkDev({ [env]: wanted }, { [env]: current}), null)
24+
})
2025
t.test('non-semver version is not the same', async t => {
2126
const wanted = { name: `test-name`, version: 'test-version-wanted' }
2227
const current = { name: `test-name`, version: 'test-version-current' }

test/check-platform.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const t = require('tap')
2+
const process = require('node:process')
23
const { checkPlatform } = require('..')
34

45
t.test('target cpu wrong', async t =>

0 commit comments

Comments
 (0)