Skip to content

Commit

Permalink
feat(filter-options): Use figgy-pudding in getFilteredPackages()
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Oct 15, 2019
1 parent ff50e29 commit 73badee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
33 changes: 24 additions & 9 deletions core/filter-options/lib/get-filtered-packages.js
@@ -1,18 +1,33 @@
"use strict";

const log = require("npmlog");
const npmlog = require("npmlog");
const figgyPudding = require("figgy-pudding");
const collectUpdates = require("@lerna/collect-updates");
const filterPackages = require("@lerna/filter-packages");

module.exports = getFilteredPackages;

function getFilteredPackages(packageGraph, execOpts, options) {
const FilterConfig = figgyPudding({
scope: {},
ignore: {},
private: {},
since: {},
continueIfNoMatch: {},
excludeDependents: {},
includeFilteredDependents: {},
includeFilteredDependencies: {},
log: { default: npmlog },
});

function getFilteredPackages(packageGraph, execOpts, opts) {
const options = FilterConfig(opts);

if (options.scope) {
log.notice("filter", "including %j", options.scope);
options.log.notice("filter", "including %j", options.scope);
}

if (options.ignore) {
log.notice("filter", "excluding %j", options.ignore);
options.log.notice("filter", "excluding %j", options.ignore);
}

let chain = Promise.resolve();
Expand All @@ -28,14 +43,14 @@ function getFilteredPackages(packageGraph, execOpts, options) {
);

if (options.since !== undefined) {
log.notice("filter", "changed since %j", options.since);
options.log.notice("filter", "changed since %j", options.since);

if (options.excludeDependents) {
log.notice("filter", "excluding dependents");
options.log.notice("filter", "excluding dependents");
}

chain = chain.then(filteredPackages =>
Promise.resolve(collectUpdates(filteredPackages, packageGraph, execOpts, options)).then(updates => {
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));
Expand All @@ -44,13 +59,13 @@ function getFilteredPackages(packageGraph, execOpts, options) {
}

if (options.includeFilteredDependents) {
log.notice("filter", "including filtered dependents");
options.log.notice("filter", "including filtered dependents");

chain = chain.then(filteredPackages => packageGraph.addDependents(filteredPackages));
}

if (options.includeFilteredDependencies) {
log.notice("filter", "including filtered dependencies");
options.log.notice("filter", "including filtered dependencies");

chain = chain.then(filteredPackages => packageGraph.addDependencies(filteredPackages));
}
Expand Down
1 change: 1 addition & 0 deletions core/filter-options/package.json
Expand Up @@ -35,6 +35,7 @@
"@lerna/collect-updates": "file:../../utils/collect-updates",
"@lerna/filter-packages": "file:../../utils/filter-packages",
"dedent": "^0.7.0",
"figgy-pudding": "^3.5.1",
"npmlog": "^4.1.2"
}
}
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 73badee

Please sign in to comment.