Skip to content

Commit

Permalink
fix: account for registries with no publisher in search (#7448)
Browse files Browse the repository at this point in the history
Fixes: #7447
  • Loading branch information
wraithgar authored Apr 30, 2024
1 parent 1674136 commit bc4c342
Show file tree
Hide file tree
Showing 3 changed files with 255 additions and 181 deletions.
8 changes: 6 additions & 2 deletions lib/utils/format-search-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TextOutputStream extends Minipass {
// Normalize
const pkg = {
authors: data.maintainers.map((m) => `${strip(m.username)}`).join(' '),
publisher: strip(data.publisher.username),
publisher: strip(data.publisher?.username || ''),
date: data.date ? data.date.toISOString().slice(0, 10) : 'prehistoric',
description: strip(data.description ?? ''),
keywords: [],
Expand Down Expand Up @@ -159,7 +159,11 @@ class TextOutputStream extends Minipass {
} else {
output = `${name}\n`
}
output += `Version ${this.#chalk.blue(pkg.version)} published ${this.#chalk.blue(pkg.date)} by ${this.#chalk.blue(pkg.publisher)}\n`
if (pkg.publisher) {
output += `Version ${this.#chalk.blue(pkg.version)} published ${this.#chalk.blue(pkg.date)} by ${this.#chalk.blue(pkg.publisher)}\n`
} else {
output += `Version ${this.#chalk.blue(pkg.version)} published ${this.#chalk.blue(pkg.date)} by ${this.#chalk.yellow('???')}\n`
}
output += `Maintainers: ${pkg.authors}\n`
if (keywords) {
output += `Keywords: ${keywords}\n`
Expand Down
23 changes: 19 additions & 4 deletions tap-snapshots/test/lib/commands/search.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/lib/commands/search.js TAP empty search results > should have expected search results 1`] = `
No matches found for "foo"
`

exports[`test/lib/commands/search.js TAP search /<name>/--color > should have expected search results with color 1`] = `
libnpm
Collection of programmatic APIs for the npm CLI
Expand Down Expand Up @@ -189,6 +185,10 @@ foo
Version 1.0.0 published prehistoric by foo
Maintainers: foo
https://npm.im/foo
custom-registry
Version 1.0.0 published prehistoric by ???
Maintainers: foo
https://npm.im/custom-registry
libnpmversion
Version 1.0.0 published prehistoric by foo
Maintainers: foo
Expand Down Expand Up @@ -274,6 +274,10 @@ Maintainers: lukekarrys
https://npm.im/pkg-no-desc
`

exports[`test/lib/commands/search.js TAP search empty search results > should have expected search results 1`] = `
No matches found for "foo"
`

exports[`test/lib/commands/search.js TAP search exclude forward slash > results should not have libnpmversion 1`] = `
libnpm
Collection of programmatic APIs for the npm CLI
Expand Down Expand Up @@ -1009,3 +1013,14 @@ Version 1.0.0 published 2019-09-26 by lukekarrys
Maintainers: lukekarrys
https://npm.im/pkg-no-desc
`

exports[`test/lib/commands/search.js TAP search no publisher > should have filtered expected search results 1`] = `
custom-registry
Version 1.0.0 published prehistoric by ???
Maintainers: foo
https://npm.im/custom-registry
libnpmversion
Version 1.0.0 published prehistoric by foo
Maintainers: foo
https://npm.im/libnpmversion
`
Loading

0 comments on commit bc4c342

Please sign in to comment.