* 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)
| 382 | * @return {Promise<{[key: string]: unknown} | undefined>} |
| 383 | */ |
| 384 | async 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 |
no outgoing calls
no test coverage detected
searching dependent graphs…