Select Git revision
commit_analyzer_default_test.go
lock-files.js 10.24 KiB
const fs = require('fs-extra');
const path = require('path');
const upath = require('upath');
const npm = require('./npm');
const yarn = require('./yarn');
module.exports = {
hasPackageLock,
hasYarnLock,
determineLockFileDirs,
writeExistingFiles,
writeUpdatedPackageFiles,
getUpdatedLockFiles,
};
function hasPackageLock(config, packageFile) {
logger.trace(
{ packageFiles: config.packageFiles, packageFile },
'hasPackageLock'
);
for (const p of config.packageFiles) {
if (p.packageFile === packageFile) {
if (p.packageLock) {
return true;
}
return false;
}
}
throw new Error(`hasPackageLock cannot find ${packageFile}`);
}
function hasYarnLock(config, packageFile) {
logger.trace(
{ packageFiles: config.packageFiles, packageFile },
'hasYarnLock'
);
for (const p of config.packageFiles) {
if (p.packageFile === packageFile) {
if (p.yarnLock) {
return true;
}
return false;
}
}
throw new Error(`hasYarnLock cannot find ${packageFile}`);
}
function determineLockFileDirs(config) {
const packageLockFileDirs = [];
const yarnLockFileDirs = [];
for (const upgrade of config.upgrades) {
if (upgrade.type === 'lockFileMaintenance') {
// Return every direcotry that contains a lockfile
for (const packageFile of config.packageFiles) {
const dirname = path.dirname(packageFile.packageFile);
if (packageFile.yarnLock) {
yarnLockFileDirs.push(dirname);
}
if (packageFile.packageLock) {
packageLockFileDirs.push(dirname);
}
}
return { packageLockFileDirs, yarnLockFileDirs };
}
}
for (const packageFile of config.updatedPackageFiles) {
if (module.exports.hasYarnLock(config, packageFile.name)) {
yarnLockFileDirs.push(path.dirname(packageFile.name));