Skip to content

Commit 5046750

Browse files
Support version apply exact (#6629)
## What's the problem this PR addresses? <!-- Describe the rationale of your PR. --> <!-- Link all issues that it closes. (Closes/Resolves #xxxx.) --> Closes: #6583 ## How did you fix it? <!-- A detailed description of your implementation. --> When applying versions, I removed the range character. ## 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. --------- Co-authored-by: Maël Nison <[email protected]>
1 parent f1a8a4d commit 5046750

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

.yarn/versions/a292aff0.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
releases:
2+
"@yarnpkg/cli": minor
3+
"@yarnpkg/plugin-version": minor
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-workspace-tools"
21+
- "@yarnpkg/builder"
22+
- "@yarnpkg/core"
23+
- "@yarnpkg/doctor"

packages/acceptance-tests/pkg-tests-specs/sources/commands/version/apply.test.ts

+50
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ describe(`Commands`, () => {
164164
),
165165
);
166166

167+
167168
const alternatives = [
168169
[`implicit`, `1.0.0`, true],
169170
[`implicit range`, `^1.0.0`, true],
@@ -220,6 +221,55 @@ describe(`Commands`, () => {
220221
},
221222
),
222223
);
224+
225+
test(
226+
`it should update the dependencies (${name}) to exact matches`,
227+
makeTemporaryEnv(
228+
{
229+
private: true,
230+
workspaces: [
231+
`packages/*`,
232+
],
233+
},
234+
async ({path, run}) => {
235+
const pkgA = ppath.join(path, `packages/pkg-a`);
236+
const pkgB = ppath.join(path, `packages/pkg-b`);
237+
238+
await xfs.mkdirpPromise(pkgA);
239+
await xfs.mkdirpPromise(pkgB);
240+
241+
await xfs.writeJsonPromise(ppath.join(pkgA, Filename.manifest), {
242+
name: `pkg-a`,
243+
version: `1.0.0`,
244+
dependencies: {
245+
[`pkg-b`]: dependency,
246+
},
247+
});
248+
249+
await xfs.writeJsonPromise(ppath.join(pkgB, Filename.manifest), {
250+
name: `pkg-b`,
251+
version: `1.0.0`,
252+
});
253+
254+
await run(`version`, `patch`, `--deferred`, {
255+
cwd: pkgB,
256+
});
257+
258+
await run(`version`, `apply`, `--all`, `--exact`);
259+
260+
await expect(xfs.readJsonPromise(ppath.join(pkgA, Filename.manifest))).resolves.toMatchObject({
261+
version: `1.0.0`,
262+
dependencies: {
263+
[`pkg-b`]: dependency.replace(/1\.0\.0/, `1.0.1`).replace(/\^/, ``),
264+
},
265+
});
266+
267+
await expect(xfs.readJsonPromise(ppath.join(pkgB, Filename.manifest))).resolves.toMatchObject({
268+
version: `1.0.1`,
269+
});
270+
},
271+
),
272+
);
223273
}
224274
});
225275
});

packages/plugin-version/sources/commands/version/apply.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export default class VersionApplyCommand extends BaseCommand {
4848
tolerateBoolean: true,
4949
});
5050

51+
exact = Option.Boolean(`--exact`, false, {
52+
description: `Use the exact version of each package, removes any range. Useful for nightly releases where the range might match another version.`,
53+
});
54+
5155
recursive = Option.Boolean(`-R,--recursive`, {
5256
description: `Release the transitive workspaces as well`,
5357
});
@@ -104,7 +108,7 @@ export default class VersionApplyCommand extends BaseCommand {
104108
return;
105109
}
106110

107-
versionUtils.applyReleases(project, filteredReleases, {report});
111+
versionUtils.applyReleases(project, filteredReleases, {report, exact: this.exact});
108112

109113
if (!this.dryRun) {
110114
if (!prerelease) {

packages/plugin-version/sources/versionUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export function applyStrategy(version: string | null, strategy: string) {
384384
return nextVersion;
385385
}
386386

387-
export function applyReleases(project: Project, newVersions: Map<Workspace, string>, {report}: {report: Report}) {
387+
export function applyReleases(project: Project, newVersions: Map<Workspace, string>, {report, exact}: {report: Report, exact?: boolean}) {
388388
const allDependents: Map<Workspace, Array<[
389389
Workspace,
390390
AllDependencies,
@@ -465,7 +465,7 @@ export function applyReleases(project: Project, newVersions: Map<Workspace, stri
465465
continue;
466466
}
467467

468-
let newRange = `${parsed[1]}${newVersion}`;
468+
let newRange = exact ? `${newVersion}` : `${parsed[1]}${newVersion}`;
469469
if (useWorkspaceProtocol)
470470
newRange = `${WorkspaceResolver.protocol}${newRange}`;
471471

0 commit comments

Comments
 (0)