/
get-tagged-packages.js
29 lines (24 loc) · 1.12 KB
/
get-tagged-packages.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
"use strict";
const path = require("path");
const log = require("npmlog");
const childProcess = require("@lerna/child-process");
module.exports.getTaggedPackages = getTaggedPackages;
/**
* Retrieve a list of graph nodes for packages that were tagged in a non-independent release.
* @param {import("@lerna/package-graph").PackageGraph} packageGraph
* @param {string} rootPath
* @param {{ cwd: string }} execOpts
* @returns {Promise<import("@lerna/package-graph").PackageGraphNode[]>}
*/
function getTaggedPackages(packageGraph, rootPath, execOpts) {
log.silly("getTaggedPackages");
// @see https://stackoverflow.com/a/424142/5707
// FIXME: --root is only necessary for tests :P
return childProcess
.exec("git", ["diff-tree", "--name-only", "--no-commit-id", "--root", "-r", "-c", "HEAD"], execOpts)
.then(({ stdout }) => {
const manifests = stdout.split("\n").filter((fp) => path.basename(fp) === "package.json");
const locations = new Set(manifests.map((fp) => path.join(rootPath, path.dirname(fp))));
return Array.from(packageGraph.values()).filter((node) => locations.has(node.location));
});
}