|
1 | 1 | const { log: { LEVELS } } = require('proc-log') |
2 | 2 | const { stripVTControlCharacters: stripAnsi } = require('util') |
3 | 3 |
|
4 | | -const labels = new Map([ |
5 | | - ['error', 'ERR!'], |
6 | | - ['warn', 'WARN'], |
7 | | - ['verbose', 'verb'], |
8 | | - ['silly', 'sill'], |
9 | | -].reduce((acc, v) => acc.concat([v, v.slice(0).reverse()]), [])) |
10 | | -const logPrefix = new RegExp(`^npm (${LEVELS.map(l => labels.get(l) ?? l).join('|')})\\s`) |
| 4 | +const logPrefix = new RegExp(`^npm (${LEVELS.join('|')})\\s`) |
11 | 5 | const isLog = (str) => logPrefix.test(stripAnsi(str)) |
12 | 6 |
|
13 | 7 | // We only strip trailing newlines since some output will |
@@ -63,15 +57,15 @@ module.exports = () => { |
63 | 57 | // Split on spaces for the heading and level/label. We know that |
64 | 58 | // none of those have spaces but could be colorized so there's no |
65 | 59 | // other good way to get each of those including control chars |
66 | | - const [rawHeading, rawLabel] = str.split(' ') |
67 | | - const rawPrefix = `${rawHeading} ${rawLabel} ` |
| 60 | + const [rawHeading, rawLevel] = str.split(' ') |
| 61 | + const rawPrefix = `${rawHeading} ${rawLevel} ` |
68 | 62 | // If message is colorized we can just replaceAll with the string since |
69 | 63 | // it will be unique due to control chars. Otherwise we create a regex |
70 | 64 | // that will only match the beginning of each line. |
71 | 65 | const prefix = stripAnsi(str) !== str ? rawPrefix : new RegExp(`^${rawPrefix}`, 'gm') |
72 | 66 |
|
73 | 67 | // The level needs color stripped always because we use it to filter logs |
74 | | - const level = labels.get(stripAnsi(rawLabel)) ?? stripAnsi(rawLabel) |
| 68 | + const level = stripAnsi(rawLevel) |
75 | 69 |
|
76 | 70 | logs.push(str.replaceAll(prefix, `${level} `)) |
77 | 71 | levelLogs.push({ level, message: str.replaceAll(prefix, '') }) |
|
0 commit comments