Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/manager/npm/post-update/__snapshots__/yarn.spec.ts.snap
Expand Up @@ -31,6 +31,13 @@ Object {
}
`;

exports[`manager/npm/post-update/yarn checkYarnrc() returns offline mirror and no yarn path for non-existant yarn-path binary 1`] = `
Object {
"offlineMirror": false,
"yarnPath": null,
}
`;

exports[`manager/npm/post-update/yarn checkYarnrc() returns offline mirror and yarn path 1`] = `
Object {
"offlineMirror": true,
Expand Down
31 changes: 31 additions & 0 deletions lib/manager/npm/post-update/yarn.spec.ts
Expand Up @@ -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) =>
Expand All @@ -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) =>
Expand All @@ -249,5 +261,24 @@ 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(''));
});
// FIXME: explicit assert condition
expect(await _yarnHelper.checkYarnrc('/tmp/renovate')).toMatchSnapshot();
rarkins marked this conversation as resolved.
Show resolved Hide resolved
expect(yarnrcContents).not.toContain('yarn-path');
});
});
});
11 changes: 10 additions & 1 deletion lib/manager/npm/post-update/yarn.ts
Expand Up @@ -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';
Expand All @@ -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
Expand Down