diff --git a/commands/publish/__tests__/publish-canary.test.js b/commands/publish/__tests__/publish-canary.test.js index ffa107f671..509d14ca39 100644 --- a/commands/publish/__tests__/publish-canary.test.js +++ b/commands/publish/__tests__/publish-canary.test.js @@ -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) { @@ -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; @@ -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 ", async () => { const cwd = await initTaggedFixture("normal"); diff --git a/commands/publish/index.js b/commands/publish/index.js index b889eecb41..09e88a9f09 100644 --- a/commands/publish/index.js +++ b/commands/publish/index.js @@ -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