MCPcopy Create free account
hub / github.com/toplenboren/simple-git-hooks / _getConfigFromFile

Function _getConfigFromFile

simple-git-hooks.js:459–484  ·  view source on GitHub ↗

* Gets user-set config from file * Since the file is not required in node.js projects it returns undefined if something is off * @param {string} projectRootPath * @param {string} fileName * @return {Promise<{[key: string]: unknown} | undefined>}

(projectRootPath, fileName)

Source from the content-addressed store, hash-verified

457 * @return {Promise<{[key: string]: unknown} | undefined>}
458 */
459async function _getConfigFromFile(projectRootPath, fileName) {
460 if (typeof projectRootPath !== "string") {
461 throw TypeError("projectRootPath is not a string")
462 }
463
464 if (typeof fileName !== "string") {
465 throw TypeError("fileName is not a string")
466 }
467
468 try {
469 const filePath = path.isAbsolute(fileName)
470 ? fileName
471 : path.normalize(projectRootPath + '/' + fileName)
472 if (filePath === __filename) {
473 return undefined
474 }
475 // handle `.json` with `require`, `import()` requires `with:{type:'json'}` which does not work for all engines
476 if (filePath.endsWith('.json')) {
477 return require(filePath)
478 }
479 const result = await import(url.pathToFileURL(filePath)) // handle `.cjs`, `.js`, `.mjs`
480 return result.default || result
481 } catch (err) {
482 return undefined
483 }
484}
485
486/**
487 * Validates the config, checks that every git hook or option is named correctly

Callers 1

_getConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected