mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
refactor: use manager not packageFile
This commit is contained in:
parent
c4cdfe8989
commit
cf336a0b21
7 changed files with 47 additions and 37 deletions
|
@ -62,15 +62,16 @@ async function detectPackageFiles(config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPackageUpdates(config) {
|
function getPackageUpdates(config) {
|
||||||
if (config.packageFile.endsWith('Dockerfile')) {
|
const { manager } = config;
|
||||||
|
if (manager === 'docker') {
|
||||||
return docker.getPackageUpdates(config);
|
return docker.getPackageUpdates(config);
|
||||||
} else if (config.packageFile.endsWith('package.json')) {
|
} else if (manager === 'npm') {
|
||||||
return npm.getPackageUpdates(config);
|
return npm.getPackageUpdates(config);
|
||||||
} else if (config.packageFile.endsWith('package.js')) {
|
} else if (manager === 'meteor') {
|
||||||
return npm.getPackageUpdates(config);
|
return npm.getPackageUpdates(config);
|
||||||
} else if (config.packageFile.endsWith('.travis.yml')) {
|
} else if (manager === 'node') {
|
||||||
return node.getPackageUpdates(config);
|
return node.getPackageUpdates(config);
|
||||||
} else if (config.packageFile.endsWith('WORKSPACE')) {
|
} else if (manager === 'bazel') {
|
||||||
return bazel.getPackageUpdates(config);
|
return bazel.getPackageUpdates(config);
|
||||||
}
|
}
|
||||||
logger.info(`Cannot find manager for ${config.packageFile}`);
|
logger.info(`Cannot find manager for ${config.packageFile}`);
|
||||||
|
@ -81,12 +82,13 @@ async function getUpdatedPackageFiles(config) {
|
||||||
const updatedPackageFiles = {};
|
const updatedPackageFiles = {};
|
||||||
|
|
||||||
for (const upgrade of config.upgrades) {
|
for (const upgrade of config.upgrades) {
|
||||||
|
const { manager } = upgrade;
|
||||||
if (upgrade.type !== 'lockFileMaintenance') {
|
if (upgrade.type !== 'lockFileMaintenance') {
|
||||||
const existingContent =
|
const existingContent =
|
||||||
updatedPackageFiles[upgrade.packageFile] ||
|
updatedPackageFiles[upgrade.packageFile] ||
|
||||||
(await platform.getFile(upgrade.packageFile, config.parentBranch));
|
(await platform.getFile(upgrade.packageFile, config.parentBranch));
|
||||||
let newContent = existingContent;
|
let newContent = existingContent;
|
||||||
if (upgrade.packageFile.endsWith('package.json')) {
|
if (manager === 'npm') {
|
||||||
newContent = npmUpdater.setNewValue(
|
newContent = npmUpdater.setNewValue(
|
||||||
existingContent,
|
existingContent,
|
||||||
upgrade.depType,
|
upgrade.depType,
|
||||||
|
@ -98,18 +100,18 @@ async function getUpdatedPackageFiles(config) {
|
||||||
upgrade.currentPackageJsonVersion,
|
upgrade.currentPackageJsonVersion,
|
||||||
upgrade.bumpVersion
|
upgrade.bumpVersion
|
||||||
);
|
);
|
||||||
} else if (upgrade.packageFile.endsWith('package.js')) {
|
} else if (manager === 'meteor') {
|
||||||
newContent = meteorUpdater.setNewValue(
|
newContent = meteorUpdater.setNewValue(
|
||||||
existingContent,
|
existingContent,
|
||||||
upgrade.depName,
|
upgrade.depName,
|
||||||
upgrade.currentVersion,
|
upgrade.currentVersion,
|
||||||
upgrade.newVersion
|
upgrade.newVersion
|
||||||
);
|
);
|
||||||
} else if (upgrade.packageFile.endsWith('Dockerfile')) {
|
} else if (manager === 'docker') {
|
||||||
newContent = dockerfileHelper.setNewValue(existingContent, upgrade);
|
newContent = dockerfileHelper.setNewValue(existingContent, upgrade);
|
||||||
} else if (upgrade.packageFile.endsWith('.travis.yml')) {
|
} else if (manager === 'node') {
|
||||||
newContent = nodeHelper.setNewValue(existingContent, upgrade);
|
newContent = nodeHelper.setNewValue(existingContent, upgrade);
|
||||||
} else if (upgrade.packageFile.endsWith('WORKSPACE')) {
|
} else if (manager === 'bazel') {
|
||||||
newContent = await bazelHelper.setNewValue(existingContent, upgrade);
|
newContent = await bazelHelper.setNewValue(existingContent, upgrade);
|
||||||
}
|
}
|
||||||
if (!newContent) {
|
if (!newContent) {
|
||||||
|
|
|
@ -28,7 +28,8 @@ async function renovateDepType(
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
let deps = [];
|
let deps = [];
|
||||||
if (config.packageFile.endsWith('package.json')) {
|
const { manager } = config;
|
||||||
|
if (manager === 'npm') {
|
||||||
// Extract all dependencies from the package.json
|
// Extract all dependencies from the package.json
|
||||||
deps = await packageJson.extractDependencies(
|
deps = await packageJson.extractDependencies(
|
||||||
packageContent,
|
packageContent,
|
||||||
|
@ -43,13 +44,13 @@ async function renovateDepType(
|
||||||
}
|
}
|
||||||
logger.debug(`deps length is ${deps.length}`);
|
logger.debug(`deps length is ${deps.length}`);
|
||||||
logger.debug({ deps }, `deps`);
|
logger.debug({ deps }, `deps`);
|
||||||
} else if (config.packageFile.endsWith('package.js')) {
|
} else if (manager === 'meteor') {
|
||||||
deps = meteorExtract.extractDependencies(packageContent);
|
deps = meteorExtract.extractDependencies(packageContent);
|
||||||
} else if (config.packageFile.endsWith('Dockerfile')) {
|
} else if (manager === 'docker') {
|
||||||
deps = dockerExtract.extractDependencies(packageContent);
|
deps = dockerExtract.extractDependencies(packageContent);
|
||||||
} else if (config.packageFile.endsWith('.travis.yml')) {
|
} else if (manager === 'node') {
|
||||||
deps = nodeExtract.extractDependencies(packageContent);
|
deps = nodeExtract.extractDependencies(packageContent);
|
||||||
} else if (config.packageFile.endsWith('WORKSPACE')) {
|
} else if (manager === 'bazel') {
|
||||||
deps = bazelExtract.extractDependencies(packageContent);
|
deps = bazelExtract.extractDependencies(packageContent);
|
||||||
}
|
}
|
||||||
deps = deps.filter(
|
deps = deps.filter(
|
||||||
|
|
|
@ -17,7 +17,8 @@ async function determineRepoUpgrades(config) {
|
||||||
logger.trace({ fullPackageFile: packageFile });
|
logger.trace({ fullPackageFile: packageFile });
|
||||||
let packageFileConfig = mergeChildConfig(config, packageFile);
|
let packageFileConfig = mergeChildConfig(config, packageFile);
|
||||||
packageFileConfig = filterConfig(packageFileConfig, 'packageFile');
|
packageFileConfig = filterConfig(packageFileConfig, 'packageFile');
|
||||||
if (packageFileConfig.packageFile.endsWith('package.json')) {
|
const { manager } = packageFileConfig;
|
||||||
|
if (manager === 'npm') {
|
||||||
logger.info(
|
logger.info(
|
||||||
{ packageFile: packageFileConfig.packageFile },
|
{ packageFile: packageFileConfig.packageFile },
|
||||||
'Renovating package.json dependencies'
|
'Renovating package.json dependencies'
|
||||||
|
@ -25,22 +26,22 @@ async function determineRepoUpgrades(config) {
|
||||||
upgrades = upgrades.concat(
|
upgrades = upgrades.concat(
|
||||||
await packageFileWorker.renovatePackageFile(packageFileConfig)
|
await packageFileWorker.renovatePackageFile(packageFileConfig)
|
||||||
);
|
);
|
||||||
} else if (packageFileConfig.packageFile.endsWith('package.js')) {
|
} else if (manager === 'meteor') {
|
||||||
logger.info('Renovating package.js (meteor) dependencies');
|
logger.info('Renovating package.js (meteor) dependencies');
|
||||||
upgrades = upgrades.concat(
|
upgrades = upgrades.concat(
|
||||||
await packageFileWorker.renovateMeteorPackageFile(packageFileConfig)
|
await packageFileWorker.renovateMeteorPackageFile(packageFileConfig)
|
||||||
);
|
);
|
||||||
} else if (packageFileConfig.packageFile.endsWith('Dockerfile')) {
|
} else if (manager === 'docker') {
|
||||||
logger.info('Renovating Dockerfile FROM');
|
logger.info('Renovating Dockerfile FROM');
|
||||||
upgrades = upgrades.concat(
|
upgrades = upgrades.concat(
|
||||||
await packageFileWorker.renovateDockerfile(packageFileConfig)
|
await packageFileWorker.renovateDockerfile(packageFileConfig)
|
||||||
);
|
);
|
||||||
} else if (packageFileConfig.packageFile.endsWith('.travis.yml')) {
|
} else if (manager === 'node') {
|
||||||
logger.info('Renovating .travis.yml node_js versions');
|
logger.info('Renovating .travis.yml node_js versions');
|
||||||
upgrades = upgrades.concat(
|
upgrades = upgrades.concat(
|
||||||
await packageFileWorker.renovateNodeFile(packageFileConfig)
|
await packageFileWorker.renovateNodeFile(packageFileConfig)
|
||||||
);
|
);
|
||||||
} else if (packageFileConfig.packageFile.endsWith('WORKSPACE')) {
|
} else if (manager === 'bazel') {
|
||||||
logger.info('Renovating bazel WORKSPACE dependencies');
|
logger.info('Renovating bazel WORKSPACE dependencies');
|
||||||
upgrades = upgrades.concat(
|
upgrades = upgrades.concat(
|
||||||
await packageFileWorker.renovateBazelFile(packageFileConfig)
|
await packageFileWorker.renovateBazelFile(packageFileConfig)
|
||||||
|
|
|
@ -134,7 +134,7 @@ describe('manager', () => {
|
||||||
it('recurses if setNewValue error', async () => {
|
it('recurses if setNewValue error', async () => {
|
||||||
config.parentBranch = 'some-branch';
|
config.parentBranch = 'some-branch';
|
||||||
config.canRebase = true;
|
config.canRebase = true;
|
||||||
config.upgrades = [{ packageFile: 'package.json' }];
|
config.upgrades = [{ packageFile: 'package.json', manager: 'npm' }];
|
||||||
npmUpdater.setNewValue.mockReturnValueOnce(null);
|
npmUpdater.setNewValue.mockReturnValueOnce(null);
|
||||||
npmUpdater.setNewValue.mockReturnValueOnce('some content');
|
npmUpdater.setNewValue.mockReturnValueOnce('some content');
|
||||||
const res = await getUpdatedPackageFiles(config);
|
const res = await getUpdatedPackageFiles(config);
|
||||||
|
@ -154,11 +154,11 @@ describe('manager', () => {
|
||||||
config.parentBranch = 'some-branch';
|
config.parentBranch = 'some-branch';
|
||||||
config.canRebase = true;
|
config.canRebase = true;
|
||||||
config.upgrades = [
|
config.upgrades = [
|
||||||
{ packageFile: 'package.json' },
|
{ packageFile: 'package.json', manager: 'npm' },
|
||||||
{ packageFile: 'Dockerfile' },
|
{ packageFile: 'Dockerfile', manager: 'docker' },
|
||||||
{ packageFile: 'packages/foo/package.js' },
|
{ packageFile: 'packages/foo/package.js', manager: 'meteor' },
|
||||||
{ packageFile: '.travis.yml' },
|
{ packageFile: '.travis.yml', manager: 'node' },
|
||||||
{ packageFile: 'WORKSPACE' },
|
{ packageFile: 'WORKSPACE', manager: 'bazel' },
|
||||||
];
|
];
|
||||||
platform.getFile.mockReturnValueOnce('old content 1');
|
platform.getFile.mockReturnValueOnce('old content 1');
|
||||||
platform.getFile.mockReturnValueOnce('old content 1');
|
platform.getFile.mockReturnValueOnce('old content 1');
|
||||||
|
|
|
@ -15,6 +15,7 @@ describe('lib/workers/dep-type/index', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
config = {
|
config = {
|
||||||
packageFile: 'package.json',
|
packageFile: 'package.json',
|
||||||
|
manager: 'npm',
|
||||||
ignoreDeps: ['a', 'b'],
|
ignoreDeps: ['a', 'b'],
|
||||||
monorepoPackages: ['e'],
|
monorepoPackages: ['e'],
|
||||||
workspaceDir: '.',
|
workspaceDir: '.',
|
||||||
|
@ -49,7 +50,7 @@ describe('lib/workers/dep-type/index', () => {
|
||||||
expect(res).toHaveLength(2);
|
expect(res).toHaveLength(2);
|
||||||
});
|
});
|
||||||
it('returns upgrades for meteor', async () => {
|
it('returns upgrades for meteor', async () => {
|
||||||
config.packageFile = 'package.js';
|
config.manager = 'meteor';
|
||||||
const content = fs.readFileSync(
|
const content = fs.readFileSync(
|
||||||
path.resolve('test/_fixtures/meteor/package-1.js'),
|
path.resolve('test/_fixtures/meteor/package-1.js'),
|
||||||
'utf8'
|
'utf8'
|
||||||
|
@ -58,7 +59,7 @@ describe('lib/workers/dep-type/index', () => {
|
||||||
expect(res).toHaveLength(6);
|
expect(res).toHaveLength(6);
|
||||||
});
|
});
|
||||||
it('returns upgrades for bazel', async () => {
|
it('returns upgrades for bazel', async () => {
|
||||||
config.packageFile = 'WORKSPACE';
|
config.manager = 'bazel';
|
||||||
const content = fs.readFileSync(
|
const content = fs.readFileSync(
|
||||||
path.resolve('test/_fixtures/bazel/WORKSPACE1'),
|
path.resolve('test/_fixtures/bazel/WORKSPACE1'),
|
||||||
'utf8'
|
'utf8'
|
||||||
|
@ -67,7 +68,7 @@ describe('lib/workers/dep-type/index', () => {
|
||||||
expect(res).toHaveLength(4);
|
expect(res).toHaveLength(4);
|
||||||
});
|
});
|
||||||
it('returns upgrades for travis', async () => {
|
it('returns upgrades for travis', async () => {
|
||||||
config.packageFile = '.travis.yml';
|
config.manager = 'node';
|
||||||
const content = fs.readFileSync(
|
const content = fs.readFileSync(
|
||||||
path.resolve('test/_fixtures/node/travis.yml'),
|
path.resolve('test/_fixtures/node/travis.yml'),
|
||||||
'utf8'
|
'utf8'
|
||||||
|
@ -76,13 +77,13 @@ describe('lib/workers/dep-type/index', () => {
|
||||||
expect(res).toHaveLength(1);
|
expect(res).toHaveLength(1);
|
||||||
});
|
});
|
||||||
it('handles malformed meteor', async () => {
|
it('handles malformed meteor', async () => {
|
||||||
config.packageFile = 'package.js';
|
config.manager = 'meteor';
|
||||||
const content = 'blah';
|
const content = 'blah';
|
||||||
const res = await depTypeWorker.renovateDepType(content, config);
|
const res = await depTypeWorker.renovateDepType(content, config);
|
||||||
expect(res).toHaveLength(0);
|
expect(res).toHaveLength(0);
|
||||||
});
|
});
|
||||||
it('returns upgrades for docker', async () => {
|
it('returns upgrades for docker', async () => {
|
||||||
config.packageFile = 'Dockerfile';
|
config.manager = 'docker';
|
||||||
config.currentFrom = 'node';
|
config.currentFrom = 'node';
|
||||||
const res = await depTypeWorker.renovateDepType(
|
const res = await depTypeWorker.renovateDepType(
|
||||||
'# a comment\nFROM something\n',
|
'# a comment\nFROM something\n',
|
||||||
|
@ -91,7 +92,7 @@ describe('lib/workers/dep-type/index', () => {
|
||||||
expect(res).toHaveLength(1);
|
expect(res).toHaveLength(1);
|
||||||
});
|
});
|
||||||
it('ignores Dockerfiles with no FROM', async () => {
|
it('ignores Dockerfiles with no FROM', async () => {
|
||||||
config.packageFile = 'Dockerfile';
|
config.manager = 'docker';
|
||||||
config.currentFrom = 'node';
|
config.currentFrom = 'node';
|
||||||
const res = await depTypeWorker.renovateDepType(
|
const res = await depTypeWorker.renovateDepType(
|
||||||
'# a comment\nRUN something\n',
|
'# a comment\nRUN something\n',
|
||||||
|
|
|
@ -27,30 +27,30 @@ describe('lib/workers/package/index', () => {
|
||||||
});
|
});
|
||||||
it('calls docker', async () => {
|
it('calls docker', async () => {
|
||||||
docker.getPackageUpdates.mockReturnValueOnce([]);
|
docker.getPackageUpdates.mockReturnValueOnce([]);
|
||||||
config.packageFile = 'Dockerfile';
|
config.manager = 'docker';
|
||||||
const res = await pkgWorker.renovatePackage(config);
|
const res = await pkgWorker.renovatePackage(config);
|
||||||
expect(res).toMatchObject([]);
|
expect(res).toMatchObject([]);
|
||||||
});
|
});
|
||||||
it('calls meteor', async () => {
|
it('calls meteor', async () => {
|
||||||
npm.getPackageUpdates.mockReturnValueOnce([]);
|
npm.getPackageUpdates.mockReturnValueOnce([]);
|
||||||
config.packageFile = 'package.js';
|
config.manager = 'meteor';
|
||||||
const res = await pkgWorker.renovatePackage(config);
|
const res = await pkgWorker.renovatePackage(config);
|
||||||
expect(res).toMatchObject([]);
|
expect(res).toMatchObject([]);
|
||||||
});
|
});
|
||||||
it('calls node', async () => {
|
it('calls node', async () => {
|
||||||
node.getPackageUpdates.mockReturnValueOnce([]);
|
node.getPackageUpdates.mockReturnValueOnce([]);
|
||||||
config.packageFile = '.travis.yml';
|
config.manager = 'node';
|
||||||
const res = await pkgWorker.renovatePackage(config);
|
const res = await pkgWorker.renovatePackage(config);
|
||||||
expect(res).toMatchObject([]);
|
expect(res).toMatchObject([]);
|
||||||
});
|
});
|
||||||
it('calls bazel', async () => {
|
it('calls bazel', async () => {
|
||||||
bazel.getPackageUpdates.mockReturnValueOnce([]);
|
bazel.getPackageUpdates.mockReturnValueOnce([]);
|
||||||
config.packageFile = 'WORKSPACE';
|
config.manager = 'bazel';
|
||||||
const res = await pkgWorker.renovatePackage(config);
|
const res = await pkgWorker.renovatePackage(config);
|
||||||
expect(res).toMatchObject([]);
|
expect(res).toMatchObject([]);
|
||||||
});
|
});
|
||||||
it('maps and filters type', async () => {
|
it('maps and filters type', async () => {
|
||||||
config.packageFile = 'package.json';
|
config.manager = 'npm';
|
||||||
config.major.enabled = false;
|
config.major.enabled = false;
|
||||||
npm.getPackageUpdates.mockReturnValueOnce([
|
npm.getPackageUpdates.mockReturnValueOnce([
|
||||||
{ type: 'pin' },
|
{ type: 'pin' },
|
||||||
|
|
|
@ -31,18 +31,23 @@ describe('workers/repository/updates/determine', () => {
|
||||||
config.packageFiles = [
|
config.packageFiles = [
|
||||||
{
|
{
|
||||||
packageFile: 'Dockerfile',
|
packageFile: 'Dockerfile',
|
||||||
|
manager: 'docker',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
packageFile: 'backend/package.json',
|
packageFile: 'backend/package.json',
|
||||||
|
manager: 'npm',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
packageFile: 'frontend/package.js',
|
packageFile: 'frontend/package.js',
|
||||||
|
manager: 'meteor',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
packageFile: '.travis.yml',
|
packageFile: '.travis.yml',
|
||||||
|
manager: 'node',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
packageFile: 'WORKSPACE',
|
packageFile: 'WORKSPACE',
|
||||||
|
manager: 'bazel',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
packageFileWorker.renovateDockerfile.mockReturnValueOnce([
|
packageFileWorker.renovateDockerfile.mockReturnValueOnce([
|
||||||
|
|
Loading…
Reference in a new issue