-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Please add a test to https://github.com/yarnpkg/berry/blob/506ded5f5f5a89553435940c74f1d857fd685a42/packages/acceptance-tests/pkg-tests-specs/sources/commands/set/version.test.ts verifying that it works as expected.
Implement fixes suggested by merceyz at yarnpkg#5942
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
7793ae4
to
688a5d4
Compare
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; |
There was a problem hiding this comment.
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
).
There was a problem hiding this comment.
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`)); |
There was a problem hiding this comment.
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`)); |
There was a problem hiding this comment.
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.
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)); | ||
}), | ||
); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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.
@merceyz Hi, sorry to bother, but could you please review this again? I've made the changes you have requested. |
What's the problem this PR addresses?
The
yarn set version
command of the CLI ignores theyarnPath
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