Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adding handling of compressed man pages #4595

Closed
wants to merge 1 commit into from

3 participants

@pshevtsov

Some Linux package managers compress man pages by default on package build. This change makes npm help to correctly handle compressed man pages.

@isaacs

I think this doesn't do what you think it does. compext is a string here, but ext.match() takes a regexp.

Create a regexp version as well. Should be something like var compextre = /^\.(gz|bz2|lzma|[FYzZ]|xz)$/

If Type(regexp) is Object and the value of the [[Class]] internal property of regexp is "RegExp", then let rx be regexp;
Else, let rx be a new RegExp object created as if by the expression new RegExp( regexp) where RegExp is the standard built-in constructor with that name.
http://es5.github.io/#x15.5.4.10

So, ext.match can take a string as parameter too, but you're right — it's better to create a regexp.

Owner

Oh, I see, yes. However, since compext is first a glob, and then treated as a regexp, it's only working by accident. It'd be better to be an anchored regexp instead (whether string or object).

@othiym23
Owner

Landed (finally! so sorry!) as 50f461d, with further tweaks in d3cb6e1 to incorporate some of @isaacs's suggestions.

@othiym23 othiym23 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 3, 2014
  1. @pshevtsov
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/help.js
View
11 lib/help.js
@@ -63,7 +63,8 @@ function help (args, cb) {
section = "package.json"
// find either /section.n or /npm-section.n
- var f = "+(npm-" + section + "|" + section + ").[0-9]"
+ var compext = "\.+(gz|bz2|lzma|[FYzZ]|xz)"
+ var f = "+(npm-" + section + "|" + section + ").[0-9]?(" + compext + ")"
return glob(manroot + "/*/" + f, function (er, mans) {
if (er)
return cb(er)
@@ -71,6 +72,14 @@ function help (args, cb) {
if (!mans.length)
return npm.commands["help-search"](args, cb)
+ mans = mans.map(function (man) {
+ var ext = path.extname(man)
+ if (ext.match(compext))
+ man = path.basename(man, ext)
+
+ return man
+ })
+
viewMan(pickMan(mans, pref), cb)
})
}
Something went wrong with that request. Please try again.