feat: discard npmrc if containing variables

.npmrc files will fail during lock file generation if they contain unexpanded variables, so it’s better to discard them instead.
This commit is contained in:
Rhys Arkins 2018-05-14 08:11:23 +02:00
parent 2b2b1d92ab
commit 1352bbeb18
2 changed files with 24 additions and 1 deletions

View file

@ -58,7 +58,15 @@ async function extractDependencies(content, packageFile, config) {
npmrc = await platform.getFile( npmrc = await platform.getFile(
upath.join(path.dirname(packageFile), '.npmrc') upath.join(path.dirname(packageFile), '.npmrc')
); );
if (!npmrc) { if (npmrc) {
if (
npmrc.includes('=${') &&
!(config.global && config.global.exposeEnv)
) {
logger.info('Discarding .npmrc file with variables');
npmrc = undefined;
}
} else {
npmrc = undefined; npmrc = undefined;
} }
} }

View file

@ -75,6 +75,21 @@ describe('manager/npm/extract', () => {
); );
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
it('finds and discards .npmrc', async () => {
platform.getFile = jest.fn(fileName => {
if (fileName === '.npmrc') {
// eslint-disable-next-line
return '//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}\n';
}
return null;
});
const res = await npmExtract.extractDependencies(
input01Content,
'package.json',
{ global: {} }
);
expect(res.npmrc).toBeUndefined();
});
it('finds lerna', async () => { it('finds lerna', async () => {
platform.getFile = jest.fn(fileName => { platform.getFile = jest.fn(fileName => {
if (fileName === 'lerna.json') { if (fileName === 'lerna.json') {