Skip to content

Commit

Permalink
fix(publish): Support --tag-version-prefix in --canary mode (#2435)
Browse files Browse the repository at this point in the history
Co-authored-by: Rafael Fakhreev <rrfakhr5@mts.ru>
Co-authored-by: Daniel Stockman <5605+evocateur@users.noreply.github.com>
  • Loading branch information
3 people committed May 23, 2020
1 parent a0402e4 commit 611c38e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions commands/publish/__tests__/publish-canary.test.js
Expand Up @@ -32,7 +32,7 @@ const lernaPublish = require("@lerna-test/command-runner")(require("../command")
// stabilize commit SHA
expect.addSnapshotSerializer(require("@lerna-test/serialize-git-sha"));

async function initTaggedFixture(fixtureName) {
async function initTaggedFixture(fixtureName, tagVersionPrefix = "v") {
const cwd = await initFixture(fixtureName);

if (fixtureName.indexOf("independent") > -1) {
Expand All @@ -44,7 +44,7 @@ async function initTaggedFixture(fixtureName) {
gitTag(cwd, "package-5@5.0.0"),
]);
} else {
await gitTag(cwd, "v1.0.0");
await gitTag(cwd, `${tagVersionPrefix}1.0.0`);
}

return cwd;
Expand Down Expand Up @@ -111,6 +111,21 @@ Object {
`);
});

test("publish --canary --tag-version-prefix='abc'", async () => {
const cwd = await initTaggedFixture("normal", "abc");

await setupChanges(cwd, ["packages/package-1/all-your-base.js", "belong to us"]);
await lernaPublish(cwd)("--canary", "--tag-version-prefix", "abc");

expect(writePkg.updatedVersions()).toMatchInlineSnapshot(`
Object {
"package-1": 1.0.1-alpha.0+SHA,
"package-2": 1.0.1-alpha.0+SHA,
"package-3": 1.0.1-alpha.0+SHA,
}
`);
});

test("publish --canary <semver>", async () => {
const cwd = await initTaggedFixture("normal");

Expand Down
2 changes: 1 addition & 1 deletion commands/publish/index.js
Expand Up @@ -358,7 +358,7 @@ class PublishCommand extends Command {

const makeVersion = fallback => ({ lastVersion = fallback, refCount, sha }) => {
// the next version is bumped without concern for preid or current index
const nextVersion = semver.inc(lastVersion, release.replace("pre", ""));
const nextVersion = semver.inc(lastVersion.replace(this.tagPrefix, ""), release.replace("pre", ""));

// semver.inc() starts a new prerelease at .0, git describe starts at .1
// and build metadata is always ignored when comparing dependency ranges
Expand Down

0 comments on commit 611c38e

Please sign in to comment.