From d4eb79930156365fad4913ee53ce7a1cd82c0923 Mon Sep 17 00:00:00 2001 From: Rafael Fakhreev Date: Sun, 2 Feb 2020 17:17:17 +0300 Subject: [PATCH] fix (publish): canaries mode support --tag-version-prefix --- .../publish/__tests__/publish-canary.test.js | 19 +++++++++++++++++-- commands/publish/index.js | 5 ++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/commands/publish/__tests__/publish-canary.test.js b/commands/publish/__tests__/publish-canary.test.js index 3cf5984033..9f7134358f 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 07d99dd7c2..1c063bc22a 100644 --- a/commands/publish/index.js +++ b/commands/publish/index.js @@ -350,10 +350,9 @@ class PublishCommand extends Command { }) ); - const makeVersion = ({ lastVersion, refCount, sha }) => { + const makeVersion = ({ lastVersion = "", 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 return `${nextVersion}-${preid}.${Math.max(0, refCount - 1)}+${sha}`;