Skip to content

Commit

Permalink
deps: are-we-there-yet@4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Oct 9, 2023
1 parent fca804a commit e0163c6
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 155 deletions.
18 changes: 10 additions & 8 deletions node_modules/are-we-there-yet/lib/tracker-base.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict'
var EventEmitter = require('events').EventEmitter
var util = require('util')
const EventEmitter = require('events')

var trackerId = 0
var TrackerBase = module.exports = function (name) {
EventEmitter.call(this)
this.id = ++trackerId
this.name = name
let trackerId = 0
class TrackerBase extends EventEmitter {
constructor (name) {
super()
this.id = ++trackerId
this.name = name
}
}
util.inherits(TrackerBase, EventEmitter)

module.exports = TrackerBase
184 changes: 90 additions & 94 deletions node_modules/are-we-there-yet/lib/tracker-group.js
Original file line number Diff line number Diff line change
@@ -1,116 +1,112 @@
'use strict'
var util = require('util')
var TrackerBase = require('./tracker-base.js')
var Tracker = require('./tracker.js')
var TrackerStream = require('./tracker-stream.js')
const TrackerBase = require('./tracker-base.js')
const Tracker = require('./tracker.js')
const TrackerStream = require('./tracker-stream.js')

var TrackerGroup = module.exports = function (name) {
TrackerBase.call(this, name)
this.parentGroup = null
this.trackers = []
this.completion = {}
this.weight = {}
this.totalWeight = 0
this.finished = false
this.bubbleChange = bubbleChange(this)
}
util.inherits(TrackerGroup, TrackerBase)
class TrackerGroup extends TrackerBase {
parentGroup = null
trackers = []
completion = {}
weight = {}
totalWeight = 0
finished = false
bubbleChange = bubbleChange(this)

function bubbleChange (trackerGroup) {
return function (name, completed, tracker) {
trackerGroup.completion[tracker.id] = completed
if (trackerGroup.finished) {
return
nameInTree () {
var names = []
var from = this
while (from) {
names.unshift(from.name)
from = from.parentGroup
}
trackerGroup.emit('change', name || trackerGroup.name, trackerGroup.completed(), trackerGroup)
return names.join('/')
}
}

TrackerGroup.prototype.nameInTree = function () {
var names = []
var from = this
while (from) {
names.unshift(from.name)
from = from.parentGroup
}
return names.join('/')
}

TrackerGroup.prototype.addUnit = function (unit, weight) {
if (unit.addUnit) {
var toTest = this
while (toTest) {
if (unit === toTest) {
throw new Error(
'Attempted to add tracker group ' +
unit.name + ' to tree that already includes it ' +
this.nameInTree(this))
addUnit (unit, weight) {
if (unit.addUnit) {
var toTest = this
while (toTest) {
if (unit === toTest) {
throw new Error(
'Attempted to add tracker group ' +
unit.name + ' to tree that already includes it ' +
this.nameInTree(this))
}
toTest = toTest.parentGroup
}
toTest = toTest.parentGroup
unit.parentGroup = this
}
unit.parentGroup = this
this.weight[unit.id] = weight || 1
this.totalWeight += this.weight[unit.id]
this.trackers.push(unit)
this.completion[unit.id] = unit.completed()
unit.on('change', this.bubbleChange)
if (!this.finished) {
this.emit('change', unit.name, this.completion[unit.id], unit)
}
return unit
}
this.weight[unit.id] = weight || 1
this.totalWeight += this.weight[unit.id]
this.trackers.push(unit)
this.completion[unit.id] = unit.completed()
unit.on('change', this.bubbleChange)
if (!this.finished) {
this.emit('change', unit.name, this.completion[unit.id], unit)

completed () {
if (this.trackers.length === 0) {
return 0
}
var valPerWeight = 1 / this.totalWeight
var completed = 0
for (var ii = 0; ii < this.trackers.length; ii++) {
var trackerId = this.trackers[ii].id
completed +=
valPerWeight * this.weight[trackerId] * this.completion[trackerId]
}
return completed
}
return unit
}

TrackerGroup.prototype.completed = function () {
if (this.trackers.length === 0) {
return 0
newGroup (name, weight) {
return this.addUnit(new TrackerGroup(name), weight)
}
var valPerWeight = 1 / this.totalWeight
var completed = 0
for (var ii = 0; ii < this.trackers.length; ii++) {
var trackerId = this.trackers[ii].id
completed +=
valPerWeight * this.weight[trackerId] * this.completion[trackerId]

newItem (name, todo, weight) {
return this.addUnit(new Tracker(name, todo), weight)
}
return completed
}

TrackerGroup.prototype.newGroup = function (name, weight) {
return this.addUnit(new TrackerGroup(name), weight)
}
newStream (name, todo, weight) {
return this.addUnit(new TrackerStream(name, todo), weight)
}

TrackerGroup.prototype.newItem = function (name, todo, weight) {
return this.addUnit(new Tracker(name, todo), weight)
}
finish () {
this.finished = true
if (!this.trackers.length) {
this.addUnit(new Tracker(), 1, true)
}
for (var ii = 0; ii < this.trackers.length; ii++) {
var tracker = this.trackers[ii]
tracker.finish()
tracker.removeListener('change', this.bubbleChange)
}
this.emit('change', this.name, 1, this)
}

TrackerGroup.prototype.newStream = function (name, todo, weight) {
return this.addUnit(new TrackerStream(name, todo), weight)
}
debug (depth = 0) {
const indent = ' '.repeat(depth)
let output = `${indent}${this.name || 'top'}: ${this.completed()}\n`

TrackerGroup.prototype.finish = function () {
this.finished = true
if (!this.trackers.length) {
this.addUnit(new Tracker(), 1, true)
}
for (var ii = 0; ii < this.trackers.length; ii++) {
var tracker = this.trackers[ii]
tracker.finish()
tracker.removeListener('change', this.bubbleChange)
this.trackers.forEach(function (tracker) {
output += tracker instanceof TrackerGroup
? tracker.debug(depth + 1)
: `${indent} ${tracker.name}: ${tracker.completed()}\n`
})
return output
}
this.emit('change', this.name, 1, this)
}

var buffer = ' '
TrackerGroup.prototype.debug = function (depth) {
depth = depth || 0
var indent = depth ? buffer.slice(0, depth) : ''
var output = indent + (this.name || 'top') + ': ' + this.completed() + '\n'
this.trackers.forEach(function (tracker) {
if (tracker instanceof TrackerGroup) {
output += tracker.debug(depth + 1)
} else {
output += indent + ' ' + tracker.name + ': ' + tracker.completed() + '\n'
function bubbleChange (trackerGroup) {
return function (name, completed, tracker) {
trackerGroup.completion[tracker.id] = completed
if (trackerGroup.finished) {
return
}
})
return output
trackerGroup.emit('change', name || trackerGroup.name, trackerGroup.completed(), trackerGroup)
}
}

module.exports = TrackerGroup
46 changes: 24 additions & 22 deletions node_modules/are-we-there-yet/lib/tracker-stream.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
'use strict'
var util = require('util')
var stream = require('readable-stream')
var delegate = require('delegates')
var Tracker = require('./tracker.js')
const stream = require('readable-stream')
const delegate = require('delegates')
const Tracker = require('./tracker.js')

var TrackerStream = module.exports = function (name, size, options) {
stream.Transform.call(this, options)
this.tracker = new Tracker(name, size)
this.name = name
this.id = this.tracker.id
this.tracker.on('change', delegateChange(this))
class TrackerStream extends stream.Transform {
constructor (name, size, options) {
super(options)
this.tracker = new Tracker(name, size)
this.name = name
this.id = this.tracker.id
this.tracker.on('change', delegateChange(this))
}

_transform (data, encoding, cb) {
this.tracker.completeWork(data.length ? data.length : 1)
this.push(data)
cb()
}

_flush (cb) {
this.tracker.finish()
cb()
}
}
util.inherits(TrackerStream, stream.Transform)

function delegateChange (trackerStream) {
return function (name, completion, tracker) {
trackerStream.emit('change', name, completion, trackerStream)
}
}

TrackerStream.prototype._transform = function (data, encoding, cb) {
this.tracker.completeWork(data.length ? data.length : 1)
this.push(data)
cb()
}

TrackerStream.prototype._flush = function (cb) {
this.tracker.finish()
cb()
}

delegate(TrackerStream.prototype, 'tracker')
.method('completed')
.method('addWork')
.method('finish')

module.exports = TrackerStream
50 changes: 26 additions & 24 deletions node_modules/are-we-there-yet/lib/tracker.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
'use strict'
var util = require('util')
var TrackerBase = require('./tracker-base.js')
const TrackerBase = require('./tracker-base.js')

var Tracker = module.exports = function (name, todo) {
TrackerBase.call(this, name)
this.workDone = 0
this.workTodo = todo || 0
}
util.inherits(Tracker, TrackerBase)
class Tracker extends TrackerBase {
constructor (name, todo) {
super(name)
this.workDone = 0
this.workTodo = todo || 0
}

Tracker.prototype.completed = function () {
return this.workTodo === 0 ? 0 : this.workDone / this.workTodo
}
completed () {
return this.workTodo === 0 ? 0 : this.workDone / this.workTodo
}

Tracker.prototype.addWork = function (work) {
this.workTodo += work
this.emit('change', this.name, this.completed(), this)
}
addWork (work) {
this.workTodo += work
this.emit('change', this.name, this.completed(), this)
}

Tracker.prototype.completeWork = function (work) {
this.workDone += work
if (this.workDone > this.workTodo) {
this.workDone = this.workTodo
completeWork (work) {
this.workDone += work
if (this.workDone > this.workTodo) {
this.workDone = this.workTodo
}
this.emit('change', this.name, this.completed(), this)
}
this.emit('change', this.name, this.completed(), this)
}

Tracker.prototype.finish = function () {
this.workTodo = this.workDone = 1
this.emit('change', this.name, 1, this)
finish () {
this.workTodo = this.workDone = 1
this.emit('change', this.name, 1, this)
}
}

module.exports = Tracker
9 changes: 5 additions & 4 deletions node_modules/are-we-there-yet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "are-we-there-yet",
"version": "4.0.0",
"version": "4.0.1",
"description": "Keep track of the overall completion of many disparate processes",
"main": "lib/index.js",
"scripts": {
Expand All @@ -24,8 +24,8 @@
},
"homepage": "https://github.com/npm/are-we-there-yet",
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "4.5.1",
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.17.0",
"tap": "^16.0.1"
},
"dependencies": {
Expand All @@ -51,6 +51,7 @@
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.5.1"
"version": "4.17.0",
"publish": true
}
}
6 changes: 3 additions & 3 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -3765,9 +3765,9 @@
"inBundle": true
},
"node_modules/are-we-there-yet": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-4.0.0.tgz",
"integrity": "sha512-nSXlV+u3vtVjRgihdTzbfWYzxPWGo424zPgQbHD0ZqIla3jqYAewDcvee0Ua2hjS5IfTAmjGlx1Jf0PKwjZDEw==",
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-4.0.1.tgz",
"integrity": "sha512-2zuA+jpOYBRgoBCfa+fB87Rk0oGJjDX6pxGzqH6f33NzUhG25Xur6R0u0Z9VVAq8Z5JvQpQI6j6rtonuivC8QA==",
"inBundle": true,
"dependencies": {
"delegates": "^1.0.0",
Expand Down

0 comments on commit e0163c6

Please sign in to comment.