MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / parseYarnLock

Function parseYarnLock

scripts/fetchLicenses.mjs:48–89  ·  view source on GitHub ↗
(lockfilePath)

Source from the content-addressed store, hash-verified

46}
47
48function 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
91function parseResolution(resolution) {
92 // resolution format: "<name>@npm:<version>"

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected