Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: only call npmlog progress methods if explicitly requested #4644

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions workspaces/arborist/lib/tracker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const _progress = Symbol('_progress')
const _onError = Symbol('_onError')
const _setProgress = Symbol('_setProgess')
const npmlog = require('npmlog')

module.exports = cls => class Tracker extends cls {
constructor (options = {}) {
super(options)
this[_setProgress] = !!options.progress
this[_progress] = new Map()
}

Expand All @@ -27,7 +29,7 @@ module.exports = cls => class Tracker extends cls {
// 1. no existing tracker, no subsection
// Create a new tracker from npmlog
// starts progress bar
if (this[_progress].size === 0) {
if (this[_setProgress] && this[_progress].size === 0) {
npmlog.enableProgress()
}

Expand Down Expand Up @@ -76,7 +78,7 @@ module.exports = cls => class Tracker extends cls {

// remove progress bar if all
// trackers are finished
if (this[_progress].size === 0) {
if (this[_setProgress] && this[_progress].size === 0) {
npmlog.disableProgress()
}
} else if (!hasTracker && subsection === null) {
Expand All @@ -92,7 +94,9 @@ module.exports = cls => class Tracker extends cls {
}

[_onError] (msg) {
npmlog.disableProgress()
if (this[_setProgress]) {
npmlog.disableProgress()
}
throw new Error(msg)
}
}
8 changes: 6 additions & 2 deletions workspaces/arborist/test/tracker.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const Tracker = require('../lib/tracker.js')(class {})
const t = require('tap')

t.test('no npmlog', t => {
const tr = new Tracker()
t.test('with progress', t => {
const tr = new Tracker({ progress: true })
t.doesNotThrow(() => {
tr.addTracker('testTracker')
})
t.doesNotThrow(() => {
tr.finishTracker('testTracker')
})

t.throws(() => {
tr.addTracker()
}, Error, `Tracker can't be null or undefined`)

t.end()
})

Expand Down