mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-15 09:06:25 +00:00
ecdcd9df4f
Rewrite of dependency extraction, particularly for npm. Paves way for easier addition of new package managers. Closes #1882
32 lines
850 B
JavaScript
32 lines
850 B
JavaScript
const yarnLockParser = require('@yarnpkg/lockfile');
|
|
|
|
module.exports = {
|
|
getYarnLock,
|
|
};
|
|
|
|
async function getYarnLock(filePath) {
|
|
const yarnLockRaw = await platform.getFile(filePath);
|
|
try {
|
|
const yarnLockParsed = yarnLockParser.parse(yarnLockRaw);
|
|
// istanbul ignore if
|
|
if (yarnLockParsed.type !== 'success') {
|
|
logger.info(
|
|
{ filePath, parseType: yarnLockParsed.type },
|
|
'Error parsing yarn.lock - not success'
|
|
);
|
|
return {};
|
|
}
|
|
const lockFile = {};
|
|
for (const [entry, val] of Object.entries(yarnLockParsed.object)) {
|
|
logger.trace({ entry, version: val.version });
|
|
lockFile[entry] = val.version;
|
|
}
|
|
return lockFile;
|
|
} catch (err) {
|
|
logger.info(
|
|
{ filePath, err, message: err.message },
|
|
'Warning: Exception parsing yarn.lock'
|
|
);
|
|
return {};
|
|
}
|
|
}
|