refactor: use manager not packageFile

This commit is contained in:
Rhys Arkins 2018-02-28 19:01:35 +01:00
parent c4cdfe8989
commit cf336a0b21
7 changed files with 47 additions and 37 deletions

View file

@ -62,15 +62,16 @@ async function detectPackageFiles(config) {
}
function getPackageUpdates(config) {
if (config.packageFile.endsWith('Dockerfile')) {
const { manager } = config;
if (manager === 'docker') {
return docker.getPackageUpdates(config);
} else if (config.packageFile.endsWith('package.json')) {
} else if (manager === 'npm') {
return npm.getPackageUpdates(config);
} else if (config.packageFile.endsWith('package.js')) {
} else if (manager === 'meteor') {
return npm.getPackageUpdates(config);
} else if (config.packageFile.endsWith('.travis.yml')) {
} else if (manager === 'node') {
return node.getPackageUpdates(config);
} else if (config.packageFile.endsWith('WORKSPACE')) {
} else if (manager === 'bazel') {
return bazel.getPackageUpdates(config);
}
logger.info(`Cannot find manager for ${config.packageFile}`);
@ -81,12 +82,13 @@ async function getUpdatedPackageFiles(config) {
const updatedPackageFiles = {};
for (const upgrade of config.upgrades) {
const { manager } = upgrade;
if (upgrade.type !== 'lockFileMaintenance') {
const existingContent =
updatedPackageFiles[upgrade.packageFile] ||
(await platform.getFile(upgrade.packageFile, config.parentBranch));
let newContent = existingContent;
if (upgrade.packageFile.endsWith('package.json')) {
if (manager === 'npm') {
newContent = npmUpdater.setNewValue(
existingContent,
upgrade.depType,
@ -98,18 +100,18 @@ async function getUpdatedPackageFiles(config) {
upgrade.currentPackageJsonVersion,
upgrade.bumpVersion
);
} else if (upgrade.packageFile.endsWith('package.js')) {
} else if (manager === 'meteor') {
newContent = meteorUpdater.setNewValue(
existingContent,
upgrade.depName,
upgrade.currentVersion,
upgrade.newVersion
);
} else if (upgrade.packageFile.endsWith('Dockerfile')) {
} else if (manager === 'docker') {
newContent = dockerfileHelper.setNewValue(existingContent, upgrade);
} else if (upgrade.packageFile.endsWith('.travis.yml')) {
} else if (manager === 'node') {
newContent = nodeHelper.setNewValue(existingContent, upgrade);
} else if (upgrade.packageFile.endsWith('WORKSPACE')) {
} else if (manager === 'bazel') {
newContent = await bazelHelper.setNewValue(existingContent, upgrade);
}
if (!newContent) {

View file

@ -28,7 +28,8 @@ async function renovateDepType(
return [];
}
let deps = [];
if (config.packageFile.endsWith('package.json')) {
const { manager } = config;
if (manager === 'npm') {
// Extract all dependencies from the package.json
deps = await packageJson.extractDependencies(
packageContent,
@ -43,13 +44,13 @@ async function renovateDepType(
}
logger.debug(`deps length is ${deps.length}`);
logger.debug({ deps }, `deps`);
} else if (config.packageFile.endsWith('package.js')) {
} else if (manager === 'meteor') {
deps = meteorExtract.extractDependencies(packageContent);
} else if (config.packageFile.endsWith('Dockerfile')) {
} else if (manager === 'docker') {
deps = dockerExtract.extractDependencies(packageContent);
} else if (config.packageFile.endsWith('.travis.yml')) {
} else if (manager === 'node') {
deps = nodeExtract.extractDependencies(packageContent);
} else if (config.packageFile.endsWith('WORKSPACE')) {
} else if (manager === 'bazel') {
deps = bazelExtract.extractDependencies(packageContent);
}
deps = deps.filter(

View file

@ -17,7 +17,8 @@ async function determineRepoUpgrades(config) {
logger.trace({ fullPackageFile: packageFile });
let packageFileConfig = mergeChildConfig(config, packageFile);
packageFileConfig = filterConfig(packageFileConfig, 'packageFile');
if (packageFileConfig.packageFile.endsWith('package.json')) {
const { manager } = packageFileConfig;
if (manager === 'npm') {
logger.info(
{ packageFile: packageFileConfig.packageFile },
'Renovating package.json dependencies'
@ -25,22 +26,22 @@ async function determineRepoUpgrades(config) {
upgrades = upgrades.concat(
await packageFileWorker.renovatePackageFile(packageFileConfig)
);
} else if (packageFileConfig.packageFile.endsWith('package.js')) {
} else if (manager === 'meteor') {
logger.info('Renovating package.js (meteor) dependencies');
upgrades = upgrades.concat(
await packageFileWorker.renovateMeteorPackageFile(packageFileConfig)
);
} else if (packageFileConfig.packageFile.endsWith('Dockerfile')) {
} else if (manager === 'docker') {
logger.info('Renovating Dockerfile FROM');
upgrades = upgrades.concat(
await packageFileWorker.renovateDockerfile(packageFileConfig)
);
} else if (packageFileConfig.packageFile.endsWith('.travis.yml')) {
} else if (manager === 'node') {
logger.info('Renovating .travis.yml node_js versions');
upgrades = upgrades.concat(
await packageFileWorker.renovateNodeFile(packageFileConfig)
);
} else if (packageFileConfig.packageFile.endsWith('WORKSPACE')) {
} else if (manager === 'bazel') {
logger.info('Renovating bazel WORKSPACE dependencies');
upgrades = upgrades.concat(
await packageFileWorker.renovateBazelFile(packageFileConfig)

View file

@ -134,7 +134,7 @@ describe('manager', () => {
it('recurses if setNewValue error', async () => {
config.parentBranch = 'some-branch';
config.canRebase = true;
config.upgrades = [{ packageFile: 'package.json' }];
config.upgrades = [{ packageFile: 'package.json', manager: 'npm' }];
npmUpdater.setNewValue.mockReturnValueOnce(null);
npmUpdater.setNewValue.mockReturnValueOnce('some content');
const res = await getUpdatedPackageFiles(config);
@ -154,11 +154,11 @@ describe('manager', () => {
config.parentBranch = 'some-branch';
config.canRebase = true;
config.upgrades = [
{ packageFile: 'package.json' },
{ packageFile: 'Dockerfile' },
{ packageFile: 'packages/foo/package.js' },
{ packageFile: '.travis.yml' },
{ packageFile: 'WORKSPACE' },
{ packageFile: 'package.json', manager: 'npm' },
{ packageFile: 'Dockerfile', manager: 'docker' },
{ packageFile: 'packages/foo/package.js', manager: 'meteor' },
{ packageFile: '.travis.yml', manager: 'node' },
{ packageFile: 'WORKSPACE', manager: 'bazel' },
];
platform.getFile.mockReturnValueOnce('old content 1');
platform.getFile.mockReturnValueOnce('old content 1');

View file

@ -15,6 +15,7 @@ describe('lib/workers/dep-type/index', () => {
beforeEach(() => {
config = {
packageFile: 'package.json',
manager: 'npm',
ignoreDeps: ['a', 'b'],
monorepoPackages: ['e'],
workspaceDir: '.',
@ -49,7 +50,7 @@ describe('lib/workers/dep-type/index', () => {
expect(res).toHaveLength(2);
});
it('returns upgrades for meteor', async () => {
config.packageFile = 'package.js';
config.manager = 'meteor';
const content = fs.readFileSync(
path.resolve('test/_fixtures/meteor/package-1.js'),
'utf8'
@ -58,7 +59,7 @@ describe('lib/workers/dep-type/index', () => {
expect(res).toHaveLength(6);
});
it('returns upgrades for bazel', async () => {
config.packageFile = 'WORKSPACE';
config.manager = 'bazel';
const content = fs.readFileSync(
path.resolve('test/_fixtures/bazel/WORKSPACE1'),
'utf8'
@ -67,7 +68,7 @@ describe('lib/workers/dep-type/index', () => {
expect(res).toHaveLength(4);
});
it('returns upgrades for travis', async () => {
config.packageFile = '.travis.yml';
config.manager = 'node';
const content = fs.readFileSync(
path.resolve('test/_fixtures/node/travis.yml'),
'utf8'
@ -76,13 +77,13 @@ describe('lib/workers/dep-type/index', () => {
expect(res).toHaveLength(1);
});
it('handles malformed meteor', async () => {
config.packageFile = 'package.js';
config.manager = 'meteor';
const content = 'blah';
const res = await depTypeWorker.renovateDepType(content, config);
expect(res).toHaveLength(0);
});
it('returns upgrades for docker', async () => {
config.packageFile = 'Dockerfile';
config.manager = 'docker';
config.currentFrom = 'node';
const res = await depTypeWorker.renovateDepType(
'# a comment\nFROM something\n',
@ -91,7 +92,7 @@ describe('lib/workers/dep-type/index', () => {
expect(res).toHaveLength(1);
});
it('ignores Dockerfiles with no FROM', async () => {
config.packageFile = 'Dockerfile';
config.manager = 'docker';
config.currentFrom = 'node';
const res = await depTypeWorker.renovateDepType(
'# a comment\nRUN something\n',

View file

@ -27,30 +27,30 @@ describe('lib/workers/package/index', () => {
});
it('calls docker', async () => {
docker.getPackageUpdates.mockReturnValueOnce([]);
config.packageFile = 'Dockerfile';
config.manager = 'docker';
const res = await pkgWorker.renovatePackage(config);
expect(res).toMatchObject([]);
});
it('calls meteor', async () => {
npm.getPackageUpdates.mockReturnValueOnce([]);
config.packageFile = 'package.js';
config.manager = 'meteor';
const res = await pkgWorker.renovatePackage(config);
expect(res).toMatchObject([]);
});
it('calls node', async () => {
node.getPackageUpdates.mockReturnValueOnce([]);
config.packageFile = '.travis.yml';
config.manager = 'node';
const res = await pkgWorker.renovatePackage(config);
expect(res).toMatchObject([]);
});
it('calls bazel', async () => {
bazel.getPackageUpdates.mockReturnValueOnce([]);
config.packageFile = 'WORKSPACE';
config.manager = 'bazel';
const res = await pkgWorker.renovatePackage(config);
expect(res).toMatchObject([]);
});
it('maps and filters type', async () => {
config.packageFile = 'package.json';
config.manager = 'npm';
config.major.enabled = false;
npm.getPackageUpdates.mockReturnValueOnce([
{ type: 'pin' },

View file

@ -31,18 +31,23 @@ describe('workers/repository/updates/determine', () => {
config.packageFiles = [
{
packageFile: 'Dockerfile',
manager: 'docker',
},
{
packageFile: 'backend/package.json',
manager: 'npm',
},
{
packageFile: 'frontend/package.js',
manager: 'meteor',
},
{
packageFile: '.travis.yml',
manager: 'node',
},
{
packageFile: 'WORKSPACE',
manager: 'bazel',
},
];
packageFileWorker.renovateDockerfile.mockReturnValueOnce([