Skip to content

Commit

Permalink
fix(publish): Identify tagged packages correctly with custom `--tag-v…
Browse files Browse the repository at this point in the history
…ersion-prefix`

Fixes #2195
  • Loading branch information
evocateur committed Jul 23, 2019
1 parent c6ce863 commit f4cbd4d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
15 changes: 15 additions & 0 deletions commands/publish/__tests__/publish-from-git.test.js
Expand Up @@ -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");

Expand Down
21 changes: 13 additions & 8 deletions commands/publish/lib/get-current-tags.js
Expand Up @@ -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
Expand All @@ -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;
});
}

0 comments on commit f4cbd4d

Please sign in to comment.