Finds and parses the Yarn configuration file for the given project.
( projectDir: string, )
| 152 | |
| 153 | /** Finds and parses the Yarn configuration file for the given project. */ |
| 154 | async function findAndParseYarnConfiguration( |
| 155 | projectDir: string, |
| 156 | ): Promise<YarnConfiguration | null> { |
| 157 | const files = await Promise.all( |
| 158 | yarnConfigFiles.map(async (entry) => ({ |
| 159 | entry, |
| 160 | content: await readFileGracefully(path.join(projectDir, entry.fileName)), |
| 161 | })), |
| 162 | ); |
| 163 | const config = files.find((entry) => entry.content !== null); |
| 164 | if (config === undefined) { |
| 165 | return null; |
| 166 | } |
| 167 | |
| 168 | try { |
| 169 | return config.entry.parse(config.content!); |
| 170 | } catch (e) { |
| 171 | Log.debug(`Could not parse determined Yarn configuration file (${config.entry.fileName}).`); |
| 172 | Log.debug(`Error:`, e); |
| 173 | return null; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Reads the specified file gracefully. |
no test coverage detected