Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(npm): retain npmrc lines without variables #9484

Merged
merged 1 commit into from Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/manager/npm/extract/index.spec.ts
Expand Up @@ -126,11 +126,11 @@ describe('manager/npm/extract', () => {
);
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 @@ -139,7 +139,7 @@ describe('manager/npm/extract', () => {
'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