* Resolves and reads the specified configuration file, optionally returning an empty object * if the configuration file cannot be read.
( configPath: string, returnNullOnConfigNotFound = false, )
| 221 | * if the configuration file cannot be read. |
| 222 | */ |
| 223 | async function readConfigFile( |
| 224 | configPath: string, |
| 225 | returnNullOnConfigNotFound = false, |
| 226 | ): Promise<{} | null> { |
| 227 | try { |
| 228 | // ESM imports expect a valid URL. On Windows, the disk name causes errors like: |
| 229 | // `ERR_UNSUPPORTED_ESM_URL_SCHEME: <..> Received protocol 'c:'` |
| 230 | return await import(pathToFileURL(configPath).toString()); |
| 231 | } catch (e) { |
| 232 | if (returnNullOnConfigNotFound) { |
| 233 | Log.debug( |
| 234 | `Could not read configuration file at ${configPath}, returning empty object instead.`, |
| 235 | ); |
| 236 | Log.debug(e); |
| 237 | |
| 238 | return null; |
| 239 | } |
| 240 | Log.error(`Could not read configuration file at ${configPath}.`); |
| 241 | Log.error(e); |
| 242 | process.exit(1); |
| 243 | } |
| 244 | } |
no test coverage detected