diff --git a/commands/publish/__tests__/publish-from-git.test.js b/commands/publish/__tests__/publish-from-git.test.js index 096d849b9e..5ca8e4a73c 100644 --- a/commands/publish/__tests__/publish-from-git.test.js +++ b/commands/publish/__tests__/publish-from-git.test.js @@ -72,6 +72,21 @@ describe("publish from-git", () => { ]); }); + it("publishes packages matching custom --tag-version-prefix", async () => { + const cwd = await initFixture("normal"); + + await gitTag(cwd, "foo/1.0.0"); + await lernaPublish(cwd)("from-git", "--tag-version-prefix", "foo/"); + + expect(npmPublish.order()).toEqual([ + "package-1", + "package-3", + "package-4", + "package-2", + // package-5 is private + ]); + }); + it("only publishes independent packages with matching tags", async () => { const cwd = await initFixture("independent"); diff --git a/commands/publish/lib/get-current-tags.js b/commands/publish/lib/get-current-tags.js index 5ad5d31165..7c58d5be1d 100644 --- a/commands/publish/lib/get-current-tags.js +++ b/commands/publish/lib/get-current-tags.js @@ -7,7 +7,7 @@ const childProcess = require("@lerna/child-process"); module.exports = getCurrentTags; function getCurrentTags(execOpts, matchingPattern) { - log.silly("getCurrentTags"); + log.silly("getCurrentTags", "matching %j", matchingPattern); const opts = Object.assign({}, execOpts, { // don't reject due to non-zero exit code when there are no results @@ -16,12 +16,17 @@ function getCurrentTags(execOpts, matchingPattern) { return childProcess .exec("git", ["tag", "--sort", "version:refname", "--points-at", "HEAD", "--list", matchingPattern], opts) - .then(listPackageNames); -} + .then(result => { + const lines = result.stdout.split("\n").filter(Boolean); + + if (matchingPattern === "*@*") { + // independent mode does not respect tagVersionPrefix, + // but embeds the package name in the tag "prefix" + return lines.map(tag => npa(tag).name); + } -function listPackageNames(result) { - return result.stdout - .split("\n") - .map(tag => tag && npa(tag).name) - .filter(Boolean); + // "fixed" mode can have a custom tagVersionPrefix, + // but it doesn't really matter as it is not used to extract package names + return lines; + }); }