Skip to content

Commit a2973cc

Browse files
authored
Fixes npmMinimalAgeGate with tags and prereleases (#6916)
## What's the problem this PR addresses? The `npmMinimalAgeGate` feature was favouring prerelease installs when running `yarn add`; it should instead remain on stable tracks until the final release passes the gate. Fixes #6914 ## How did you fix it? Added a check to only allow prereleases to be used if the initial tag version is also a prerelease. ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent 7b0f301 commit a2973cc

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

.yarn/versions/bbd0ef35.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-npm": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-init"
11+
- "@yarnpkg/plugin-interactive-tools"
12+
- "@yarnpkg/plugin-nm"
13+
- "@yarnpkg/plugin-npm-cli"
14+
- "@yarnpkg/plugin-pack"
15+
- "@yarnpkg/plugin-patch"
16+
- "@yarnpkg/plugin-pnp"
17+
- "@yarnpkg/plugin-pnpm"
18+
- "@yarnpkg/plugin-stage"
19+
- "@yarnpkg/plugin-typescript"
20+
- "@yarnpkg/plugin-version"
21+
- "@yarnpkg/plugin-workspace-tools"
22+
- "@yarnpkg/builder"
23+
- "@yarnpkg/core"
24+
- "@yarnpkg/doctor"

packages/acceptance-tests/pkg-tests-core/sources/utils/tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const RELEASE_DATE_PACKAGES: Record<string, Record<string, number | string>> = {
181181
"release-date": {
182182
"1.0.0": new Date(new Date().getTime() - /* 10 days */ 1000 * 60 * 60 * 24 * 10).toISOString(),
183183
"1.1.0": new Date(new Date().getTime() - /* 5 days */ 1000 * 60 * 60 * 24 * 5).toISOString(),
184+
"1.1.1-beta": new Date(new Date().getTime() - /* 3 days */ 1000 * 60 * 60 * 24 * 3).toISOString(),
184185
"1.1.1": new Date().toISOString(),
185186
},
186187
"release-date-transitive": {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = require(`./package.json`);
2+
3+
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
4+
for (const dep of Object.keys(module.exports[key] || {})) {
5+
module.exports[key][dep] = require(dep);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "release-date",
3+
"version": "1.1.1-beta",
4+
"dependencies": {
5+
"release-date-transitive": "^1.0.0"
6+
}
7+
}

packages/plugin-npm/sources/NpmTagResolver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ export class NpmTagResolver implements Resolver {
5959
let version = distTags[tag];
6060

6161
if (tag === `latest` && !isPackageApproved({configuration: opts.project.configuration, ident: descriptor, version, publishTimes: times})) {
62+
const toleratePrereleases = version.includes(`-`);
63+
6264
const nextVersion = semver.rsort(versions).find(candidateVersion => {
63-
return semver.lt(candidateVersion, version) && isPackageApproved({configuration: opts.project.configuration, ident: descriptor, version: candidateVersion, publishTimes: times});
65+
return semver.lt(candidateVersion, version) && (toleratePrereleases || !candidateVersion.includes(`-`)) && isPackageApproved({configuration: opts.project.configuration, ident: descriptor, version: candidateVersion, publishTimes: times});
6466
});
6567

6668
if (!nextVersion)

0 commit comments

Comments
 (0)