Welcome to mirror list, hosted at ThFree Co, Russian Federation.

log-shim.js « utils « lib - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d5a36d967413f757f3a0891b0397c57faf1a6fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const NPMLOG = require('npmlog')
const PROCLOG = require('proc-log')

// Sets getter and optionally a setter
// otherwise setting should throw
const accessors = (obj, set) => (k) => ({
  get: () => obj[k],
  set: set ? (v) => (obj[k] = v) : () => {
    throw new Error(`Cant set ${k}`)
  },
})

// Set the value to a bound function on the object
const value = (obj) => (k) => ({
  value: (...args) => obj[k].apply(obj, args),
})

const properties = {
  // npmlog getters/setters
  level: accessors(NPMLOG, true),
  heading: accessors(NPMLOG, true),
  levels: accessors(NPMLOG),
  gauge: accessors(NPMLOG),
  stream: accessors(NPMLOG),
  tracker: accessors(NPMLOG),
  progressEnabled: accessors(NPMLOG),
  // npmlog methods
  useColor: value(NPMLOG),
  enableColor: value(NPMLOG),
  disableColor: value(NPMLOG),
  enableUnicode: value(NPMLOG),
  disableUnicode: value(NPMLOG),
  enableProgress: value(NPMLOG),
  disableProgress: value(NPMLOG),
  clearProgress: value(NPMLOG),
  showProgress: value(NPMLOG),
  newItem: value(NPMLOG),
  newGroup: value(NPMLOG),
  // proclog methods
  notice: value(PROCLOG),
  error: value(PROCLOG),
  warn: value(PROCLOG),
  info: value(PROCLOG),
  verbose: value(PROCLOG),
  http: value(PROCLOG),
  silly: value(PROCLOG),
  pause: value(PROCLOG),
  resume: value(PROCLOG),
}

const descriptors = Object.entries(properties).reduce((acc, [k, v]) => {
  acc[k] = { enumerable: true, ...v(k) }
  return acc
}, {})

// Create an object with the allowed properties rom npm log and all
// the logging methods from proc log
// XXX: this should go away and requires of this should be replaced with proc-log + new display
module.exports = Object.freeze(Object.defineProperties({}, descriptors))