-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
get-current-tags.js
38 lines (31 loc) · 1.25 KB
/
get-current-tags.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict";
const log = require("npmlog");
const npa = require("npm-package-arg");
const childProcess = require("@lerna/child-process");
module.exports.getCurrentTags = getCurrentTags;
/**
* Retrieve a list of git tags pointing to the current HEAD that match the provided pattern.
* @param {import("@lerna/child-process").ExecOpts} execOpts
* @param {string} matchingPattern
* @returns {string[]}
*/
function getCurrentTags(execOpts, matchingPattern) {
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
reject: false,
});
return childProcess
.exec("git", ["tag", "--sort", "version:refname", "--points-at", "HEAD", "--list", matchingPattern], opts)
.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);
}
// "fixed" mode can have a custom tagVersionPrefix,
// but it doesn't really matter as it is not used to extract package names
return lines;
});
}