mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +00:00
refactor: detectPackageFiles returns packageFiles not config (#1092)
This commit is contained in:
parent
9c1b7d78cd
commit
9769f5a5db
7 changed files with 30 additions and 62 deletions
|
@ -17,36 +17,32 @@ module.exports = {
|
|||
getUpdatedPackageFiles,
|
||||
};
|
||||
|
||||
async function detectPackageFiles(input) {
|
||||
const config = { ...input };
|
||||
async function detectPackageFiles(config) {
|
||||
const { logger } = config;
|
||||
let packageFiles = [];
|
||||
const fileList = (await config.api.getFileList()).filter(
|
||||
file =>
|
||||
!config.ignorePaths.some(
|
||||
ignorePath => file.includes(ignorePath) || minimatch(file, ignorePath)
|
||||
)
|
||||
);
|
||||
logger.debug({ config }, 'detectPackageFiles');
|
||||
config.types = {};
|
||||
logger.trace({ config }, 'detectPackageFiles');
|
||||
const packageJsonFiles = await npmDetect.detectPackageFiles(config, fileList);
|
||||
if (packageJsonFiles.length) {
|
||||
logger.info({ packageJsonFiles }, 'Found package.json files');
|
||||
config.packageFiles = config.packageFiles.concat(packageJsonFiles);
|
||||
config.types.npm = true;
|
||||
packageFiles = packageFiles.concat(packageJsonFiles);
|
||||
}
|
||||
const meteorFiles = await meteorDetect.detectPackageFiles(config, fileList);
|
||||
if (meteorFiles.length) {
|
||||
logger.info({ packageJsonFiles }, 'Found meteor files');
|
||||
config.packageFiles = config.packageFiles.concat(meteorFiles);
|
||||
config.types.meteor = true;
|
||||
packageFiles = packageFiles.concat(meteorFiles);
|
||||
}
|
||||
const dockerFiles = await dockerDetect.detectPackageFiles(config, fileList);
|
||||
if (dockerFiles.length) {
|
||||
logger.info({ dockerFiles }, 'Found Dockerfiles');
|
||||
config.packageFiles = config.packageFiles.concat(dockerFiles);
|
||||
config.types.docker = true;
|
||||
packageFiles = packageFiles.concat(dockerFiles);
|
||||
}
|
||||
return config;
|
||||
return packageFiles;
|
||||
}
|
||||
|
||||
async function getPackageUpdates(config) {
|
||||
|
|
|
@ -75,7 +75,7 @@ async function renovateRepository(repoConfig, token) {
|
|||
// Detect package files in default branch if not manually provisioned
|
||||
if (config.packageFiles.length === 0) {
|
||||
logger.debug('Detecting package files');
|
||||
config = await manager.detectPackageFiles(config);
|
||||
config.packageFiles = await manager.detectPackageFiles(config);
|
||||
// If we can't detect any package.json then return
|
||||
if (config.packageFiles.length === 0) {
|
||||
logger.info('Cannot detect package files');
|
||||
|
|
|
@ -10,10 +10,10 @@ module.exports = {
|
|||
};
|
||||
|
||||
async function createOnboardingBranch(inputConfig) {
|
||||
let config = { ...inputConfig };
|
||||
const config = { ...inputConfig };
|
||||
const { logger } = config;
|
||||
logger.debug('Creating onboarding branch');
|
||||
config = await manager.detectPackageFiles(config);
|
||||
config.packageFiles = await manager.detectPackageFiles(config);
|
||||
if (config.packageFiles.length === 0) {
|
||||
throw new Error('no package files');
|
||||
}
|
||||
|
|
|
@ -22,12 +22,11 @@ Array [
|
|||
exports[`manager detectPackageFiles(config) ignores node modules 1`] = `
|
||||
Array [
|
||||
"package.json",
|
||||
"not_node_mldules/backend/package.json",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`manager detectPackageFiles(config) ignores node modules 2`] = `undefined`;
|
||||
|
||||
exports[`manager detectPackageFiles(config) ignores node modules 3`] = `Array []`;
|
||||
exports[`manager detectPackageFiles(config) ignores node modules 3`] = `undefined`;
|
||||
|
||||
exports[`manager detectPackageFiles(config) skips meteor package files with no json 1`] = `Array []`;
|
||||
|
|
|
@ -28,8 +28,8 @@ describe('manager', () => {
|
|||
'backend/package.json',
|
||||
]);
|
||||
const res = await manager.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(2);
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(2);
|
||||
});
|
||||
it('finds meteor package files', async () => {
|
||||
config.meteor.enabled = true;
|
||||
|
@ -38,8 +38,8 @@ describe('manager', () => {
|
|||
]); // meteor
|
||||
config.api.getFileContent.mockReturnValueOnce('Npm.depends( {} )');
|
||||
const res = await manager.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(1);
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(1);
|
||||
});
|
||||
it('skips meteor package files with no json', async () => {
|
||||
config.meteor.enabled = true;
|
||||
|
@ -48,8 +48,8 @@ describe('manager', () => {
|
|||
]); // meteor
|
||||
config.api.getFileContent.mockReturnValueOnce('Npm.depends(packages)');
|
||||
const res = await manager.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(0);
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(0);
|
||||
});
|
||||
it('finds Dockerfiles', async () => {
|
||||
config.api.getFileList.mockReturnValueOnce([
|
||||
|
@ -63,18 +63,17 @@ describe('manager', () => {
|
|||
'ARG foo\nFROM something\nRUN something'
|
||||
);
|
||||
const res = await manager.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(1);
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(1);
|
||||
});
|
||||
it('ignores node modules', async () => {
|
||||
config.api.getFileList.mockReturnValueOnce([
|
||||
'package.json',
|
||||
'node_modules/backend/package.json',
|
||||
'not_node_mldules/backend/package.json',
|
||||
]);
|
||||
const res = await manager.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(2);
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(1);
|
||||
expect(res.foundIgnoredPaths).toMatchSnapshot();
|
||||
expect(res.warnings).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -79,46 +79,31 @@ describe('workers/repository', () => {
|
|||
it('does not skip repository if its a configured fork', async () => {
|
||||
config.isFork = true;
|
||||
config.renovateFork = true;
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: [] },
|
||||
}));
|
||||
manager.detectPackageFiles.mockReturnValueOnce([]);
|
||||
await repositoryWorker.renovateRepository(config);
|
||||
});
|
||||
it('sets custom base branch', async () => {
|
||||
config.baseBranch = 'some-branch';
|
||||
config.api.branchExists.mockReturnValueOnce(true);
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: [] },
|
||||
}));
|
||||
manager.detectPackageFiles.mockReturnValueOnce([]);
|
||||
await repositoryWorker.renovateRepository(config);
|
||||
expect(config.api.setBaseBranch.mock.calls).toHaveLength(1);
|
||||
});
|
||||
it('errors when missing custom base branch', async () => {
|
||||
config.baseBranch = 'some-branch';
|
||||
config.api.branchExists.mockReturnValueOnce(false);
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: [] },
|
||||
}));
|
||||
manager.detectPackageFiles.mockReturnValueOnce([]);
|
||||
await repositoryWorker.renovateRepository(config);
|
||||
expect(config.api.setBaseBranch.mock.calls).toHaveLength(0);
|
||||
});
|
||||
it('skips repository if no package.json', async () => {
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: [] },
|
||||
}));
|
||||
manager.detectPackageFiles.mockReturnValueOnce([]);
|
||||
await repositoryWorker.renovateRepository(config);
|
||||
expect(apis.resolvePackageFiles.mock.calls.length).toBe(0);
|
||||
expect(config.logger.error.mock.calls.length).toBe(0);
|
||||
});
|
||||
it('does not skip repository if package.json', async () => {
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: ['package.json'] },
|
||||
}));
|
||||
manager.detectPackageFiles.mockReturnValueOnce(['package.json']);
|
||||
config.api.getFileJson = jest.fn(() => ({ a: 1 }));
|
||||
apis.mergeRenovateJson.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
|
@ -138,15 +123,9 @@ describe('workers/repository', () => {
|
|||
expect(config.logger.error.mock.calls.length).toBe(0);
|
||||
});
|
||||
it('uses onboarding custom baseBranch', async () => {
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: ['package.json'] },
|
||||
}));
|
||||
manager.detectPackageFiles.mockReturnValueOnce(['package.json']);
|
||||
config.api.getFileJson = jest.fn(() => ({ a: 1 }));
|
||||
apis.mergeRenovateJson.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: ['package.json'] },
|
||||
}));
|
||||
manager.detectPackageFiles.mockReturnValueOnce(['package.json']);
|
||||
apis.mergeRenovateJson.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: ['package.json'], baseBranch: 'next' },
|
||||
|
@ -162,10 +141,7 @@ describe('workers/repository', () => {
|
|||
expect(config.logger.error.mock.calls.length).toBe(0);
|
||||
});
|
||||
it('errors onboarding custom baseBranch', async () => {
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: ['package.json'] },
|
||||
}));
|
||||
manager.detectPackageFiles.mockReturnValueOnce(['package.json']);
|
||||
config.api.getFileJson = jest.fn(() => ({ a: 1 }));
|
||||
apis.mergeRenovateJson.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
|
|
|
@ -248,9 +248,7 @@ describe('lib/workers/repository/onboarding', () => {
|
|||
expect(config.api.commitFilesToBranch.mock.calls[0]).toMatchSnapshot();
|
||||
});
|
||||
it('throws if no packageFiles', async () => {
|
||||
manager.detectPackageFiles = jest.fn(input => ({
|
||||
...input,
|
||||
}));
|
||||
manager.detectPackageFiles = jest.fn(() => []);
|
||||
let e;
|
||||
try {
|
||||
await onboarding.getOnboardingStatus(config);
|
||||
|
|
Loading…
Reference in a new issue