Skip to content

Commit 0b1d7c3

Browse files
fix: allow searching packages with no description (#6779)
Co-authored-by: Luke Karrys <luke@lukekarrys.com>
1 parent 66ef765 commit 0b1d7c3

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/utils/format-search-stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function highlightSearchTerms (str, terms) {
143143
function normalizePackage (data, opts) {
144144
return {
145145
name: ansiTrim(data.name),
146-
description: ansiTrim(data.description),
146+
description: ansiTrim(data.description ?? ''),
147147
author: data.maintainers.map((m) => `=${ansiTrim(m.username)}`).join(' '),
148148
keywords: Array.isArray(data.keywords)
149149
? data.keywords.map(ansiTrim).join(' ')

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

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ NAME | DESCRIPTION | AUTHOR | DATE
2424
@npmcli/map-workspaces | Retrieves a… | =nlf… | 2020-09-30 | 1.0.1 | npm npmcli libnpm cli workspaces map-workspaces
2525
libnpmversion | library to do the… | =nlf… | 2020-11-04 | 1.0.7 |
2626
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
27+
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
2728
`
2829

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

4648
exports[`test/lib/commands/search.js TAP search <name> --parseable > should have expected search results as parseable 1`] = `
@@ -57,6 +59,7 @@ libnpmfund Programmatic API for npm fund =nlf =ruyadorno =darcyclarke =isaacs 20
5759
@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
5860
libnpmversion library to do the things that 'npm version' does =nlf =ruyadorno =darcyclarke =isaacs 2020-11-04 1.0.7
5961
@types/libnpmsearch TypeScript definitions for libnpmsearch =types 2019-09-26 2.0.1
62+
pkg-no-desc =lukekarrys 2019-09-26 1.0.0
6063
`
6164

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

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

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

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

133140
exports[`test/lib/commands/search.js TAP search exclude username with upper case letters > results should not have nlf 1`] = `
134141
NAME | DESCRIPTION | AUTHOR | DATE | VERSION | KEYWORDS
135142
@evocateur/libnpmaccess | programmatic… | =evocateur | 2019-07-16 | 3.1.2 |
136143
@evocateur/libnpmpublish | Programmatic API… | =evocateur | 2019-07-16 | 1.2.2 |
137144
@types/libnpmsearch | TypeScript… | =types | 2019-09-26 | 2.0.1 |
145+
pkg-no-desc | | =lukekarrys | 2019-09-26 | 1.0.0 |
138146
`

test/fixtures/libnpmsearch-stream-result.js

+7
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,11 @@ module.exports = [
275275
publisher: { username: 'types', email: 'ts-npm-types@microsoft.com' },
276276
maintainers: [{ username: 'types', email: 'ts-npm-types@microsoft.com' }],
277277
},
278+
{
279+
name: 'pkg-no-desc',
280+
scope: 'unscoped',
281+
version: '1.0.0',
282+
date: '2019-09-26T22:24:28.713Z',
283+
maintainers: [{ username: 'lukekarrys', email: 'lukekarrys' }],
284+
},
278285
]

0 commit comments

Comments
 (0)