Skip to content

Commit f38882e

Browse files
authored
Merge pull request #163 from Agoric/ta/yarn-doctor
feat: check for yarn version
2 parents 749eb48 + be6f8d6 commit f38882e

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

packages/synthetic-chain/src/cli/doctor.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,12 @@ const fixupProposal = (proposal: ProposalInfo) => {
4040
}
4141
};
4242

43-
export const runDoctor = (proposals: ProposalInfo[]) => {
44-
console.log('Running doctor...');
45-
46-
console.log('enabling corepack');
47-
execSync('corepack enable', { stdio: 'inherit' });
48-
49-
// path to yarn
43+
const checkYarn = () => {
5044
const yarnpath = execSync('which yarn', {
5145
encoding: 'utf-8',
5246
});
47+
console.log(yarnpath);
48+
5349
if (yarnpath.includes('homebrew')) {
5450
// Homebrew's yarn install overrides Node's corepack install
5551
console.error(
@@ -58,7 +54,32 @@ export const runDoctor = (proposals: ProposalInfo[]) => {
5854
console.error(' brew uninstall yarn');
5955
process.exit(1);
6056
}
61-
console.log(yarnpath);
57+
58+
const packageJson = JSON.parse(
59+
fs.readFileSync(path.join('package.json'), 'utf-8'),
60+
);
61+
const expectedYarnVersion =
62+
packageJson.packageManager.match(/yarn@(\d+\.\d+\.\d+)/)[1];
63+
const actualYarnVersion = execSync('yarn --version', {
64+
encoding: 'utf-8',
65+
}).trim();
66+
if (actualYarnVersion !== expectedYarnVersion) {
67+
console.log({ actualYarnVersion, expectedYarnVersion });
68+
console.error(
69+
`Corepack specifies yarn version ${expectedYarnVersion} but the path has ${actualYarnVersion}`,
70+
);
71+
console.error('Find a way to remove the global yarn before proceeding.');
72+
process.exit(1);
73+
}
74+
};
75+
76+
export const runDoctor = (proposals: ProposalInfo[]) => {
77+
console.log('Running doctor...');
78+
79+
console.log('enabling corepack');
80+
execSync('corepack enable', { stdio: 'inherit' });
81+
82+
checkYarn();
6283

6384
console.log('Verifying the CLI runs and create the Dockerfiles');
6485
execSync('yarn synthetic-chain prepare-build', { stdio: 'inherit' });

0 commit comments

Comments
 (0)