Skip to content
Snippets Groups Projects
Commit 2f4d5836 authored by Țurcanu Dragomir's avatar Țurcanu Dragomir Committed by Rhys Arkins
Browse files

feat: Raise config error if config found within nested package.json (#1777)

Raises config error if renovate config found in a nested package.json

Closes #1742
parent ab265352
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ async function resolvePackageFile(config, inputFile) {
logger.debug(
`Resolving packageFile ${JSON.stringify(packageFile.packageFile)}`
);
const pFileRaw = await platform.getFile(packageFile.packageFile);
if (!pFileRaw) {
logger.info(
......@@ -45,6 +46,20 @@ async function resolvePackageFile(config, inputFile) {
});
return null;
}
if (
inputFile.packageFile.includes('package.json') &&
inputFile.packageFile !== 'package.json' &&
packageFile.content.renovate !== undefined
) {
const error = new Error('config-validation');
error.configFile = packageFile.packageFile;
error.validationError = 'package.json configuration error';
error.validationMessage =
'Nested package.json must not contain renovate configuration';
throw error;
}
if (!config.ignoreNpmrcFile) {
packageFile.npmrc = await platform.getFile(
upath.join(path.dirname(packageFile.packageFile), '.npmrc')
......
......@@ -169,5 +169,21 @@ describe('manager/resolve', () => {
expect(res.packageFiles).toMatchSnapshot();
expect(res.warnings).toHaveLength(0);
});
it('checks if renovate config in nested package.json throws an error', async () => {
manager.detectPackageFiles = jest.fn(() => [
{ packageFile: 'package.json', manager: 'npm' },
]);
platform.getFileList.mockReturnValue(['test/package.json']);
platform.getFile.mockReturnValueOnce(
'{"name": "test/package.json", "version": "0.0.1", "renovate":{"enabled": true}}'
);
let e;
try {
await resolvePackageFiles(config);
} catch (err) {
e = err;
}
expect(e).toEqual(new Error('config-validation'));
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment