@contrast/agent-lib
Advanced tools
Comparing version
67
index.js
@@ -5,25 +5,52 @@ 'use strict'; | ||
const { sep } = require('path'); | ||
const suffix = { | ||
linux: '-gnu', | ||
darwin: '', | ||
win32: '-msvc' | ||
}[platform]; | ||
const {version} = require('./package.json'); | ||
const { version: packageVersion } = require('./package.json'); | ||
const { GLIBC, MUSL, familySync, versionSync } = require('detect-libc'); | ||
try { | ||
const bindingsPath = `${__dirname}${sep}contrast.${platform}-${process.arch}${suffix}.node`; | ||
module.exports = require(`${bindingsPath}`); | ||
} catch(e) { | ||
const first_failure = e; | ||
// account for alpine (uses its own suffix). | ||
if (platform === 'linux') { | ||
try { | ||
const bindingsPath = `${__dirname}${sep}contrast.${platform}-${process.arch}-musl.node`; | ||
module.exports = require(`${bindingsPath}`); | ||
} catch (e) { | ||
console.log(first_failure); | ||
throw e; | ||
let bindingsPath = () => { | ||
switch (platform) { | ||
case 'linux': { | ||
const family = familySync(); | ||
switch (family) { | ||
case GLIBC: { | ||
const glibcVersion = versionSync(); | ||
if (glibcVersion) { | ||
const [major, minor] = glibcVersion.split('.'); | ||
if (major < 2 || (major == 2 && minor < 17)) { | ||
throw new Error(`Unsupported glibc version. Only version 2.17.0 or above is supported. Detected version ${glibcVersion}`); | ||
} | ||
if (major == 2 && (minor >= 17 && minor < 28)) { | ||
return `${__dirname}${sep}contrast.${platform}-${process.arch}-glibc217.node` | ||
} | ||
} | ||
return `${__dirname}${sep}contrast.${platform}-${process.arch}-gnu.node`; | ||
} | ||
case MUSL: { | ||
return `${__dirname}${sep}contrast.${platform}-${process.arch}-musl.node`; | ||
} | ||
default: { | ||
throw new Error(`Unsupported glibc family. ${family} is not supported.`); | ||
} | ||
} | ||
} | ||
case 'win32': { | ||
return `${__dirname}${sep}contrast.${platform}-${process.arch}-msvc.node`; | ||
} | ||
case 'darwin': { | ||
return `${__dirname}${sep}contrast.${platform}-${process.arch}.node`; | ||
} | ||
default: { | ||
throw new Error(`Unsupported platform. ${platform} is not supported.`); | ||
} | ||
} | ||
} | ||
module.exports.version = version; | ||
try { | ||
module.exports = require(`${bindingsPath()}`); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
module.exports.version = packageVersion; |
{ | ||
"name": "@contrast/agent-lib", | ||
"version": "5.2.2", | ||
"version": "5.3.0", | ||
"description": "", | ||
@@ -26,4 +26,7 @@ "keywords": [], | ||
"build:debug": "napi build --platform", | ||
"build:napi_cost": "napi build --platform --release --features napi_cost", | ||
"build:raspv3": "napi build --platform --release --features raspv3", | ||
"format:rs": "cargo fmt", | ||
"test": "mocha test/*.test.js" | ||
"test": "mocha test/*.test.js", | ||
"test:raspv3": "RASPV3_TEST=true mocha test/*.test.js" | ||
}, | ||
@@ -40,3 +43,6 @@ "devDependencies": { | ||
"mocha": "^9.2.0" | ||
}, | ||
"dependencies": { | ||
"detect-libc": "^2.0.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
28674319
78.38%10
42.86%50
92.31%2
-33.33%1
Infinity%8
60%+ Added
+ Added