2017-11-05 04:45:49 +00:00
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const { migrateAndValidate } = require('../config/migrate-validate');
|
|
|
|
const presets = require('../config/presets');
|
|
|
|
|
|
|
|
const manager = require('./index');
|
|
|
|
const dockerResolve = require('../manager/docker/resolve');
|
|
|
|
const { mergeChildConfig } = require('../config');
|
|
|
|
const { checkMonorepos } = require('../manager/npm/monorepos');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
resolvePackageFiles,
|
|
|
|
};
|
|
|
|
|
|
|
|
async function resolvePackageFiles(config) {
|
|
|
|
logger.trace({ config }, 'resolvePackageFiles()');
|
|
|
|
const allPackageFiles = config.packageFiles.length
|
|
|
|
? config.packageFiles
|
|
|
|
: await manager.detectPackageFiles(config);
|
2017-11-05 12:51:29 +00:00
|
|
|
logger.debug({ allPackageFiles }, 'allPackageFiles');
|
2017-11-17 05:06:06 +00:00
|
|
|
async function resolvePackageFile(p) {
|
|
|
|
const packageFile = typeof p === 'string' ? { packageFile: p } : p;
|
2017-11-05 04:45:49 +00:00
|
|
|
if (packageFile.packageFile.endsWith('package.json')) {
|
|
|
|
logger.debug(`Resolving packageFile ${JSON.stringify(packageFile)}`);
|
2017-11-08 11:23:32 +00:00
|
|
|
const pFileRaw = await platform.getFile(packageFile.packageFile);
|
2017-11-05 04:45:49 +00:00
|
|
|
if (!pFileRaw) {
|
|
|
|
logger.info(
|
|
|
|
{ packageFile: packageFile.packageFile },
|
|
|
|
'Cannot find package.json'
|
|
|
|
);
|
|
|
|
config.errors.push({
|
|
|
|
depName: packageFile.packageFile,
|
|
|
|
message: 'Cannot find package.json',
|
|
|
|
});
|
2017-11-17 05:06:06 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
packageFile.content = JSON.parse(pFileRaw);
|
|
|
|
} catch (err) {
|
|
|
|
logger.info(
|
|
|
|
{ packageFile: packageFile.packageFile },
|
|
|
|
'Cannot parse package.json'
|
|
|
|
);
|
|
|
|
config.warnings.push({
|
|
|
|
depName: packageFile.packageFile,
|
|
|
|
message: 'Cannot parse package.json (invalid JSON)',
|
|
|
|
});
|
|
|
|
return null;
|
2017-11-05 04:45:49 +00:00
|
|
|
}
|
|
|
|
if (!config.ignoreNpmrcFile) {
|
2017-11-08 11:23:32 +00:00
|
|
|
packageFile.npmrc = await platform.getFile(
|
2017-11-05 04:45:49 +00:00
|
|
|
path.join(path.dirname(packageFile.packageFile), '.npmrc')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (!packageFile.npmrc) {
|
|
|
|
delete packageFile.npmrc;
|
|
|
|
}
|
2017-11-08 11:23:32 +00:00
|
|
|
packageFile.yarnrc = await platform.getFile(
|
2017-11-05 04:45:49 +00:00
|
|
|
path.join(path.dirname(packageFile.packageFile), '.yarnrc')
|
|
|
|
);
|
|
|
|
if (!packageFile.yarnrc) {
|
|
|
|
delete packageFile.yarnrc;
|
|
|
|
}
|
2017-11-17 05:06:06 +00:00
|
|
|
// hoist renovate config if exists
|
|
|
|
if (packageFile.content.renovate) {
|
|
|
|
logger.debug(
|
|
|
|
{
|
|
|
|
packageFile: packageFile.packageFile,
|
|
|
|
config: packageFile.content.renovate,
|
|
|
|
},
|
|
|
|
`Found package.json renovate config`
|
|
|
|
);
|
|
|
|
const migratedConfig = migrateAndValidate(
|
|
|
|
config,
|
|
|
|
packageFile.content.renovate
|
|
|
|
);
|
|
|
|
logger.debug(
|
|
|
|
{ config: migratedConfig },
|
|
|
|
'package.json migrated config'
|
2017-11-05 04:45:49 +00:00
|
|
|
);
|
2017-11-17 05:06:06 +00:00
|
|
|
const resolvedConfig = await presets.resolveConfigPresets(
|
|
|
|
migratedConfig
|
2017-11-05 04:45:49 +00:00
|
|
|
);
|
2017-11-17 05:06:06 +00:00
|
|
|
logger.debug(
|
|
|
|
{ config: resolvedConfig },
|
|
|
|
'package.json resolved config'
|
|
|
|
);
|
|
|
|
Object.assign(packageFile, resolvedConfig);
|
|
|
|
delete packageFile.content.renovate;
|
2017-11-05 04:45:49 +00:00
|
|
|
} else {
|
2017-11-17 05:06:06 +00:00
|
|
|
logger.debug(
|
|
|
|
{ packageFile: packageFile.packageFile },
|
|
|
|
`No renovate config`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Detect if lock files are used
|
|
|
|
const yarnLockFileName = path.join(
|
|
|
|
path.dirname(packageFile.packageFile),
|
|
|
|
'yarn.lock'
|
|
|
|
);
|
|
|
|
packageFile.yarnLock = await platform.getFile(yarnLockFileName);
|
|
|
|
if (packageFile.yarnLock) {
|
|
|
|
logger.debug(
|
|
|
|
{ packageFile: packageFile.packageFile },
|
|
|
|
'Found yarn.lock'
|
|
|
|
);
|
2017-11-05 04:45:49 +00:00
|
|
|
}
|
2017-11-17 05:06:06 +00:00
|
|
|
const packageLockFileName = path.join(
|
|
|
|
path.dirname(packageFile.packageFile),
|
|
|
|
'package-lock.json'
|
|
|
|
);
|
|
|
|
packageFile.packageLock = await platform.getFile(packageLockFileName);
|
|
|
|
if (packageFile.packageLock) {
|
|
|
|
logger.debug(
|
|
|
|
{ packageFile: packageFile.packageFile },
|
|
|
|
'Found package-lock.json'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return packageFile;
|
2017-11-05 04:45:49 +00:00
|
|
|
} else if (packageFile.packageFile.endsWith('package.js')) {
|
|
|
|
// meteor
|
2017-11-17 05:06:06 +00:00
|
|
|
return mergeChildConfig(config.meteor, packageFile);
|
2017-11-05 04:45:49 +00:00
|
|
|
} else if (packageFile.packageFile.endsWith('Dockerfile')) {
|
|
|
|
logger.debug('Resolving Dockerfile');
|
2017-11-17 05:06:06 +00:00
|
|
|
return dockerResolve.resolvePackageFile(config, packageFile);
|
2017-11-05 04:45:49 +00:00
|
|
|
}
|
2017-11-17 05:06:06 +00:00
|
|
|
return null;
|
2017-11-05 04:45:49 +00:00
|
|
|
}
|
2017-11-17 05:06:06 +00:00
|
|
|
logger.debug('queue');
|
|
|
|
const queue = allPackageFiles.map(p => resolvePackageFile(p));
|
|
|
|
const packageFiles = (await Promise.all(queue)).filter(p => p !== null);
|
2017-11-05 04:45:49 +00:00
|
|
|
return checkMonorepos({ ...config, packageFiles });
|
|
|
|
}
|