Skip to content

Commit bc4c342

Browse files
authored
fix: account for registries with no publisher in search (#7448)
Fixes: #7447
1 parent 1674136 commit bc4c342

File tree

3 files changed

+255
-181
lines changed

3 files changed

+255
-181
lines changed

lib/utils/format-search-stream.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TextOutputStream extends Minipass {
9595
// Normalize
9696
const pkg = {
9797
authors: data.maintainers.map((m) => `${strip(m.username)}`).join(' '),
98-
publisher: strip(data.publisher.username),
98+
publisher: strip(data.publisher?.username || ''),
9999
date: data.date ? data.date.toISOString().slice(0, 10) : 'prehistoric',
100100
description: strip(data.description ?? ''),
101101
keywords: [],
@@ -159,7 +159,11 @@ class TextOutputStream extends Minipass {
159159
} else {
160160
output = `${name}\n`
161161
}
162-
output += `Version ${this.#chalk.blue(pkg.version)} published ${this.#chalk.blue(pkg.date)} by ${this.#chalk.blue(pkg.publisher)}\n`
162+
if (pkg.publisher) {
163+
output += `Version ${this.#chalk.blue(pkg.version)} published ${this.#chalk.blue(pkg.date)} by ${this.#chalk.blue(pkg.publisher)}\n`
164+
} else {
165+
output += `Version ${this.#chalk.blue(pkg.version)} published ${this.#chalk.blue(pkg.date)} by ${this.#chalk.yellow('???')}\n`
166+
}
163167
output += `Maintainers: ${pkg.authors}\n`
164168
if (keywords) {
165169
output += `Keywords: ${keywords}\n`

tap-snapshots/test/lib/commands/search.js.test.cjs

+19-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
* Make sure to inspect the output below. Do not ignore changes!
66
*/
77
'use strict'
8-
exports[`test/lib/commands/search.js TAP empty search results > should have expected search results 1`] = `
9-
No matches found for "foo"
10-
`
11-
128
exports[`test/lib/commands/search.js TAP search /<name>/--color > should have expected search results with color 1`] = `
139
libnpm
1410
Collection of programmatic APIs for the npm CLI
@@ -189,6 +185,10 @@ foo
189185
Version 1.0.0 published prehistoric by foo
190186
Maintainers: foo
191187
https://npm.im/foo
188+
custom-registry
189+
Version 1.0.0 published prehistoric by ???
190+
Maintainers: foo
191+
https://npm.im/custom-registry
192192
libnpmversion
193193
Version 1.0.0 published prehistoric by foo
194194
Maintainers: foo
@@ -274,6 +274,10 @@ Maintainers: lukekarrys
274274
https://npm.im/pkg-no-desc
275275
`
276276

277+
exports[`test/lib/commands/search.js TAP search empty search results > should have expected search results 1`] = `
278+
No matches found for "foo"
279+
`
280+
277281
exports[`test/lib/commands/search.js TAP search exclude forward slash > results should not have libnpmversion 1`] = `
278282
libnpm
279283
Collection of programmatic APIs for the npm CLI
@@ -1009,3 +1013,14 @@ Version 1.0.0 published 2019-09-26 by lukekarrys
10091013
Maintainers: lukekarrys
10101014
https://npm.im/pkg-no-desc
10111015
`
1016+
1017+
exports[`test/lib/commands/search.js TAP search no publisher > should have filtered expected search results 1`] = `
1018+
custom-registry
1019+
Version 1.0.0 published prehistoric by ???
1020+
Maintainers: foo
1021+
https://npm.im/custom-registry
1022+
libnpmversion
1023+
Version 1.0.0 published prehistoric by foo
1024+
Maintainers: foo
1025+
https://npm.im/libnpmversion
1026+
`

0 commit comments

Comments
 (0)