(baseDirOrAssertions?: unknown, returnNullOnConfigNotFound = false)
| 118 | returnNullOnConfigNotFound: true, |
| 119 | ): Promise<NgDevConfig<Assertions<A>> | null>; |
| 120 | export async function getConfig(baseDirOrAssertions?: unknown, returnNullOnConfigNotFound = false) { |
| 121 | let cachedConfig = getCachedConfig(); |
| 122 | |
| 123 | if (cachedConfig === null) { |
| 124 | let baseDir: string; |
| 125 | if (typeof baseDirOrAssertions === 'string') { |
| 126 | baseDir = baseDirOrAssertions; |
| 127 | } else { |
| 128 | baseDir = determineRepoBaseDirFromCwd(); |
| 129 | } |
| 130 | |
| 131 | // If the global config is not defined, load it from the file system. |
| 132 | // The full path to the configuration file. |
| 133 | const configPath = join(baseDir, CONFIG_FILE_PATH_MATCHER); |
| 134 | // Read the configuration and validate it before caching it for the future. |
| 135 | cachedConfig = await readConfigFile(configPath, returnNullOnConfigNotFound); |
| 136 | |
| 137 | if (returnNullOnConfigNotFound && !cachedConfig) { |
| 138 | return null; |
| 139 | } |
| 140 | |
| 141 | // Store the newly-read configuration in the cache. |
| 142 | setCachedConfig(cachedConfig); |
| 143 | } |
| 144 | |
| 145 | if (Array.isArray(baseDirOrAssertions)) { |
| 146 | for (const assertion of baseDirOrAssertions) { |
| 147 | assertion(cachedConfig); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // Return a clone of the cached global config to ensure that a new instance of the config |
| 152 | // is returned each time, preventing unexpected effects of modifications to the config object. |
| 153 | return {...cachedConfig, __isNgDevConfigObject: true}; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Get the local user configuration from the file system, returning the already loaded copy if it is |
no test coverage detected