(cwd = process.cwd())
| 66 | * `path` by resolving the input when it's missing. |
| 67 | */ |
| 68 | export function loadLinks(cwd = process.cwd()): LinkedRepo[] { |
| 69 | try { |
| 70 | const parsed = JSON.parse(fs.readFileSync(linksFilePath(cwd), "utf8")) as { |
| 71 | links?: Array<Partial<LinkedRepo>> |
| 72 | } |
| 73 | if (!Array.isArray(parsed.links)) return [] |
| 74 | const out: LinkedRepo[] = [] |
| 75 | for (const raw of parsed.links) { |
| 76 | if (!raw) continue |
| 77 | const input = typeof raw.input === "string" ? raw.input : typeof raw.path === "string" ? raw.path : undefined |
| 78 | if (!input) continue |
| 79 | const resolved = typeof raw.path === "string" ? raw.path : resolveLinkTarget(input) |
| 80 | if (!resolved) continue |
| 81 | out.push({ input, path: resolved }) |
| 82 | } |
| 83 | return out |
| 84 | } catch { |
| 85 | return [] |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | function saveLinks(cwd: string, links: LinkedRepo[]): void { |
| 90 | const file = linksFilePath(cwd) |
no test coverage detected