From fcf42c74288a673120bdf23bd7ad76110eb1ee32 Mon Sep 17 00:00:00 2001 From: Guan Tong Date: Sun, 2 Aug 2026 19:15:50 +0800 Subject: [PATCH] fix: respect custom viewer in npm help --- lib/commands/help.js | 2 +- test/lib/commands/help.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/commands/help.js b/lib/commands/help.js index d520dd1cceb45..1b7d0e9a4921d 100644 --- a/lib/commands/help.js +++ b/lib/commands/help.js @@ -87,7 +87,7 @@ class Help extends BaseCommand { return openUrl(this.npm, this.htmlMan(man), 'help available at the following URL', true) } - let args = ['man', [man]] + let args = [viewer, [man]] if (viewer === 'woman') { args = ['emacsclient', ['-e', `(woman-find-file '${man}')`]] } diff --git a/test/lib/commands/help.js b/test/lib/commands/help.js index 77d05d7b5048c..2461c5a90b469 100644 --- a/test/lib/commands/help.js +++ b/test/lib/commands/help.js @@ -111,6 +111,18 @@ t.test('npm help whoami', async t => { t.match(spawnArgs[0], /npm-whoami\.1$/) }) +t.test('npm help with custom viewer', async t => { + const { getArgs } = await mockHelp(t, { + exec: ['whoami'], + config: { viewer: 'batman' }, + }) + + const [spawnBin, spawnArgs] = getArgs() + t.equal(spawnBin, 'batman', 'calls the configured viewer') + t.equal(spawnArgs.length, 1) + t.match(spawnArgs[0], /npm-whoami\.1$/) +}) + t.test('npm help 1 install', async t => { const { getArgs } = await mockHelp(t, { exec: ['1', 'install'],