@lhci/utils
Advanced tools
Comparing version 0.3.7 to 0.3.8
{ | ||
"name": "@lhci/utils", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"license": "Apache-2.0", | ||
@@ -17,3 +17,3 @@ "repository": { | ||
}, | ||
"gitHead": "3a34a7b0a9f57b78ec1d5c1be5263262408c61fa" | ||
"gitHead": "2204f91151a2558a1ea3fe68677c5f6a9385747f" | ||
} |
@@ -14,2 +14,4 @@ /** | ||
const RC_FILE_NAMES = [ | ||
'.lighthouserc.js', | ||
'lighthouserc.js', | ||
'.lighthouserc.json', | ||
@@ -23,2 +25,3 @@ 'lighthouserc.json', | ||
const JS_FILE_EXTENSION_REGEX = /\.(js)$/i; | ||
const YAML_FILE_EXTENSION_REGEX = /\.(yml|yaml)$/i; | ||
@@ -73,3 +76,8 @@ | ||
function parseFileContentToJSON(pathToRcFile, contents) { | ||
// Check if file path ends in yaml or yml | ||
// Check if file path ends in .js | ||
if (JS_FILE_EXTENSION_REGEX.test(pathToRcFile)) { | ||
return require(pathToRcFile); | ||
} | ||
// Check if file path ends in .yaml or .yml | ||
if (YAML_FILE_EXTENSION_REGEX.test(pathToRcFile)) { | ||
@@ -79,2 +87,4 @@ // Parse yaml content to JSON | ||
} | ||
// Fallback to JSON parsing | ||
return JSON.parse(contents); | ||
@@ -81,0 +91,0 @@ } |
@@ -13,2 +13,3 @@ /** | ||
const ASSERTION_RESULTS_PATH = path.join(LHCI_DIR, 'assertion-results.json'); | ||
const URL_LINK_MAP_PATH = path.join(LHCI_DIR, 'links.json'); | ||
@@ -104,2 +105,16 @@ function ensureDirectoryExists(baseDir = LHCI_DIR) { | ||
/** | ||
* @param {Map<string, string>} targetUrlMap | ||
*/ | ||
function writeUrlMapToFile(targetUrlMap) { | ||
/** @type {Record<string, string>} */ | ||
const urlMapAsObject = {}; | ||
for (const [testedUrl, link] of targetUrlMap.entries()) { | ||
urlMapAsObject[testedUrl] = link; | ||
} | ||
fs.writeFileSync(URL_LINK_MAP_PATH, JSON.stringify(urlMapAsObject, null, 2)); | ||
} | ||
module.exports = { | ||
@@ -114,2 +129,3 @@ getHTMLReportForLHR, | ||
replaceUrlPatterns, | ||
writeUrlMapToFile, | ||
}; |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
379378
8776
12