PHP 8.2.30
Preview: tree-check.js Size: 4.04 KB
/opt/alt/alt-nodejs20/root/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/tree-check.js

const debug = require('./debug.js')

const checkTree = (tree, checkUnreachable = true) => {
  const log = [['START TREE CHECK', tree.path]]

  // this can only happen in tests where we have a "tree" object
  // that isn't actually a tree.
  if (!tree.root || !tree.root.inventory) {
    return tree
  }

  const { inventory } = tree.root
  const seen = new Set()
  const check = (node, via = tree, viaType = 'self') => {
    log.push([
      'CHECK',
      node && node.location,
      via && via.location,
      viaType,
      'seen=' + seen.has(node),
      'promise=' + !!(node && node.then),
      'root=' + !!(node && node.isRoot),
    ])

    if (!node || seen.has(node) || node.then) {
      return
    }

    seen.add(node)

    if (node.isRoot && node !== tree.root) {
      throw Object.assign(new Error('double root'), {
        node: node.path,
        realpath: node.realpath,
        tree: tree.path,
        root: tree.root.path,
        via: via.path,
        viaType,
        log,
      })
    }

    if (node.root !== tree.root) {
      throw Object.assign(new Error('node from other root in tree'), {
        node: node.path,
        realpath: node.realpath,
        tree: tree.path,
        root: tree.root.path,
        via: via.path,
        viaType,
        otherRoot: node.root && node.root.path,
        log,
      })
    }

    if (!node.isRoot && node.inventory.size !== 0) {
      throw Object.assign(new Error('non-root has non-zero inventory'), {
        node: node.path,
        tree: tree.path,
        root: tree.root.path,
        via: via.path,
        viaType,
        inventory: [...node.inventory.values()].map(node =>
          [node.path, node.location]),
        log,
      })
    }

    if (!node.isRoot && !inventory.has(node) && !node.dummy) {
      throw Object.assign(new Error('not in inventory'), {
        node: node.path,
        tree: tree.path,
        root: tree.root.path,
        via: via.path,
        viaType,
        log,
      })
    }

    const devEdges = [...node.edgesOut.values()].filter(e => e.dev)
    if (!node.isTop && devEdges.length) {
      throw Object.assign(new Error('dev edges on non-top node'), {
        node: node.path,
        tree: tree.path,
        root: tree.root.path,
        via: via.path,
        viaType,
        devEdges: devEdges.map(e => [e.type, e.name, e.spec, e.error]),
        log,
      })
    }

    if (node.path === tree.root.path && node !== tree.root && !tree.root.isLink) {
      throw Object.assign(new Error('node with same path as root'), {
        node: node.path,
        tree: tree.path,
        root: tree.root.path,
        via: via.path,
        viaType,
        log,
      })
    }

    if (!node.isLink && node.path !== node.realpath) {
      throw Object.assign(new Error('non-link with mismatched path/realpath'), {
        node: node.path,
        tree: tree.path,
        realpath: node.realpath,
        root: tree.root.path,
        via: via.path,
        viaType,
        log,
      })
    }

    const { parent, fsParent, target } = node
    check(parent, node, 'parent')
    check(fsParent, node, 'fsParent')
    check(target, node, 'target')
    log.push(['CHILDREN', node.location, ...node.children.keys()])
    for (const kid of node.children.values()) {
      check(kid, node, 'children')
    }
    for (const kid of node.fsChildren) {
      check(kid, node, 'fsChildren')
    }
    for (const link of node.linksIn) {
      check(link, node, 'linksIn')
    }
    for (const top of node.tops) {
      check(top, node, 'tops')
    }
    log.push(['DONE', node.location])
  }
  check(tree)
  if (checkUnreachable) {
    for (const node of inventory.values()) {
      if (!seen.has(node) && node !== tree.root) {
        throw Object.assign(new Error('unreachable in inventory'), {
          node: node.path,
          realpath: node.realpath,
          location: node.location,
          root: tree.root.path,
          tree: tree.path,
          log,
        })
      }
    }
  }
  return tree
}

// should only ever run this check in debug mode
module.exports = tree => tree
debug(() => module.exports = checkTree)

Directory Contents

Dirs: 1 × Files: 38

Name Size Perms Modified Actions
arborist DIR
- drwxr-xr-x 2026-03-14 07:02:08
Edit Download
4.89 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
11.95 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
3.42 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
13.94 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
1.21 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
1.29 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
1.25 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
691 B lrw-r--r-- 2026-02-23 03:24:42
Edit Download
5.00 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
9.57 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
6.63 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
1.07 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
1.26 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
273 B lrw-r--r-- 2026-02-23 03:24:42
Edit Download
3.25 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
3.06 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
42.97 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
1.32 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
225 B lrw-r--r-- 2026-02-23 03:24:42
Edit Download
3.12 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
2.50 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
2.57 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
19.75 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
5.10 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
28.84 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
2.59 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
136 B lrw-r--r-- 2026-02-23 03:24:42
Edit Download
638 B lrw-r--r-- 2026-02-23 03:24:42
Edit Download
501 B lrw-r--r-- 2026-02-23 03:24:42
Edit Download
36.89 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
2.19 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
1.35 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
874 B lrw-r--r-- 2026-02-23 03:24:42
Edit Download
2.92 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
4.04 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
1.45 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
5.82 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download
10.56 KB lrw-r--r-- 2026-02-23 03:24:42
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).