Skip to content

Commit

Permalink
feat(npm): remove ignoreNpmrcFile support (#9409)
Browse files Browse the repository at this point in the history
Removes support for the ignoreNpmrcFile config option.

BREAKING CHANGE: ignoreNpmrcFile is no longer supported. Use an empty string for config.npmrc instead.
  • Loading branch information
rarkins committed Apr 22, 2021
1 parent 59d728b commit 13ece70
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 58 deletions.
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 @@ -125,6 +125,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 @@ -572,12 +572,6 @@ const options: RenovateOptions[] = [
default: 'auto',
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 @@ -44,6 +44,7 @@ describe(getName(__filename), () => {
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 @@ -207,6 +207,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/index .extractPackageFile() finds complex yarn work
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/index .extractPackageFile() finds simple yarn works
Object {
"constraints": Object {},
"deps": Array [],
"ignoreNpmrcFile": undefined,
"lernaClient": "npm",
"lernaPackages": undefined,
"managerData": Object {
Expand All @@ -1086,7 +1074,6 @@ exports[`manager/npm/extract/index .extractPackageFile() finds simple yarn works
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 @@ -113,6 +113,20 @@ describe(getName(__filename), () => {
);
expect(res.npmrc).toBeDefined();
});
it('ignores .npmrc when config.npmrc is defined', async () => {
fs.readLocalFile = jest.fn((fileName) => {
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 @@ -126,7 +140,7 @@ describe(getName(__filename), () => {
'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'
);
} else {
npmrc = npmrcContent;
if (npmrc?.includes('package-lock')) {
logger.debug('Stripping package-lock setting from .npmrc');
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 @@ -354,7 +348,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;
versioning?: string;
updateInternalDeps?: boolean;
Expand Down Expand Up @@ -89,7 +89,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 @@ -203,7 +203,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

0 comments on commit 13ece70

Please sign in to comment.