pax_global_header00006660000000000000000000000064142024303610014505gustar00rootroot0000000000000052 comment=0e10bbb465414b99078fcdd9c69b0bc2df3ed745 detect-libc-2.0.1/000077500000000000000000000000001420243036100136645ustar00rootroot00000000000000detect-libc-2.0.1/.github/000077500000000000000000000000001420243036100152245ustar00rootroot00000000000000detect-libc-2.0.1/.github/workflows/000077500000000000000000000000001420243036100172615ustar00rootroot00000000000000detect-libc-2.0.1/.github/workflows/integration.yml000066400000000000000000000151261420243036100223340ustar00rootroot00000000000000name: Integration tests on: - push - pull_request jobs: integration: name: ${{ matrix.name }} container: ${{ matrix.container }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: include: - name: Alpine 3.11 / Node.js 8 container: node:8-alpine3.11 node-version: 8 expected-family: musl expected-version: 1.1.24 - name: Alpine 3.11 / Node.js 16 container: node:16-alpine3.11 node-version: 16 expected-family: musl expected-version: 1.1.24 - name: Alpine 3.12 / Node.js 12 container: node:12-alpine3.12 node-version: 12 expected-family: musl expected-version: 1.1.24 - name: Alpine 3.15 / Node.js 16 container: node:16-alpine3.15 node-version: 16 expected-family: musl expected-version: 1.2.2 - name: Amazon 1 / Node.js 8 container: amazonlinux:1 node-version: 8 expected-family: glibc expected-version: 2.17 - name: Amazon 1 / Node.js 16 container: amazonlinux:1 node-version: 16 expected-family: glibc expected-version: 2.17 - name: Amazon 2 / Node.js 10 container: amazonlinux:2 node-version: 10 expected-family: glibc expected-version: 2.26 - name: Amazon 2 / Node.js 16 container: amazonlinux:2 node-version: 16 expected-family: glibc expected-version: 2.26 - name: CentOS 7 / Node.js 8 container: centos:centos7 node-version: 8 expected-family: glibc expected-version: 2.17 - name: CentOS 7 / Node.js 16 container: centos:centos7 node-version: 16 expected-family: glibc expected-version: 2.17 - name: CentOS 8 / Node.js 10 container: quay.io/centos/centos:stream8 node-version: 10 expected-family: glibc expected-version: 2.28 - name: CentOS 8 / Node.js 16 container: quay.io/centos/centos:stream8 node-version: 16 expected-family: glibc expected-version: 2.28 - name: Debian 9 / Node.js 8 container: node:8-stretch-slim node-version: 8 expected-family: glibc expected-version: 2.24 - name: Debian 9 / Node.js 16 container: node:16-stretch-slim node-version: 16 expected-family: glibc expected-version: 2.24 - name: Debian 10 / Node.js 8 container: node:8-buster-slim node-version: 8 expected-family: glibc expected-version: 2.28 - name: Debian 11 / Node.js 16 container: node:16-bullseye-slim node-version: 16 expected-family: glibc expected-version: 2.31 - name: Fedora 33 / Node.js 10 container: fedora:33 node-version: 10 expected-family: glibc expected-version: 2.32 - name: Fedora 33 / Node.js 16 container: fedora:33 node-version: 16 expected-family: glibc expected-version: 2.32 - name: Fedora 35 / Node.js 12 container: fedora:35 node-version: 12 expected-family: glibc expected-version: 2.34 - name: Fedora 35 / Node.js 16 container: fedora:35 node-version: 16 expected-family: glibc expected-version: 2.34 - name: OpenSUSE 15.1 / Node.js 10 container: opensuse/leap:15.1 node-version: 10 expected-family: glibc expected-version: 2.26 - name: OpenSUSE 15.3 / Node.js 14 container: opensuse/leap:15.3 node-version: 14 expected-family: glibc expected-version: 2.31 - name: Ubuntu 14.04 / Node.js 8 container: ubuntu:14.04 node-version: 8 expected-family: glibc expected-version: 2.19 - name: Ubuntu 16.04 / Node.js 16 container: ubuntu:16.04 node-version: 16 expected-family: glibc expected-version: 2.23 - name: Ubuntu 18.04 / Node.js 8 container: ubuntu:18.04 node-version: 8 expected-family: glibc expected-version: 2.27 - name: Ubuntu 21.10 / Node.js 16 container: ubuntu:21.10 node-version: 16 expected-family: glibc expected-version: 2.34 - name: Void glibc / Node.js 16 container: voidlinux/voidlinux node-version: 16 expected-family: glibc expected-version: 2.32 - name: Void musl / Node.js 16 container: voidlinux/voidlinux-musl node-version: 16 expected-family: musl expected-version: 1.1.24 steps: - name: Install Node.js (RHEL) if: contains(matrix.container, 'amazonlinux') || contains(matrix.container, 'centos') || contains(matrix.container, 'fedora') run: | yum module disable -y nodejs || true curl -sL https://rpm.nodesource.com/setup_${{ matrix.node-version }}.x | bash - yum install -y git nodejs - name: Install Node.js (OpenSUSE) if: contains(matrix.container, 'opensuse') run: | zypper refresh zypper --non-interactive install git nodejs${{ matrix.node-version }} - name: Install Node.js (Ubuntu) if: contains(matrix.container, 'ubuntu') run: | apt-get update apt-get install -y curl git gnupg curl -sL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - curl -sL https://deb.nodesource.com/setup_${{ matrix.node-version }}.x | bash - apt-get install -y nodejs - name: Install Node.js (Void) if: contains(matrix.container, 'void') run: xbps-install -Sy git nodejs - name: Checkout uses: actions/checkout@v1 - name: Verify expectations run: | export EXPECTED="${{ matrix.expected-family }} ${{ matrix.expected-version }}" export ACTUAL="$(node ./test/integration.js)" echo "Expected: $EXPECTED" echo "Actual: $ACTUAL" test "$EXPECTED" = "$ACTUAL" detect-libc-2.0.1/.github/workflows/unit.yml000066400000000000000000000010671420243036100207670ustar00rootroot00000000000000name: Unit tests on: - push - pull_request jobs: unit: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: matrix: node-version: - 8 - 10 - 12 - 14 - 16 steps: - name: Checkout uses: actions/checkout@v2 - name: Install Node.js uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - name: Install dependencies run: npm install - name: Run unit tests run: npm test detect-libc-2.0.1/.gitignore000066400000000000000000000000671420243036100156570ustar00rootroot00000000000000.nyc_output/ coverage/ node_modules/ package-lock.json detect-libc-2.0.1/LICENSE000066400000000000000000000261351420243036100147000ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. detect-libc-2.0.1/README.md000066400000000000000000000060611420243036100151460ustar00rootroot00000000000000# detect-libc Node.js module to detect details of the C standard library (libc) implementation provided by a given Linux system. 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`). For previous v1.x releases, please see the [v1](https://github.com/lovell/detect-libc/tree/v1) branch. ## Install ```sh npm install detect-libc ``` ## API ### GLIBC ```ts const GLIBC: string = 'glibc'; ``` A String constant containing the value `glibc`. ### MUSL ```ts const MUSL: string = 'musl'; ``` A String constant containing the value `musl`. ### family ```ts function family(): Promise; ``` Resolves asychronously with: * `glibc` or `musl` when the libc family can be determined * `null` when the libc family cannot be determined * `null` when run on a non-Linux platform ```js const { family, GLIBC, MUSL } = require('detect-libc'); switch (await family()) { case GLIBC: ... case MUSL: ... case null: ... } ``` ### familySync ```ts function familySync(): string | null; ``` Synchronous version of `family()`. ```js const { familySync, GLIBC, MUSL } = require('detect-libc'); switch (familySync()) { case GLIBC: ... case MUSL: ... case null: ... } ``` ### version ```ts function version(): Promise; ``` Resolves asychronously with: * The version when it can be determined * `null` when the libc family cannot be determined * `null` when run on a non-Linux platform ```js const { version } = require('detect-libc'); const v = await version(); if (v) { const [major, minor, patch] = v.split('.'); } ``` ### versionSync ```ts function versionSync(): string | null; ``` Synchronous version of `version()`. ```js const { versionSync } = require('detect-libc'); const v = versionSync(); if (v) { const [major, minor, patch] = v.split('.'); } ``` ### isNonGlibcLinux ```ts function isNonGlibcLinux(): Promise; ``` Resolves asychronously with: * `false` when the libc family is `glibc` * `true` when the libc family is not `glibc` * `false` when run on a non-Linux platform ```js const { isNonGlibcLinux } = require('detect-libc'); if (await isNonGlibcLinux()) { ... } ``` ### isNonGlibcLinuxSync ```ts function isNonGlibcLinuxSync(): boolean; ``` Synchronous version of `isNonGlibcLinux()`. ```js const { isNonGlibcLinuxSync } = require('detect-libc'); if (isNonGlibcLinuxSync()) { ... } ``` ## Licensing Copyright 2017, 2022 Lovell Fuller Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0.html) Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. detect-libc-2.0.1/index.d.ts000066400000000000000000000005401420243036100155640ustar00rootroot00000000000000export const GLIBC: 'glibc'; export const MUSL: 'musl'; export function family(): Promise; export function familySync(): string | null; export function isNonGlibcLinux(): Promise; export function isNonGlibcLinuxSync(): boolean; export function version(): Promise; export function versionSync(): string | null; detect-libc-2.0.1/lib/000077500000000000000000000000001420243036100144325ustar00rootroot00000000000000detect-libc-2.0.1/lib/detect-libc.js000066400000000000000000000075141420243036100171560ustar00rootroot00000000000000'use strict'; const childProcess = require('child_process'); const { isLinux, getReport } = require('./process'); const command = 'getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true'; let commandOut = ''; const safeCommand = () => { if (!commandOut) { return new Promise((resolve) => { childProcess.exec(command, (err, out) => { commandOut = err ? ' ' : out; resolve(commandOut); }); }); } return commandOut; }; const safeCommandSync = () => { if (!commandOut) { try { commandOut = childProcess.execSync(command, { encoding: 'utf8' }); } catch (_err) { commandOut = ' '; } } return commandOut; }; /** * A String constant containing the value `glibc`. * @type {string} * @public */ const GLIBC = 'glibc'; /** * A String constant containing the value `musl`. * @type {string} * @public */ const MUSL = 'musl'; const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-'); const familyFromReport = () => { const report = getReport(); if (report.header && report.header.glibcVersionRuntime) { return GLIBC; } if (Array.isArray(report.sharedObjects)) { if (report.sharedObjects.some(isFileMusl)) { return MUSL; } } return null; }; const familyFromCommand = (out) => { const [getconf, ldd1] = out.split(/[\r\n]+/); if (getconf && getconf.includes(GLIBC)) { return GLIBC; } if (ldd1 && ldd1.includes(MUSL)) { return MUSL; } return null; }; /** * Resolves with the libc family when it can be determined, `null` otherwise. * @returns {Promise} */ const family = async () => { let family = null; if (isLinux()) { family = familyFromReport(); if (!family) { const out = await safeCommand(); family = familyFromCommand(out); } } return family; }; /** * Returns the libc family when it can be determined, `null` otherwise. * @returns {?string} */ const familySync = () => { let family = null; if (isLinux()) { family = familyFromReport(); if (!family) { const out = safeCommandSync(); family = familyFromCommand(out); } } return family; }; /** * Resolves `true` only when the platform is Linux and the libc family is not `glibc`. * @returns {Promise} */ const isNonGlibcLinux = async () => isLinux() && await family() !== GLIBC; /** * Returns `true` only when the platform is Linux and the libc family is not `glibc`. * @returns {boolean} */ const isNonGlibcLinuxSync = () => isLinux() && familySync() !== GLIBC; const versionFromReport = () => { const report = getReport(); if (report.header && report.header.glibcVersionRuntime) { return report.header.glibcVersionRuntime; } return null; }; const versionSuffix = (s) => s.trim().split(/\s+/)[1]; const versionFromCommand = (out) => { const [getconf, ldd1, ldd2] = out.split(/[\r\n]+/); if (getconf && getconf.includes(GLIBC)) { return versionSuffix(getconf); } if (ldd1 && ldd2 && ldd1.includes(MUSL)) { return versionSuffix(ldd2); } return null; }; /** * Resolves with the libc version when it can be determined, `null` otherwise. * @returns {Promise} */ const version = async () => { let version = null; if (isLinux()) { version = versionFromReport(); if (!version) { const out = await safeCommand(); version = versionFromCommand(out); } } return version; }; /** * Returns the libc version when it can be determined, `null` otherwise. * @returns {?string} */ const versionSync = () => { let version = null; if (isLinux()) { version = versionFromReport(); if (!version) { const out = safeCommandSync(); version = versionFromCommand(out); } } return version; }; module.exports = { GLIBC, MUSL, family, familySync, isNonGlibcLinux, isNonGlibcLinuxSync, version, versionSync }; detect-libc-2.0.1/lib/process.js000066400000000000000000000004731420243036100164520ustar00rootroot00000000000000'use strict'; const isLinux = () => process.platform === 'linux'; let report = null; const getReport = () => { if (!report) { /* istanbul ignore next */ report = isLinux() && process.report ? process.report.getReport() : {}; } return report; }; module.exports = { isLinux, getReport }; detect-libc-2.0.1/package.json000066400000000000000000000014611420243036100161540ustar00rootroot00000000000000{ "name": "detect-libc", "version": "2.0.1", "description": "Node.js module to detect the C standard library (libc) implementation family and version", "main": "lib/detect-libc.js", "files": [ "lib/", "index.d.ts" ], "scripts": { "test": "semistandard && nyc --reporter=lcov --check-coverage --branches=100 ava test/unit.js" }, "repository": { "type": "git", "url": "git://github.com/lovell/detect-libc" }, "keywords": [ "libc", "glibc", "musl" ], "author": "Lovell Fuller ", "contributors": [ "Niklas Salmoukas " ], "license": "Apache-2.0", "devDependencies": { "ava": "^2.4.0", "nyc": "^15.1.0", "proxyquire": "^2.1.3", "semistandard": "^14.2.3" }, "engines": { "node": ">=8" } } detect-libc-2.0.1/test/000077500000000000000000000000001420243036100146435ustar00rootroot00000000000000detect-libc-2.0.1/test/integration.js000066400000000000000000000003321420243036100175220ustar00rootroot00000000000000'use strict'; const { familySync, versionSync } = require('../'); const family = familySync() || 'unknown-family'; const version = versionSync() || 'unknown-version'; process.stdout.write(`${family} ${version}\n`); detect-libc-2.0.1/test/unit.js000066400000000000000000000136001420243036100161600ustar00rootroot00000000000000'use strict'; const test = require('ava'); const proxyquire = require('proxyquire') .noCallThru() .noPreserveCache(); test('constants', (t) => { t.plan(2); const libc = require('../'); t.is(libc.GLIBC, 'glibc'); t.is(libc.MUSL, 'musl'); }); test('linux - glibc family and version detected via report', async (t) => { t.plan(6); const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({ header: { glibcVersionRuntime: '1.23' } }) } }); t.is(await libc.family(), libc.GLIBC); t.is(await libc.version(), '1.23'); t.false(await libc.isNonGlibcLinux()); t.is(libc.familySync(), libc.GLIBC); t.is(libc.versionSync(), '1.23'); t.false(libc.isNonGlibcLinuxSync()); }); test('linux - musl family detected via report', async (t) => { t.plan(4); const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({ sharedObjects: ['/lib/ld-musl-x86_64.so.1'] }) } }); t.is(await libc.family(), libc.MUSL); t.true(await libc.isNonGlibcLinux()); t.is(libc.familySync(), libc.MUSL); t.true(libc.isNonGlibcLinuxSync()); }); test('linux - glibc family detected via async child process', async (t) => { t.plan(2); const out = 'glibc 1.23\nldd (GLIBC) 1.23\nCopyright\netc'; const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({}) }, child_process: { exec: (_c, cb) => cb(null, out) } }); t.is(await libc.family(), libc.GLIBC); t.false(await libc.isNonGlibcLinux()); }); test('linux - glibc family detected via sync child process', async (t) => { t.plan(2); const out = 'glibc 1.23\nldd (GLIBC) 1.23\nCopyright\netc'; const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({}) }, child_process: { execSync: () => out } }); t.is(libc.familySync(), libc.GLIBC); t.false(libc.isNonGlibcLinuxSync()); }); test('linux - musl family detected via child process', async (t) => { t.plan(4); const out = 'getconf: GNU_LIBC_VERSION: unknown variable\nmusl libc\nVersion 1.2.3\netc'; const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({ sharedObjects: [] }) }, child_process: { exec: (_c, cb) => cb(null, out), execSync: () => out } }); t.is(await libc.family(), libc.MUSL); t.true(await libc.isNonGlibcLinux()); t.is(libc.familySync(), libc.MUSL); t.true(libc.isNonGlibcLinuxSync()); }); test('linux - unknown family', async (t) => { t.plan(4); const out = 'unknown'; const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({}) }, child_process: { exec: (_c, cb) => cb(null, out), execSync: () => out } }); t.is(await libc.family(), null); t.true(await libc.isNonGlibcLinux()); t.is(libc.familySync(), null); t.true(libc.isNonGlibcLinuxSync()); }); test('linux - unknown family (exec fails)', async (t) => { t.plan(4); const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({}) }, child_process: { exec: (_c, cb) => cb(new Error()), execSync: () => { throw new Error(); } } }); t.is(await libc.family(), null); t.true(await libc.isNonGlibcLinux()); t.is(libc.familySync(), null); t.true(libc.isNonGlibcLinuxSync()); }); test('non-linux - unknown family', async (t) => { t.plan(4); const libc = proxyquire('../', { './process': { isLinux: () => false } }); t.is(await libc.family(), null); t.false(await libc.isNonGlibcLinux()); t.is(libc.familySync(), null); t.false(libc.isNonGlibcLinuxSync()); }); // version test('linux - glibc version detected via child process', async (t) => { t.plan(2); const out = 'glibc 1.23\nldd (GLIBC) 1.23\nCopyright\netc'; const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({}) }, child_process: { exec: (_c, cb) => cb(null, out), execSync: () => out } }); t.is(await libc.version(), '1.23'); t.is(libc.versionSync(), '1.23'); }); test('linux - musl version detected via child process', async (t) => { t.plan(2); const out = 'getconf: GNU_LIBC_VERSION: unknown variable\nmusl libc\nVersion 1.2.3\netc'; const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({}) }, child_process: { exec: (_c, cb) => cb(null, out), execSync: () => out } }); t.is(await libc.version(), '1.2.3'); t.is(libc.versionSync(), '1.2.3'); }); test('linux - unknown version', async (t) => { t.plan(2); const out = 'unknown'; const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({}) }, child_process: { exec: (_c, cb) => cb(null, out), execSync: () => out } }); t.is(await libc.version(), null); t.is(libc.versionSync(), null); }); test('linux - unknown version (exec fails)', async (t) => { t.plan(2); const libc = proxyquire('../', { './process': { isLinux: () => true, getReport: () => ({}) }, child_process: { exec: (_c, cb) => cb(new Error()), execSync: () => { throw new Error(); } } }); t.is(await libc.version(), null); t.is(libc.versionSync(), null); }); test('non-linux - unknown version', async (t) => { t.plan(2); const libc = proxyquire('../', { './process': { isLinux: () => false } }); t.is(await libc.version(), null); t.is(libc.versionSync(), null); }); test('process (internal)', (t) => { t.plan(3); const process = require('../lib/process'); t.is(typeof process.isLinux(), 'boolean'); t.is(typeof process.getReport(), 'object'); t.is(process.getReport(), process.getReport()); });