workspace-tools
Version:
A collection of utilities that are useful in a git-controlled monorepo managed by one of these tools:
37 lines • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseBerryLock = void 0;
/**
* Convert a Yarn Berry (v2+) YAML lock file contents into a standardized format.
*/
function parseBerryLock(yaml) {
const results = {};
if (yaml) {
for (const [keySpec, descriptor] of Object.entries(yaml)) {
if (keySpec === "__metadata") {
continue;
}
const keys = keySpec.split(", ");
for (const key of keys) {
const normalizedKey = normalizeKey(key);
results[normalizedKey] = {
version: descriptor.version,
dependencies: descriptor.dependencies ?? {},
};
}
}
}
return {
object: results,
type: "success",
};
}
exports.parseBerryLock = parseBerryLock;
// normalizes the version range as a key lookup
function normalizeKey(key) {
if (key.includes("npm:")) {
return key.replace(/npm:/, "");
}
return key;
}
//# sourceMappingURL=parseBerryLock.js.map