Skip to content

Commit

Permalink
fix: allow searching packages with no description
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Aug 18, 2023
1 parent fb956b5 commit f916d33
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/format-search-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function highlightSearchTerms (str, terms) {
function normalizePackage (data, opts) {
return {
name: ansiTrim(data.name),
description: ansiTrim(data.description),
description: ansiTrim(data.description ?? ''),
author: data.maintainers.map((m) => `=${ansiTrim(m.username)}`).join(' '),
keywords: Array.isArray(data.keywords)
? data.keywords.map(ansiTrim).join(' ')
Expand Down
8 changes: 8 additions & 0 deletions tap-snapshots/test/lib/commands/search.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ NAME | DESCRIPTION | AUTHOR | DATE
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
libnpmversion | library to do the… | =nlf… | 2020-11-04 | 1.0.7 |
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
`

exports[`test/lib/commands/search.js TAP search <name> --color > should have expected search results with color 1`] = `
Expand All @@ -41,6 +42,7 @@ NAME | DESCRIPTION | AUTHOR | DATE
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
libnpmversion | library to do the… | =nlf… | 2020-11-04 | 1.0.7 | 
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 | 
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 | 
`

exports[`test/lib/commands/search.js TAP search <name> --parseable > should have expected search results as parseable 1`] = `
Expand All @@ -57,6 +59,7 @@ libnpmfund Programmatic API for npm fund =nlf =ruyadorno =darcyclarke =isaacs 20
@npmcli/map-workspaces Retrieves a name:pathname Map for a given workspaces config =nlf =ruyadorno =darcyclarke =isaacs 2020-09-30 1.0.1 npm npmcli libnpm cli workspaces map-workspaces
libnpmversion library to do the things that 'npm version' does =nlf =ruyadorno =darcyclarke =isaacs 2020-11-04 1.0.7
@types/libnpmsearch TypeScript definitions for libnpmsearch =types 2019-09-26 2.0.1
pkg-no-desc =lukekarrys 2019-09-26 1.0.0
`

exports[`test/lib/commands/search.js TAP search <name> > should have filtered expected search results 1`] = `
Expand All @@ -80,6 +83,7 @@ libnpmfund | Programmatic API… | =nlf… | 2020-12
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
libnpmversion | library to do the… | =nlf… | 2020-11-04 | 1.0.7 |
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
`

exports[`test/lib/commands/search.js TAP search exclude forward slash > results should not have libnpmversion 1`] = `
Expand All @@ -96,6 +100,7 @@ libnpmpublish | Programmatic API… | =nlf… | 2020-11
libnpmfund | Programmatic API… | =nlf… | 2020-12-08 | 1.0.2 | npm npmcli libnpm cli git fund gitfund
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
`

exports[`test/lib/commands/search.js TAP search exclude regex > results should not have libnpmversion 1`] = `
Expand All @@ -112,6 +117,7 @@ libnpmpublish | Programmatic API… | =nlf… | 2020-11
libnpmfund | Programmatic API… | =nlf… | 2020-12-08 | 1.0.2 | npm npmcli libnpm cli git fund gitfund
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
`

exports[`test/lib/commands/search.js TAP search exclude string > results should not have libnpmversion 1`] = `
Expand All @@ -128,11 +134,13 @@ libnpmpublish | Programmatic API… | =nlf… | 2020-11
libnpmfund | Programmatic API… | =nlf… | 2020-12-08 | 1.0.2 | npm npmcli libnpm cli git fund gitfund
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
`

exports[`test/lib/commands/search.js TAP search exclude username with upper case letters > results should not have nlf 1`] = `
NAME | DESCRIPTION | AUTHOR | DATE | VERSION | KEYWORDS
@evocateur/libnpmaccess | programmatic… | =evocateur | 2019-07-16 | 3.1.2 |
@evocateur/libnpmpublish | Programmatic API… | =evocateur | 2019-07-16 | 1.2.2 |
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
`
7 changes: 7 additions & 0 deletions test/fixtures/libnpmsearch-stream-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,11 @@ module.exports = [
publisher: { username: 'types', email: 'ts-npm-types@microsoft.com' },
maintainers: [{ username: 'types', email: 'ts-npm-types@microsoft.com' }],
},
{
name: 'pkg-no-desc',
scope: 'unscoped',
version: '1.0.0',
date: '2019-09-26T22:24:28.713Z',
maintainers: [{ username: 'lukekarrys', email: 'lukekarrys' }],
},
]

0 comments on commit f916d33

Please sign in to comment.