Skip to content

Commit 27f5cc2

Browse files
committed
Fix invalid yarn version message
1 parent 2e7d127 commit 27f5cc2

4 files changed

+16
-5
lines changed

src/monorepo-workflow-operations.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,10 @@ describe('monorepo-workflow-operations', () => {
456456
);
457457

458458
expect(fixConstraintsSpy).toHaveBeenCalledTimes(1);
459-
expect(fixConstraintsSpy).toHaveBeenCalledWith(projectDirectoryPath);
459+
expect(fixConstraintsSpy).toHaveBeenCalledWith(
460+
projectDirectoryPath,
461+
stdout,
462+
);
460463

461464
expect(installDependenciesSpy).toHaveBeenCalledTimes(1);
462465
expect(installDependenciesSpy).toHaveBeenCalledWith(

src/monorepo-workflow-operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export async function followMonorepoWorkflow({
148148
});
149149
await executeReleasePlan(project, releasePlan, stderr);
150150
await removeFile(releaseSpecificationPath);
151-
await fixConstraints(project.directoryPath);
151+
await fixConstraints(project.directoryPath, stdout);
152152
await installDependencies(project.directoryPath);
153153
await commitAllChanges(
154154
project.directoryPath,

src/yarn-commands.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'fs';
12
import { when } from 'jest-when';
23
import {
34
fixConstraints,
@@ -25,8 +26,9 @@ describe('yarn-commands', () => {
2526
when(jest.spyOn(miscUtils, 'getStdoutFromCommand'))
2627
.calledWith('yarn', ['--version'])
2728
.mockResolvedValue('2.0.0');
29+
const stdout = fs.createWriteStream('/dev/null');
2830

29-
await fixConstraints(repositoryDirectoryPath);
31+
await fixConstraints(repositoryDirectoryPath, stdout);
3032

3133
expect(miscUtils.runCommand).toHaveBeenCalledWith(
3234
'yarn',
@@ -42,8 +44,9 @@ describe('yarn-commands', () => {
4244
when(jest.spyOn(miscUtils, 'getStdoutFromCommand'))
4345
.calledWith('yarn', ['--version'])
4446
.mockResolvedValue('1.0.0');
47+
const stdout = fs.createWriteStream('/dev/null');
4548

46-
await fixConstraints(repositoryDirectoryPath);
49+
await fixConstraints(repositoryDirectoryPath, stdout);
4750

4851
expect(miscUtils.runCommand).toHaveBeenCalledTimes(0);
4952
});

src/yarn-commands.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { WriteStream } from 'fs';
12
import { debug, runCommand, getStdoutFromCommand } from './misc-utils.js';
23

34
/**
@@ -14,11 +15,13 @@ export async function getYarnVersion(): Promise<string> {
1415
* Runs `yarn constraints --fix` to fix any constraint issues.
1516
*
1617
* @param repositoryDirectoryPath - The path to the repository directory.
18+
* @param stderr - A stream that can be used to write to standard error.
1719
* @returns The standard output of the command.
1820
* @throws An execa error object if the command fails in some way.
1921
*/
2022
export async function fixConstraints(
2123
repositoryDirectoryPath: string,
24+
stderr: Pick<WriteStream, 'write'>,
2225
): Promise<void> {
2326
const version = await getYarnVersion();
2427
const majorVersion = parseInt(version.split('.')[0], 10);
@@ -29,7 +32,9 @@ export async function fixConstraints(
2932
});
3033
debug('Yarn constraints fixed successfully.');
3134
} else {
32-
debug('Skipping constraints fix as Yarn version is less than 2.');
35+
stderr.write(
36+
'Skipping constraints fix, current Yarn version does not support this feature.',
37+
);
3338
}
3439
}
3540

0 commit comments

Comments
 (0)