From f3584b5fea7aa188ad0e9efe84f35a974d38a7af Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 15 May 2018 20:52:25 +0200
Subject: [PATCH] fix(yarn): optimise existing file writing

---
 lib/manager/npm/post-update/index.js | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/lib/manager/npm/post-update/index.js b/lib/manager/npm/post-update/index.js
index 88a02e84cb..18dded9eff 100644
--- a/lib/manager/npm/post-update/index.js
+++ b/lib/manager/npm/post-update/index.js
@@ -184,7 +184,7 @@ async function writeExistingFiles(config, packageFiles) {
     if (npmLock) {
       const npmLockPath = upath.join(config.tmpDir.path, npmLock);
       if (config.type === 'lockFileMaintenance') {
-        logger.trace(`Removing ${npmLock}`);
+        logger.debug(`Ensuring ${npmLock} is removed`);
         await fs.remove(npmLockPath);
       } else {
         logger.debug(`Writing ${npmLock}`);
@@ -192,16 +192,17 @@ async function writeExistingFiles(config, packageFiles) {
         await fs.outputFile(npmLockPath, existingNpmLock);
       }
     }
-    if (packageFile.yarnLock && config.type !== 'lockFileMaintenance') {
-      logger.debug(`Writing yarn.lock to ${basedir}`);
-      const yarnLock = await platform.getFile(packageFile.yarnLock);
-      await fs.outputFile(
-        upath.join(config.tmpDir.path, packageFile.yarnLock),
-        yarnLock
-      );
-    } else {
-      logger.trace(`Removing ${basedir}/yarn.lock`);
-      await fs.remove(upath.join(basedir, 'yarn.lock'));
+    const { yarnLock } = packageFile;
+    if (yarnLock) {
+      const yarnLockPath = upath.join(config.tmpDir.path, yarnLock);
+      if (config.type === 'lockFileMaintenance') {
+        logger.debug(`Ensuring ${yarnLock} is removed`);
+        await fs.remove(yarnLockPath);
+      } else {
+        logger.debug(`Writing ${yarnLock}`);
+        const existingYarnLock = await platform.getFile(yarnLock);
+        await fs.outputFile(yarnLockPath, existingYarnLock);
+      }
     }
     // TODO: Update the below with this once https://github.com/pnpm/pnpm/issues/992 is fixed
     const pnpmBug992 = true;
-- 
GitLab