Skip to content
Snippets Groups Projects
Unverified Commit fdb6104b authored by Kevin James's avatar Kevin James Committed by GitHub
Browse files

fix(manager/mix): support lockfiles in subdirs (#10689)

parent daff0f2e
No related branches found
Tags v0.29.2
No related merge requests found
...@@ -83,6 +83,7 @@ describe(getName(), () => { ...@@ -83,6 +83,7 @@ describe(getName(), () => {
jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce();
setAdminConfig({ ...adminConfig, binarySource: 'docker' }); setAdminConfig({ ...adminConfig, binarySource: 'docker' });
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock'); fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
const execSnapshots = mockExecAll(exec); const execSnapshots = mockExecAll(exec);
fs.readLocalFile.mockResolvedValueOnce('New mix.lock'); fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
expect( expect(
...@@ -96,8 +97,24 @@ describe(getName(), () => { ...@@ -96,8 +97,24 @@ describe(getName(), () => {
expect(execSnapshots).toMatchSnapshot(); 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 () => { it('catches write errors', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current mix.lock'); fs.readLocalFile.mockResolvedValueOnce('Current mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
fs.writeLocalFile.mockImplementationOnce(() => { fs.writeLocalFile.mockImplementationOnce(() => {
throw new Error('not found'); throw new Error('not found');
}); });
...@@ -113,6 +130,7 @@ describe(getName(), () => { ...@@ -113,6 +130,7 @@ describe(getName(), () => {
it('catches exec errors', async () => { it('catches exec errors', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current mix.lock'); fs.readLocalFile.mockResolvedValueOnce('Current mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
exec.mockImplementationOnce(() => { exec.mockImplementationOnce(() => {
throw new Error('exec-error'); throw new Error('exec-error');
}); });
......
...@@ -2,7 +2,11 @@ import { quote } from 'shlex'; ...@@ -2,7 +2,11 @@ import { quote } from 'shlex';
import { TEMPORARY_ERROR } from '../../constants/error-messages'; import { TEMPORARY_ERROR } from '../../constants/error-messages';
import { logger } from '../../logger'; import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec'; 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'; import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
export async function updateArtifacts({ export async function updateArtifacts({
...@@ -16,7 +20,7 @@ export async function updateArtifacts({ ...@@ -16,7 +20,7 @@ export async function updateArtifacts({
return null; return null;
} }
const lockFileName = 'mix.lock'; const lockFileName = getSiblingFileName(packageFileName, 'mix.lock');
try { try {
await writeLocalFile(packageFileName, newPackageFileContent); await writeLocalFile(packageFileName, newPackageFileContent);
} catch (err) { } catch (err) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment