/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib
NameSizeModeActions
arborist/-0755rm
add-rm-pkg-deps.js50080644editdlrm
audit-report.js96190644editdlrm
calc-dep-flags.js33590644editdlrm
can-place-dep.js142730644editdlrm
case-insensitive-map.js12390644editdlrm
consistent-resolve.js12470644editdlrm
debug.js12820644editdlrm
deepest-nesting-target.js6910644editdlrm
dep-valid.js51280644editdlrm
diff.js103270644editdlrm
edge.js99880644editdlrm
from-path.js10950644editdlrm
gather-dep-set.js12860644editdlrm
index.js2730644editdlrm
inventory.js33210644editdlrm
isolated-classes.js27170644editdlrm
link.js31140644editdlrm
node.js498280644editdlrm
optional-set.js12010644editdlrm
override-resolves.js2250644editdlrm
override-set.js87730644editdlrm
packument-cache.js25570644editdlrm
peer-entry-sets.js26320644editdlrm
place-dep.js202500644editdlrm
printable.js52220644editdlrm
query-selector-all.js303610644editdlrm
realpath.js26550644editdlrm
relpath.js1360644editdlrm
reset-dep-flags.js5420644editdlrm
retire-path.js5010644editdlrm
shrinkwrap.js377210644editdlrm
signal-handling.js22450644editdlrm
signals.js13810644editdlrm
spec-from-lock.js8740644editdlrm
tracker.js29910644editdlrm
tree-check.js41420644editdlrm
version-from-tgz.js14880644editdlrm
vuln.js59580644editdlrm
yarn-lock.js108130644editdlrm
Edit: /usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js (3359B)
// Dep flag (dev, peer, etc.) calculation requires default or reset flags. // Flags are true by default and are unset to false as we walk deps. // We iterate outward edges looking for dep flags that can // be unset based on the current nodes flags and edge type. // Examples: // - a non-optional node with a non-optional edge out, the edge node should not be optional // - a non-peer node with a non-peer edge out, the edge node should not be peer // If a node is changed, we add to the queue and continue until no more changes. // Flags that remain after all this unsetting should be valid. // Examples: // - a node still flagged optional must only be reachable via optional edges // - a node still flagged peer must only be reachable via peer edges const calcDepFlags = (tree, resetRoot = true) => { if (resetRoot) { tree.unsetDepFlags() } const seen = new Set() const queue = [tree] let node while (node = queue.pop()) { seen.add(node) // Unset extraneous from all parents to avoid removal of children. if (!node.extraneous) { for (let n = node.resolveParent; n?.extraneous; n = n.resolveParent) { n.extraneous = false } } // for links, map their hierarchy appropriately if (node.isLink) { // node.target can be null, we check to ensure it's not null before proceeding if (node.target == null) { continue } node.target.dev = node.dev node.target.optional = node.optional node.target.devOptional = node.devOptional node.target.peer = node.peer node.target.extraneous = node.extraneous queue.push(node.target) continue } for (const { peer, optional, dev, to } of node.edgesOut.values()) { // if the dep is missing, then its flags are already maximally unset if (!to) { continue } let changed = false // only optional peer dependencies should stay extraneous if (to.extraneous && !node.extraneous && !(peer && optional)) { to.extraneous = false changed = true } if (to.dev && !node.dev && !dev) { to.dev = false changed = true } if (to.optional && !node.optional && !optional) { to.optional = false changed = true } // devOptional is the *overlap* of the dev and optional tree. // A node may be depended on by separate dev and optional nodes. // It SHOULD NOT be removed when pruning dev OR optional. // It SHOULD be removed when pruning dev AND optional. // We only unset here if a node is not dev AND not optional because // if we did unset, it would prevent any overlap deeper in the tree. // We correct this later by removing if dev OR optional is set. if (to.devOptional && !node.devOptional && !node.dev && !node.optional && !dev && !optional) { to.devOptional = false changed = true } if (to.peer && !node.peer && !peer) { to.peer = false changed = true } if (changed) { queue.push(to) } } } // Remove incorrect devOptional flags now that we have walked all deps. seen.delete(tree) for (const node of seen.values()) { if (node.devOptional && (node.dev || node.optional)) { node.devOptional = false } } } module.exports = calcDepFlags