From 41b5c4b36b7bd6f6a3b1666ac67accb109e09ce6 Mon Sep 17 00:00:00 2001 From: Ameer Arsala Date: Thu, 22 Aug 2024 18:58:17 -0700 Subject: [PATCH 01/10] aye update your library brother --- lib/detect-libc.js | 2 +- lib/filesystem.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/detect-libc.js b/lib/detect-libc.js index fe49987..06f29b3 100644 --- a/lib/detect-libc.js +++ b/lib/detect-libc.js @@ -3,7 +3,7 @@ 'use strict'; -const childProcess = require('child_process'); +const childProcess = require('node:child_process'); const { isLinux, getReport } = require('./process'); const { LDD_PATH, readFile, readFileSync } = require('./filesystem'); diff --git a/lib/filesystem.js b/lib/filesystem.js index de7e007..0965c0b 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -3,7 +3,7 @@ 'use strict'; -const fs = require('fs'); +const fs = require('node:fs'); /** * The path where we can find the ldd From 3de162a019c4060450bfea1ee8dad949d2057f36 Mon Sep 17 00:00:00 2001 From: Ameer Arsala Date: Thu, 22 Aug 2024 19:00:25 -0700 Subject: [PATCH 02/10] forgot this --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d5adec3..9eeb2c0 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "author": "Lovell Fuller ", "contributors": [ "Niklas Salmoukas ", - "Vinícius Lourenço " + "Vinícius Lourenço ", + "Ameer Arsala " ], "license": "Apache-2.0", "devDependencies": { From 1e453cfa05032f74368c8578a748fa1eb40b316a Mon Sep 17 00:00:00 2001 From: Ameer Arsala Date: Thu, 22 Aug 2024 19:02:54 -0700 Subject: [PATCH 03/10] my version --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9eeb2c0..c50f7fe 100644 --- a/package.json +++ b/package.json @@ -14,18 +14,18 @@ }, "repository": { "type": "git", - "url": "git://github.com/lovell/detect-libc" + "url": "git://github.com/AmeerArsala/detect-libc" }, "keywords": [ "libc", "glibc", "musl" ], - "author": "Lovell Fuller ", + "author": "Ameer Arsala ", "contributors": [ + "Lovell Fuller ", "Niklas Salmoukas ", - "Vinícius Lourenço ", - "Ameer Arsala " + "Vinícius Lourenço " ], "license": "Apache-2.0", "devDependencies": { From 42360bcf60491c35eda4ed0b3c7d0e9c80424fb5 Mon Sep 17 00:00:00 2001 From: Ameer Arsala Date: Thu, 22 Aug 2024 19:04:24 -0700 Subject: [PATCH 04/10] this too --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c50f7fe..378bcf6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "detect-libc", - "version": "2.0.3", + "name": "@ameerarsala/detect-libc", + "version": "2.0.4-0", "description": "Node.js module to detect the C standard library (libc) implementation family and version", "main": "lib/detect-libc.js", "files": [ From ce45c62d197363a15f8238b7a1c53c948185053f Mon Sep 17 00:00:00 2001 From: Ameer Arsala Date: Thu, 22 Aug 2024 19:06:38 -0700 Subject: [PATCH 05/10] Updated README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 23212fd..a629bdb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # detect-libc +**IF YOU ARE READING THIS, YES. THIS ONE IS THE ONE THAT FIXES THE CLOUDFLARE ISSUE. HAVE FUN TESTING IN DEV!** + Node.js module to detect details of the C standard library (libc) implementation provided by a given Linux system. From 726f615c5d3764e61ec0f56144a93cf7f9390467 Mon Sep 17 00:00:00 2001 From: Ameer Arsala <56413920+AmeerArsala@users.noreply.github.com> Date: Sun, 25 Aug 2024 12:37:08 -0700 Subject: [PATCH 06/10] Update package.json --- package.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 378bcf6..d5adec3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@ameerarsala/detect-libc", - "version": "2.0.4-0", + "name": "detect-libc", + "version": "2.0.3", "description": "Node.js module to detect the C standard library (libc) implementation family and version", "main": "lib/detect-libc.js", "files": [ @@ -14,16 +14,15 @@ }, "repository": { "type": "git", - "url": "git://github.com/AmeerArsala/detect-libc" + "url": "git://github.com/lovell/detect-libc" }, "keywords": [ "libc", "glibc", "musl" ], - "author": "Ameer Arsala ", + "author": "Lovell Fuller ", "contributors": [ - "Lovell Fuller ", "Niklas Salmoukas ", "Vinícius Lourenço " ], From ba39587c1fa5d729373dda22747ec8843b0ee344 Mon Sep 17 00:00:00 2001 From: Ameer Arsala <56413920+AmeerArsala@users.noreply.github.com> Date: Sun, 25 Aug 2024 12:39:07 -0700 Subject: [PATCH 07/10] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index a629bdb..23212fd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # detect-libc -**IF YOU ARE READING THIS, YES. THIS ONE IS THE ONE THAT FIXES THE CLOUDFLARE ISSUE. HAVE FUN TESTING IN DEV!** - Node.js module to detect details of the C standard library (libc) implementation provided by a given Linux system. From b54f208fafbdbca4ebc062e4fc65d0144eeeb852 Mon Sep 17 00:00:00 2001 From: Ameer Arsala Date: Wed, 28 Aug 2024 12:58:24 -0700 Subject: [PATCH 08/10] made the necessary safeRequire adjustments --- lib/detect-libc.js | 3 ++- lib/filesystem.js | 3 ++- lib/utils.js | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 lib/utils.js diff --git a/lib/detect-libc.js b/lib/detect-libc.js index 06f29b3..fc08edf 100644 --- a/lib/detect-libc.js +++ b/lib/detect-libc.js @@ -3,7 +3,8 @@ 'use strict'; -const childProcess = require('node:child_process'); +const { safeRequire } = require('./utils'); +const childProcess = safeRequire('child_process', 'node:child_process'); const { isLinux, getReport } = require('./process'); const { LDD_PATH, readFile, readFileSync } = require('./filesystem'); diff --git a/lib/filesystem.js b/lib/filesystem.js index 0965c0b..2322f5c 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -3,7 +3,8 @@ 'use strict'; -const fs = require('node:fs'); +const { safeRequire } = require('./utils'); +const fs = safeRequire('fs', 'node:fs'); /** * The path where we can find the ldd diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 0000000..ceb11eb --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,22 @@ +'use strict'; + +// Safe require +const safeRequire = (moduleName, ...fallbacks) => { + try { + // Try to require the primary module + return require(moduleName); + } catch (error) { + // If module not found, try fallbacks + for (const fallback of fallbacks) { + try { + return require(fallback); + } catch (fallbackError) { + // Skip to the next fallback if it fails + } + } + + return null; + } +}; + +module.exports = { safeRequire }; From ad136dddbd9a305641fe9c8fa7eb4f491894f8ac Mon Sep 17 00:00:00 2001 From: Ameer Arsala Date: Fri, 27 Sep 2024 13:53:40 -0700 Subject: [PATCH 09/10] added null safety --- lib/detect-libc.js | 12 ++++++++---- lib/filesystem.js | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/detect-libc.js b/lib/detect-libc.js index fc08edf..0087947 100644 --- a/lib/detect-libc.js +++ b/lib/detect-libc.js @@ -17,10 +17,13 @@ let commandOut = ''; const safeCommand = () => { if (!commandOut) { return new Promise((resolve) => { - childProcess.exec(command, (err, out) => { - commandOut = err ? ' ' : out; - resolve(commandOut); - }); + // null check + if (childProcess) { + childProcess.exec(command, (err, out) => { + commandOut = err ? ' ' : out; + resolve(commandOut); + }); + } }); } return commandOut; @@ -29,6 +32,7 @@ const safeCommand = () => { const safeCommandSync = () => { if (!commandOut) { try { + // No null check needed since the error will be caught commandOut = childProcess.execSync(command, { encoding: 'utf8' }); } catch (_err) { commandOut = ' '; diff --git a/lib/filesystem.js b/lib/filesystem.js index 2322f5c..e863b0a 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -17,7 +17,7 @@ const LDD_PATH = '/usr/bin/ldd'; * @param {string} path * @returns {string} */ -const readFileSync = (path) => fs.readFileSync(path, 'utf-8'); +const readFileSync = (path) => fs ? fs.readFileSync(path, 'utf-8') : null; /** * Read the content of a file @@ -26,13 +26,16 @@ const readFileSync = (path) => fs.readFileSync(path, 'utf-8'); * @returns {Promise} */ const readFile = (path) => new Promise((resolve, reject) => { - fs.readFile(path, 'utf-8', (err, data) => { - if (err) { - reject(err); - } else { - resolve(data); - } - }); + // null check + if (fs) { + fs.readFile(path, 'utf-8', (err, data) => { + if (err) { + reject(err); + } else { + resolve(data); + } + }); + } }); module.exports = { From 70c9c320f1312fd0aa882093dec9f2e17d3ce84b Mon Sep 17 00:00:00 2001 From: Ameer Arsala Date: Sat, 28 Sep 2024 07:28:45 -0700 Subject: [PATCH 10/10] using a traditional loop now --- lib/utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index ceb11eb..63bb2b3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -7,7 +7,8 @@ const safeRequire = (moduleName, ...fallbacks) => { return require(moduleName); } catch (error) { // If module not found, try fallbacks - for (const fallback of fallbacks) { + for (let i = 0; i < fallbacks.length; i++) { + const fallback = fallbacks[i]; try { return require(fallback); } catch (fallbackError) {