11// Copyright 2017 Lovell Fuller and others.
22// SPDX-License-Identifier: Apache-2.0
33
4- ' use strict' ;
4+ " use strict" ;
55
6- const childProcess = require ( 'node:child_process' ) ;
7- const { isLinux, getReport } = require ( './process' ) ;
8- const { LDD_PATH , readFile, readFileSync } = require ( './filesystem' ) ;
6+ const { safeRequire } = require ( "./utils" ) ;
7+
8+ const childProcess = safeRequire ( "child_process" , "node:child_process" ) ;
9+ const { isLinux, getReport } = require ( "./process" ) ;
10+ const { LDD_PATH , readFile, readFileSync } = require ( "./filesystem" ) ;
911
1012let cachedFamilyFilesystem ;
1113let cachedVersionFilesystem ;
1214
13- const command = 'getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true' ;
14- let commandOut = '' ;
15+ const command =
16+ "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true" ;
17+ let commandOut = "" ;
1518
1619const safeCommand = ( ) => {
1720 if ( ! commandOut ) {
1821 return new Promise ( ( resolve ) => {
1922 childProcess . exec ( command , ( err , out ) => {
20- commandOut = err ? ' ' : out ;
23+ commandOut = err ? " " : out ;
2124 resolve ( commandOut ) ;
2225 } ) ;
2326 } ) ;
@@ -28,9 +31,9 @@ const safeCommand = () => {
2831const safeCommandSync = ( ) => {
2932 if ( ! commandOut ) {
3033 try {
31- commandOut = childProcess . execSync ( command , { encoding : ' utf8' } ) ;
34+ commandOut = childProcess . execSync ( command , { encoding : " utf8" } ) ;
3235 } catch ( _err ) {
33- commandOut = ' ' ;
36+ commandOut = " " ;
3437 }
3538 }
3639 return commandOut ;
@@ -41,7 +44,7 @@ const safeCommandSync = () => {
4144 * @type {string }
4245 * @public
4346 */
44- const GLIBC = ' glibc' ;
47+ const GLIBC = " glibc" ;
4548
4649/**
4750 * A Regexp constant to get the GLIBC Version.
@@ -54,9 +57,9 @@ const RE_GLIBC_VERSION = /LIBC[a-z0-9 \-).]*?(\d+\.\d+)/i;
5457 * @type {string }
5558 * @public
5659 */
57- const MUSL = ' musl' ;
60+ const MUSL = " musl" ;
5861
59- const isFileMusl = ( f ) => f . includes ( ' libc.musl-' ) || f . includes ( ' ld-musl-' ) ;
62+ const isFileMusl = ( f ) => f . includes ( " libc.musl-" ) || f . includes ( " ld-musl-" ) ;
6063
6164const familyFromReport = ( ) => {
6265 const report = getReport ( ) ;
@@ -83,10 +86,10 @@ const familyFromCommand = (out) => {
8386} ;
8487
8588const getFamilyFromLddContent = ( content ) => {
86- if ( content . includes ( ' musl' ) ) {
89+ if ( content . includes ( " musl" ) ) {
8790 return MUSL ;
8891 }
89- if ( content . includes ( ' GNU C Library' ) ) {
92+ if ( content . includes ( " GNU C Library" ) ) {
9093 return GLIBC ;
9194 }
9295 return null ;
@@ -158,7 +161,7 @@ const familySync = () => {
158161 * Resolves `true` only when the platform is Linux and the libc family is not `glibc`.
159162 * @returns {Promise<boolean> }
160163 */
161- const isNonGlibcLinux = async ( ) => isLinux ( ) && await family ( ) !== GLIBC ;
164+ const isNonGlibcLinux = async ( ) => isLinux ( ) && ( await family ( ) ) !== GLIBC ;
162165
163166/**
164167 * Returns `true` only when the platform is Linux and the libc family is not `glibc`.
@@ -263,5 +266,5 @@ module.exports = {
263266 isNonGlibcLinux,
264267 isNonGlibcLinuxSync,
265268 version,
266- versionSync
269+ versionSync,
267270} ;
0 commit comments