-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(detect-libc): faster musl check by looking for ldd file
- Loading branch information
Showing
5 changed files
with
534 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @type {Record<string, string | undefined | null>} | ||
*/ | ||
const cacheObject = {}; | ||
|
||
module.exports = { | ||
cacheFn: (key, fn, async = false) => { | ||
return () => { | ||
const cachedValue = cacheObject[key]; | ||
|
||
if (cachedValue !== undefined) { | ||
if (async) { | ||
return Promise.resolve(cachedValue); | ||
} | ||
|
||
return cachedValue; | ||
} | ||
|
||
const result = fn(); | ||
|
||
if (async) { | ||
return result.then(value => { | ||
cacheObject[key] = value; | ||
|
||
return value; | ||
}); | ||
} | ||
|
||
cacheObject[key] = result; | ||
|
||
return result; | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
Oops, something went wrong.