forked from lerna/lerna
-
Notifications
You must be signed in to change notification settings - Fork 2
/
get-filtered-packages.js
49 lines (35 loc) · 1.4 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
"use strict";
const log = require("npmlog");
const collectUpdates = require("@lerna/collect-updates");
const filterPackages = require("@lerna/filter-packages");
module.exports = getFilteredPackages;
function getFilteredPackages(packageGraph, execOpts, options) {
if (options.scope) {
log.notice("filter", "including %j", options.scope);
}
if (options.ignore) {
log.notice("filter", "excluding %j", options.ignore);
}
let chain = Promise.resolve();
chain = chain.then(() =>
filterPackages(packageGraph.rawPackageList, options.scope, options.ignore, options.private)
);
if (options.since !== undefined) {
log.notice("filter", "changed since %j", options.since);
chain = chain.then(filteredPackages =>
Promise.resolve(collectUpdates(filteredPackages, packageGraph, execOpts, options)).then(updates => {
const updated = new Set(updates.map(({ pkg }) => pkg.name));
return filteredPackages.filter(pkg => updated.has(pkg.name));
})
);
}
if (options.includeFilteredDependents) {
log.notice("filter", "including filtered dependents");
chain = chain.then(filteredPackages => packageGraph.addDependents(filteredPackages));
}
if (options.includeFilteredDependencies) {
log.notice("filter", "including filtered dependencies");
chain = chain.then(filteredPackages => packageGraph.addDependencies(filteredPackages));
}
return chain;
}