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: Uses current release dir path, if exists #5942

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

jplukas
Copy link
Contributor

@jplukas jplukas commented Nov 4, 2023

What's the problem this PR addresses?
The yarn set version command of the CLI ignores the yarnPath variable.

Closes #5911

How did you fix it?
Changed the function invoked by the CLI in order to set the releases path to the content of the variable yarnPath, as defined in the .yarnrc.yml file if it's defined. Otherwise the default value of .yarn/releases/ holds.

Checklist

  • I have read the Contributing Guide.
  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/plugin-essentials/sources/commands/set/version.ts Outdated Show resolved Hide resolved
packages/plugin-essentials/sources/commands/set/version.ts Outdated Show resolved Hide resolved
.yarn/versions/94f0ddf0.yml Outdated Show resolved Hide resolved
fernandohjunqueira added a commit to jplukas/berry that referenced this pull request Nov 6, 2023
Implement fixes suggested by merceyz at
yarnpkg#5942
jplukas and others added 5 commits November 9, 2023 15:43
Implement fixes suggested by merceyz at
yarnpkg#5942
Since the releases folder is no longer hardcoded, we must get the actual releases folder from the configuration file, in order to perform some tests.
Adds tests to validate the expected behavior of the new functionality, modifies the check function used by the tests in this suite, and alter some function calls, in order to accommodate for the changes
@jplukas jplukas force-pushed the feat/set-version-yarnpath branch from 7793ae4 to 688a5d4 Compare November 9, 2023 18:43
Comment on lines +201 to +208
async function check(path: PortablePath, checks: {corepackVersion: string | RegExp, usePath: boolean}, releasesDir?: PortablePath) {
releasesDir = checks.usePath ? (releasesDir ?? ppath.join(path, `.yarn/releases`)) : undefined;
const yarnrcPath = ppath.join(path, Filename.rc);
const manifestPath = ppath.join(path, Filename.manifest);

let releases: Array<string> | null;
try {
releases = await xfs.readdirPromise(releasesPath);
releases = releasesDir ? await xfs.readdirPromise(releasesDir) : null;
Copy link
Contributor Author

@jplukas jplukas Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the releases dir path is no longer hardcoded, I figured I should change the check function, in order to make the releases dir path a parameter, rather than a constant.
Also, the parameter is optional, and defaults to .yarn/releases (if the usePath parameter is true).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, my first ideia was to retrieve the releases dir path from the .yarnrc.yml file, but that seemed to make the tests super slow. So I made it a parameter.

@@ -101,7 +101,7 @@ describe(`Commands`, () => {
await xfs.writeFilePromise(ppath.join(projectDir, Filename.lockfile), ``);

await run(`set`, `version`, `self`, {cwd: projectDir});
await check(projectDir, {corepackVersion: /[0-9]+\./, usePath: true});
await check(projectDir, {corepackVersion: /[0-9]+\./, usePath: true}, ppath.join(path, `.yarn/releases`));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the tests where the yarnPath is set outside of the project, simply omitting the releasesDir parameter (in the new version of the check function) wouldn't work.

@@ -136,20 +136,57 @@ describe(`Commands`, () => {
await xfs.writeFilePromise(ppath.join(projectDir, Filename.lockfile), ``);

await run(`set`, `version`, `self`, `--only-if-needed`, {cwd: projectDir});
await check(projectDir, {corepackVersion: /[0-9]+\./, usePath: true});
await check(projectDir, {corepackVersion: /[0-9]+\./, usePath: true}, ppath.join(path, `.yarn/releases`));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the tests where the yarnPath is set outside of the project, simply omitting the releasesDir parameter (in the new version of the check function) wouldn't work.

Comment on lines +143 to 178
test(
`it should respect the current yarnPath, if it is defined`,
makeTemporaryEnv({}, {
env: {COREPACK_ROOT: undefined},
}, async ({path, run, source}) => {
await run(`set`, `version`, `4.0.0`);
await check(path, {corepackVersion: `4.0.0`, usePath: true});
const oldYarnPath = ppath.join(path, `.yarn/releases/yarn-4.0.0.cjs`);
const releasesPath = ppath.join(path, `releases_dir`);
await xfs.mkdirPromise(releasesPath);
const yarnAbsPath = ppath.join(releasesPath, `/yarn-4.0.0.cjs`);
const yarnPath = ppath.relative(path, yarnAbsPath);
await xfs.renamePromise(oldYarnPath, yarnAbsPath);
await xfs.writeFilePromise(ppath.join(path, Filename.rc), `yarnPath: ${yarnPath}`);
await run(`set`, `version`, `3.0.0`);
await check(path, {corepackVersion: `3.0.0`, usePath: true}, ppath.dirname(yarnAbsPath));
}),
);
test(
`it should respect the current yarnPath if defined, even when corepack is enabled and the version range is semver`,
makeTemporaryEnv({}, {
env: {COREPACK_ROOT: undefined},
}, async ({path, run, source}) => {
await run(`set`, `version`, `4.0.0`);
await check(path, {corepackVersion: `4.0.0`, usePath: true});
const oldYarnPath = ppath.join(path, `.yarn/releases/yarn-4.0.0.cjs`);
const releasesPPath = ppath.join(path, `releases_dir`);
await xfs.mkdirPromise(releasesPPath);
const yarnAbsPath = ppath.join(releasesPPath, `/yarn-4.0.0.cjs`);
const yarnPath = ppath.relative(path, yarnAbsPath);
await xfs.renamePromise(oldYarnPath, yarnAbsPath);
await xfs.writeFilePromise(ppath.join(path, Filename.rc), `yarnPath: ${yarnPath}`);
await run(`set`, `version`, `3.0.0`, {env: {COREPACK_ROOT: `/path/to/corepack`}});
await check(path, {corepackVersion: `3.0.0`, usePath: true}, ppath.dirname(yarnAbsPath));
}),
);
Copy link
Contributor Author

@jplukas jplukas Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tests, as requested in #5942 (review)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure which packages should I mark to release, or what kind of update should I mark the packages with (whether it's a patch, or minor update). Clarifications would be welcome 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed some tests, in order for them to be compatible with the new functionality. Please let me know if this was the right decision, or if I should not have changed existing tests.

@jplukas jplukas requested a review from merceyz November 10, 2023 16:08
@jplukas
Copy link
Contributor Author

jplukas commented Nov 26, 2023

@merceyz Hi, sorry to bother, but could you please review this again? I've made the changes you have requested.
I'm not entirely sure if pinging you here is the right course of action, please let me know if I'm being rude or disrespectful.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: yarn set version doesn't respect current yarn path
3 participants