Skip to content

Commit

Permalink
fix: prevent duplicate consola instances when different versions used…
Browse files Browse the repository at this point in the history
… by packages
  • Loading branch information
Pooya Parsa committed Apr 15, 2018
1 parent 76197c4 commit 0bce262
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ import env from 'std-env'
import Consola from './consola'
import Reporters from './reporters'

const _consola = new Consola({
level: env.debug ? 4 : 3
})
// Attach consola to the global to prevent
// duplicated instances when used with different packages/versions

if (env.minimalCLI) {
_consola.add(new Reporters.BasicReporter())
} else {
_consola.add(new Reporters.FancyReporter())
}
let consola = global && global.consola

if (!consola) {
consola = new Consola({
level: env.debug ? 4 : 3
})

Object.assign(_consola, { Consola }, Reporters)
if (env.minimalCLI) {
consola.add(new Reporters.BasicReporter())
} else {
consola.add(new Reporters.FancyReporter())
}

Object.assign(consola, { Consola }, Reporters)
}

export default _consola
export default consola

0 comments on commit 0bce262

Please sign in to comment.