/
get-filtered-packages.js
86 lines (68 loc) · 2.31 KB
/
get-filtered-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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"use strict";
const log = require("npmlog");
const collectUpdates = require("@lerna/collect-updates");
const filterPackages = require("@lerna/filter-packages");
module.exports = getFilteredPackages;
/**
* @typedef {object} FilterOptions
* @property {string} scope
* @property {string} ignore
* @property {boolean} private
* @property {string} since
* @property {boolean} continueIfNoMatch
* @property {boolean} excludeDependents
* @property {boolean} includeDependents
* @property {boolean} includeDependencies
* @property {boolean} includeMergedTags
* @property {typeof log} log
*/
/**
* Retrieve a list of Package instances filtered by various options.
* @param {PackageGraph} packageGraph
* @param {CommandExecOpts} execOpts
* @param {Partial<FilterOptions>} opts
* @returns {Promise<Package>}
*/
function getFilteredPackages(packageGraph, execOpts, opts) {
const options = { log, ...opts };
if (options.scope) {
options.log.notice("filter", "including %j", options.scope);
}
if (options.ignore) {
options.log.notice("filter", "excluding %j", options.ignore);
}
let chain = Promise.resolve();
chain = chain.then(() =>
filterPackages(
packageGraph.rawPackageList,
options.scope,
options.ignore,
options.private,
options.continueIfNoMatch
)
);
if (options.since !== undefined) {
options.log.notice("filter", "changed since %j", options.since);
if (options.excludeDependents) {
options.log.notice("filter", "excluding dependents");
}
if (options.includeMergedTags) {
options.log.notice("filter", "including merged tags");
}
chain = chain.then((filteredPackages) =>
Promise.resolve(collectUpdates(filteredPackages, packageGraph, execOpts, opts)).then((updates) => {
const updated = new Set(updates.map(({ pkg }) => pkg.name));
return filteredPackages.filter((pkg) => updated.has(pkg.name));
})
);
}
if (options.includeDependents) {
options.log.notice("filter", "including dependents");
chain = chain.then((filteredPackages) => packageGraph.addDependents(filteredPackages));
}
if (options.includeDependencies) {
options.log.notice("filter", "including dependencies");
chain = chain.then((filteredPackages) => packageGraph.addDependencies(filteredPackages));
}
return chain;
}