Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .yarn/versions/59b2c8b4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/plugin-version": minor

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe(`Commands`, () => {
test(
`it shouldn't work if the strategy isn't semver and there is no prior version`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await expect(run(`version`, `patch`)).rejects.toThrow();
await expect(run(`version`, `patch`)).rejects.toThrow(`Usage Error: Can't bump the version if there wasn't a version to begin with - use 0.0.0 as initial version then run the command again.`);
}),
);

Expand All @@ -15,7 +15,7 @@ describe(`Commands`, () => {
version: `1.0.0`,
}, async ({path, run, source}) => {
await run(`version`, `1.1.0`, `--deferred`);
await expect(run(`version`, `1.0.1`)).rejects.toThrow();
await expect(run(`version`, `1.0.1`)).rejects.toThrow(`Usage Error: Can't bump the version to one that would be lower than the current deferred one (1.1.0)`);
}),
);

Expand All @@ -25,7 +25,7 @@ describe(`Commands`, () => {
version: `1.0.0`,
}, async ({path, run, source}) => {
await run(`version`, `1.1.0`, `--deferred`);
await expect(run(`version`, `patch`)).rejects.toThrow();
await expect(run(`version`, `patch`)).rejects.toThrow(`Usage Error: Can't bump the version to one that would be lower than the current deferred one (1.1.0)`);
}),
);

Expand Down Expand Up @@ -99,7 +99,33 @@ describe(`Commands`, () => {
);

test(
`it shouldn't immediatly increase the version number for a workspace when using --deferred`,
`it should bump then append a prerelease version number to a release version`,
makeTemporaryEnv({
version: `1.2.3`,
}, async ({path, run, source}) => {
await run(`version`, `prerelease`);

await expect(xfs.readJsonPromise(`${path}/package.json` as PortablePath)).resolves.toMatchObject({
version: `1.2.4-0`,
});
}),
);

test(
`it should bump the prerelease version number on a prerelease version`,
makeTemporaryEnv({
version: `11.22.33-9`,
}, async ({path, run, source}) => {
await run(`version`, `prerelease`);

await expect(xfs.readJsonPromise(`${path}/package.json` as PortablePath)).resolves.toMatchObject({
version: `11.22.33-10`,
});
}),
);

test(
`it shouldn't immediately increase the version number for a workspace when using --deferred`,
makeTemporaryEnv({
version: `0.0.0`,
}, async ({path, run, source}) => {
Expand All @@ -118,7 +144,7 @@ describe(`Commands`, () => {
);

test(
`it shouldn't immediatly increase the version number for a workspace when using preferDeferredVersions`,
`it shouldn't immediately increase the version number for a workspace when using preferDeferredVersions`,
makeTemporaryEnv({
version: `0.0.0`,
}, {
Expand All @@ -139,7 +165,7 @@ describe(`Commands`, () => {
);

test(
`it should immediatly increase the version number for a workspace when using --immediate, even if preferDeferredVersions is set`,
`it should immediately increase the version number for a workspace when using --immediate, even if preferDeferredVersions is set`,
makeTemporaryEnv({
version: `0.0.0`,
}, {
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin-version/sources/versionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ describe(`versionUtils`, () => {
expect(versionUtils.applyPrerelease(`1.3.0`, {current: `1.2.3-rc.41`, prerelease: `rc.%n`})).toEqual(`1.3.0-rc.1`);
});
});

describe(`applyStrategy`, () => {
it(`should increase the prerelease number with prerelease strategy`, () => {
expect(versionUtils.applyStrategy(`1.2.3-0`, `prerelease`)).toEqual(`1.2.3-1`);
});

it(`should apply prepatch, preminor, premajor strategies`, () => {
expect(versionUtils.applyStrategy(`1.2.3`, `prepatch`)).toEqual(`1.2.4-0`);
expect(versionUtils.applyStrategy(`1.2.3`, `preminor`)).toEqual(`1.3.0-0`);
expect(versionUtils.applyStrategy(`1.2.3`, `premajor`)).toEqual(`2.0.0-0`);
});
});
});
9 changes: 8 additions & 1 deletion packages/plugin-version/sources/versionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export enum Decision {
MAJOR = `major`,
MINOR = `minor`,
PATCH = `patch`,
PREMAJOR = `premajor`,
PREMINOR = `preminor`,
PREPATCH = `prepatch`,
PRERELEASE = `prerelease`,
}

Expand Down Expand Up @@ -88,7 +91,11 @@ export async function resolveVersionFiles(project: Project, {prerelease = null}:
const baseVersion = workspace.manifest.raw.stableVersion ?? workspace.manifest.version;

const candidateRelease = candidateReleases.get(workspace);
const suggestedRelease = applyStrategy(baseVersion, validateReleaseDecision(decision));
// In case of prerelease decision with a prerelease version, the trailing number should be bumped
const suggestedRelease = Decision.PRERELEASE === decision ?
applyStrategy(workspace.manifest.version, validateReleaseDecision(decision)) :
applyStrategy(baseVersion, validateReleaseDecision(decision));


if (suggestedRelease === null)
throw new Error(`Assertion failed: Expected ${baseVersion} to support being bumped via strategy ${decision}`);
Expand Down
Loading