Skip to content

Commit 668ec7f

Browse files
authored
fix: only call npmlog progress methods if explicitly requested (#4644)
Fixes #3314
1 parent ff1367f commit 668ec7f

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

workspaces/arborist/lib/tracker.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const _progress = Symbol('_progress')
22
const _onError = Symbol('_onError')
3+
const _setProgress = Symbol('_setProgess')
34
const npmlog = require('npmlog')
45

56
module.exports = cls => class Tracker extends cls {
67
constructor (options = {}) {
78
super(options)
9+
this[_setProgress] = !!options.progress
810
this[_progress] = new Map()
911
}
1012

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

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

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

9496
[_onError] (msg) {
95-
npmlog.disableProgress()
97+
if (this[_setProgress]) {
98+
npmlog.disableProgress()
99+
}
96100
throw new Error(msg)
97101
}
98102
}

workspaces/arborist/test/tracker.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
const Tracker = require('../lib/tracker.js')(class {})
22
const t = require('tap')
33

4-
t.test('no npmlog', t => {
5-
const tr = new Tracker()
4+
t.test('with progress', t => {
5+
const tr = new Tracker({ progress: true })
66
t.doesNotThrow(() => {
77
tr.addTracker('testTracker')
88
})
99
t.doesNotThrow(() => {
1010
tr.finishTracker('testTracker')
1111
})
1212

13+
t.throws(() => {
14+
tr.addTracker()
15+
}, Error, `Tracker can't be null or undefined`)
16+
1317
t.end()
1418
})
1519

0 commit comments

Comments
 (0)