From 3460dbe08ca0779ba9d0a7c6b4598a1765e7f6c9 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Tue, 16 Apr 2019 23:09:35 +0200 Subject: [PATCH] fix(npm): remove local .npmrc file if ignoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In gitFs, it’s not enough to just skip writing a .npmrc file if we are ignoring it - the file is already in the file system so we need to delete it so that npm/yarn don’t try to use it. --- lib/manager/npm/extract/index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/manager/npm/extract/index.js b/lib/manager/npm/extract/index.js index b04fcd5a36..4c1f5f6db0 100644 --- a/lib/manager/npm/extract/index.js +++ b/lib/manager/npm/extract/index.js @@ -1,3 +1,4 @@ +const fs = require('fs-extra'); const path = require('path'); const upath = require('upath'); const validateNpmPackageName = require('validate-npm-package-name'); @@ -92,10 +93,13 @@ async function extractPackageFile(content, fileName, config) { delete lockFiles.shrinkwrapJson; let npmrc; - if (!config.ignoreNpmrcFile) { - npmrc = await platform.getFile( - upath.join(path.dirname(fileName), '.npmrc') - ); + const npmrcFileName = upath.join(path.dirname(fileName), '.npmrc'); + const npmrcFileNameLocal = upath.join(config.localDir || '', npmrcFileName); + // istanbul ignore if + if (config.ignoreNpmrcFile) { + await fs.remove(npmrcFileNameLocal); + } else { + npmrc = await platform.getFile(npmrcFileName); if (npmrc && npmrc.includes('package-lock')) { logger.info('Stripping package-lock setting from npmrc'); npmrc = npmrc.replace(/(^|\n)package-lock.*?(\n|$)/g, '\n'); @@ -104,6 +108,7 @@ async function extractPackageFile(content, fileName, config) { if (npmrc.includes('=${') && !(global.trustLevel === 'high')) { logger.info('Discarding .npmrc file with variables'); npmrc = undefined; + await fs.remove(npmrcFileNameLocal); } } else { npmrc = undefined; -- GitLab