Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/utils/format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// All logging goes through here, both to console and log files

const { formatWithOptions: baseFormatWithOptions } = require('node:util')
const { redactLog } = require('@npmcli/redact')

// These are most assuredly not a mistake
// https://eslint.org/docs/latest/rules/no-control-regex
Expand Down Expand Up @@ -40,7 +43,7 @@ function STRIP_C01 (str) {

const formatWithOptions = ({ prefix: prefixes = [], eol = '\n', ...options }, ...args) => {
const prefix = prefixes.filter(p => p != null).join(' ')
const formatted = STRIP_C01(baseFormatWithOptions(options, ...args))
const formatted = redactLog(STRIP_C01(baseFormatWithOptions(options, ...args)))
// Splitting could be changed to only `\n` once we are sure we only emit unix newlines.
// The eol param to this function will put the correct newlines in place for the returned string.
const lines = formatted.split(/\r?\n/)
Expand Down
2 changes: 2 additions & 0 deletions test/lib/utils/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ t.test('can log cleanly', async (t) => {
const { log, logs } = await mockDisplay(t)

log.error('', 'test\x00message')
log.info('', 'fetch DELETE 200 https://registry.npmjs.org/-/user/token/npm_000000000000000000000000000000000000 477ms')
t.match(logs.error, ['test^@message'])
t.match(logs.info, ['fetch DELETE 200 https://registry.npmjs.org/-/user/token/npm_*** 477ms'])
})

t.test('can handle special eresolves', async (t) => {
Expand Down
Loading