mirror of
https://gitee.com/onvia/ccc-tnt-psd2ui
synced 2026-03-24 15:11:53 +00:00
mac npm-packages
This commit is contained in:
@@ -8,6 +8,9 @@ Currently supports detection of GNU glibc and MUSL libc.
|
||||
Provides asychronous and synchronous functions for the
|
||||
family (e.g. `glibc`, `musl`) and version (e.g. `1.23`, `1.2.3`).
|
||||
|
||||
The version numbers of libc implementations
|
||||
are not guaranteed to be semver-compliant.
|
||||
|
||||
For previous v1.x releases, please see the
|
||||
[v1](https://github.com/lovell/detect-libc/tree/v1) branch.
|
||||
|
||||
@@ -147,7 +150,7 @@ if (isNonGlibcLinuxSync()) { ... }
|
||||
|
||||
## Licensing
|
||||
|
||||
Copyright 2017, 2022 Lovell Fuller
|
||||
Copyright 2017 Lovell Fuller and others.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2017 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const GLIBC: 'glibc';
|
||||
export const MUSL: 'musl';
|
||||
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
// Copyright 2017 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const childProcess = require('child_process');
|
||||
const { isLinux, getReport } = require('./process');
|
||||
const { LDD_PATH, readFile, readFileSync } = require('./filesystem');
|
||||
|
||||
let cachedFamilyFilesystem;
|
||||
let cachedVersionFilesystem;
|
||||
|
||||
const command = 'getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true';
|
||||
let commandOut = '';
|
||||
@@ -36,6 +43,12 @@ const safeCommandSync = () => {
|
||||
*/
|
||||
const GLIBC = 'glibc';
|
||||
|
||||
/**
|
||||
* A Regexp constant to get the GLIBC Version.
|
||||
* @type {string}
|
||||
*/
|
||||
const RE_GLIBC_VERSION = /GLIBC\s(\d+\.\d+)/;
|
||||
|
||||
/**
|
||||
* A String constant containing the value `musl`.
|
||||
* @type {string}
|
||||
@@ -43,6 +56,18 @@ const GLIBC = 'glibc';
|
||||
*/
|
||||
const MUSL = 'musl';
|
||||
|
||||
/**
|
||||
* This string is used to find if the {@link LDD_PATH} is GLIBC
|
||||
* @type {string}
|
||||
*/
|
||||
const GLIBC_ON_LDD = GLIBC.toUpperCase();
|
||||
|
||||
/**
|
||||
* This string is used to find if the {@link LDD_PATH} is musl
|
||||
* @type {string}
|
||||
*/
|
||||
const MUSL_ON_LDD = MUSL.toLowerCase();
|
||||
|
||||
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-');
|
||||
|
||||
const familyFromReport = () => {
|
||||
@@ -69,6 +94,40 @@ const familyFromCommand = (out) => {
|
||||
return null;
|
||||
};
|
||||
|
||||
const getFamilyFromLddContent = (content) => {
|
||||
if (content.includes(MUSL_ON_LDD)) {
|
||||
return MUSL;
|
||||
}
|
||||
if (content.includes(GLIBC_ON_LDD)) {
|
||||
return GLIBC;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const familyFromFilesystem = async () => {
|
||||
if (cachedFamilyFilesystem !== undefined) {
|
||||
return cachedFamilyFilesystem;
|
||||
}
|
||||
cachedFamilyFilesystem = null;
|
||||
try {
|
||||
const lddContent = await readFile(LDD_PATH);
|
||||
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
||||
} catch (e) {}
|
||||
return cachedFamilyFilesystem;
|
||||
};
|
||||
|
||||
const familyFromFilesystemSync = () => {
|
||||
if (cachedFamilyFilesystem !== undefined) {
|
||||
return cachedFamilyFilesystem;
|
||||
}
|
||||
cachedFamilyFilesystem = null;
|
||||
try {
|
||||
const lddContent = readFileSync(LDD_PATH);
|
||||
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
||||
} catch (e) {}
|
||||
return cachedFamilyFilesystem;
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolves with the libc family when it can be determined, `null` otherwise.
|
||||
* @returns {Promise<?string>}
|
||||
@@ -76,7 +135,10 @@ const familyFromCommand = (out) => {
|
||||
const family = async () => {
|
||||
let family = null;
|
||||
if (isLinux()) {
|
||||
family = familyFromReport();
|
||||
family = await familyFromFilesystem();
|
||||
if (!family) {
|
||||
family = familyFromReport();
|
||||
}
|
||||
if (!family) {
|
||||
const out = await safeCommand();
|
||||
family = familyFromCommand(out);
|
||||
@@ -92,7 +154,10 @@ const family = async () => {
|
||||
const familySync = () => {
|
||||
let family = null;
|
||||
if (isLinux()) {
|
||||
family = familyFromReport();
|
||||
family = familyFromFilesystemSync();
|
||||
if (!family) {
|
||||
family = familyFromReport();
|
||||
}
|
||||
if (!family) {
|
||||
const out = safeCommandSync();
|
||||
family = familyFromCommand(out);
|
||||
@@ -113,6 +178,36 @@ const isNonGlibcLinux = async () => isLinux() && await family() !== GLIBC;
|
||||
*/
|
||||
const isNonGlibcLinuxSync = () => isLinux() && familySync() !== GLIBC;
|
||||
|
||||
const versionFromFilesystem = async () => {
|
||||
if (cachedVersionFilesystem !== undefined) {
|
||||
return cachedVersionFilesystem;
|
||||
}
|
||||
cachedVersionFilesystem = null;
|
||||
try {
|
||||
const lddContent = await readFile(LDD_PATH);
|
||||
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
||||
if (versionMatch) {
|
||||
cachedVersionFilesystem = versionMatch[1];
|
||||
}
|
||||
} catch (e) {}
|
||||
return cachedVersionFilesystem;
|
||||
};
|
||||
|
||||
const versionFromFilesystemSync = () => {
|
||||
if (cachedVersionFilesystem !== undefined) {
|
||||
return cachedVersionFilesystem;
|
||||
}
|
||||
cachedVersionFilesystem = null;
|
||||
try {
|
||||
const lddContent = readFileSync(LDD_PATH);
|
||||
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
||||
if (versionMatch) {
|
||||
cachedVersionFilesystem = versionMatch[1];
|
||||
}
|
||||
} catch (e) {}
|
||||
return cachedVersionFilesystem;
|
||||
};
|
||||
|
||||
const versionFromReport = () => {
|
||||
const report = getReport();
|
||||
if (report.header && report.header.glibcVersionRuntime) {
|
||||
@@ -141,7 +236,10 @@ const versionFromCommand = (out) => {
|
||||
const version = async () => {
|
||||
let version = null;
|
||||
if (isLinux()) {
|
||||
version = versionFromReport();
|
||||
version = await versionFromFilesystem();
|
||||
if (!version) {
|
||||
version = versionFromReport();
|
||||
}
|
||||
if (!version) {
|
||||
const out = await safeCommand();
|
||||
version = versionFromCommand(out);
|
||||
@@ -157,7 +255,10 @@ const version = async () => {
|
||||
const versionSync = () => {
|
||||
let version = null;
|
||||
if (isLinux()) {
|
||||
version = versionFromReport();
|
||||
version = versionFromFilesystemSync();
|
||||
if (!version) {
|
||||
version = versionFromReport();
|
||||
}
|
||||
if (!version) {
|
||||
const out = safeCommandSync();
|
||||
version = versionFromCommand(out);
|
||||
|
||||
41
npm-packages/mac-v3.4.+/detect-libc/lib/filesystem.js
Normal file
41
npm-packages/mac-v3.4.+/detect-libc/lib/filesystem.js
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2017 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
/**
|
||||
* The path where we can find the ldd
|
||||
*/
|
||||
const LDD_PATH = '/usr/bin/ldd';
|
||||
|
||||
/**
|
||||
* Read the content of a file synchronous
|
||||
*
|
||||
* @param {string} path
|
||||
* @returns {string}
|
||||
*/
|
||||
const readFileSync = (path) => fs.readFileSync(path, 'utf-8');
|
||||
|
||||
/**
|
||||
* Read the content of a file
|
||||
*
|
||||
* @param {string} path
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
const readFile = (path) => new Promise((resolve, reject) => {
|
||||
fs.readFile(path, 'utf-8', (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
LDD_PATH,
|
||||
readFileSync,
|
||||
readFile
|
||||
};
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2017 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const isLinux = () => process.platform === 'linux';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "detect-libc",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"description": "Node.js module to detect the C standard library (libc) implementation family and version",
|
||||
"main": "lib/detect-libc.js",
|
||||
"files": [
|
||||
@@ -8,7 +8,9 @@
|
||||
"index.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "semistandard && nyc --reporter=lcov --check-coverage --branches=100 ava test/unit.js"
|
||||
"test": "semistandard && nyc --reporter=lcov --check-coverage --branches=100 ava test/unit.js",
|
||||
"bench": "node benchmark/detect-libc",
|
||||
"bench:calls": "node benchmark/call-familySync.js && sleep 1 && node benchmark/call-isNonGlibcLinuxSync.js && sleep 1 && node benchmark/call-versionSync.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -21,11 +23,13 @@
|
||||
],
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"contributors": [
|
||||
"Niklas Salmoukas <niklas@salmoukas.com>"
|
||||
"Niklas Salmoukas <niklas@salmoukas.com>",
|
||||
"Vinícius Lourenço <vinyygamerlol@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"ava": "^2.4.0",
|
||||
"benchmark": "^2.1.4",
|
||||
"nyc": "^15.1.0",
|
||||
"proxyquire": "^2.1.3",
|
||||
"semistandard": "^14.2.3"
|
||||
|
||||
Reference in New Issue
Block a user