From fdb6104bc3904a54833c9e9aecd61d0d2865142b Mon Sep 17 00:00:00 2001
From: Kevin James <KevinJames@thekev.in>
Date: Mon, 5 Jul 2021 10:44:20 -0700
Subject: [PATCH] fix(manager/mix): support lockfiles in subdirs (#10689)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
---
 lib/manager/mix/artifacts.spec.ts | 18 ++++++++++++++++++
 lib/manager/mix/artifacts.ts      |  8 ++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/lib/manager/mix/artifacts.spec.ts b/lib/manager/mix/artifacts.spec.ts
index dfe078d1fa..99b4828e9e 100644
--- a/lib/manager/mix/artifacts.spec.ts
+++ b/lib/manager/mix/artifacts.spec.ts
@@ -83,6 +83,7 @@ describe(getName(), () => {
     jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce();
     setAdminConfig({ ...adminConfig, binarySource: 'docker' });
     fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
+    fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
     const execSnapshots = mockExecAll(exec);
     fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
     expect(
@@ -96,8 +97,24 @@ describe(getName(), () => {
     expect(execSnapshots).toMatchSnapshot();
   });
 
+  it('returns updated mix.lock in subdir', async () => {
+    setAdminConfig({ ...adminConfig, binarySource: 'docker' });
+    fs.getSiblingFileName.mockReturnValueOnce('subdir/mix.lock');
+    mockExecAll(exec);
+    expect(
+      await updateArtifacts({
+        packageFileName: 'subdir/mix.exs',
+        updatedDeps: [{ depName: 'plug' }],
+        newPackageFileContent: '{}',
+        config,
+      })
+    ).toBeNull();
+    expect(fs.readLocalFile).toHaveBeenCalledWith('subdir/mix.lock', 'utf8');
+  });
+
   it('catches write errors', async () => {
     fs.readLocalFile.mockResolvedValueOnce('Current mix.lock');
+    fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
     fs.writeLocalFile.mockImplementationOnce(() => {
       throw new Error('not found');
     });
@@ -113,6 +130,7 @@ describe(getName(), () => {
 
   it('catches exec errors', async () => {
     fs.readLocalFile.mockResolvedValueOnce('Current mix.lock');
+    fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
     exec.mockImplementationOnce(() => {
       throw new Error('exec-error');
     });
diff --git a/lib/manager/mix/artifacts.ts b/lib/manager/mix/artifacts.ts
index 05c5a594de..8b1b68e0e7 100644
--- a/lib/manager/mix/artifacts.ts
+++ b/lib/manager/mix/artifacts.ts
@@ -2,7 +2,11 @@ import { quote } from 'shlex';
 import { TEMPORARY_ERROR } from '../../constants/error-messages';
 import { logger } from '../../logger';
 import { ExecOptions, exec } from '../../util/exec';
-import { readLocalFile, writeLocalFile } from '../../util/fs';
+import {
+  getSiblingFileName,
+  readLocalFile,
+  writeLocalFile,
+} from '../../util/fs';
 import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
 
 export async function updateArtifacts({
@@ -16,7 +20,7 @@ export async function updateArtifacts({
     return null;
   }
 
-  const lockFileName = 'mix.lock';
+  const lockFileName = getSiblingFileName(packageFileName, 'mix.lock');
   try {
     await writeLocalFile(packageFileName, newPackageFileContent);
   } catch (err) {
-- 
GitLab