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): remove ignoreNpmrcFile support #9409

Merged
merged 2 commits into from Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 0 additions & 7 deletions docs/usage/configuration-options.md
Expand Up @@ -969,13 +969,6 @@ The above is the same as if you wrote this package rule:
}
```

## ignoreNpmrcFile

By default, Renovate will look for and use any `.npmrc` file it finds in a repository.
Additionally, it will be read in by `npm` or `yarn` at the time of lock file generation.
Sometimes this causes problems, for example if the file contains placeholder values, so you can configure this to `true` and Renovate will ignore any `.npmrc` files it finds and temporarily remove the file before running `npm install` or `yarn install`.
Renovate will try to configure this to `true` also if you have configured any `npmrc` string within your config file.

## ignorePaths

Using this setting, you can selectively ignore package files that you don't want Renovate autodiscovering.
Expand Down
1 change: 1 addition & 0 deletions lib/config/__snapshots__/migration.spec.ts.snap
Expand Up @@ -123,6 +123,7 @@ Object {
"minor": Object {
"automerge": true,
},
"npmrc": "",
"nvmrc": Object {
"packageRules": Array [
Object {
Expand Down
6 changes: 0 additions & 6 deletions lib/config/definitions.ts
Expand Up @@ -552,12 +552,6 @@ const options: RenovateOptions[] = [
default: null,
admin: true,
},
{
name: 'ignoreNpmrcFile',
description: 'Whether to ignore any .npmrc file found in repository.',
type: 'boolean',
default: false,
},
{
name: 'autodiscover',
description: 'Autodiscover all repositories.',
Expand Down
1 change: 1 addition & 0 deletions lib/config/migration.spec.ts
Expand Up @@ -34,6 +34,7 @@ describe('config/migration', () => {
onboarding: 'false' as never,
multipleMajorPrs: true,
gitFs: false,
ignoreNpmrcFile: true,
separateMajorReleases: true,
separatePatchReleases: true,
suppressNotifications: ['lockFileErrors', 'prEditNotification'],
Expand Down
3 changes: 3 additions & 0 deletions lib/config/migration.ts
Expand Up @@ -198,6 +198,9 @@ export function migrateConfig(
migratedConfig.allowScripts ??= true;
migratedConfig.exposeAllEnv ??= true;
}
} else if (key === 'ignoreNpmrcFile') {
delete migratedConfig.ignoreNpmrcFile;
migratedConfig.npmrc ||= '';
} else if (
key === 'branchName' &&
is.string(val) &&
Expand Down
14 changes: 0 additions & 14 deletions lib/manager/npm/extract/__snapshots__/index.spec.ts.snap
Expand Up @@ -11,7 +11,6 @@ Object {
"skipReason": "invalid-name",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
Expand Down Expand Up @@ -135,7 +134,6 @@ Object {
"prettyDepType": "engine",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
Expand Down Expand Up @@ -299,7 +297,6 @@ Object {
"sourceUrl": "https://github.com/owner/n",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
Expand Down Expand Up @@ -349,7 +346,6 @@ Object {
"skipReason": "unknown-version",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
Expand Down Expand Up @@ -410,7 +406,6 @@ Object {
"skipReason": "unknown-volta",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
Expand Down Expand Up @@ -465,7 +460,6 @@ Object {
"skipReason": "unknown-version",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
Expand Down Expand Up @@ -602,7 +596,6 @@ Object {
"prettyDepType": "resolutions",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": "npm",
"lernaPackages": undefined,
"managerData": Object {
Expand Down Expand Up @@ -739,7 +732,6 @@ Object {
"prettyDepType": "resolutions",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": "yarn",
"lernaPackages": undefined,
"managerData": Object {
Expand Down Expand Up @@ -876,7 +868,6 @@ Object {
"prettyDepType": "resolutions",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
Expand All @@ -899,7 +890,6 @@ exports[`manager/npm/extract .extractPackageFile() finds complex yarn workspaces
Object {
"constraints": Object {},
"deps": Array [],
"ignoreNpmrcFile": undefined,
"lernaClient": "npm",
"lernaPackages": undefined,
"managerData": Object {
Expand Down Expand Up @@ -1038,7 +1028,6 @@ Object {
"prettyDepType": "resolutions",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": "npm",
"lernaPackages": undefined,
"managerData": Object {
Expand All @@ -1061,7 +1050,6 @@ exports[`manager/npm/extract .extractPackageFile() finds simple yarn workspaces
Object {
"constraints": Object {},
"deps": Array [],
"ignoreNpmrcFile": undefined,
"lernaClient": "npm",
"lernaPackages": undefined,
"managerData": Object {
Expand All @@ -1086,7 +1074,6 @@ exports[`manager/npm/extract .extractPackageFile() finds simple yarn workspaces
Object {
"constraints": Object {},
"deps": Array [],
"ignoreNpmrcFile": undefined,
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
Expand Down Expand Up @@ -1225,7 +1212,6 @@ Object {
"prettyDepType": "resolutions",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
Expand Down
16 changes: 15 additions & 1 deletion lib/manager/npm/extract/index.spec.ts
Expand Up @@ -112,6 +112,20 @@ describe('manager/npm/extract', () => {
);
expect(res.npmrc).toBeDefined();
});
it('ignores .npmrc when config.npmrc is defined', async () => {
fs.readLocalFile = jest.fn((fileName) => {
viceice marked this conversation as resolved.
Show resolved Hide resolved
if (fileName === '.npmrc') {
return 'some-npmrc\n';
}
return null;
});
const res = await npmExtract.extractPackageFile(
input01Content,
'package.json',
{ npmrc: 'some-configured-npmrc' }
);
expect(res.npmrc).toBeUndefined();
});
it('finds and discards .npmrc', async () => {
fs.readLocalFile = jest.fn((fileName) => {
if (fileName === '.npmrc') {
Expand All @@ -125,7 +139,7 @@ describe('manager/npm/extract', () => {
'package.json',
{}
);
expect(res.npmrc).toBeUndefined();
expect(res.npmrc).toEqual('');
});
it('finds lerna', async () => {
fs.readLocalFile = jest.fn((fileName) => {
Expand Down
39 changes: 16 additions & 23 deletions lib/manager/npm/extract/index.ts
Expand Up @@ -6,11 +6,7 @@ import * as datasourceGithubTags from '../../../datasource/github-tags';
import { id as npmId } from '../../../datasource/npm';
import { logger } from '../../../logger';
import { SkipReason } from '../../../types';
import {
deleteLocalFile,
getSiblingFileName,
readLocalFile,
} from '../../../util/fs';
import { getSiblingFileName, readLocalFile } from '../../../util/fs';
import * as nodeVersioning from '../../../versioning/node';
import { isValid, isVersion } from '../../../versioning/npm';
import type {
Expand Down Expand Up @@ -95,26 +91,24 @@ export async function extractPackageFile(
delete lockFiles.shrinkwrapJson;

let npmrc: string;
let ignoreNpmrcFile: boolean;
const npmrcFileName = getSiblingFileName(fileName, '.npmrc');
// istanbul ignore if
if (config.ignoreNpmrcFile) {
await deleteLocalFile(npmrcFileName);
} else {
npmrc = await readLocalFile(npmrcFileName, 'utf8');
if (npmrc?.includes('package-lock')) {
logger.debug('Stripping package-lock setting from npmrc');
npmrc = npmrc.replace(/(^|\n)package-lock.*?(\n|$)/g, '\n');
}
if (is.string(npmrc)) {
const npmrcContent = await readLocalFile(npmrcFileName, 'utf8');
if (is.string(npmrcContent)) {
if (is.string(config.npmrc)) {
logger.debug(
{ npmrcFileName },
'Repo .npmrc file is ignored due to presence of config.npmrc'
rarkins marked this conversation as resolved.
Show resolved Hide resolved
);
} else {
npmrc = npmrcContent;
if (npmrc?.includes('package-lock')) {
logger.debug('Stripping package-lock setting from npmrc');
rarkins marked this conversation as resolved.
Show resolved Hide resolved
npmrc = npmrc.replace(/(^|\n)package-lock.*?(\n|$)/g, '\n');
}
if (npmrc.includes('=${') && !getAdminConfig().exposeAllEnv) {
logger.debug('Discarding .npmrc file with variables');
ignoreNpmrcFile = true;
npmrc = undefined;
await deleteLocalFile(npmrcFileName);
logger.debug('Overriding .npmrc file with variables');
npmrc = '';
}
} else {
npmrc = undefined;
}
}
const yarnrcFileName = getSiblingFileName(fileName, '.yarnrc');
Expand Down Expand Up @@ -363,7 +357,6 @@ export async function extractPackageFile(
packageFileVersion,
packageJsonType,
npmrc,
ignoreNpmrcFile,
yarnrc,
...lockFiles,
managerData: {
Expand Down
3 changes: 0 additions & 3 deletions lib/manager/npm/post-update/index.ts
Expand Up @@ -144,9 +144,6 @@ export async function writeExistingFiles(
} catch (err) /* istanbul ignore next */ {
logger.warn({ npmrcFilename, err }, 'Error writing .npmrc');
}
} else if (config.ignoreNpmrcFile) {
logger.debug('Removing ignored .npmrc file before artifact generation');
await remove(npmrcFilename);
}
if (packageFile.yarnrc) {
logger.debug(`Writing .yarnrc to ${basedir}`);
Expand Down
3 changes: 1 addition & 2 deletions lib/manager/types.ts
Expand Up @@ -23,7 +23,7 @@ export interface ExtractConfig extends ManagerConfig {
endpoint?: string;
gradle?: { timeout?: number };
aliases?: Record<string, string>;
ignoreNpmrcFile?: boolean;
npmrc?: string;
yarnrc?: string;
skipInstalls?: boolean;
versioning?: string;
Expand Down Expand Up @@ -85,7 +85,6 @@ export interface PackageFile<T = Record<string, any>>
datasource?: string;
registryUrls?: string[];
deps: PackageDependency[];
ignoreNpmrcFile?: boolean;
lernaClient?: string;
lernaPackages?: string[];
mavenProps?: Record<string, any>;
Expand Down
Expand Up @@ -14,7 +14,6 @@ Array [
"prettyDepType": "dependency",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
Expand Down
1 change: 0 additions & 1 deletion lib/workers/repository/init/config.ts
Expand Up @@ -196,7 +196,6 @@ export async function mergeRenovateConfig(
'Ignoring any .npmrc files in repository due to configured npmrc'
);
npmApi.setNpmrc(resolvedConfig.npmrc);
resolvedConfig.ignoreNpmrcFile = true;
}
// istanbul ignore if
if (resolvedConfig.hostRules) {
Expand Down