pax_global_header 0000666 0000000 0000000 00000000064 14270325727 0014523 g ustar 00root root 0000000 0000000 52 comment=a7d9cce05be9a5607161c1f30b536c034d699257
are-we-there-yet-3.0.1/ 0000775 0000000 0000000 00000000000 14270325727 0014610 5 ustar 00root root 0000000 0000000 are-we-there-yet-3.0.1/.commitlintrc.js 0000664 0000000 0000000 00000000553 14270325727 0017733 0 ustar 00root root 0000000 0000000 /* This file is automatically added by @npmcli/template-oss. Do not edit. */
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'deps', 'chore']],
'header-max-length': [2, 'always', 80],
'subject-case': [0, 'always', ['lower-case', 'sentence-case', 'start-case']],
},
}
are-we-there-yet-3.0.1/.eslintrc.js 0000664 0000000 0000000 00000000545 14270325727 0017053 0 ustar 00root root 0000000 0000000 /* This file is automatically added by @npmcli/template-oss. Do not edit. */
'use strict'
const { readdirSync: readdir } = require('fs')
const localConfigs = readdir(__dirname)
.filter((file) => file.startsWith('.eslintrc.local.'))
.map((file) => `./${file}`)
module.exports = {
root: true,
extends: [
'@npmcli',
...localConfigs,
],
}
are-we-there-yet-3.0.1/.github/ 0000775 0000000 0000000 00000000000 14270325727 0016150 5 ustar 00root root 0000000 0000000 are-we-there-yet-3.0.1/.github/CODEOWNERS 0000664 0000000 0000000 00000000132 14270325727 0017537 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
* @npm/cli-team
are-we-there-yet-3.0.1/.github/ISSUE_TEMPLATE/ 0000775 0000000 0000000 00000000000 14270325727 0020333 5 ustar 00root root 0000000 0000000 are-we-there-yet-3.0.1/.github/ISSUE_TEMPLATE/bug.yml 0000664 0000000 0000000 00000002655 14270325727 0021643 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Bug
description: File a bug/issue
title: "[BUG]
"
labels: [ Bug, Needs Triage ]
body:
- type: checkboxes
attributes:
label: Is there an existing issue for this?
description: Please [search here](./issues) to see if an issue already exists for your problem.
options:
- label: I have searched the existing issues
required: true
- type: textarea
attributes:
label: Current Behavior
description: A clear & concise description of what you're experiencing.
validations:
required: false
- type: textarea
attributes:
label: Expected Behavior
description: A clear & concise description of what you expected to happen.
validations:
required: false
- type: textarea
attributes:
label: Steps To Reproduce
description: Steps to reproduce the behavior.
value: |
1. In this environment...
2. With this config...
3. Run '...'
4. See error...
validations:
required: false
- type: textarea
attributes:
label: Environment
description: |
examples:
- **npm**: 7.6.3
- **Node**: 13.14.0
- **OS**: Ubuntu 20.04
- **platform**: Macbook Pro
value: |
- npm:
- Node:
- OS:
- platform:
validations:
required: false
are-we-there-yet-3.0.1/.github/ISSUE_TEMPLATE/config.yml 0000664 0000000 0000000 00000000145 14270325727 0022323 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
blank_issues_enabled: true
are-we-there-yet-3.0.1/.github/dependabot.yml 0000664 0000000 0000000 00000000565 14270325727 0021006 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
allow:
- dependency-type: direct
versioning-strategy: increase-if-necessary
commit-message:
prefix: deps
prefix-development: chore
labels:
- "Dependencies"
are-we-there-yet-3.0.1/.github/settings.yml 0000664 0000000 0000000 00000000055 14270325727 0020533 0 ustar 00root root 0000000 0000000 ---
_extends: '.github:npm-cli/settings.yml'
are-we-there-yet-3.0.1/.github/workflows/ 0000775 0000000 0000000 00000000000 14270325727 0020205 5 ustar 00root root 0000000 0000000 are-we-there-yet-3.0.1/.github/workflows/audit.yml 0000664 0000000 0000000 00000001370 14270325727 0022037 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Audit
on:
workflow_dispatch:
schedule:
# "At 01:00 on Monday" https://crontab.guru/#0_1_*_*_1
- cron: "0 1 * * 1"
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --no-audit --no-fund --package-lock
- run: npm audit
are-we-there-yet-3.0.1/.github/workflows/ci.yml 0000664 0000000 0000000 00000005114 14270325727 0021324 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: CI
on:
workflow_dispatch:
pull_request:
branches:
- '*'
push:
branches:
- main
- latest
schedule:
# "At 02:00 on Monday" https://crontab.guru/#0_2_*_*_1
- cron: "0 2 * * 1"
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --no-audit --no-fund
- run: npm run lint
test:
strategy:
fail-fast: false
matrix:
node-version:
- 12.13.0
- 12.x
- 14.15.0
- 14.x
- 16.0.0
- 16.x
platform:
- os: ubuntu-latest
shell: bash
- os: macos-latest
shell: bash
- os: windows-latest
shell: cmd
runs-on: ${{ matrix.platform.os }}
defaults:
run:
shell: ${{ matrix.platform.shell }}
steps:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Update to workable npm (windows)
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.'))
run: |
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
tar xf npm-7.5.4.tgz
cd package
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
cd ..
rmdir /s /q package
- name: Update npm to 7
# If we do test on npm 10 it needs npm7
if: startsWith(matrix.node-version, '10.')
run: npm i --prefer-online --no-fund --no-audit -g npm@7
- name: Update npm to latest
if: ${{ !startsWith(matrix.node-version, '10.') }}
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --no-audit --no-fund
- run: npm test --ignore-scripts
are-we-there-yet-3.0.1/.github/workflows/codeql-analysis.yml 0000664 0000000 0000000 00000002001 14270325727 0024011 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: "CodeQL"
on:
push:
branches:
- main
- latest
pull_request:
# The branches below must be a subset of the branches above
branches:
- main
- latest
schedule:
# "At 03:00 on Monday" https://crontab.guru/#0_3_*_*_1
- cron: "0 3 * * 1"
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ javascript ]
steps:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
are-we-there-yet-3.0.1/.github/workflows/post-dependabot.yml 0000664 0000000 0000000 00000002641 14270325727 0024023 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Post Dependabot Actions
on: pull_request
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
permissions:
contents: write
jobs:
template-oss-apply:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: npm install and commit
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr checkout ${{ github.event.pull_request.number }}
npm install --ignore-scripts --no-audit --no-fund
npm run template-oss-apply
git add .
git commit -am "chore: postinstall for dependabot template-oss PR"
git push
npm run lint
are-we-there-yet-3.0.1/.github/workflows/pull-request.yml 0000664 0000000 0000000 00000002143 14270325727 0023372 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Pull Request Linting
on:
pull_request:
types:
- opened
- reopened
- edited
- synchronize
jobs:
check:
name: Check PR Title or Commits
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- name: Install deps
run: npm i -D @commitlint/cli @commitlint/config-conventional
- name: Check commits OR PR title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
npx --offline commitlint -V --from origin/main --to ${{ github.event.pull_request.head.sha }} \
|| echo $PR_TITLE | npx --offline commitlint -V
are-we-there-yet-3.0.1/.github/workflows/release-please.yml 0000664 0000000 0000000 00000001314 14270325727 0023616 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Release Please
on:
push:
branches:
- main
- latest
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
changelog-types: >
[
{"type":"feat","section":"Features","hidden":false},
{"type":"fix","section":"Bug Fixes","hidden":false},
{"type":"docs","section":"Documentation","hidden":false},
{"type":"deps","section":"Dependencies","hidden":false},
{"type":"chore","hidden":true}
]
are-we-there-yet-3.0.1/.gitignore 0000664 0000000 0000000 00000000570 14270325727 0016602 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
# ignore everything in the root
/*
# keep these
!/.eslintrc.local.*
!**/.gitignore
!/docs/
!/tap-snapshots/
!/test/
!/map.js
!/scripts/
!/README*
!/LICENSE*
!/CHANGELOG*
!/.commitlintrc.js
!/.eslintrc.js
!/.github/
!/.gitignore
!/.npmrc
!/CODE_OF_CONDUCT.md
!/SECURITY.md
!/bin/
!/lib/
!/package.json
are-we-there-yet-3.0.1/.npmrc 0000664 0000000 0000000 00000000135 14270325727 0015727 0 ustar 00root root 0000000 0000000 ; This file is automatically added by @npmcli/template-oss. Do not edit.
package-lock=false
are-we-there-yet-3.0.1/CHANGELOG.md 0000664 0000000 0000000 00000004076 14270325727 0016430 0 ustar 00root root 0000000 0000000 # Changelog
## [3.0.1](https://github.com/npm/are-we-there-yet/compare/v3.0.0...v3.0.1) (2022-07-21)
### Bug Fixes
* replace deprecated String.prototype.substr() ([#140](https://github.com/npm/are-we-there-yet/issues/140)) ([6145a9e](https://github.com/npm/are-we-there-yet/commit/6145a9ef6908c0feb107ac41f704e0aabe2718d0))
## [3.0.0](https://www.github.com/npm/are-we-there-yet/compare/v2.0.0...v3.0.0) (2022-02-09)
### ⚠ BREAKING CHANGES
* This drops support for node10 and non-LTS versions of node 12 and node 14
### Bug Fixes
* @npmcli/template-oss@2.7.1 ([f742777](https://www.github.com/npm/are-we-there-yet/commit/f7427775fcf59185b99693d2e5480e1185de8589))
### Documentation
* rename CHANGE.md to CHANGELOG.md ([2667644](https://www.github.com/npm/are-we-there-yet/commit/2667644d37bf9d1d9c25cdf3a133d607f151b8c2))
## 1.1.5 2018-05-24
* [#92](https://github.com/iarna/are-we-there-yet/pull/92) Fix bug where
`finish` would throw errors when including `TrackerStream` objects in
`TrackerGroup` collections. (@brianloveswords)
## 1.1.4 2017-04-21
* Fix typo in package.json
## 1.1.3 2017-04-21
* Improve documentation and limit files included in the distribution.
## 1.1.2 2016-03-15
* Add tracker group cycle detection and tests for it
## 1.1.1 2016-01-29
* Fix a typo in stream completion tracker
## 1.1.0 2016-01-29
* Rewrote completion percent computation to be low impact– no more walking a
tree of completion groups every time we need this info. Previously, with
medium sized tree of completion groups, even a relatively modest number of
calls to the top level `completed()` method would result in absurd numbers
of calls overall as it walked down the tree. We now, instead, keep track as
we bubble up changes, so the computation is limited to when data changes and
to the depth of that one branch, instead of _every_ node. (Plus, we were already
incurring _this_ cost, since we already bubbled out changes.)
* Moved different tracker types out to their own files.
* Made tests test for TOO MANY events too.
* Standarized the source code formatting
are-we-there-yet-3.0.1/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000000507 14270325727 0017411 0 ustar 00root root 0000000 0000000
All interactions in this repo are covered by the [npm Code of
Conduct](https://docs.npmjs.com/policies/conduct)
The npm cli team may, at its own discretion, moderate, remove, or edit
any interactions such as pull requests, issues, and comments.
are-we-there-yet-3.0.1/LICENSE.md 0000664 0000000 0000000 00000001315 14270325727 0016214 0 ustar 00root root 0000000 0000000 ISC License
Copyright npm, Inc.
Permission to use, copy, modify, and/or distribute this
software for any purpose with or without fee is hereby
granted, provided that the above copyright notice and this
permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
USE OR PERFORMANCE OF THIS SOFTWARE.
are-we-there-yet-3.0.1/README.md 0000664 0000000 0000000 00000014704 14270325727 0016075 0 ustar 00root root 0000000 0000000 are-we-there-yet
----------------
Track complex hierarchies of asynchronous task completion statuses. This is
intended to give you a way of recording and reporting the progress of the big
recursive fan-out and gather type workflows that are so common in async.
What you do with this completion data is up to you, but the most common use case is to
feed it to one of the many progress bar modules.
Most progress bar modules include a rudimentary version of this, but my
needs were more complex.
Usage
=====
```javascript
var TrackerGroup = require("are-we-there-yet").TrackerGroup
var top = new TrackerGroup("program")
var single = top.newItem("one thing", 100)
single.completeWork(20)
console.log(top.completed()) // 0.2
fs.stat("file", function(er, stat) {
if (er) throw er
var stream = top.newStream("file", stat.size)
console.log(top.completed()) // now 0.1 as single is 50% of the job and is 20% complete
// and 50% * 20% == 10%
fs.createReadStream("file").pipe(stream).on("data", function (chunk) {
// do stuff with chunk
})
top.on("change", function (name) {
// called each time a chunk is read from "file"
// top.completed() will start at 0.1 and fill up to 0.6 as the file is read
})
})
```
Shared Methods
==============
* var completed = tracker.completed()
Implemented in: `Tracker`, `TrackerGroup`, `TrackerStream`
Returns the ratio of completed work to work to be done. Range of 0 to 1.
* tracker.finish()
Implemented in: `Tracker`, `TrackerGroup`
Marks the tracker as completed. With a TrackerGroup this marks all of its
components as completed.
Marks all of the components of this tracker as finished, which in turn means
that `tracker.completed()` for this will now be 1.
This will result in one or more `change` events being emitted.
Events
======
All tracker objects emit `change` events with the following arguments:
```
function (name, completed, tracker)
```
`name` is the name of the tracker that originally emitted the event,
or if it didn't have one, the first containing tracker group that had one.
`completed` is the percent complete (as returned by `tracker.completed()` method).
`tracker` is the tracker object that you are listening for events on.
TrackerGroup
============
* var tracker = new TrackerGroup(**name**)
* **name** *(optional)* - The name of this tracker group, used in change
notifications if the component updating didn't have a name. Defaults to undefined.
Creates a new empty tracker aggregation group. These are trackers whose
completion status is determined by the completion status of other trackers added to this aggregation group.
Ex.
```javascript
var tracker = new TrackerGroup("parent")
var foo = tracker.newItem("firstChild", 100)
var bar = tracker.newItem("secondChild", 100)
foo.finish()
console.log(tracker.completed()) // 0.5
bar.finish()
console.log(tracker.completed()) // 1
```
* tracker.addUnit(**otherTracker**, **weight**)
* **otherTracker** - Any of the other are-we-there-yet tracker objects
* **weight** *(optional)* - The weight to give the tracker, defaults to 1.
Adds the **otherTracker** to this aggregation group. The weight determines
how long you expect this tracker to take to complete in proportion to other
units. So for instance, if you add one tracker with a weight of 1 and
another with a weight of 2, you're saying the second will take twice as long
to complete as the first. As such, the first will account for 33% of the
completion of this tracker and the second will account for the other 67%.
Returns **otherTracker**.
* var subGroup = tracker.newGroup(**name**, **weight**)
The above is exactly equivalent to:
```javascript
var subGroup = tracker.addUnit(new TrackerGroup(name), weight)
```
* var subItem = tracker.newItem(**name**, **todo**, **weight**)
The above is exactly equivalent to:
```javascript
var subItem = tracker.addUnit(new Tracker(name, todo), weight)
```
* var subStream = tracker.newStream(**name**, **todo**, **weight**)
The above is exactly equivalent to:
```javascript
var subStream = tracker.addUnit(new TrackerStream(name, todo), weight)
```
* console.log( tracker.debug() )
Returns a tree showing the completion of this tracker group and all of its
children, including recursively entering all of the children.
Tracker
=======
* var tracker = new Tracker(**name**, **todo**)
* **name** *(optional)* The name of this counter to report in change
events. Defaults to undefined.
* **todo** *(optional)* The amount of work todo (a number). Defaults to 0.
Ordinarily these are constructed as a part of a tracker group (via
`newItem`).
* var completed = tracker.completed()
Returns the ratio of completed work to work to be done. Range of 0 to 1. If
total work to be done is 0 then it will return 0.
* tracker.addWork(**todo**)
* **todo** A number to add to the amount of work to be done.
Increases the amount of work to be done, thus decreasing the completion
percentage. Triggers a `change` event.
* tracker.completeWork(**completed**)
* **completed** A number to add to the work complete
Increase the amount of work complete, thus increasing the completion percentage.
Will never increase the work completed past the amount of work todo. That is,
percentages > 100% are not allowed. Triggers a `change` event.
* tracker.finish()
Marks this tracker as finished, tracker.completed() will now be 1. Triggers
a `change` event.
TrackerStream
=============
* var tracker = new TrackerStream(**name**, **size**, **options**)
* **name** *(optional)* The name of this counter to report in change
events. Defaults to undefined.
* **size** *(optional)* The number of bytes being sent through this stream.
* **options** *(optional)* A hash of stream options
The tracker stream object is a pass through stream that updates an internal
tracker object each time a block passes through. It's intended to track
downloads, file extraction and other related activities. You use it by piping
your data source into it and then using it as your data source.
If your data has a length attribute then that's used as the amount of work
completed when the chunk is passed through. If it does not (eg, object
streams) then each chunk counts as completing 1 unit of work, so your size
should be the total number of objects being streamed.
* tracker.addWork(**todo**)
* **todo** Increase the expected overall size by **todo** bytes.
Increases the amount of work to be done, thus decreasing the completion
percentage. Triggers a `change` event.
are-we-there-yet-3.0.1/SECURITY.md 0000664 0000000 0000000 00000000246 14270325727 0016403 0 ustar 00root root 0000000 0000000
Please send vulnerability reports through [hackerone](https://hackerone.com/github).
are-we-there-yet-3.0.1/lib/ 0000775 0000000 0000000 00000000000 14270325727 0015356 5 ustar 00root root 0000000 0000000 are-we-there-yet-3.0.1/lib/index.js 0000664 0000000 0000000 00000000243 14270325727 0017022 0 ustar 00root root 0000000 0000000 'use strict'
exports.TrackerGroup = require('./tracker-group.js')
exports.Tracker = require('./tracker.js')
exports.TrackerStream = require('./tracker-stream.js')
are-we-there-yet-3.0.1/lib/tracker-base.js 0000664 0000000 0000000 00000000422 14270325727 0020255 0 ustar 00root root 0000000 0000000 'use strict'
var EventEmitter = require('events').EventEmitter
var util = require('util')
var trackerId = 0
var TrackerBase = module.exports = function (name) {
EventEmitter.call(this)
this.id = ++trackerId
this.name = name
}
util.inherits(TrackerBase, EventEmitter)
are-we-there-yet-3.0.1/lib/tracker-group.js 0000664 0000000 0000000 00000006320 14270325727 0020502 0 ustar 00root root 0000000 0000000 'use strict'
var util = require('util')
var TrackerBase = require('./tracker-base.js')
var Tracker = require('./tracker.js')
var 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)
function bubbleChange (trackerGroup) {
return function (name, completed, tracker) {
trackerGroup.completion[tracker.id] = completed
if (trackerGroup.finished) {
return
}
trackerGroup.emit('change', name || trackerGroup.name, trackerGroup.completed(), trackerGroup)
}
}
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))
}
toTest = toTest.parentGroup
}
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
}
TrackerGroup.prototype.completed = function () {
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
}
TrackerGroup.prototype.newGroup = function (name, weight) {
return this.addUnit(new TrackerGroup(name), weight)
}
TrackerGroup.prototype.newItem = function (name, todo, weight) {
return this.addUnit(new Tracker(name, todo), weight)
}
TrackerGroup.prototype.newStream = function (name, todo, weight) {
return this.addUnit(new TrackerStream(name, todo), weight)
}
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.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'
}
})
return output
}
are-we-there-yet-3.0.1/lib/tracker-stream.js 0000664 0000000 0000000 00000001703 14270325727 0020641 0 ustar 00root root 0000000 0000000 'use strict'
var util = require('util')
var stream = require('readable-stream')
var delegate = require('delegates')
var 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))
}
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')
are-we-there-yet-3.0.1/lib/tracker.js 0000664 0000000 0000000 00000001504 14270325727 0017347 0 ustar 00root root 0000000 0000000 'use strict'
var util = require('util')
var 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)
Tracker.prototype.completed = function () {
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)
}
Tracker.prototype.completeWork = function (work) {
this.workDone += work
if (this.workDone > this.workTodo) {
this.workDone = this.workTodo
}
this.emit('change', this.name, this.completed(), this)
}
Tracker.prototype.finish = function () {
this.workTodo = this.workDone = 1
this.emit('change', this.name, 1, this)
}
are-we-there-yet-3.0.1/package.json 0000664 0000000 0000000 00000002673 14270325727 0017106 0 ustar 00root root 0000000 0000000 {
"name": "are-we-there-yet",
"version": "3.0.1",
"description": "Keep track of the overall completion of many disparate processes",
"main": "lib/index.js",
"scripts": {
"test": "tap",
"npmclilint": "npmcli-lint",
"lint": "eslint \"**/*.js\"",
"lintfix": "npm run lint -- --fix",
"posttest": "npm run lint",
"postsnap": "npm run lintfix --",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force"
},
"repository": {
"type": "git",
"url": "https://github.com/npm/are-we-there-yet.git"
},
"author": "GitHub Inc.",
"license": "ISC",
"bugs": {
"url": "https://github.com/npm/are-we-there-yet/issues"
},
"homepage": "https://github.com/npm/are-we-there-yet",
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "3.5.0",
"tap": "^16.0.1"
},
"dependencies": {
"delegates": "^1.0.0",
"readable-stream": "^3.6.0"
},
"files": [
"bin/",
"lib/"
],
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
},
"tap": {
"branches": 68,
"statements": 92,
"functions": 86,
"lines": 92
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "3.5.0"
}
}
are-we-there-yet-3.0.1/test/ 0000775 0000000 0000000 00000000000 14270325727 0015567 5 ustar 00root root 0000000 0000000 are-we-there-yet-3.0.1/test/lib/ 0000775 0000000 0000000 00000000000 14270325727 0016335 5 ustar 00root root 0000000 0000000 are-we-there-yet-3.0.1/test/lib/test-event.js 0000664 0000000 0000000 00000001626 14270325727 0020776 0 ustar 00root root 0000000 0000000 'use strict'
var util = require('util')
module.exports = function (obj, event, next) {
var timeout = setTimeout(gotTimeout, 10)
obj.once(event, gotResult)
function gotTimeout () {
obj.removeListener(event, gotResult)
next(new Error('Timeout listening for ' + event))
}
var result = []
function gotResult () {
result = Array.prototype.slice.call(arguments)
clearTimeout(timeout)
timeout = setTimeout(gotNoMoreResults, 10)
obj.once(event, gotTooManyResults)
}
function gotNoMoreResults () {
obj.removeListener(event, gotTooManyResults)
var args = [null].concat(result)
next.apply(null, args)
}
function gotTooManyResults () {
var secondResult = Array.prototype.slice.call(arguments)
clearTimeout(timeout)
next(new Error(
'Got too many results, first ' +
util.inspect(result) + ' and then ' +
util.inspect(secondResult))
)
}
}
are-we-there-yet-3.0.1/test/lib/tracker.js 0000664 0000000 0000000 00000003055 14270325727 0020331 0 ustar 00root root 0000000 0000000 'use strict'
var test = require('tap').test
var Tracker = require('../..').Tracker
var testEvent = require('./test-event.js')
var name = 'test'
test('initialization', function (t) {
var simple = new Tracker(name)
t.equal(simple.completed(), 0, 'Nothing todo is 0 completion')
t.end()
})
var track
var todo = 100
test('completion', function (t) {
track = new Tracker(name, todo)
t.equal(track.completed(), 0, 'Nothing done is 0 completion')
testEvent(track, 'change', afterCompleteWork)
track.completeWork(todo)
t.equal(track.completed(), 1, 'completeWork: 100% completed')
function afterCompleteWork (er, onChangeName) {
t.equal(er, null, 'completeWork: on change event fired')
t.equal(onChangeName, name, 'completeWork: on change emits the correct name')
t.end()
}
})
test('add more work', function (t) {
testEvent(track, 'change', afterAddWork)
track.addWork(todo)
t.equal(track.completed(), 0.5, 'addWork: 50% completed')
function afterAddWork (er, onChangeName) {
t.equal(er, null, 'addWork: on change event fired')
t.equal(onChangeName, name, 'addWork: on change emits the correct name')
t.end()
}
})
test('complete more work', function (t) {
track.completeWork(200)
t.equal(track.completed(), 1, 'completeWork: Over completion is still only 100% complete')
t.end()
})
test('finish is always 100%', function (t) {
var finishtest = new Tracker(name, todo)
finishtest.completeWork(50)
finishtest.finish()
t.equal(finishtest.completed(), 1, 'finish: Explicitly finishing moves to 100%')
t.end()
})
are-we-there-yet-3.0.1/test/lib/trackergroup.js 0000664 0000000 0000000 00000010052 14270325727 0021401 0 ustar 00root root 0000000 0000000 'use strict'
var test = require('tap').test
var TrackerGroup = require('../..').TrackerGroup
var testEvent = require('./test-event.js')
test('TrackerGroup', function (t) {
var name = 'test'
var track = new TrackerGroup(name)
t.equal(track.completed(), 0, 'Nothing todo is 0 completion')
testEvent(track, 'change', afterFinishEmpty)
track.finish()
var a, b
function afterFinishEmpty (er, onChangeName, completion) {
t.equal(er, null, 'finishEmpty: on change event fired')
t.equal(onChangeName, name, 'finishEmpty: on change emits the correct name')
t.equal(completion, 1, 'finishEmpty: passed through completion was correct')
t.equal(track.completed(), 1, 'finishEmpty: Finishing an empty group actually finishes it')
track = new TrackerGroup(name)
a = track.newItem('a', 10, 1)
b = track.newItem('b', 10, 1)
t.equal(track.completed(), 0, 'Initially empty')
testEvent(track, 'change', afterCompleteWork)
a.completeWork(5)
}
function afterCompleteWork (er, onChangeName, completion) {
t.equal(er, null, 'on change event fired')
t.equal(onChangeName, 'a', 'on change emits the correct name')
t.equal(completion, 0.25, 'Complete half of one is a quarter overall')
t.equal(track.completed(), 0.25, 'Complete half of one is a quarter overall')
testEvent(track, 'change', afterFinishAll)
track.finish()
}
function afterFinishAll (er, onChangeName, completion) {
t.equal(er, null, 'finishAll: on change event fired')
t.equal(onChangeName, name, 'finishAll: on change emits the correct name')
t.equal(completion, 1, 'Finishing everything ')
t.equal(track.completed(), 1, 'Finishing everything ')
track = new TrackerGroup(name)
a = track.newItem('a', 10, 2)
b = track.newItem('b', 10, 1)
t.equal(track.completed(), 0, 'weighted: Initially empty')
testEvent(track, 'change', afterWeightedCompleteWork)
a.completeWork(5)
}
function afterWeightedCompleteWork (er, onChangeName, completion) {
t.equal(er, null, 'weighted: on change event fired')
t.equal(onChangeName, 'a', 'weighted: on change emits the correct name')
t.equal(Math.floor(completion * 100), 33, 'weighted: Complete half of double weighted')
t.equal(Math.floor(track.completed() * 100), 33, 'weighted: Complete half of double weighted')
testEvent(track, 'change', afterWeightedFinishAll)
track.finish()
}
function afterWeightedFinishAll (er, onChangeName, completion) {
t.equal(er, null, 'weightedFinishAll: on change event fired')
t.equal(onChangeName, name, 'weightedFinishAll: on change emits the correct name')
t.equal(completion, 1, 'weightedFinishaAll: Finishing everything ')
t.equal(track.completed(), 1, 'weightedFinishaAll: Finishing everything ')
track = new TrackerGroup(name)
a = track.newGroup('a', 10)
b = track.newGroup('b', 10)
var a1 = a.newItem('a.1', 10)
a1.completeWork(5)
t.equal(track.completed(), 0.25, 'nested: Initially quarter done')
testEvent(track, 'change', afterNestedComplete)
b.finish()
}
function afterNestedComplete (er, onChangeName, completion) {
t.equal(er, null, 'nestedComplete: on change event fired')
t.equal(onChangeName, 'b', 'nestedComplete: on change emits the correct name')
t.equal(completion, 0.75, 'nestedComplete: Finishing everything ')
t.equal(track.completed(), 0.75, 'nestedComplete: Finishing everything ')
t.end()
}
})
test('cycles', function (t) {
var track = new TrackerGroup('top')
testCycle(track, track)
var layer1 = track.newGroup('layer1')
testCycle(layer1, track)
t.end()
function testCycle (addTo, toAdd) {
try {
addTo.addUnit(toAdd)
t.fail(toAdd.name)
} catch (ex) {
console.log(ex)
t.pass(toAdd.name)
}
}
})
test('should properly handle finish calls when the group contains a stream', function (t) {
var track = new TrackerGroup('test')
track.newStream('test-stream', 100)
try {
track.finish()
t.pass('did not error on `finish()` call')
} catch (e) {
t.fail('threw error on `finish()` call')
}
t.end()
})
are-we-there-yet-3.0.1/test/lib/trackerstream.js 0000664 0000000 0000000 00000002724 14270325727 0021547 0 ustar 00root root 0000000 0000000 'use strict'
var test = require('tap').test
var util = require('util')
var stream = require('readable-stream')
var TrackerStream = require('../..').TrackerStream
var testEvent = require('./test-event.js')
var Sink = function () {
stream.Writable.apply(this, arguments)
}
util.inherits(Sink, stream.Writable)
Sink.prototype._write = function (data, encoding, cb) {
cb()
}
test('TrackerStream', function (t) {
t.plan(9)
var name = 'test'
var track = new TrackerStream(name)
t.equal(track.completed(), 0, 'Nothing todo is 0 completion')
var todo = 10
track = new TrackerStream(name, todo)
t.equal(track.completed(), 0, 'Nothing done is 0 completion')
track.pipe(new Sink())
testEvent(track, 'change', afterCompleteWork)
track.write('0123456789')
function afterCompleteWork (er, onChangeName) {
t.equal(er, null, 'write: on change event fired')
t.equal(onChangeName, name, 'write: on change emits the correct name')
t.equal(track.completed(), 1, 'write: 100% completed')
testEvent(track, 'change', afterAddWork)
track.addWork(10)
}
function afterAddWork (er, onChangeName) {
t.equal(er, null, 'addWork: on change event fired')
t.equal(track.completed(), 0.5, 'addWork: 50% completed')
testEvent(track, 'change', afterAllWork)
track.write('ABCDEFGHIJKLMNOPQRST')
}
function afterAllWork (er) {
t.equal(er, null, 'allWork: on change event fired')
t.equal(track.completed(), 1, 'allWork: 100% completed')
}
})