Skip to content

Commit 0708b3b

Browse files
authoredApr 24, 2024··
fix: use name of level instead of label for logging prefixes (#7414)
1 parent 7f4e667 commit 0708b3b

File tree

3 files changed

+30
-40
lines changed

3 files changed

+30
-40
lines changed
 

‎lib/utils/display.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ const LEVEL_OPTIONS = {
3838
},
3939
error: {
4040
index: 1,
41-
label: 'ERR!',
4241
},
4342
warn: {
4443
index: 2,
45-
label: 'WARN',
4644
},
4745
notice: {
4846
index: 3,
@@ -55,11 +53,9 @@ const LEVEL_OPTIONS = {
5553
},
5654
verbose: {
5755
index: 6,
58-
label: 'verb',
5956
},
6057
silly: {
6158
index: 7,
62-
label: 'sill',
6359
},
6460
}
6561

@@ -338,7 +334,7 @@ class Display {
338334
const title = args.shift()
339335
const prefix = [
340336
this.#logColors.heading(this.#heading),
341-
this.#logColors[level](levelOpts.label ?? level),
337+
this.#logColors[level](level),
342338
title ? this.#logColors.title(title) : null,
343339
]
344340
this.#stderrWrite({ prefix }, ...args)

‎smoke-tests/tap-snapshots/test/index.js.test.cjs

+25-25
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,31 @@ npm {NPM}
4343
`
4444

4545
exports[`test/index.js TAP basic npm ci > should throw mismatch deps in lock file error 1`] = `
46-
npm ERR! code EUSAGE
47-
npm ERR!
48-
npm ERR! \`npm ci\` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with \`npm install\` before continuing.
49-
npm ERR!
50-
npm ERR! Invalid: lock file's abbrev@1.0.4 does not satisfy abbrev@1.1.1
51-
npm ERR!
52-
npm ERR! Clean install a project
53-
npm ERR!
54-
npm ERR! Usage:
55-
npm ERR! npm ci
56-
npm ERR!
57-
npm ERR! Options:
58-
npm ERR! [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
59-
npm ERR! [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
60-
npm ERR! [--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
61-
npm ERR! [--strict-peer-deps] [--foreground-scripts] [--ignore-scripts] [--no-audit]
62-
npm ERR! [--no-bin-links] [--no-fund] [--dry-run]
63-
npm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
64-
npm ERR! [-ws|--workspaces] [--include-workspace-root] [--install-links]
65-
npm ERR!
66-
npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
67-
npm ERR!
68-
npm ERR! Run "npm help ci" for more info
69-
70-
npm ERR! A complete log of this run can be found in: {NPM}/{TESTDIR}/cache/_logs/{LOG}
46+
npm error code EUSAGE
47+
npm error
48+
npm error \`npm ci\` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with \`npm install\` before continuing.
49+
npm error
50+
npm error Invalid: lock file's abbrev@1.0.4 does not satisfy abbrev@1.1.1
51+
npm error
52+
npm error Clean install a project
53+
npm error
54+
npm error Usage:
55+
npm error npm ci
56+
npm error
57+
npm error Options:
58+
npm error [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]
59+
npm error [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
60+
npm error [--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]]
61+
npm error [--strict-peer-deps] [--foreground-scripts] [--ignore-scripts] [--no-audit]
62+
npm error [--no-bin-links] [--no-fund] [--dry-run]
63+
npm error [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
64+
npm error [-ws|--workspaces] [--include-workspace-root] [--install-links]
65+
npm error
66+
npm error aliases: clean-install, ic, install-clean, isntall-clean
67+
npm error
68+
npm error Run "npm help ci" for more info
69+
70+
npm error A complete log of this run can be found in: {NPM}/{TESTDIR}/cache/_logs/{LOG}
7171
`
7272

7373
exports[`test/index.js TAP basic npm diff > should have expected diff output 1`] = `

‎test/fixtures/mock-logs.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
const { log: { LEVELS } } = require('proc-log')
22
const { stripVTControlCharacters: stripAnsi } = require('util')
33

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`)
115
const isLog = (str) => logPrefix.test(stripAnsi(str))
126

137
// We only strip trailing newlines since some output will
@@ -63,15 +57,15 @@ module.exports = () => {
6357
// Split on spaces for the heading and level/label. We know that
6458
// none of those have spaces but could be colorized so there's no
6559
// 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} `
6862
// If message is colorized we can just replaceAll with the string since
6963
// it will be unique due to control chars. Otherwise we create a regex
7064
// that will only match the beginning of each line.
7165
const prefix = stripAnsi(str) !== str ? rawPrefix : new RegExp(`^${rawPrefix}`, 'gm')
7266

7367
// 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)
7569

7670
logs.push(str.replaceAll(prefix, `${level} `))
7771
levelLogs.push({ level, message: str.replaceAll(prefix, '') })

0 commit comments

Comments
 (0)
Please sign in to comment.