Skip to content

Commit

Permalink
wip: adding devEngines
Browse files Browse the repository at this point in the history
Super preliminary loop that will not even work right w/ libc
  • Loading branch information
wraithgar committed Aug 19, 2024
1 parent 3d0d00b commit 634bfd2
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 20 deletions.
31 changes: 31 additions & 0 deletions lib/current-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const process = require('node:process')

function os () {
return process.platform
}

function cpu () {
return process.arch
}

function isMusl (file) {
return file.includes('libc.musl-') || file.includes('ld-musl-')
}

// libc checks only work in linux, environment and os check needs to happen out of band from this function
function libcFamily () {
let family = null
const report = process.report.getReport()
if (report.header?.glibcVersionRuntime) {
family = 'glibc'
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
family = 'musl'
}
return family
}

module.exports = {
cpu,
libcFamily,
os,
}
31 changes: 31 additions & 0 deletions lib/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const process = require('node:process')

function os () {
return process.platform
}

function cpu () {
return process.arch
}

function isMusl (file) {

This comment has been minimized.

Copy link
@Okikz04

Okikz04 Sep 23, 2024

Hi

return file.includes('libc.musl-') || file.includes('ld-musl-')
}

// libc checks only work in linux, environment and os check needs to happen out of band from this function
function libcFamily (environment) {
let family = null
const report = process.report.getReport()
if (report.header?.glibcVersionRuntime) {
family = 'glibc'
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
family = 'musl'
}
return family
}

module.exports = {
cpu,
libcFamily,
os,
}
33 changes: 13 additions & 20 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const process = require('node:process')
const satisfies = require('semver/functions/satisfies')
const validRange = require('semver/ranges/valid')
const currentEnv = require('./current-env.js')

/*
Expand Down Expand Up @@ -48,14 +48,16 @@ function checkDev (wanted = {}, current = {}, opts = {}) {
failures[env] = w
break
}
if (validRange(w.version)) {
if (!satisfies(currentEnv.version, w.version, opts.semver)) {
if (w.version) {
if (validRange(w.version)) {
if (!satisfies(currentEnv.version, w.version, opts.semver)) {
failures[env] = w
break
}
} else if (currentEnv.version !== w.version) {
failures[env] = w
break
}
} else if (currentEnv.version !== w.version) {
failures[env] = w
break
}
}
}
Expand Down Expand Up @@ -86,19 +88,15 @@ function checkEngine (target, npmVer, nodeVer, force = false) {
}
}

function isMusl (file) {
return file.includes('libc.musl-') || file.includes('ld-musl-')
}

function checkPlatform (target, force = false, environment = {}) {
if (force) {
return
}

const platform = environment.os || process.platform
const arch = environment.cpu || process.arch
const platform = environment.os || currentEnv.os()
const cpu = environment.cpu || currentEnv.cpu()
const osOk = target.os ? checkList(platform, target.os) : true
const cpuOk = target.cpu ? checkList(arch, target.cpu) : true
const cpuOk = target.cpu ? checkList(cpu, target.cpu) : true

let libcOk = true
let libcFamily = null
Expand All @@ -109,12 +107,7 @@ function checkPlatform (target, force = false, environment = {}) {
} else if (platform !== 'linux') {
libcOk = false
} else {
const report = process.report.getReport()
if (report.header?.glibcVersionRuntime) {
libcFamily = 'glibc'
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
libcFamily = 'musl'
}
libcFamily = currentEnv.libcFamily()
libcOk = libcFamily ? checkList(libcFamily, target.libc) : false
}
}
Expand All @@ -124,7 +117,7 @@ function checkPlatform (target, force = false, environment = {}) {
pkgid: target._id,
current: {
os: platform,
cpu: arch,
cpu,
libc: libcFamily,
},
required: {
Expand Down
5 changes: 5 additions & 0 deletions test/check-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ t.test('tests all the right fields', async t => {
const wanted = { name: `test-${env}-wanted` }
t.same(checkDev({ [env]: wanted }), { [env]: wanted })
})
t.test('name only', async t => {
const wanted = { name: 'test-name' }
const current = { name: 'test-name' }
t.same(checkDev({ [env]: wanted }, { [env]: current}), null)
})
t.test('non-semver version is not the same', async t => {
const wanted = { name: `test-name`, version: 'test-version-wanted' }
const current = { name: `test-name`, version: 'test-version-current' }
Expand Down
1 change: 1 addition & 0 deletions test/check-platform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const t = require('tap')
const process = require('node:process')
const { checkPlatform } = require('..')

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

0 comments on commit 634bfd2

Please sign in to comment.