diff --git a/lib/commands/help.js b/lib/commands/help.js index 40f5ad9b30092..c390f1a5bb2dd 100644 --- a/lib/commands/help.js +++ b/lib/commands/help.js @@ -61,9 +61,10 @@ class Help extends BaseCommand { const f = `${manroot}/${manSearch}/?(npm-)${section}.[0-9]*` let mans = await glob(f) mans = mans.sort((a, b) => { - // Because of the glob we know the manNumberRegex will pass - const aManNumber = a.match(manNumberRegex)[1] - const bManNumber = b.match(manNumberRegex)[1] + // Because the glob is (subtly) different from manNumberRegex, + // we can't rely on it passing. + const aManNumber = (a.match(manNumberRegex) || Infinity)[1] + const bManNumber = (b.match(manNumberRegex) || Infinity)[1] // man number sort first so that 1 aka commands are preferred if (aManNumber !== bManNumber) {