From f9b639eb6c504ded6cdd59e83e26a392bfe81e5d Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Thu, 8 Apr 2021 10:56:34 -0700 Subject: [PATCH] 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: https://github.com/npm/cli/pull/3052 Credit: @Yash-Singh1 Close: #3052 Reviewed-by: @wraithgar --- docs/content/commands/npm-bugs.md | 6 +++--- lib/bugs.js | 3 +++ test/lib/bugs.js | 14 +++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/content/commands/npm-bugs.md b/docs/content/commands/npm-bugs.md index dd1ab299f9c55..714db4440cdf2 100644 --- a/docs/content/commands/npm-bugs.md +++ b/docs/content/commands/npm-bugs.md @@ -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 diff --git a/lib/bugs.js b/lib/bugs.js index a0cef4c5ec4fa..5085a25b4a64a 100644 --- a/lib/bugs.js +++ b/lib/bugs.js @@ -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 diff --git a/test/lib/bugs.js b/test/lib/bugs.js index 1cc6e06eee650..e5b238ffcea13 100644 --- a/test/lib/bugs.js +++ b/test/lib/bugs.js @@ -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', @@ -59,7 +69,7 @@ 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', @@ -67,6 +77,8 @@ t.test('open bugs urls', t => { 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)