diff --git a/lib/workers/branch/lock-files.js b/lib/workers/branch/lock-files.js index 441628a3389864c6753c423bfba9886f12c199e1..c591516dd15c1c706ec25b5a4b590dbee764b390 100644 --- a/lib/workers/branch/lock-files.js +++ b/lib/workers/branch/lock-files.js @@ -155,62 +155,61 @@ async function writeExistingFiles(config) { if (!config.packageFiles) { return; } - for (const packageFile of config.packageFiles) { + const npmFiles = config.packageFiles.filter(p => + p.packageFile.endsWith('package.json') + ); + for (const packageFile of npmFiles) { const basedir = upath.join( config.tmpDir.path, path.dirname(packageFile.packageFile) ); - if (packageFile.packageFile.endsWith('package.json')) { - logger.debug(`Writing package.json to ${basedir}`); - // Massage the file to eliminate yarn errors - const massagedFile = { ...packageFile.content }; - if (massagedFile.name) { - massagedFile.name = massagedFile.name.replace(/[{}]/g, ''); - } - delete massagedFile.engines; - delete massagedFile.scripts; - await fs.outputFile( - upath.join(basedir, 'package.json'), - JSON.stringify(massagedFile) - ); + logger.debug(`Writing package.json to ${basedir}`); + // Massage the file to eliminate yarn errors + const massagedFile = { ...packageFile.content }; + if (massagedFile.name) { + massagedFile.name = massagedFile.name.replace(/[{}]/g, ''); + } + delete massagedFile.engines; + delete massagedFile.scripts; + await fs.outputFile( + upath.join(basedir, 'package.json'), + JSON.stringify(massagedFile) + ); - if (config.copyLocalLibs) { - const toCopy = listLocalLibs(massagedFile.dependencies); - toCopy.push(...listLocalLibs(massagedFile.devDependencies)); - if (toCopy.length !== 0) { - logger.debug(`listOfNeededLocalFiles files to copy: ${toCopy}`); - await Promise.all( - toCopy.map(async localPath => { - const resolvedLocalPath = upath.join( - path.resolve(basedir, localPath) + if (config.copyLocalLibs) { + const toCopy = listLocalLibs(massagedFile.dependencies); + toCopy.push(...listLocalLibs(massagedFile.devDependencies)); + if (toCopy.length !== 0) { + logger.debug(`listOfNeededLocalFiles files to copy: ${toCopy}`); + await Promise.all( + toCopy.map(async localPath => { + const resolvedLocalPath = upath.join( + path.resolve(basedir, localPath) + ); + if (!resolvedLocalPath.startsWith(upath.join(config.tmpDir.path))) { + logger.info( + `local lib '${toCopy}' will not be copied because it's out of the repo.` ); - if ( - !resolvedLocalPath.startsWith(upath.join(config.tmpDir.path)) - ) { - logger.info( - `local lib '${toCopy}' will not be copied because it's out of the repo.` + } else { + // at the root of local Lib we should find a package.json so that yarn/npm will use it to update *lock file + const resolvedRepoPath = upath.join( + resolvedLocalPath.substring(config.tmpDir.path.length + 1), + 'package.json' + ); + const fileContent = await platform.getFile(resolvedRepoPath); + if (fileContent !== null) { + await fs.outputFile( + upath.join(resolvedLocalPath, 'package.json'), + fileContent ); } else { - // at the root of local Lib we should find a package.json so that yarn/npm will use it to update *lock file - const resolvedRepoPath = upath.join( - resolvedLocalPath.substring(config.tmpDir.path.length + 1), - 'package.json' + logger.info( + `listOfNeededLocalFiles - file '${resolvedRepoPath}' not found.` ); - const fileContent = await platform.getFile(resolvedRepoPath); - if (fileContent !== null) { - await fs.outputFile( - upath.join(resolvedLocalPath, 'package.json'), - fileContent - ); - } else { - logger.info( - `listOfNeededLocalFiles - file '${resolvedRepoPath}' not found.` - ); - } } - }) - ); - } + } + }) + ); } } if (packageFile.npmrc) { @@ -243,6 +242,7 @@ async function writeExistingFiles(config) { packageLock ); } else { + logger.debug({ config }, `Removing ${basedir}/package-lock.json`); await fs.remove(upath.join(basedir, 'package-lock.json')); } if (packageFile.yarnLock && config.type !== 'lockFileMaintenance') { @@ -254,6 +254,7 @@ async function writeExistingFiles(config) { existingYarnLock || (await platform.getFile(packageFile.yarnLock)); await fs.outputFile(upath.join(basedir, 'yarn.lock'), yarnLock); } else { + logger.debug(`Removing ${basedir}/yarn.lock`); await fs.remove(upath.join(basedir, 'yarn.lock')); } // TODO: Update the below with this once https://github.com/pnpm/pnpm/issues/992 is fixed