Skip to content

Commit

Permalink
feat(bugs): fall back to email if provided
Browse files Browse the repository at this point in the history
If a bugs url is not provided, but a `mailto` is, then that is used.

PR-URL: #3052
Credit: @Yash-Singh1
Close: #3052
Reviewed-by: @wraithgar
  • Loading branch information
Yash-Singh1 authored and wraithgar committed Apr 14, 2021
1 parent 58914be commit f9b639e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/content/commands/npm-bugs.md
Expand Up @@ -15,9 +15,9 @@ aliases: issues
### Description
This command tries to guess at the likely location of a package's bug
tracker URL, and then tries to open it using the `--browser` config param.
If no package name is provided, it will search for a `package.json` in the
current folder and use the `name` property.
tracker URL or the `mailto` URL of the support email, and then tries to
open it using the `--browser` config param. If no package name is provided, it
will search for a `package.json` in the current folder and use the `name` property.
### Configuration
Expand Down
3 changes: 3 additions & 0 deletions lib/bugs.js
Expand Up @@ -43,6 +43,9 @@ class Bugs extends BaseCommand {

if (typeof mani.bugs === 'object' && mani.bugs.url)
return mani.bugs.url

if (typeof mani.bugs === 'object' && mani.bugs.email)
return `mailto:${mani.bugs.email}`
}

// try to get it from the repo, if possible
Expand Down
14 changes: 13 additions & 1 deletion test/lib/bugs.js
Expand Up @@ -31,6 +31,16 @@ const pacote = {
version: '1.2.3',
repository: { url: 'https://github.com/foo/repoobj' },
}
: spec === 'mailtest' ? {
name: 'mailtest',
version: '3.7.4',
bugs: { email: 'hello@example.com' },
}
: spec === 'secondmailtest' ? {
name: 'secondmailtest',
version: '0.1.1',
bugs: { email: 'ABC432abc@a.b.example.net' },
}
: spec === '.' ? {
name: 'thispkg',
version: '1.2.3',
Expand Down Expand Up @@ -59,14 +69,16 @@ t.test('usage', (t) => {
t.end()
})

t.test('open bugs urls', t => {
t.test('open bugs urls & emails', t => {
const expect = {
nobugs: 'https://www.npmjs.com/package/nobugs',
'bugsobj-nourl': 'https://www.npmjs.com/package/bugsobj-nourl',
bugsurl: 'https://bugzilla.localhost/bugsurl',
bugsobj: 'https://bugzilla.localhost/bugsobj',
repourl: 'https://github.com/foo/repourl/issues',
repoobj: 'https://github.com/foo/repoobj/issues',
mailtest: 'mailto:hello@example.com',
secondmailtest: 'mailto:ABC432abc@a.b.example.net',
'.': 'https://example.com',
}
const keys = Object.keys(expect)
Expand Down

0 comments on commit f9b639e

Please sign in to comment.