Skip to content

Commit e910640

Browse files
committed
wip: refactor omit filter to be single function
1 parent d4c128b commit e910640

File tree

1 file changed

+16
-18
lines changed
  • workspaces/arborist/lib/arborist

1 file changed

+16
-18
lines changed

workspaces/arborist/lib/arborist/reify.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -483,29 +483,27 @@ module.exports = cls => class Reifier extends cls {
483483

484484
process.emit('time', 'reify:trashOmits')
485485

486-
const filterTop = node => {
486+
const omitNodes = this.idealTree.inventory.filter((node) => {
487+
const { top } = node
487488
// if the top is not the root or workspace filter it out
488-
if (!node.isProjectRoot && !node.isWorkspace) {
489+
if (!top.isProjectRoot && !top.isWorkspace) {
489490
return false
490491
}
491-
// if we have no filter set, then include it by default
492-
if (!this.diff?.filterSet?.size) {
493-
return true
492+
// if there is a non-empty filter set, and our top node is not in it then
493+
// it should be filtered out
494+
if (this.diff?.filterSet?.size && !this.diff.filterSet.has(top)) {
495+
return false
494496
}
495-
// otherwise include based on if the top node is in our filter set
496-
return this.diff.filterSet.has(node)
497-
}
498-
499-
const filter = node =>
500-
filterTop(node.top) &&
501-
(
502-
node.peer && this[_omitPeer] ||
503-
node.dev && this[_omitDev] ||
504-
node.optional && this[_omitOptional] ||
505-
node.devOptional && this[_omitOptional] && this[_omitDev]
506-
)
497+
// then filter based on the dep type and which omit flags were set
498+
return (
499+
node.peer && this[_omitPeer] ||
500+
node.dev && this[_omitDev] ||
501+
node.optional && this[_omitOptional] ||
502+
node.devOptional && this[_omitOptional] && this[_omitDev]
503+
)
504+
})
507505

508-
for (const node of this.idealTree.inventory.filter(filter)) {
506+
for (const node of omitNodes) {
509507
this[_addNodeToTrashList](node)
510508
}
511509

0 commit comments

Comments
 (0)