Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: account for registries with no publisher in search #7448

Merged
merged 1 commit into from
Apr 30, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
`