Skip to content

Commit

Permalink
feat(npm): retain npmrc lines without variables (#9484)
Browse files Browse the repository at this point in the history
Instead of ignoring the entire .npmrc file if it contains environment variables, instead just strip out the necessary lines.

BREAKING: .npmrc files with environment variables will no longer be completely ignore - instead only the lines with variables will be stripped.
  • Loading branch information
rarkins committed Apr 22, 2021
1 parent 89b5a57 commit bf63a45
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/manager/npm/extract/index.spec.ts
Expand Up @@ -127,11 +127,11 @@ describe(getName(__filename), () => {
);
expect(res.npmrc).toBeUndefined();
});
it('finds and discards .npmrc', async () => {
it('finds and filters .npmrc with variables', async () => {
fs.readLocalFile = jest.fn((fileName) => {
if (fileName === '.npmrc') {
// eslint-disable-next-line
return '//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}\n';
return 'registry=https://registry.npmjs.org\n//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}\n';
}
return null;
});
Expand All @@ -140,7 +140,7 @@ describe(getName(__filename), () => {
'package.json',
{}
);
expect(res.npmrc).toEqual('');
expect(res.npmrc).toEqual('registry=https://registry.npmjs.org\n');
});
it('finds lerna', async () => {
fs.readLocalFile = jest.fn((fileName) => {
Expand Down
10 changes: 8 additions & 2 deletions lib/manager/npm/extract/index.ts
Expand Up @@ -106,8 +106,14 @@ export async function extractPackageFile(
npmrc = npmrc.replace(/(^|\n)package-lock.*?(\n|$)/g, '\n');
}
if (npmrc.includes('=${') && !getAdminConfig().exposeAllEnv) {
logger.debug('Overriding .npmrc file with variables');
npmrc = '';
logger.debug(
{ npmrcFileName },
'Stripping .npmrc file of lines with variables'
);
npmrc = npmrc
.split('\n')
.filter((line) => !line.includes('=${'))
.join('\n');
}
}
}
Expand Down

0 comments on commit bf63a45

Please sign in to comment.