Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

fix(refactor): update deps, lint, test coverage #79

Merged
merged 1 commit into from Jul 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,44 @@
name: CI

on: [push, pull_request]

jobs:
build:
strategy:
matrix:
node-version: [10.0.x, 10.x, 12.0.x, 12.x, 14.0.x, 14.x, 15.x, 16.x]
platform:
- os: ubuntu-latest
shell: bash
- os: macos-latest
shell: bash
- os: windows-latest
shell: bash
- os: windows-latest
shell: powershell

runs-on: ${{ matrix.platform.os }}
defaults:
run:
shell: ${{ matrix.platform.shell }}

steps:
- name: Checkout Repository
uses: actions/checkout@v1.1.0

- name: Use Nodejs ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Update npm
run: npm i -g npm@latest

- name: Install dependencies
run: npm ci

- name: Run Tap Tests
run: npm test

- name: List dependencies
run: npm ls -a
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
node_modules
npm-debug.log
npm-debug.log
.nyc_output
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

156 changes: 109 additions & 47 deletions log.js
Expand Up @@ -13,11 +13,12 @@ var stream = process.stderr
Object.defineProperty(log, 'stream', {
set: function (newStream) {
stream = newStream
if (this.gauge) this.gauge.setWriteTo(stream, stream)
if (this.gauge)
this.gauge.setWriteTo(stream, stream)
},
get: function () {
return stream
}
},
})

// by default, decide based on tty-ness.
Expand Down Expand Up @@ -46,8 +47,8 @@ log.gauge = new Gauge(stream, {
{type: 'activityIndicator', kerning: 1, length: 1},
{type: 'section', default: ''},
':',
{type: 'logline', kerning: 1, default: ''}
]
{type: 'logline', kerning: 1, default: ''},
],
})

log.tracker = new Progress.TrackerGroup()
Expand Down Expand Up @@ -77,15 +78,20 @@ log.setGaugeTemplate = function (template) {
}

log.enableProgress = function () {
if (this.progressEnabled) return
if (this.progressEnabled)
return

this.progressEnabled = true
this.tracker.on('change', this.showProgress)
if (this._pause) return
if (this._paused)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the bugfix. It's this._paused not this._pause

return

this.gauge.enable()
}

log.disableProgress = function () {
if (!this.progressEnabled) return
if (!this.progressEnabled)
return
this.progressEnabled = false
this.tracker.removeListener('change', this.showProgress)
this.gauge.disable()
Expand All @@ -97,10 +103,20 @@ var mixinLog = function (tracker) {
// mixin the public methods from log into the tracker
// (except: conflicts and one's we handle specially)
Object.keys(log).forEach(function (P) {
if (P[0] === '_') return
if (trackerConstructors.filter(function (C) { return C === P }).length) return
if (tracker[P]) return
if (typeof log[P] !== 'function') return
if (P[0] === '_')
return

if (trackerConstructors.filter(function (C) {
return C === P
}).length)
return

if (tracker[P])
return

if (typeof log[P] !== 'function')
return

var func = log[P]
tracker[P] = function () {
return func.apply(log, arguments)
Expand All @@ -111,32 +127,44 @@ var mixinLog = function (tracker) {
if (tracker instanceof Progress.TrackerGroup) {
trackerConstructors.forEach(function (C) {
var func = tracker[C]
tracker[C] = function () { return mixinLog(func.apply(tracker, arguments)) }
tracker[C] = function () {
return mixinLog(func.apply(tracker, arguments))
}
})
}
return tracker
}

// Add tracker constructors to the top level log object
trackerConstructors.forEach(function (C) {
log[C] = function () { return mixinLog(this.tracker[C].apply(this.tracker, arguments)) }
log[C] = function () {
return mixinLog(this.tracker[C].apply(this.tracker, arguments))
}
})

log.clearProgress = function (cb) {
if (!this.progressEnabled) return cb && process.nextTick(cb)
if (!this.progressEnabled)
return cb && process.nextTick(cb)

this.gauge.hide(cb)
}

log.showProgress = function (name, completed) {
if (!this.progressEnabled) return
if (!this.progressEnabled)
return

var values = {}
if (name) values.section = name
if (name)
values.section = name

var last = log.record[log.record.length - 1]
if (last) {
values.subsection = last.prefix
var disp = log.disp[last.level] || last.level
var logline = this._format(disp, log.style[last.level])
if (last.prefix) logline += ' ' + this._format(last.prefix, this.prefixStyle)
if (last.prefix)
logline += ' ' + this._format(last.prefix, this.prefixStyle)

logline += ' ' + last.message.split(/\r?\n/)[0]
values.logline = logline
}
Expand All @@ -147,19 +175,23 @@ log.showProgress = function (name, completed) {
// temporarily stop emitting, but don't drop
log.pause = function () {
this._paused = true
if (this.progressEnabled) this.gauge.disable()
if (this.progressEnabled)
this.gauge.disable()
}

log.resume = function () {
if (!this._paused) return
if (!this._paused)
return

this._paused = false

var b = this._buffer
this._buffer = []
b.forEach(function (m) {
this.emitLog(m)
}, this)
if (this.progressEnabled) this.gauge.enable()
if (this.progressEnabled)
this.gauge.enable()
}

log._buffer = []
Expand All @@ -184,22 +216,26 @@ log.log = function (lvl, prefix, message) {
Object.defineProperty(arg, 'stack', {
value: stack = arg.stack + '',
enumerable: true,
writable: true
writable: true,
})
}
}
if (stack) a.unshift(stack + '\n')
if (stack)
a.unshift(stack + '\n')
message = util.format.apply(util, a)

var m = { id: id++,
level: lvl,
prefix: String(prefix || ''),
message: message,
messageRaw: a }
var m = {
id: id++,
level: lvl,
prefix: String(prefix || ''),
message: message,
messageRaw: a,
}

this.emit('log', m)
this.emit('log.' + lvl, m)
if (m.prefix) this.emit(m.prefix, m)
if (m.prefix)
this.emit(m.prefix, m)

this.record.push(m)
var mrs = this.maxRecordSize
Expand All @@ -217,11 +253,18 @@ log.emitLog = function (m) {
this._buffer.push(m)
return
}
if (this.progressEnabled) this.gauge.pulse(m.prefix)
if (this.progressEnabled)
this.gauge.pulse(m.prefix)

var l = this.levels[m.level]
if (l === undefined) return
if (l < this.levels[this.level]) return
if (l > 0 && !isFinite(l)) return
if (l === undefined)
return

if (l < this.levels[this.level])
return

if (l > 0 && !isFinite(l))
return

// If 'disp' is null or undefined, use the lvl as a default
// Allows: '', 0 as valid disp
Expand All @@ -234,53 +277,72 @@ log.emitLog = function (m) {
}
this.write(disp, log.style[m.level])
var p = m.prefix || ''
if (p) this.write(' ')
if (p)
this.write(' ')

this.write(p, this.prefixStyle)
this.write(' ' + line + '\n')
}, this)
this.showProgress()
}

log._format = function (msg, style) {
if (!stream) return
if (!stream)
return

var output = ''
if (this.useColor()) {
style = style || {}
var settings = []
if (style.fg) settings.push(style.fg)
if (style.bg) settings.push('bg' + style.bg[0].toUpperCase() + style.bg.slice(1))
if (style.bold) settings.push('bold')
if (style.underline) settings.push('underline')
if (style.inverse) settings.push('inverse')
if (settings.length) output += consoleControl.color(settings)
if (style.beep) output += consoleControl.beep()
if (style.fg)
settings.push(style.fg)

if (style.bg)
settings.push('bg' + style.bg[0].toUpperCase() + style.bg.slice(1))

if (style.bold)
settings.push('bold')

if (style.underline)
settings.push('underline')

if (style.inverse)
settings.push('inverse')

if (settings.length)
output += consoleControl.color(settings)

if (style.beep)
output += consoleControl.beep()
}
output += msg
if (this.useColor()) {
if (this.useColor())
output += consoleControl.color('reset')
}

return output
}

log.write = function (msg, style) {
if (!stream) return
if (!stream)
return

stream.write(this._format(msg, style))
}

log.addLevel = function (lvl, n, style, disp) {
// If 'disp' is null or undefined, use the lvl as a default
if (disp == null) disp = lvl
if (disp == null)
disp = lvl

this.levels[lvl] = n
this.style[lvl] = style
if (!this[lvl]) {
this[lvl] = function () {
var a = new Array(arguments.length + 1)
a[0] = lvl
for (var i = 0; i < arguments.length; i++) {
for (var i = 0; i < arguments.length; i++)
a[i + 1] = arguments[i]
}

return this.log.apply(this, a)
}.bind(this)
}
Expand Down