# Lockfile lint's current version does not work with the updated structure of the yarn v2 lockfile # This patch updates it so that it can parse and read the lockfile entries. diff --git a/src/ParseLockfile.js b/src/ParseLockfile.js index 0f0c951027ec83c61769bb6a48943420dff133b8..bad2d251cf376bf3ef4b444a0d49f03a602d7a6e 100644 --- a/src/ParseLockfile.js +++ b/src/ParseLockfile.js @@ -21,13 +21,13 @@ const { * @return boolean */ function checkSampleContent (lockfile) { - const [sampleKey, sampleValue] = Object.entries(lockfile)[0] + const [sampleKey, sampleValue] = Object.entries(lockfile)[1] return ( sampleKey.match(/.*@.*/) && (sampleValue && typeof sampleValue === 'object' && sampleValue.hasOwnProperty('version') && - sampleValue.hasOwnProperty('resolved')) + sampleValue.hasOwnProperty('resolution')) ) } /** @@ -41,7 +41,24 @@ function yarnParseAndVerify (lockfileBuffer) { if (!hasSensibleContent) { throw Error('Lockfile does not seem to contain a valid dependency list') } - return {type: 'success', object: lockfile} + const normalized = Object.fromEntries(Object.entries(lockfile).map(([packageName, packageDetails]) => { + const resolution = packageDetails.resolution; + if (!resolution) { + return [packageName, packageDetails]; + } + const splitByAt = resolution.split('@'); + let resolvedPackageName; + let host; + if (splitByAt.length > 2 && resolution[0] === '@') { + resolvedPackageName = `@${splitByAt[1]}`; + host = splitByAt[2]; + } else { + [resolvedPackageName, host] = splitByAt; + } + + return [packageName, { ...packageDetails, resolved: host}] + })) + return {type: 'success', object: normalized} } class ParseLockfile { /**