Skip to content
Snippets Groups Projects
Commit 5e3806f3 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

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

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.
parent d5922394
No related branches found
No related tags found
No related merge requests found
......@@ -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;
});
......@@ -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) => {
......
......@@ -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');
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment