Skip to content
Snippets Groups Projects
Unverified Commit 16aff741 authored by Derek's avatar Derek Committed by GitHub
Browse files

feat(yarn): ignore yarn-path if binary does not exist (#12322)


Co-authored-by: default avatarRhys Arkins <rhys@arkins.net>
parent 48c5a3c5
No related branches found
No related tags found
No related merge requests found
......@@ -223,6 +223,12 @@ describe('manager/npm/post-update/yarn', () => {
describe('checkYarnrc()', () => {
it('returns offline mirror and yarn path', async () => {
fs.exists.mockImplementation((path) => {
if (path === './.yarn/cli.js') {
return new Promise<boolean>((resolve) => resolve(true));
}
return new Promise<boolean>((resolve) => resolve(false));
});
fs.readFile.mockImplementation((filename, encoding) => {
if (filename.endsWith('.yarnrc')) {
return new Promise<string>((resolve) =>
......@@ -238,6 +244,12 @@ describe('manager/npm/post-update/yarn', () => {
});
it('returns no offline mirror and unquoted yarn path', async () => {
fs.exists.mockImplementation((path) => {
if (path === './.yarn/cli.js') {
return new Promise<boolean>((resolve) => resolve(true));
}
return new Promise<boolean>((resolve) => resolve(false));
});
fs.readFile.mockImplementation((filename, encoding) => {
if (filename.endsWith('.yarnrc')) {
return new Promise<string>((resolve) =>
......@@ -249,5 +261,27 @@ describe('manager/npm/post-update/yarn', () => {
// FIXME: explicit assert condition
expect(await _yarnHelper.checkYarnrc('/tmp/renovate')).toMatchSnapshot();
});
it('returns offline mirror and no yarn path for non-existant yarn-path binary', async () => {
let yarnrcContents = 'yarn-path ./.yarn/cli.js\n';
fs.writeFile.mockImplementation((filename, fileContents) => {
if (filename.endsWith('.yarnrc')) {
yarnrcContents = fileContents;
}
return new Promise<void>((resolve) => resolve());
});
fs.readFile.mockImplementation((filename, encoding) => {
if (filename.endsWith('.yarnrc')) {
return new Promise<string>((resolve) => resolve(yarnrcContents));
}
return new Promise<string>((resolve) => resolve(''));
});
const { offlineMirror, yarnPath } = await _yarnHelper.checkYarnrc(
'/tmp/renovate'
);
expect(offlineMirror).toBeFalse();
expect(yarnPath).toBeNull();
expect(yarnrcContents).not.toContain('yarn-path');
});
});
});
......@@ -11,7 +11,7 @@ import { id as npmId } from '../../../datasource/npm';
import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import { ExecOptions, exec } from '../../../util/exec';
import { readFile, remove } from '../../../util/fs';
import { exists, readFile, remove, writeFile } from '../../../util/fs';
import { regEx } from '../../../util/regex';
import type { PostUpdateConfig, Upgrade } from '../../types';
import { getNodeConstraint } from './node-version';
......@@ -35,6 +35,15 @@ export async function checkYarnrc(
if (pathLine) {
yarnPath = pathLine.replace(regEx(/^yarn-path\s+"?(.+?)"?$/), '$1');
}
const yarnBinaryExists = await exists(yarnPath);
if (!yarnBinaryExists) {
const scrubbedYarnrc = yarnrc.replace(
regEx(/^yarn-path\s+"?.+?"?$/gm),
''
);
await writeFile(`${cwd}/.yarnrc`, scrubbedYarnrc);
yarnPath = null;
}
}
} catch (err) /* istanbul ignore next */ {
// not found
......
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