Load catalog definitions from the package manager's workspace YAML and/or root package.json
(rootDir: string, pm: PackageManager)
| 165 | |
| 166 | /** Load catalog definitions from the package manager's workspace YAML and/or root package.json */ |
| 167 | async function loadCatalogs(rootDir: string, pm: PackageManager): Promise<CatalogMap> { |
| 168 | // Only the package manager's own YAML file is consulted (pnpm-workspace.yaml |
| 169 | // for pnpm, .yarnrc.yml for Yarn) — other PMs don't recognize it. |
| 170 | let workspaceYaml: string | null = null; |
| 171 | const yamlFile = catalogYamlFile(pm); |
| 172 | if (yamlFile) { |
| 173 | const wsFile = resolve(rootDir, yamlFile); |
| 174 | if (await exists(wsFile)) { |
| 175 | workspaceYaml = await readText(wsFile); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | let pkgJsonText: string | null = null; |
| 180 | const pkgJsonPath = resolve(rootDir, 'package.json'); |
| 181 | if (await exists(pkgJsonPath)) { |
| 182 | pkgJsonText = await readText(pkgJsonPath); |
| 183 | } |
| 184 | |
| 185 | return parseCatalogs(workspaceYaml, pkgJsonText); |
| 186 | } |
| 187 | |
| 188 | /** Extract the catalog name from a `catalog:` / `catalog:<name>` range, normalizing the default alias */ |
| 189 | function catalogNameFromRange(range: string): string { |
no test coverage detected
searching dependent graphs…