PHP 8.2.30
Preview: tracker.js Size: 2.92 KB
/proc/self/root/opt/alt/alt-nodejs20/root/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/tracker.js

const proggy = require('proggy')

module.exports = cls => class Tracker extends cls {
  #progress = new Map()

  #createTracker (key, name) {
    const tracker = new proggy.Tracker(name ?? key)
    tracker.on('done', () => this.#progress.delete(key))
    this.#progress.set(key, tracker)
  }

  addTracker (section, subsection = null, key = null) {
    if (section === null || section === undefined) {
      this.#onError(`Tracker can't be null or undefined`)
    }

    if (key === null) {
      key = subsection
    }

    const hasTracker = this.#progress.has(section)
    const hasSubtracker = this.#progress.has(`${section}:${key}`)

    if (hasTracker && subsection === null) {
      // 0. existing tracker, no subsection
      this.#onError(`Tracker "${section}" already exists`)
    } else if (!hasTracker && subsection === null) {
      // 1. no existing tracker, no subsection
      // Create a new progress tracker
      this.#createTracker(section)
    } else if (!hasTracker && subsection !== null) {
      // 2. no parent tracker and subsection
      this.#onError(`Parent tracker "${section}" does not exist`)
    } else if (!hasTracker || !hasSubtracker) {
      // 3. existing parent tracker, no subsection tracker
      // Create a new subtracker and update parents
      const parentTracker = this.#progress.get(section)
      parentTracker.update(parentTracker.value, parentTracker.total + 1)
      this.#createTracker(`${section}:${key}`, `${section}:${subsection}`)
    }
    // 4. existing parent tracker, existing subsection tracker
    // skip it
  }

  finishTracker (section, subsection = null, key = null) {
    if (section === null || section === undefined) {
      this.#onError(`Tracker can't be null or undefined`)
    }

    if (key === null) {
      key = subsection
    }

    const hasTracker = this.#progress.has(section)
    const hasSubtracker = this.#progress.has(`${section}:${key}`)

    // 0. parent tracker exists, no subsection
    // Finish parent tracker and remove from this.#progress
    if (hasTracker && subsection === null) {
      // check if parent tracker does
      // not have any remaining children
      const keys = this.#progress.keys()
      for (const key of keys) {
        if (key.match(new RegExp(section + ':'))) {
          this.finishTracker(section, key)
        }
      }
      // remove parent tracker
      this.#progress.get(section).finish()
    } else if (!hasTracker && subsection === null) {
      // 1. no existing parent tracker, no subsection
      this.#onError(`Tracker "${section}" does not exist`)
    } else if (!hasTracker || hasSubtracker) {
      // 2. subtracker exists
      // Finish subtracker and remove from this.#progress
      const parentTracker = this.#progress.get(section)
      parentTracker.update(parentTracker.value + 1)
      this.#progress.get(`${section}:${key}`).finish()
    }
    // 3. existing parent tracker, no subsection
  }

  #onError (msg) {
    throw new Error(msg)
  }
}

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).