Skip to content

Commit f4cbd4d

Browse files
committed
fix(publish): Identify tagged packages correctly with custom --tag-version-prefix
Fixes #2195
1 parent c6ce863 commit f4cbd4d

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

commands/publish/__tests__/publish-from-git.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ describe("publish from-git", () => {
7272
]);
7373
});
7474

75+
it("publishes packages matching custom --tag-version-prefix", async () => {
76+
const cwd = await initFixture("normal");
77+
78+
await gitTag(cwd, "foo/1.0.0");
79+
await lernaPublish(cwd)("from-git", "--tag-version-prefix", "foo/");
80+
81+
expect(npmPublish.order()).toEqual([
82+
"package-1",
83+
"package-3",
84+
"package-4",
85+
"package-2",
86+
// package-5 is private
87+
]);
88+
});
89+
7590
it("only publishes independent packages with matching tags", async () => {
7691
const cwd = await initFixture("independent");
7792

commands/publish/lib/get-current-tags.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const childProcess = require("@lerna/child-process");
77
module.exports = getCurrentTags;
88

99
function getCurrentTags(execOpts, matchingPattern) {
10-
log.silly("getCurrentTags");
10+
log.silly("getCurrentTags", "matching %j", matchingPattern);
1111

1212
const opts = Object.assign({}, execOpts, {
1313
// don't reject due to non-zero exit code when there are no results
@@ -16,12 +16,17 @@ function getCurrentTags(execOpts, matchingPattern) {
1616

1717
return childProcess
1818
.exec("git", ["tag", "--sort", "version:refname", "--points-at", "HEAD", "--list", matchingPattern], opts)
19-
.then(listPackageNames);
20-
}
19+
.then(result => {
20+
const lines = result.stdout.split("\n").filter(Boolean);
21+
22+
if (matchingPattern === "*@*") {
23+
// independent mode does not respect tagVersionPrefix,
24+
// but embeds the package name in the tag "prefix"
25+
return lines.map(tag => npa(tag).name);
26+
}
2127

22-
function listPackageNames(result) {
23-
return result.stdout
24-
.split("\n")
25-
.map(tag => tag && npa(tag).name)
26-
.filter(Boolean);
28+
// "fixed" mode can have a custom tagVersionPrefix,
29+
// but it doesn't really matter as it is not used to extract package names
30+
return lines;
31+
});
2732
}

0 commit comments

Comments
 (0)