Skip to content

Commit f9b639e

Browse files
Yash-Singh1wraithgar
authored andcommitted
feat(bugs): fall back to email if provided
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
1 parent 58914be commit f9b639e

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

docs/content/commands/npm-bugs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ aliases: issues
1515
### Description
1616
1717
This command tries to guess at the likely location of a package's bug
18-
tracker URL, and then tries to open it using the `--browser` config param.
19-
If no package name is provided, it will search for a `package.json` in the
20-
current folder and use the `name` property.
18+
tracker URL or the `mailto` URL of the support email, and then tries to
19+
open it using the `--browser` config param. If no package name is provided, it
20+
will search for a `package.json` in the current folder and use the `name` property.
2121
2222
### Configuration
2323

lib/bugs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Bugs extends BaseCommand {
4343

4444
if (typeof mani.bugs === 'object' && mani.bugs.url)
4545
return mani.bugs.url
46+
47+
if (typeof mani.bugs === 'object' && mani.bugs.email)
48+
return `mailto:${mani.bugs.email}`
4649
}
4750

4851
// try to get it from the repo, if possible

test/lib/bugs.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ const pacote = {
3131
version: '1.2.3',
3232
repository: { url: 'https://github.com/foo/repoobj' },
3333
}
34+
: spec === 'mailtest' ? {
35+
name: 'mailtest',
36+
version: '3.7.4',
37+
bugs: { email: '[email protected]' },
38+
}
39+
: spec === 'secondmailtest' ? {
40+
name: 'secondmailtest',
41+
version: '0.1.1',
42+
bugs: { email: '[email protected]' },
43+
}
3444
: spec === '.' ? {
3545
name: 'thispkg',
3646
version: '1.2.3',
@@ -59,14 +69,16 @@ t.test('usage', (t) => {
5969
t.end()
6070
})
6171

62-
t.test('open bugs urls', t => {
72+
t.test('open bugs urls & emails', t => {
6373
const expect = {
6474
nobugs: 'https://www.npmjs.com/package/nobugs',
6575
'bugsobj-nourl': 'https://www.npmjs.com/package/bugsobj-nourl',
6676
bugsurl: 'https://bugzilla.localhost/bugsurl',
6777
bugsobj: 'https://bugzilla.localhost/bugsobj',
6878
repourl: 'https://github.com/foo/repourl/issues',
6979
repoobj: 'https://github.com/foo/repoobj/issues',
80+
mailtest: 'mailto:[email protected]',
81+
secondmailtest: 'mailto:[email protected]',
7082
'.': 'https://example.com',
7183
}
7284
const keys = Object.keys(expect)

0 commit comments

Comments
 (0)