Skip to content

Commit

Permalink
refactor(publish): Gather current tags filtered by --list glob
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Nov 27, 2018
1 parent 1aa1712 commit 3b98973
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions commands/publish/index.js
Expand Up @@ -198,12 +198,15 @@ class PublishCommand extends Command {
}

detectFromGit() {
const { tagVersionPrefix = "v" } = this.options;
const matchingPattern = this.project.isIndependent() ? "*@*" : `${tagVersionPrefix}*.*.*`;

let chain = Promise.resolve();

// attempting to publish a tagged release with local changes is not allowed
chain = chain.then(() => this.verifyWorkingTreeClean());

chain = chain.then(() => getCurrentTags(this.execOpts));
chain = chain.then(() => getCurrentTags(this.execOpts, matchingPattern));
chain = chain.then(taggedPackageNames => {
if (!taggedPackageNames.length) {
this.logger.notice("from-git", "No tagged release found");
Expand All @@ -212,7 +215,7 @@ class PublishCommand extends Command {
}

if (this.project.isIndependent()) {
return taggedPackageNames.map(name => this.packageGraph.get(name)).filter(name => name !== undefined);
return taggedPackageNames.map(name => this.packageGraph.get(name));
}

return getTaggedPackages(this.packageGraph, this.project.rootPath, this.execOpts);
Expand Down
4 changes: 2 additions & 2 deletions commands/publish/lib/get-current-tags.js
Expand Up @@ -6,7 +6,7 @@ const childProcess = require("@lerna/child-process");

module.exports = getCurrentTags;

function getCurrentTags(execOpts) {
function getCurrentTags(execOpts, matchingPattern) {
log.silly("getCurrentTags");

const opts = Object.assign({}, execOpts, {
Expand All @@ -15,7 +15,7 @@ function getCurrentTags(execOpts) {
});

return childProcess
.exec("git", ["tag", "--sort", "version:refname", "--points-at", "HEAD"], opts)
.exec("git", ["tag", "--sort", "version:refname", "--points-at", "HEAD", "--list", matchingPattern], opts)
.then(listPackageNames);
}

Expand Down
4 changes: 2 additions & 2 deletions integration/lerna-publish-custom-tag.test.js
Expand Up @@ -25,6 +25,6 @@ test("lerna publish from-git handles custom tags", async () => {

const args = ["publish", "--yes", "from-git"];

const { stdout } = await cliRunner(cwd, env)(...args);
expect(stdout).toMatchInlineSnapshot("", ``);
const { stderr } = await cliRunner(cwd, env)(...args);
expect(stderr).toMatch("lerna notice from-git No tagged release found");
});

0 comments on commit 3b98973

Please sign in to comment.