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

Function _getConfigFromFile

simple-git-hooks.js:384–409  ·  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

382 * @return {Promise<{[key: string]: unknown} | undefined>}
383 */
384async function _getConfigFromFile(projectRootPath, fileName) {
385 if (typeof projectRootPath !== "string") {
386 throw TypeError("projectRootPath is not a string")
387 }
388
389 if (typeof fileName !== "string") {
390 throw TypeError("fileName is not a string")
391 }
392
393 try {
394 const filePath = path.isAbsolute(fileName)
395 ? fileName
396 : path.normalize(projectRootPath + '/' + fileName)
397 if (filePath === __filename) {
398 return undefined
399 }
400 // handle `.json` with `require`, `import()` requires `with:{type:'json'}` which does not work for all engines
401 if (filePath.endsWith('.json')) {
402 return require(filePath)
403 }
404 const result = await import(url.pathToFileURL(filePath)) // handle `.cjs`, `.js`, `.mjs`
405 return result.default || result
406 } catch (err) {
407 return undefined
408 }
409}
410
411/**
412 * 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…