| 46 | } |
| 47 | |
| 48 | function parseYarnLock(lockfilePath) { |
| 49 | const content = fs.readFileSync(lockfilePath, "utf-8"); |
| 50 | const lines = content.split("\n"); |
| 51 | |
| 52 | const packages = []; |
| 53 | let currentEntry = null; |
| 54 | |
| 55 | for (const line of lines) { |
| 56 | // New top-level entry (package descriptor line starts with a quote at column 0) |
| 57 | if (line.startsWith('"') && line.endsWith(":")) { |
| 58 | currentEntry = { descriptor: line.slice(0, -1), resolution: null, linkType: null }; |
| 59 | continue; |
| 60 | } |
| 61 | |
| 62 | if (!currentEntry) continue; |
| 63 | |
| 64 | const trimmed = line.trimStart(); |
| 65 | |
| 66 | if (trimmed.startsWith("resolution:")) { |
| 67 | // e.g. resolution: "@ai-sdk/anthropic@npm:3.0.50" |
| 68 | const match = trimmed.match(/resolution:\s*"(.+)"/); |
| 69 | if (match) { |
| 70 | currentEntry.resolution = match[1]; |
| 71 | } |
| 72 | } else if (trimmed.startsWith("linkType:")) { |
| 73 | const match = trimmed.match(/linkType:\s*(\w+)/); |
| 74 | if (match) { |
| 75 | currentEntry.linkType = match[1]; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // When we have both resolution and linkType, the entry is complete enough |
| 80 | if (currentEntry.resolution && currentEntry.linkType) { |
| 81 | if (currentEntry.linkType === "hard") { |
| 82 | packages.push(currentEntry.resolution); |
| 83 | } |
| 84 | currentEntry = null; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return packages; |
| 89 | } |
| 90 | |
| 91 | function parseResolution(resolution) { |
| 92 | // resolution format: "<name>@npm:<version>" |