MCPcopy Create free account
hub / github.com/angular/dev-infra / readConfigFile

Function readConfigFile

ng-dev/utils/config.ts:223–244  ·  view source on GitHub ↗

* Resolves and reads the specified configuration file, optionally returning an empty object * if the configuration file cannot be read.

(
  configPath: string,
  returnNullOnConfigNotFound = false,
)

Source from the content-addressed store, hash-verified

221 * if the configuration file cannot be read.
222 */
223async 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}

Callers 2

getConfigFunction · 0.85
getUserConfigFunction · 0.85

Calls 2

toStringMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected